Oracle / PLSQL Cursors - PROCEDURE myprocedure AS LV_TEST_CUR SYS_REFCURSOR; LV_QUERY VARCHAR2(200); LV_DATE DATE; BEGIN LV_QUERY:='select sysdate as mydate from dual'; OPEN LV_TEST_CUR FOR LV_QUERY; /*FOR CUR_VAR IN LV_TEST_CUR LOOP dbms_output.put_line(CUR_VAR.mydate); end LOOP; */ LOOP FETCH LV_TEST_CUR INTO LV_DATE; EXIT WHEN LV_TEST_CUR%NOTFOUND; DBMS_OUTPUT. Oracle / PLSQL Cursors In Oracle, a cursor is a mechanism by which you can assign a name to a SELECT statement and manipulate the information within that SQL statement. The following is a list of topics that explain how to use Cursors in Oracle/PLSQL
Cursors in PL/SQL - GeeksforGeeks PUT_LINE(LV_DATE); END LOOP; CLOSE LV_TEST_CUR; END myprocedure; create or replace PROCEDURE myprocedure AS LV_TEST_CUR SYS_REFCURSOR; LV_QUERY VARCHAR2(200); LV_DATE DATE; BEGIN FOR CUR_VAR IN (select sysdate as mydate from dual) LOOP dbms_output.put_line(CUR_VAR.mydate); end LOOP; END myprocedure; / syntax with dynamic SQL; see the example in the documentation, which shows the method you're using when that code is commented out anyway. There are four steps in using an Explicit Cursor. DECLARE the cursor in the Declaration section. OPEN the cursor in the Execution Section. FETCH the data from the cursor into PL/SQL variables or records in the Execution Section. CLOSE the cursor in the Execution Section before you end the PL/SQL.
PL/SQL - Cursors - Tutorialspoint Your example doesn't need to be dynamic at all, but I assume you've just simplified it for this question. A cursor is a pointer to this context area. PL/SQL controls the context area through a cursor. A cursor holds the rows one or more returned by a SQL statement. The set of rows the cursor holds is referred to as the active set. You can name a cursor so that it could be referred to in a program to fetch and process.
How to write the following pl/sql block without using Cursor? If it had a placeholder then there would be nowhere to set its value. Firstly, the query used in your cursor has an ORDER BY clause in it. If this query returns a lot of rows, Oracle has to fetch them all and sort them all before it can return the first row. If this query returns a lot of rows, Oracle has to fetch them all and sort them all before it can return the first row.