oracle 游標使用根據工齡更新年假

2021-07-12 06:36:14 字數 2659 閱讀 3415

create or replace procedure update_cmcc_work_age is

--id

workageid   cmcc_work_age.work_age_id%type;

--工齡

workageyear cmcc_work_age.work_age%type;

--是否勞模

ismodelworker cmcc_work_age.is_model_worker%type;

--定義游標(簡單的說就是乙個可以遍歷的結果集)

cursor v_workage is

select work_age_id, work_age,is_model_worker

from cmcc_work_age;

-- where cmcc_work_age.work_age != '0';

begin

--遍歷游標處理後更新到表。遍歷游標有幾種方法,用loop語句是其中比較直觀的一種。

--每年年初凌晨執行,工齡加1

update cmcc_work_age  set work_age = work_age + 1;

commit;

open v_workage;

loop

fetch v_workage

into workageid, workageyear,ismodelworker;

exit when v_workage%notfound;

--dbms_output.put_line('工齡:' || workageid);

--工齡少於5年非勞模

if (workageyear < 5 and ismodelworker=0) then

update cmcc_work_age

set holiday_num = '5'

where work_age_id = workageid;

commit;

--工齡少於5年勞模

elsif (workageyear < 5 and ismodelworker=1) then

update cmcc_work_age

set holiday_num = '10'

where work_age_id = workageid;

commit;

elsif (workageyear >= 5 and workageyear < 10 and ismodelworker=0) then

update cmcc_work_age

set holiday_num = '10'

where work_age_id = workageid;

commit;

elsif (workageyear >= 5 and workageyear < 10 and ismodelworker=1) then

update cmcc_work_age

set holiday_num = '15'

where work_age_id = workageid;

commit;

elsif (workageyear >= 10 and workageyear < 15 and ismodelworker=0) then

update cmcc_work_age

set holiday_num = '12'

where work_age_id = workageid;

commit;

elsif (workageyear >= 10 and workageyear < 15 and ismodelworker=1) then

update cmcc_work_age

set holiday_num = '17'

where work_age_id = workageid;

commit;

elsif (workageyear >= 15 and workageyear < 20 and ismodelworker=0) then

update cmcc_work_age

set holiday_num = '15'

where work_age_id = workageid;

commit;

elsif (workageyear >= 15 and workageyear < 20 and ismodelworker=1) then

update cmcc_work_age

set holiday_num = '20'

where work_age_id = workageid;

commit;

elsif (workageyear >= 20  and ismodelworker=0)  then

update cmcc_work_age

set holiday_num = '20'

where work_age_id = workageid;

commit;

else

update cmcc_work_age

set holiday_num = '25'

where work_age_id = workageid;

commit;

end if;

end loop;

close v_workage;

end;

oracle學習 九 游標的使用(持續更)

為什麼要使用?筆者查閱了一些資料之後得到的結論是,關係型資料庫是面向集合的,而游標是面向行的,游標可對取出來的集合 結果集 中每一行進行相同或不同的操作,還提供對基於游標位置而對錶中資料進行刪除或更新的能力,某些特 殊的查詢操作也可以通過游標去完成,讓你在查詢暫時沒辦法的時候多了一種選擇。游標的型別...

oracle 游標使用

create or replace function errortyperead return varchar2 is result varchar2 3000 type cursor type is ref cursor tempname varchar2 100 cursor testcur i...

oracle游標使用

在進行pl sql程式設計時,我們都會使用游標,游標有兩種,一種是顯式游標,使用類似如下方式 open 游標 loop fetch into exit when notfound end loop close 游標 另一種是隱式游標,使用類似如下 for 游標變數 in 游標 loop 賦值變數 游...