• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Oracle外部程序的触发小结_oracle

oracle 搞代码 7年前 (2018-06-14) 223次浏览 已收录 0个评论

在论坛里曾经看过一个帖子,有位用户问了这么一个问题:oracle 里一个表插入一条数据,提交后,如何让外部程序收到这个消息?

  当时没有留意,现在想想好像应该可以总结一下了。举例:

  1、过程中:

...  declare  myexcept exception;  inserted_count1 number;  inserted_count2 number;  ...  begin  insert into table values(...);  inserted_count1 := sql%rowcount;  ...                            --可以判断inserted_count1是否大于0来确定是否插入了数据  commit;  inserted_count2 := sql%rowcount; --这里inserted_count2为0  ...              --事实上,这里一定是提交成功才会执行,否则会跳到exception段  yourprocess(yourpara);--调用你自己的过程或语句跟别的过程通信  ...  exception  when others then     ---你可以根据sqlcode自己去查具体的提交失败原因  ...  yourprocess_for_fail(yourpara)   --调用你自己的过程跟别的过程通信  ...  end;

  2、直接外部操作,建触发器:

  create or replace trigger table after insert  for each row
  ...
  begin
  ...
  yourprocess(yourprara);
  ...
  end;

  当然,2的方法这只能更总到提交前,如果要监视提交后状态,你可以在操作表建立标志位或专门建个表,操作表发生变化就通过trigger更新变化信息到状态表,扫描状态表就知道是否commit;成功了

http://www.gaodaima.com/31484.htmlOracle外部程序的触发小结_oracle

  我想这位用户应该通过trigger来调用java source来实现插入数据后来通知外部程序来做一些事情:

  使用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.

  上面是调用HelloWorld的例子,你可以修改HelloWorld方法,然后在触发器里面调用以实现这位用户的要求!

欢迎大家阅读《Oracle外部程序的触发小结_oracle,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Oracle外部程序的触发小结_oracle
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址