简单的oracle触发器例子

简单的oracle触发器例子

---术前访视术后随访触发器
create or replace trigger t_update_trigger
after update or insert or delete
on MED_SMARTREPORT_TEMPLATE
for each row
declare
stateCount number;
begin
select count(1) into stateCount from MED_Template_State where ReportTemplateID=:NEW.ReportTemplateID;
if stateCount>0 then
update MED_Template_State set ReportState=ReportState+1 where ReportTemplateID=:NEW.ReportTemplateID;
else
insert into MED_Template_State(ReportTemplateID,ReportState) values(:NEW.ReportTemplateID,1);
end if;
end;

select * from MED_Template


select * from MED_ANESTHESIA_INPUT_DICT for update;
---数据字典触发器
create or replace trigger trigger_MEDANESTHESIAINPUTDICT
after  insert or update  or delete
on MED_ANESTHESIA_INPUT_DICT
for each row
declare
stateCount number;
begin
select count(1) into stateCount from MED_Template_State where ReportTemplateID=3;
if stateCount>0 then
update MED_Template_State set ReportState=ReportState+1 where ReportTemplateID=3;
else
insert into MED_Template_State(ReportTemplateID,ReportState) values(3,1);
end if;
end;
--select * from MED_Template_State


select * from MED_ANAESTHESIA_DICT for update;

select * from MED_Template_State
---麻醉字典触发器
create or replace trigger trigger_MEDANAESTHESIADICT
after  insert or update  or delete
on MED_ANAESTHESIA_DICT
for each row
declare
stateCount number;
begin
select count(1) into stateCount from MED_Template_State where ReportTemplateID=4;
if stateCount>0 then
update MED_Template_State set ReportState=ReportState+1 where ReportTemplateID=4;
else
insert into MED_Template_State(ReportTemplateID,ReportState) values(4,1);
end if;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C# 访问Oracle示例+PL/SQL+存储过程+触发器 完整示例 测试可用 --PL/SQL基础1 declare begin dbms_output.('不输出不换行'); dbms_output.put_line('输出并换行'); end; --PL/SQL基础2 declare dig number(20,2); begin select avg(price) into dig from products; dbms_output.put_line('电子产品的平均价格是'||dig); end; --PL/SQL基础3 根据产品编号获得产品对象 --pname products.name%type; pname变量的类型与products.name列的类型一样 declare pid constant products.id%type:=1; --定义常量,初值1 pname products.name%type; pdate products.adddate%type; begin --pid:=1; select name,adddate into pname,pdate from products where id=pid; dbms_output.put_line('产品名称是:'||pname||',日期'||pdate); end; --PL/SQL基础4 根据产品编号获得产品对象 --obj products%rowtype; obj与products表的单行类型一样,可以通过点运算取值obj.price declare obj products%rowtype; begin select * into obj from products where id=&编号; dbms_output.put_line('产品名称是:'||obj.name||',价格:'||obj.price); end; --PL/SQL基础5 条件if declare vid products.id%type; vprice products.price%type; begin vid:=&编号; select price into vprice from products where id=vid; if vprice100 and vprice<=1000 then dbms_output.put_line('价格在100—1000之间'); else dbms_output.put_line('价格在1000以上'); end if; end; --PL/SQL基础5 多条件case begin case '&等级' when 'A' then dbms_output.put_line('优秀'); when 'B' then dbms_output.put_line('合格'); when 'C' then dbms_output.put_line('不合格'); end case; end; select id, name, typeid, price, adddate from products create table students( Id int primary key, sex int ) insert into students select 1,1 from dual union select 2,0 from dual union select 3,1 from dual union select 4,0 from dual union select 5,1 from dual insert into students(Id) values(6) select * from students; select translate(translate('1心1意 3心2意','1','一'),'3','三') from dual; select id,nvl(translate(translate(sex,1,'女'),0,'男'),'未知') from students; select id,case as 性别 from( sele
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值