詳解Oracle游標(biāo)的簡(jiǎn)易用法
下面看下Oracle游標(biāo)的簡(jiǎn)易用法,具體代碼如下所示:
create or replace procedure NW_DelYW(iOPERATION_ID number, sUserID varchar2) is sCurDJBH yw_operation_link.djbh%type; cursor table_yw(ywid yw_operation.id%type) is select * from yw_operation_link t1 where t1.operation_id = ywid; begin for dr in table_yw(iOPERATION_ID) loop sCurDJBH := dr.djbh; --取得opercationid /* select t1.operation_id into sOperationID from yw_operation_link t1 where t1.djbh = sCurDJBH;*/ --寫(xiě)日志 insert into log_zfywinfo (DJBH, DJDL, DJXL, DLMC, XLMC, SLR, SLRID, SQRXM, FWZL, ZFRQ, ZFRID, zfr) select distinct sCurDJBH, t4.id, t3.id, t4.name, t3.name, t1.slry, t1.slryid, t1.SQRXM, t1.zl, sysdate, sUserID, (select tt.name from pw_user tt where tt.id=sUserID) from yw_operation t1 join yw_operation_link t2 on t2.operation_id = t1.ID join BUSINESS_TYPE t3 on t3.id = t1.business_id join BUSINESS_CLASS t4 on t4.id = t3.parent_id where t1.ID = dr.operation_id; exception when others then rollback; dbms_output.put_line(sqlerrm); end NW_DelYW;
Oracle使用cursor 游標(biāo)循環(huán)添加刪除更新。
知識(shí)點(diǎn)擴(kuò)展:
Oracle游標(biāo)簡(jiǎn)單示例
使用游標(biāo)打印員工姓名和薪水
set serveroutput on; declare cursor cemp is select ename,sal from emp; cname emp.ename%type; csal emp.sal%type; begin open cemp; loop fetch cemp into cname,csal; exit when cemp%notfound; dbms_output.put_line(cname || '的薪水是' || csal); end loop; end; /
帶參數(shù)的游標(biāo)
使用游標(biāo)打印某部門(mén)號(hào)的所有員工姓名
set serveroutput on; declare cursor cemp(cno emp.deptno%type) is select ename from emp where emp.deptno = cno; cname emp.ename%type; begin open cemp(10); loop fetch cemp into cname; exit when cemp%notfound; dbms_output.put_line(cname); end loop; end; /
總結(jié)
以上所述是小編給大家介紹的詳解Oracle游標(biāo)的簡(jiǎn)易用法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
Win7 64位下PowerDesigner連接64位Oracle11g數(shù)據(jù)庫(kù)
這篇文章主要為大家詳細(xì)介紹了Win7 64位下PowerDesigner連接64位Oracle11g數(shù)據(jù)庫(kù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08WINDOWS下使用DOS命令行連接oracle數(shù)據(jù)庫(kù)
本文講述了通過(guò)windows下的DOS命令連接oracle數(shù)據(jù)庫(kù)并進(jìn)行簡(jiǎn)單操作的方法2018-03-03Oracle截取字符串去掉字段末尾指定長(zhǎng)度的字符
這篇文章主要介紹了Oracle截取字符串去掉字段末尾指定長(zhǎng)度的字符 的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08Oracle 12c實(shí)現(xiàn)手工建庫(kù)而非CDB及CDB創(chuàng)建的方法
這篇文章主要給大家介紹了關(guān)于Oracle 12c實(shí)現(xiàn)手工建庫(kù)而非CDB及CDB創(chuàng)建的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用oracle 12c具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-10-10深入淺析Orcale的nvl函數(shù)和SQL Server的isnull函數(shù)
這篇文章主要介紹了Orcale的nvl函數(shù)和SQL Server的isnull函數(shù)的相關(guān)資料,需要的朋友可以參考下2017-10-10Oracle數(shù)據(jù)庫(kù)"記錄被另一個(gè)用戶(hù)鎖住"解決方法(推薦)
數(shù)據(jù)庫(kù)是一個(gè)多用戶(hù)使用的共享資源。當(dāng)多個(gè)用戶(hù)并發(fā)地存取數(shù)據(jù)時(shí),在數(shù)據(jù)庫(kù)中就會(huì)產(chǎn)生多個(gè)事務(wù)同時(shí)存取同一數(shù)據(jù)的情況。這篇文章主要介紹了Oracle數(shù)據(jù)庫(kù)"記錄被另一個(gè)用戶(hù)鎖住"解決方法2018-03-03Oracle出現(xiàn)超出打開(kāi)游標(biāo)最大數(shù)的解決方法
這篇文章主要介紹了Oracle出現(xiàn)超出打開(kāi)游標(biāo)最大數(shù)的解決方法,涉及針對(duì)Oracle游標(biāo)位置的判斷與處理技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06