Oracle儲存過程中多層巢狀游標的用法

2021-06-20 04:53:51 字數 2386 閱讀 7221

oracle sql指令碼**  

create or replace  

procedure p_delete_qk (pid in number, deep in number) as  

-- pid = 分類id  deep = 深度,層級  

one_val number;  

two_val number;  

three_val number;  

cursor var_one is select "id" from t_qk where parentid = pid;  

cursor var_two is select "id" from t_qk where parentid = one_val;  

cursor var_three is  select "id" from t_wz where qkid = two_val;  

begin     

if deep = 0 then  

for oneid in var_one loop         

one_val:= oneid."id";  

for twoid in var_two loop     

two_val:= twoid."id";  

--刪除與文章關聯表  

for threeid in var_three loop  

three_val:= threeid."id";  

delete from q_browse where wzid = three_val;--瀏覽量     

delete from q_attention where wzid = three_val;--關注量  

end loop;  

--刪除這個分類下的所有文章  

delete from t_wz where qkid = two_val;  

--刪除**分類  

delete from t_qk where "id" = two_val;  

end loop;  

--刪除二級分類  

delete from t_qk where "id" = one_val;    

end loop;  

--刪除期刊期數  

delete from t_qkqs where qkid = pid;  

--刪除

delete from q_download where qkid = pid;      

--刪除本身  

delete from t_qk where "id" = pid;  

end if;  

if deep = 1 then  

for twoid in var_one loop                     

two_val:= twoid."id";  

for threeid in var_three loop     

three_val:= threeid."id";  

delete from q_browse where wzid = three_val;--瀏覽量     

delete from q_attention where wzid = three_val;--關注量  

end loop;     

--刪除這個分類下的所有文章  

delete from t_wz where qkid = two_val;  

--刪除**分類  

delete from t_qk where "id" = two_val;                

end loop;  

--刪除二級分類  

delete from t_qk where "id" = pid;        

end if;  

if deep = 2 then          

two_val:= pid;  

--刪除與文章關聯表  

for threeid in var_three loop  

three_val:= threeid."id";     

delete from q_browse where wzid = three_val;--瀏覽量     

delete from q_attention where wzid = three_val;--關注量  

end loop;     

--刪除這個分類下的所有文章  

delete from t_wz where qkid = pid;  

--刪除**分類  

delete from t_qk where "id" = pid;            

end if;  

end;  

oracle儲存過程中is和as區別

一直糾結於儲存過程的is與as最近在網上查了巨多資料,總結如下 在儲存過程 procedure 和函式 function 中沒有區別 在檢視 view 中只能用as不能用is 在游標 cursor 中只能用is不能用as。從其定義也可以看出沒什麼區別,要是有估計暫時也很少有人發下 create or...

oracle 儲存過程 游標巢狀

這是一段將裝置的gps資料的工作小時數進行統計的儲存過程,首先通過游標取出所有裝置資訊,然後對每一台裝置進行工作小時數統計,其中用到了游標巢狀 create or replace procedure cmtools.proc statistics workhour is v begindate da...

儲存過程中呼叫儲存過程

use northwind go 儲存過程1 功能 通過員工firstname inputempfirstname 獲得 員工id outid if exists select name from sysobjects where name p getempleeidbyname and type ...