Oracle cursor use 1

Source: Internet
Author: User

CURSOR is also called a CURSOR. It is often used in relational databases. In PL/SQL programs, you can use CURSOR and SELECT to query data in tables or views and read data row by row. Oracle cursors include display cursors and implicit cursors. Explicit Cursor: The Cursor defined in the PL/SQL program for query is called a display Cursor. Implicit Cursor: A Cursor automatically allocated by the Oracle system when UPDATE/DELETE statements are not defined in PL/SQL programs and used in PL/SQL. I. show cursor 1. use step (1) define (2) Open (3) Use (4) Close 2. first, CREATE the test table student. The script is as follows: create table "STUDENT" ("STUNAME" VARCHAR2 (10 BYTE), "STUNO" VARCHAR2 (4 BYTE ), "AGE" NUMBER, "GENDER" VARCHAR2 (2 CHAR) (1 ). use the WHILE loop to process the cursor create or replace PROCEDURE PROC_STU1 as begin -- display the cursor usage, and use the while LOOP declare -- 1. defines the cursor, named cur_stu cursor cur_stu is select stuno, stuname from student order by stuno; -- defines the variable and stores the data retrieved from the cursor v_stuno varchar (4); v_stuname varchar (20 ); begin -- 2. open cur_stu; -- 3. extract the current row of the cursor and store it in the variable fetch cur_stu into v_stuno, v_stuname; while cur_stu % found -- the cursor indicates that there are data rows, continue loop -- print the result dbms_output.PUT_LINE (v_stuno | '->' | v_stuname); -- continue to extract the current row referred to by the cursor into the variable fetch cur_stu into v_stuno, v_stuname; end loop; close cur_stu; -- 4. close the cursor end; END PROC_STU1; (2 ). use IF .. ELSE replaces the while loop processing cursor create or replace PROCEDURE PROC_STU2 as begin -- display cursor usage, use if to judge declare -- 1. defines the cursor, named cur_stu cursor cur_stu is select stuno, stuname from student order by stuno; -- defines the variable and stores the data retrieved from the cursor v_stuno varchar (4); v_stuname varchar (20 ); begin -- 2. open cur_stu; Author: wangliya110

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.