儲存過程小記

2021-05-09 21:19:18 字數 1901 閱讀 7280

簡單示例一:

create or replace procedure testp(isal in number)--輸入引數不能有長度限制

isxname varchar2(10); --變數要有長度限制

cursor cur_1 is select ename from emp where sal>isal;--游標定義

begin

dbms_output.put_line('hello world');

for rec in cur_1 loop--迭代游標

begin

xname := rec.ename;

dbms_output.put_line('name:'||xname);

end;

end loop;

end;

示例二:

create or replace procedure p_form_submit_task(arg_pid in varchar2,arg_begin_date in date,arg_end_date in date,arg_type in varchar2)

isa_state varchar2(20);

cursor cur_1 is

select form_id fid,period_type pt,submit_date_limit sdl,begin_declare_date bdd,

biz_date_begin bdb,biz_date_end bde from form_submit_task_rule

where rule_prop1=arg_type and biz_date_begin>=arg_begin_date and biz_date_end<=arg_end_date;

begin

for rec in cur_1 loop

begin

--先判斷是否有相應記錄

select state into a_state from form_submit_task where pid=arg_pid and form_id=rec.fid and biz_date_begin=rec.bdb and biz_date_end=rec.bde;

--如果有記錄且為未提交記錄,則更新記錄

if a_state ='0' then

begin

update form_submit_task set enterprise_type=arg_type,period_type=rec.pt,submit_date_limit=rec.sdl

where pid=arg_pid and form_id=rec.fid and biz_date_begin=rec.bdb and biz_date_end=rec.bde;

-- dbms_output.put_line('update``````');

end;

end if;

exception

--沒有記錄就直接插入記錄

when no_data_found then

insert into form_submit_task(task_id,task_type,form_id,pid,enterprise_type,period_type,submit_date_limit,begin_declare_date,biz_date_begin,biz_date_end,state,overdue_days)

values(sys_guid(),'cwbb',rec.fid,arg_pid,arg_type,rec.pt,rec.sdl,rec.bdd,rec.bdb,rec.bde,'0',0);

--dbms_output.put_line('insert``````');

end;

end loop;

commit;

end;

儲存過程小記

use un visa go 建立儲存過程 create procedure pro test yc int,lyq int,nsx int output asif yc lyq print yc lyq else print yc0 and yc 0 set nsx yc print nsx go...

MySQL儲存過程小記

首先來看兩張表 drop table ifexists field indexcreate table field index schema name varchar 100 not null,field name varchar 100 not null,next index int notnul...

Oracle儲存過程小記

oracle儲存過程小記 dual 在oracle中,我們有時候會需要判斷乙個字串裡邊是否包含有某乙個串 首先,oracle為我們提供了instr這個函式 instr string1,string2 start position nth appearance 引數分析 string1,源字串,要在此...