How To Retrieve Data from an Explicit Cursor?
Submitted by: AdministratorIf you have a cursor opened ready to use, you can use the FETCH ... INTO statement to retrieve data from the cursor into variables. FETCH statement will:
► Retrieve all the fields from the row pointed by the current cursor pointer and assign them to variables listed in the INTO clause.
► Move the cursor pointer to the next row.
► Update cursor attributes like FOUND and NOTFOUND.
Here is a sample script showing you how to use FETCH statement:
CREATE OR REPLACE PROCEDURE ggl_CENTER AS
CURSOR t_list IS SELECT first_name, last_name
FROM employees;
f_name VARCHAR2(10);
l_name VARCHAR2(10);
BEGIN
OPEN t_list;
FETCH t_list INTO f_name, l_name;
DBMS_OUTPUT.PUT_LINE('Name = ' || f_name || ' '
|| l_name);
FETCH t_list INTO f_name, l_name;
DBMS_OUTPUT.PUT_LINE('Name = ' || f_name || ' '
|| l_name);
-- FETCH t_list INTO l_name; -- must have two variables
CLOSE t_list;
END;
/
Name = Ellen Abel
Name = Sundar Ande
Submitted by: Administrator
► Retrieve all the fields from the row pointed by the current cursor pointer and assign them to variables listed in the INTO clause.
► Move the cursor pointer to the next row.
► Update cursor attributes like FOUND and NOTFOUND.
Here is a sample script showing you how to use FETCH statement:
CREATE OR REPLACE PROCEDURE ggl_CENTER AS
CURSOR t_list IS SELECT first_name, last_name
FROM employees;
f_name VARCHAR2(10);
l_name VARCHAR2(10);
BEGIN
OPEN t_list;
FETCH t_list INTO f_name, l_name;
DBMS_OUTPUT.PUT_LINE('Name = ' || f_name || ' '
|| l_name);
FETCH t_list INTO f_name, l_name;
DBMS_OUTPUT.PUT_LINE('Name = ' || f_name || ' '
|| l_name);
-- FETCH t_list INTO l_name; -- must have two variables
CLOSE t_list;
END;
/
Name = Ellen Abel
Name = Sundar Ande
Submitted by: Administrator
Read Online Oracle Database Job Interview Questions And Answers
Top Oracle Database Questions
☺ | How To Write Date and Time Interval Literals in Oracle? |
☺ | How To View the Dropped Tables in Your Recycle Bin? |
☺ | How Run SQL*Plus Commands That Are Stored in a Local File? |
☺ | How To Run SQL*Plus Commands in SQL Developer? |
☺ | How To Use IN Conditions in Oracle? |
Top DB Oracle Categories
☺ | Oracle PL-SQL Interview Questions. |
☺ | Oracle DBA Interview Questions. |
☺ | Oracle D2K Interview Questions. |
☺ | OCI Interview Questions. |
☺ | Oracle RMAN Interview Questions. |