-3

Explanation with example of syscursor.

When to use syscursor in plsql procedure? I have go through websites but didn't get how and when to use this.

Sindhu
  • 420
  • 1
  • 4
  • 16
  • 1
    There is a whole chapter related to cursors in the documentation: https://docs.oracle.com/database/121/LNPLS/static.htm#LNPLS00602 There are many articles in the web: http://www.oracle.com/technetwork/issue-archive/2013/13-mar/o23plsql-1906474.html I vote to close this question as too broad. – krokodilko Jan 19 '17 at 04:31
  • Possible duplicate of [Alternate of sys\_refcursor](http://stackoverflow.com/questions/35503839/alternate-of-sys-refcursor) – Sindhu Mar 28 '17 at 07:28

2 Answers2

0

As far as I know there is nothing like "syscursor" in Oracle. May be you are referring to SYS_REFCURSOR

The following url should help you in understanding how and when to use it.

https://oracle-base.com/articles/misc/using-ref-cursors-to-return-recordsets

TechEnthusiast
  • 1,795
  • 2
  • 17
  • 32
0

SYS_REFCURSOR are used by PL/SQL procedures to return recordsets.

Example - lets get all table details for a given schema and return through sys_refcursor

CREATE OR REPLACE PROCEDURE GET_TABLE_DETAILS(schemaName    IN VARCHAR2,
                                              table_details OUT SYS_REFCURSOR) IS
  BEGIN
    OPEN table_details FOR
      select table_name, column_name, data_type from ALL_TAB_COLUMNS where OWNER = schemaName;
    END GET_TABLE_DETAILS;

Here table_details out parameter will contain the result data of the select query, it can be retrieved as below.

DECLARE
  table_details_cursor  SYS_REFCURSOR;
  tab_name   ALL_TAB_COLUMNS.table_name%TYPE;
  col_name   ALL_TAB_COLUMNS.column_name%TYPE;
  data_type  ALL_TAB_COLUMNS.data_type%TYPE;
BEGIN
  GET_TABLE_DETAILS (schemaName    => 'DUMMY',
                     table_details => table_details_cursor);

  LOOP 
    FETCH table_details_cursor
    INTO  tab_name, col_name, data_type;
    EXIT WHEN table_details_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(tab_name || ' | ' || col_name || ' | ' || data_type);
  END LOOP;
  CLOSE table_details_cursor;
END;

However, you need to get through the Oracle documentation for detailed explanation - Oracle - Cursors Documenatation

Srikanth Balaji
  • 2,638
  • 4
  • 18
  • 31