Oracle underlying stored procedures and cursors

Source: Internet
Author: User

One, a stored procedure with a cursor

  There are two types of cursors as arguments:

  1. Declaring the system cursor type Sys_refcursor

1) The cursor acts as a parameter to the stored procedure:

--stored procedures with cursorsCREATE OR REPLACE PROCEDUREPro_emp_in (Emp_cur sys_refcursor) asv_name EMP. Ename%TYPE; V_sal EMP. SAL%TYPE;BEGINLOOPFETCHEmp_cur intoV_name, V_sal; Dbms_output. Put_Line ('Name:' ||V_name|| 'Sal:' ||v_sal); EXIT  whenEmp_cur%NOTFOUND; ENDLOOP;END;

To invoke a stored procedure with a cursor:

-- calling a stored procedure with a cursor DECLARE   emp_cur sys_refcursor; BEGIN  OPEN  for    SELECT  from EMP;   = emp_cur);   CLOSE emp_cur; END;

  

2) stored procedure with output cursors

-- sys_refcursor type of system cursor with output parameters CREATE OR REPLACE PROCEDURE  as BEGIN  OPEN  for    SELECT  from EMP E;   -- and query statement binding END;

To call a stored procedure with an output cursor:

--calling a stored procedure with a cursor with an output typeDECLAREv_name EMP. Ename%TYPE; V_sal EMP. SAL%TYPE;    Emp_cur Sys_refcursor; --declaring system cursor typesBEGINpro_emp (Emp_cur=emp_cur); LOOPFETCHEmp_cur intoV_name, V_sal; Dbms_output. Put_Line ('Name:' ||V_name|| 'Sal:' ||v_sal); EXIT  whenEmp_cur%NOTFOUND; ENDLOOP; CLOSEemp_cur;END;

2. Declare a custom cursor type.

  

Oracle underlying stored procedures and cursors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.