前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Oracle触发器写法和举例[通俗易懂]

Oracle触发器写法和举例[通俗易懂]

作者头像
全栈程序员站长
发布2022-09-13 10:10:39
1K0
发布2022-09-13 10:10:39
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

1、declare 声明变量后的每个变量都要加分号; 2、所有的语句结束和sql语句结尾,都要加分号; 3、变量赋值 variable :=’1234′ 如:recordId := ‘1234’; 4、插入列数据获取 :new.colname 如:new.exec_record_id 5、sql查询写入变量 select colname into variable 如: select verify_date into execDate from orders_executed_record where record_id=’1234′;

触发器举例:

代码语言:javascript
复制
CREATE OR REPLACE TRIGGER "TR_NUTRITION"
 after update on inp_bill_detail
  for each row
declare
    myexp exception;
    execDate date;
    recordId varchar2(30);
begin
    recordId :=:new.exec_record_id;
    if :new.exec_record_id is not null then
        select nvl(oen.verify_date,oer.execute_date_time) into execDate
        from orders_executed_record oer left join orders_executed_nutrition oen on oer.record_id=oen.record_id
        where oer.record_id = recordId ;
        if execDate is not null then
           raise myexp;
         end if;
    end if;
    exception
        when myexp then raise_application_error('-20002', '计费后,执行(核对)日期不能为空,计费ID=' || :new.detail_no || ' 执行ID=' || recordId);
end ;

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/159865.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档