一、創建存儲過程
1、存儲過程寫法
create or replace procedure HVM_BYQ_TJ --變壓器統計信息--->入庫 (id in number) as begin for num in 1..2 loop if num=1 then update hvm_zsb_tj set byq=(select count(0) as hangshu from hvm_view_ObjectZTPJ_Byq t where t.StsRes = '正常狀態' and t.bdzdydj = '500kV') where id=1; end if; if num=2 then update hvm_zsb_tj set byq=(select count(0) as hangshu from hvm_view_ObjectZTPJ_Byq t where t.StsRes = '注意狀態' and t.bdzdydj = '500kV') where id=2; end if; end loop; end HVM_BYQ_TJ;
2、調用
call HVM_BYQ_TJ(1);
二、觸發器調用存儲過程
1、創建觸發器
create or replace trigger HVM_ZTPJ_BYQ after insert or update or delete on Xftpj_Pjjl_Byq declare
begin --直接寫存儲過程名稱+; hvm_byq_tj(1); end HVM_ZTPJ_BYQ;
2、觸發器的啟用與禁用
alter table xftpj_pjjl_byq disable all triggers; --禁用觸發器 alter table xftpj_pjjl_byq enable all triggers; --啟用觸發器
參考文章