Get the App
SLTechnology News&Howtos  ›  Database  › 

Explain in detail the simple use of Oracle cursors

Shulou Source: shulou.com Published: 2022-06-01 03:35:12 09月29日 Update

Let's take a look at the simple use of Oracle cursors, as shown below:

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;-- get opercationid / * select t1.operation_id into sOperationID from yw_operation_link T1 where t1.djbh = sCurDJBH * /-- write log 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 uses cursor cursor loops to add and delete updates.

Knowledge point expansion:

Simple example of Oracle cursors

Use cursors to print employee names and salaries

Set serveroutput on;declarecursor 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 | | 'salary is' | | csal); end loop;end;/

Cursor with parameters

Use cursors to print the names of all employees in a department number

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;/

Summary

The above is the simple usage of the Oracle cursor introduced by the editor to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

Tags: Cursor easy employee name salary help code provenance parameters logs questions knowledge knowledge points examples websites house numbers loops support updates Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Shulou Technology Linux Shulou Tech Info