Oracle cursor Program

Source: Internet
Author: User
Tags oracle cursor rowcount

Oracle CURSOR program declare cursor EMP_CURSOR is select FIRST_NAME from employees; -- TYPE NAME_ARRAY_TYPE IS varchar (5) OF VARCHAR2 (10); TYPE NAME_ARRAY_TYPE is varray (5) OF VARCHAR2 (10 ); NAME_ARRAY NAME_ARRAY_TYPE; rows int: = 2; V_COUNT INT: = 0; begin if not EMP_CURSOR % ISOPEN -- check whether the cursor opens then open emp_cursor; end if; -- OPEN EMP_CURSOR; loop fetch EMP_CURSOR bulk collect into NAME_ARRAY limit rows; -- If limit rows is not added, extract all data from cursor DBMS_OUTPUT.PUT_LINE ('############' | EMP_CURSOR % ROWCOUNT ); -- The total number of cursor retrieved each time DBMS_OUTPUT.PUT_LINE ('***********************'); for I IN 1 .. (EMP_CURSOR % ROWCOUNT-V_COUNT) LOOP -- remove the processed cursor data DBMS_OUTPUT.PUT_LINE (NAME_ARRAY (I); END LOOP; DBMS_OUTPUT.PUT_LINE ('&'); V_COUNT: = EMP_CURSOR % ROWCOUNT; exit when EMP_CURSOR % NOTFOUND; end loop; CLOSE EMP_CURSOR; END; the following IS a simple cursor processing data: declare cursor EMP_CURSOR is select FIRST_NAME, LAST_NAME from employees; V_FIRSTNAME EMPLOYEES. FIRST_NAME % TYPE; V_LASTNAME EMPLOYEES. LAST_NAME % TYPE; begin open EMP_CURSOR; loop fetch EMP_CURSOR INTO V_FIRSTNAME, V_LASTNAME; exit when EMP_CURSOR % NOTFOUND; values (V_FIRSTNAME | ':' | V_LASTNAME); end loop; CLOSE EMP_CURSOR; END;

Related Article

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.