Basic Oracle Concepts and Programming Question:
Download Job Interview Questions and Answers PDF
How To Open a Cursor Variable?
Answer:
A cursor variable must be opened with a specific query statement before you can fetch data fields from its data rows. To open a cursor variable, you can use the OPEN ... FOR statement as shown in the following tutorial exercise:
CREATE OR REPLACE PROCEDURE ggl_CENTER AS
TYPE emp_ref IS REF CURSOR RETURN employees%ROWTYPE;
TYPE any_ref IS REF CURSOR;
emp_cur emp_ref;
any_cur any_ref;
sys_cur SYS_REFCURSOR;
BEGIN
OPEN emp_cur FOR SELECT * FROM employees;
OPEN any_cur FOR SELECT * FROM employees;
OPEN sys_cur FOR SELECT * FROM employees;
CLOSE sys_cur;
CLOSE any_cur;
CLOSE emp_cur;
END;
/
CREATE OR REPLACE PROCEDURE ggl_CENTER AS
TYPE emp_ref IS REF CURSOR RETURN employees%ROWTYPE;
TYPE any_ref IS REF CURSOR;
emp_cur emp_ref;
any_cur any_ref;
sys_cur SYS_REFCURSOR;
BEGIN
OPEN emp_cur FOR SELECT * FROM employees;
OPEN any_cur FOR SELECT * FROM employees;
OPEN sys_cur FOR SELECT * FROM employees;
CLOSE sys_cur;
CLOSE any_cur;
CLOSE emp_cur;
END;
/
Download Oracle Database Interview Questions And Answers
PDF
Previous Question | Next Question |
How To Define an Oracle Cursor Variable? | How To Loop through a Cursor Variable? |