create or replace procedure a_meas_miinsp_plan_update
asvs_msg varchar2(4000);
log_body varchar2(400);
log_body2 varchar2(400);
updatecount number;
plancodes varchar2(1000);
codeday varchar2(40); --前幾天
cur_1 sys_refcursor; --宣告游標變數
v_plan_code varchar2(400); --當前plancode
v_plan_name varchar2(400); --當前planname
begin
insert into a_meas_miinsp_log(create_date,body,execute,logtype) values(sysdate,'開始執行a_meas_miinsp_plan_update儲存過程','execute','a_meas_miinsp_plan_update');
select a_dics.code into codeday
from a_dics
inner join a_diccategory on a_dics.categoryid = a_diccategory.keyid
where a_dics.status = 1 and a_diccategory.code = 'meas_recycleday' and a_dics.title ='檢定';
if(codeday is null)
then
begin
insert into a_meas_miinsp_log(create_date,body,execute,logtype) values(sysdate,'資料字典中不存在配置單據**天數','execute','a_meas_miinsp_plan_update');
insert into a_meas_miinsp_log(create_date,body,execute,logtype) values(sysdate,'結束執行a_meas_miinsp_plan_update儲存過程','execute','a_meas_miinsp_plan_update');
commit;
return;
end;
end if;
--定義游標(簡單的說就是乙個可以遍歷的結果集)
open cur_1 for
--cursor cur_1 is
select plan_code,plan_name from a_meas_miinsp_plan
where
--create_date < to_date(to_char(sysdate - interval codeday day,'yyyy-mm-dd'),'yyyy-mm-dd')
to_date(to_char(create_date,'yyyy-mm-dd'),'yyyy-mm-dd') <= to_date(to_char(sysdate -codeday,'yyyy-mm-dd'),'yyyy-mm-dd')
and report_state in (1,2);
loop
fetch cur_1 into v_plan_code,v_plan_name;
exit when cur_1%notfound;
update a_meas_instru_ccount a set
a.mi_status=(
select b.old_mi_status from a_meas_miinsp_detail b where
b.plan_code=v_plan_code and
b.mi_id=a.mi_id )
,operatedate=sysdate,operateuser='sysadmin'
where exists (
select b.old_mi_status from a_meas_miinsp_detail b where
b.plan_code=v_plan_code and
b.mi_id=a.mi_id);
log_body :='修改'||v_plan_name||'檢定計畫下器具狀態為原來狀態.';
plancodes:=plancodes||v_plan_code||',';
insert into a_meas_miinsp_log(create_date,body,execute,logtype) values(sysdate,log_body,'update','a_meas_miinsp_plan_update+a_meas_instru_ccount');
end loop;
select count(*) into updatecount from a_meas_miinsp_plan
where
--create_date < to_date(to_char(sysdate - interval codeday day,'yyyy-mm-dd'),'yyyy-mm-dd')
to_date(to_char(create_date,'yyyy-mm-dd'),'yyyy-mm-dd') <= to_date(to_char(sysdate -codeday,'yyyy-mm-dd'),'yyyy-mm-dd')
and report_state in (1,2) ;
if(updatecount>0)
then
--更新檢定計畫表中的三天前的編制狀態記錄為 已** 狀態
--update a_meas_miinsp_plan set report_state=7 where create_date < to_date(to_char(sysdate - interval codeday day,'yyyy-mm-dd'),'yyyy-mm-dd');
update a_meas_miinsp_plan set report_state=7,change_time=sysdate,change_userid='sysadmin' where to_date(to_char(create_date,'yyyy-mm-dd'),'yyyy-mm-dd') <= to_date(to_char(sysdate -codeday,'yyyy-mm-dd'),'yyyy-mm-dd')
and report_state in (1,2) ;
--新增日誌
log_body2 :='修改'||updatecount||'條編制狀態的檢定計畫:'||plancodes;
insert into a_meas_miinsp_log(create_date,body,execute,logtype) values(sysdate,log_body2,'update','a_meas_miinsp_plan_update+a_meas_miinsp_plan');
end if;
insert into a_meas_miinsp_log(create_date,body,execute,logtype) values(sysdate,'結束執行a_meas_miinsp_plan_update儲存過程','execute','a_meas_miinsp_plan_update');
commit;
exception
when others then
vs_msg := 'error in a_meas_miinsp_plan_update '||substr(sqlerrm,1,500);
rollback;
--新增日誌
insert into a_meas_miinsp_log(create_date,body,execute,logtype) values(sysdate,vs_msg,'update','a_meas_miinsp_plan_update');
commit;
return;
end;
oracle 儲存過程引數
oracle 儲存過程型別 1 in 輸入型別,即由應用程式將資料傳入oracle儲存過程中 這種引數在儲存過程中是唯讀引數,在儲存過程中無法對該型別的引數進行修改 2 out 輸出引數,是在儲存過程中對該值進行賦值,在程式中獲取值。3 in out 輸入輸出引數,兼具以上兩種特性,但可讀可寫。驗證...
oracle儲存過程 帶引數的儲存過程
帶引數的儲存過程 舉例 為指定的員工漲100元的工資,列印漲前和漲後的工資 如果帶參,需要指定是輸入引數還是輸出引數 create orreplace procedure raisesalary eno in number as 定義乙個變數儲存漲前的薪水,引用emp中sal的型別作為psal的型別...
Oracle儲存過程傳遞陣列引數
今天晚上,和同事聊起oracle儲存過程傳遞陣列引數能否使用資料,之後就在自己的電腦上試試,試了試是可以使用。先要定義乙個型別myvarray list 陣列的長度是10,陣列中存放的資料型別是varchar2。sql create or replace type myvarray list as ...