国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > Oracle > 正文

Oracle外部程序的觸發(fā)小結(jié)

2024-08-29 13:31:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
在論壇里曾經(jīng)看過(guò)一個(gè)帖子,有位用戶(hù)問(wèn)了這么一個(gè)問(wèn)題:oracle 里一個(gè)表插入一條數(shù)據(jù),提交后,如何讓外部程序收到這個(gè)消息?

  當(dāng)時(shí)沒(méi)有留意,現(xiàn)在想想好像應(yīng)該可以總結(jié)一下了。舉例:

  1、過(guò)程中:
...  declare  myexcept exception;  inserted_count1 number;  inserted_count2 number;  ...  begin  insert into table values(...);  inserted_count1 := sql%rowcount;  ...                            --可以判斷inserted_count1是否大于0來(lái)確定是否插入了數(shù)據(jù)  commit;  inserted_count2 := sql%rowcount; --這里inserted_count2為0  ...              --事實(shí)上,這里一定是提交成功才會(huì)執(zhí)行,否則會(huì)跳到exception段  yourprocess(yourpara);--調(diào)用你自己的過(guò)程或語(yǔ)句跟別的過(guò)程通信  ...  exception  when others then     ---你可以根據(jù)sqlcode自己去查具體的提交失敗原因  ...  yourprocess_for_fail(yourpara)   --調(diào)用你自己的過(guò)程跟別的過(guò)程通信  ...  end;
  2、直接外部操作,建觸發(fā)器:

  create or replace trigger table after insert  for each row
  ...
  begin
  ...
  yourprocess(yourprara);
  ...
  end;
  當(dāng)然,2的方法這只能更總到提交前,如果要監(jiān)視提交后狀態(tài),你可以在操作表建立標(biāo)志位或?qū)iT(mén)建個(gè)表,操作表發(fā)生變化就通過(guò)trigger更新變化信息到狀態(tài)表,掃描狀態(tài)表就知道是否commit;成功了

  我想這位用戶(hù)應(yīng)該通過(guò)trigger來(lái)調(diào)用java source來(lái)實(shí)現(xiàn)插入數(shù)據(jù)后來(lái)通知外部程序來(lái)做一些事情:

  使用java source的例子如下:

sql> create or replace and compile java source named helloworld
  2 as
  3 public class helloworld {
  4 public static void db_run (){
  5 system.out.println("hello world");
  6 }
  7 }
  8 /
  java created.
  
  sql> create or replace procedure run_helloworld
  2 as language java
  3 name 'helloworld.db_run()';
  4 /
  procedure created.
  sql> set serveroutput on size 5000
  sql> call dbms_java.set_output(5000) ;
  call completed.
  sql>
  sql> exec run_helloworld ;
  hello world
  pl/sql procedure successfully completed.
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桦甸市| 武汉市| 东兰县| 河南省| 龙海市| 咸丰县| 乌什县| 荔波县| 武宁县| 舟山市| 兰考县| 漾濞| 收藏| 吴桥县| 鸡泽县| 桦甸市| 高安市| 平潭县| 五常市| 永和县| 兴隆县| 丹巴县| 广德县| 额济纳旗| 天气| 商丘市| 凤城市| 永仁县| 沾化县| 体育| 筠连县| 龙江县| 兴隆县| 车险| 三台县| 和平县| 鲁甸县| 湛江市| 满洲里市| 治多县| 柏乡县|