详解Oracle游标的简易用法
下面看下Oracle游标的简易用法,具体代码如下所示:
createorreplaceprocedureNW_DelYW(iOPERATION_IDnumber, sUserIDvarchar2)is sCurDJBHyw_operation_link.djbh%type; cursortable_yw(ywidyw_operation.id%type)is select*fromyw_operation_linkt1wheret1.operation_id=ywid; begin fordrintable_yw(iOPERATION_ID)loop sCurDJBH:=dr.djbh; --取得opercationid /*selectt1.operation_id intosOperationID fromyw_operation_linkt1 wheret1.djbh=sCurDJBH;*/ --写日志 insertintolog_zfywinfo (DJBH, DJDL, DJXL, DLMC, XLMC, SLR, SLRID, SQRXM, FWZL, ZFRQ, ZFRID, zfr) selectdistinctsCurDJBH, t4.id, t3.id, t4.name, t3.name, t1.slry, t1.slryid, t1.SQRXM, t1.zl, sysdate, sUserID, (selecttt.namefrompw_userttwherett.id=sUserID) fromyw_operationt1 joinyw_operation_linkt2 ont2.operation_id=t1.ID joinBUSINESS_TYPEt3 ont3.id=t1.business_id joinBUSINESS_CLASSt4 ont4.id=t3.parent_id wheret1.ID=dr.operation_id; exception whenothersthen rollback; dbms_output.put_line(sqlerrm); endNW_DelYW;
Oracle使用cursor游标循环添加删除更新。
知识点扩展:
Oracle游标简单示例
使用游标打印员工姓名和薪水
setserveroutputon; declare cursorcempisselectename,salfromemp; cnameemp.ename%type; csalemp.sal%type; begin opencemp; loop fetchcempintocname,csal; exitwhencemp%notfound; dbms_output.put_line(cname||'的薪水是'||csal); endloop; end; /
带参数的游标
使用游标打印某部门号的所有员工姓名
setserveroutputon; declare cursorcemp(cnoemp.deptno%type)isselectenamefromempwhereemp.deptno=cno; cnameemp.ename%type; begin opencemp(10); loop fetchcempintocname; exitwhencemp%notfound; dbms_output.put_line(cname); endloop; end; /
总结
以上所述是小编给大家介绍的详解Oracle游标的简易用法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!