爪哇一角

          共同探討STRUTS#HIBERNATE#SPRING#EJB等技術(shù)
          posts - 3, comments - 6, trackbacks - 0, articles - 99
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          ORACLE----觸發(fā)器,存儲過程及JOB

          Posted on 2006-09-20 16:14 非洲小白臉 閱讀(375) 評論(0)  編輯  收藏 所屬分類: oracle

          ORACLE----觸發(fā)器,存儲過程及JOB

          一、ORACLE中創(chuàng)建自增的ID字段
          1、創(chuàng)建序列
          ?create *sequence_name* ?increment by 1 start with 1 maxvalue 999999999;
          2、創(chuàng)建觸發(fā)器---(創(chuàng)建一個基于該表的before insert 觸發(fā)器,在觸發(fā)器中使用該SEQUENCE)
          create or replace trigger *triger_name*
          before insert on???????*table_name*
          referencing old as old new as new for each row
          begin
          select? *sequence_name.nextval into :new.id from dual;
          end;
          例:
          ??????create sequence FP_FP_SEQ
          ??????minvalue 1
          ??????maxvalue 999999999999999999999999999
          ??????start with 49231
          ??????increment by 1
          ??????cache 10;

          ??????create or replace trigger FP_FP_tig before insert on FP_FP for each row
          ??????begin
          ???????select FP_FP_seq.nextval into :new.id from dual;
          ??????end;
          /
          二、ORACLE中JOB的應(yīng)用
          1、創(chuàng)建存儲過程
          create or replace procedure??? *pro_name
          as
          begin
          ?insert into agri_exhibition_basecur (messid,title,type,pub_date)?? select id,title,sort,pub_date from agri_message? where??? (trunc(sysdate-pub_date)=0 and rownum<6) and sort='供' ;
          ?insert into agri_exhibition_basecur (messid,title,type,pub_date)?? select id,title,sort,pub_date from agri_message? where??? (trunc(sysdate-pub_date)=0 and rownum<6) and sort='求' ;
          end;
          /
          2、創(chuàng)建JOB
          variable jobdxm number;
          begin
          dbms_job.submit(:jobdxm,'exhi_pro_dxm;',sysdate,'trunc(sysdate,''dd'')+32.5/24');
          end;
          三、收集的一個簡單的JOB實列
          1、創(chuàng)建測試表
          SQL> create table a(a date);

          表已創(chuàng)建。

          2、創(chuàng)建一個自定義過程
          SQL> create or replace procedure test as
          ? 2? begin
          ? 3? insert into a values(sysdate);
          ? 4? end;
          ? 5? /

          過程已創(chuàng)建。

          3、創(chuàng)建JOB
          SQL> variable job1 number;
          SQL>
          SQL> begin
          ? 2? dbms_job.submit(:job1,'test;',sysdate,'sysdate+1/1440');  --每天1440分鐘,即一分鐘運行test過程一次
          ? 3? end;
          ? 4? /

          PL/SQL 過程已成功完成。

          4、運行JOB
          SQL> begin
          ? 2? dbms_job.run(:job1);
          ? 3? end;
          ? 4? /

          PL/SQL 過程已成功完成。

          SQL> select to_char(a,'yyyy/mm/dd hh24:mi:ss') 時間 from a;

          時間
          -------------------
          2001/01/07 23:51:21
          2001/01/07 23:52:22
          2001/01/07 23:53:24

          5、刪除JOB
          SQL> begin
          ? 2? dbms_job.remove(:job1);
          ? 3? end;
          ? 4? /

          PL/SQL 過程已成功完成。
          6、一些必要的參數(shù)
          修改initsid.ora參數(shù)
          job_queue_processes = 4
          job_queue_interval = 10
          job_queue_keep_connections=true

          修改可執(zhí)行作業(yè)個數(shù)為20個
          ALTER SYSTEM SET JOB_QUEUE_PROCESSES = 20

          修改取消限制模式
          ALTER SYSTEM DISABLE RESTRICTED SESSION;

          7、兩個必要的表
          ????? user_jobs及dba_jobs_running

          8、相關(guān)的幾個JOB操作
          刪除job:dbms_job.remove(jobno);
          修改要執(zhí)行的操作:job:dbms_job.what(jobno,what);
          修改下次執(zhí)行時間:dbms_job.next_date(job,next_date);
          修改間隔時間:dbms_job.interval(job,interval);
          停止job:dbms.broken(job,broken,nextdate);
          啟動job:dbms_job.run(jobno);

          主站蜘蛛池模板: 博罗县| 工布江达县| 永丰县| 南川市| 类乌齐县| 胶南市| 疏勒县| 晋江市| 临湘市| 南溪县| 吐鲁番市| 浮梁县| 绵阳市| 贵溪市| 蕉岭县| 怀宁县| 襄垣县| 巴彦淖尔市| 通山县| 扎鲁特旗| 姜堰市| 蒲城县| 贡嘎县| 万年县| 丹东市| 岑溪市| 姜堰市| 红河县| 静海县| 金寨县| 岚皋县| 房产| 巴林右旗| 新化县| 华阴市| 思南县| 邯郸县| 北辰区| 山东| 崇礼县| 杭锦后旗|