Definition of a cursor: The Role of a cursor has been mentioned in the previous article. If the query result contains more than one row, you need to use a cursor. In the article rdquo; Introduction to PLSQL in Oracle Data
Definition of a cursor: The Role of a cursor has been mentioned in the previous article. If the query result contains more than one row, you need to use a cursor. In the article rdquo; PL/SQL in Oracle Data
Cursor definition:
The role of a cursor
As mentioned in the previous article, if the query result contains more than one row, a cursor is required. For more information about PL/SQL in Oracle data, see.
Procedure:
Define a cursor
Syntax: CURSOR cursor_name is select _ statement;
Open cursor
Syntax: open cursor_name;
Extract data
Using the fetch keyword, the record of the current row is captured and the record pointer is moved down to a row. Just like the ResultSet in JdbC.
Syntax: fetch cursor_name into variable1, variable2.
Some attributes of the cursor
Close cursor
Syntax: close cursor_name
The sample code is as follows:
Common method:
--- Use of cursors
Declare
-- Define a cursor to extract all tab_stu data
Cursor c_tab_stu is
Select * from tab_stu;
R_tab_stu tab_stu % rowtype; -- use rowtype to store cursor data
Begin
-- Open the cursor
Open c_tab_stu;
-- Extract data
Fetch c_tab_stu into r_tab_stu;
Dbms_output.put_line ('stu _ id: '| r_tab_stu.stu_id );
Dbms_output.put_line ('stu _ name: '| r_tab_stu.stu_name );
Dbms_output.put_line ('stu _ age: '| r_tab_stu.stu_age );
-- Close the cursor
Close c_tab_stu;
End;
Next, let's take a look at the highlights of page 2nd:
Related reading:
Comparison of Three Types of cursor Cycle Efficiency in PL/SQL
Use of Oracle Advanced explicit cursor
Use of insert in Oracle stored procedures, including the use of cursors
Usage of Oracle display cursor
Simple use of Oracle cursor