RSS Feed

PL/SQL Cursor Based Records

Cursor-Based records

Cursor-Based record has fields that match in name, datatype, and order to the final list of columns in the cursor’s SELECT statement.

Example 1 of Cursor Based Records

You can use the %ROWTYPE with an explicit cursor or cursor variable where each field corresponds to a column or aliased expression in the cursor SELECT statement.
In the below example, a record is declared with the same structure as an explicit cursor:
DECLARE 
 CURSOR Books_Cursor IS
  SELECT * FROM books
  WHERE author LIKE '%john%';

my_book_cur_rec Books_Cursor%ROWTYPE;


Example 2 of Cursor Based Records

Cursor emp_cur is
Select ename, eno. , hiredate
From emp;

emp_rec emp_cur%ROWTYPE

Example 3 of Cursor Based Records

CURSOR c IS
SELECT beer, price
FROM Sells
WHERE bar = 'Joe''s bar';

Bp1 c%ROWTYPE;

No comments:

Post a Comment