Oracle cursor FOR loop ____oracle

Source: Internet
Author: User
Tags dname oracle cursor first row
The For Loop Pl/sql language of the/* cursor provides the cursor's for loop statement, "Automatically performs the function of the cursor's open,fetch,close statement and circular statement," and when entering the loop, the cursor for Loop statement automatically opens the cursor and extracts the data from the first row of cursors.
When the program completes the current extracted data and enters the next loop, the cursor for Loop statement automatically extracts the next row of data for the program to process, when all the data rows in the result set end the loop and the cursor is automatically closed; For index_variable in cursor_name[(Value[,value] ...)]

Loop--Cursor processing code end loop; Where index_variable is the index variable implied by the cursor for loop statement, the variable is a record variable, the structure is the same as the collection of structures returned by the cursor query statement, and the extracted cursor data can be read by referencing the index record variable element in the program, Index_
The names of the elements in the variable are the same as the column names in the selection list of the cursor query statement, and if computed columns exist in the selection list of the cursor query statement, you must specify aliases for the computed columns to access the column data through the index variables in the cursor for loop statement;
:: Do not manually manipulate cursors in your program, and do not define records in your program that control the FOR loop:: * * DECLARE CURSOR c_sal is select emp.empno,emp.ename,emp.sal from EMP; Begin for V_sal in C_sal Loop--implicitly open cursor: Implied monitoring c_sal%notfound: implicitly close cursor Dbms_output.put_line (to_char (v_sal.empno) | | ....'|| v_sal.ename| |
    To_char (v_sal.sal));
End Loop;

End
  /*:: When the declared cursor with parameters, through the cursor for Loop statement for the cursor pass parameters:::: The cursor can be seen as a method, with parameters of the method * * DECLARE CURSOR c_cursor (dept_no number default 10)
is select Dept.dname,dept.loc from dept where Dept.deptno <= Dept_no; Begin Dbms_output.put_line (' when dept_nThe parameter of O is 30 o'clock: '); For C1_rec in C_cursor loop dbms_output.put_line (c1_rec.dname| | ': ' | |
    C1_REC.LOC);
End Loop;

End
    /* Pl/sql also allows the use of subqueries in cursor for loop statements to implement the function of a cursor/declare begin for C1_rec in (select Dept.dname,dept.loc from dept) loop Dbms_output.put_line (c1_rec.dname| | ' ...'||
  C1_REC.LOC);
End Loop;
 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.