create or replace procedure xs_test_update_bac is
cursor curtestupdatebac is
select id,
substr(bachelor_edu,
instr(bachelor_edu, '從') + 1,
instr(bachelor_edu, '年到') - 2) as startyear,
substr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
1,instr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
'年') - 1) as endyear,
substr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
instr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
'年') + 1) as yuanxi,
bachelor_edu
from test_alumni_user
where bachelor_edu <> '從年到年'
and bachelor_edu <> '無'
and instr(bachelor_edu, '年到') > 0;
--校友使用者型別
rec_curtestupdatebac curtestupdatebac%rowtype;
begin
--判斷游標是否被開啟,如果已經開啟,首先關閉
if curtestupdatebac%isopen then
--關閉游標
close curtestupdatebac;
end if;
--開啟游標
open curtestupdatebac;
--進行迴圈
loop
--開啟游標裡的一條記錄,賦到游標變數裡
fetch curtestupdatebac
into rec_curtestupdatebac;
--判斷游標裡是否還有記錄,如果沒有記錄,關閉游標,退出迴圈
if curtestupdatebac%notfound then
close curtestupdatebac;
exit;
else
update test_alumni_user u
set u.bachelor_edu_begin_day=rec_curtestupdatebac.startyear,
u.bachelor_edu_end_day = rec_curtestupdatebac.endyear,
u.bachelor_departments = rec_curtestupdatebac.yuanxi
where u.id = rec_curtestupdatebac.id;
end if;
commit;
end loop;
exception
when others then
rollback;
end xs_test_update_bac;
Oracle儲存過程呼叫儲存過程
oracle儲存過程呼叫有返回結果集的儲存過程一般用光標的方式,宣告乙個游標,把結果集放到游標裡面,然後迴圈游標 declare newcs sys refcursor cs1 number cs2 number cstype table rowtype table列的個數和newcs返回的個數一樣...
ORACLE儲存過程
自定義函式開始 create or replace function fn wftemplateidget templatecategoryid number,organid number,templatemode number return number istemplateid number i...
Oracle 儲存過程
create or replace procedure p 有就替換,沒有就建立 iscursor c is select from emp for update begin for v emp in c loop if v emp.deptno 10 then update emp2 set sa...