Ref Cursor statement

TYPE V_TYPE IS REF CURSOR


V_CUR V_TYPE;


is that this decalrion is correct or not?

How do decalre

user10447332 wrote:
TYPE V_TYPE IS REF CURSOR

V_CUR V_TYPE;

is that this decalrion is correct or not?

Not. There is no need of a type defined by the user (unless the definition of type strong ref Cursor - use that is questionable in PL/SQL). Use rather SYS_REFCURSOR .

For example

--// run in SQL*Plus

--// define a bind variable
var c refcursor

declare
  myCursor sys_refcursor;
begin
  --// create the ref cursor
  open myCursor for select * from user_objects order by 1;

  --// pass the ref cursor handle to the client
  :c := myCursor;
end;
/

--// consume the cursor output in the client
print c

Tags: Database

Similar Questions

  • REP-0737: must be a function of return type 'ref cursor.

    Hi all

    I have create a ref cursor query in reports 10 g. But it is giving error REP-0737: must be a function of return type 'ref cursor.

    Here is my code

    function QR_1RefCurDS return sys_refcursor is
    
     My_Cur Sys_Refcursor;
    begin
      Open My_Cur for select * from scott.emp order by deptno;
      return My_Cur
    end;
    

    fate of the screen.

    Ref_Cursor_in_reports10g.jpg

    Oracle Forms/Reports has a complete PL/SQL engine and (only) the SQL parser.

    However, the engine of forms/States PL / SQL and SQL Analyzer are at a level that was in the Oracle 8.0 database.

    So, in the forms/States functions/procedures and forms/States triggers, you can not use SQL commands that did not exist in the 8.0 database.

    The predefined SYS_REFCURSOR type is introduced in Oracle 9i.

    Use this:

    PACKAGE test_rc IS

    TYPE of rc_type IS REF CURSOR RETURN emp % ROWTYPE;

    END;

    FUNCTION RETURN QR_1RefCurDS Test_rc.rc_type IS

    test_rc.rc_type RC;

    BEGIN

    OPEN the RC to SELECT * FROM emp;

    RETURN rc;

    END;

    Kind regards

    Zlatko

  • Ref cursor error message

    Hello expert;

    I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message

    ORA-06503: PL/SQL: function returned no value - slider Ref

    .. Please see below.

    function f_de return latest_cur is
    my_l_cur l_cur;
    
    begin
    open my_l_cur for
    select max(dateadded) as dateadded
    from tbl_test;
    end;
    

    I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.

    user13328581 wrote:

    Hello expert;

    I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message

    ORA-06503: PL/SQL: function returned no value - slider Ref

    .. Please see below.

    1. latest_cur the f_de function return is
    2. my_l_cur l_cur;
    3. Start
    4. Open the my_l_cur for
    5. Select max (dateadded) as dateadded
    6. of tbl_test;
    7. end;

    I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.

    by definition a FUNCTION returns a value, but your code isn't working; Therefore, the error is thrown.

    RETURN MY_L_CUR;

    the top line should take place before the END; statement.

  • Irregular data loss - function from PL/SQL returning data using Ref Cursor

    Database Version: 10.2.0.4.0 (node 2 CARS)

    The high-level process flow is as below:
    (1) insert records in a few tables & commit the same
    (2) call the pl/sql function to extract files (on certain conditions with joins with other tables) of the tables which are filled in step 1.
    -> It uses the ORDER BY clause to queries inline & line number 5000 records return for each call.
    Sense - if inline query is supposed to return 1,00,000 records then 20 calls to the same function. This, because the application cannot contain records beyond number.
    (3) the data returned by the ref cursor is then processed by application (Tibco BW) to generate the flat file.

    We are facing the problem of data loss in the file and there is no fixed model. It happens once between 200-300 calls process.
    Resolution: When the problem occurs, triggering the process and in almost every time re-outbreak of the process provides required data.

    Guidance on what could be the reason?

    * Examples of Code for the function:
    CREATE OR REPLACE FUNCTION FUNC_GET_HRCH_TOTAL_DATA)
    outinstrid in NUMBERS
    outinstrkey in NUMBERS
    rownumberstart in NUMBERS
    rownumbereend in NUMBERS
    err_code OUT VARCHAR2,
    err_msg OUT VARCHAR2)
    RETURN PACK_TYPES. HRCH_TOTAL_CURSOR
    IS
    REF_HRCH_TOTAL_CURSOR PACK_TYPES. HRCH_TOTAL_CURSOR;
    BEGIN

    OPEN FOR REF_HRCH_TOTAL_CURSOR
    SELECT *.
    FROM (SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order, ROWNUM ROWNUMBER
    OF AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
    WHERE A.outputid = B.outputid
    AND A.outputid = C.outputid AND A.outputkey = B.outputkey
    AND A.outputkey = C.outputkey AND A.outputid = outinstrid
    AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
    AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
    ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
    WHERE ROWNUMBER < rownumbereend
    AND ROWNUMBER > = rownumberstart;


    RETURN REF_HRCH_TOTAL_CURSOR;
    EXCEPTION
    WHILE OTHERS
    THEN
    err_code: = x_progress | ' - ' || SQLCODE;
    err_msg: = SUBSTR (SQLERRM, 1, 500);

    END FUNC_GET_HRCH_TOTAL_DATA;
    /

    Published by: meet_sanc on February 16, 2013 10:42

    Your SELECT statement is almost certainly incorrect

    SELECT *
      FROM ( SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order,ROWNUM ROWNUMBER
               FROM AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
              WHERE A.outputid = B.outputid
                AND A.outputid = C.outputid AND A.outputkey = B.outputkey
                AND A.outputkey = C.outputkey AND A.outputid = outinstrid
                AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
                AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
              ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
     WHERE ROWNUMBER < rownumbereend
       AND ROWNUMBER >= rownumberstart;
    

    Since the ORDER BY is applied after the ROWNUM is assigned in this case, your query is requested for a period of 5000 lines any arbitrariness. It would be perfectly valid for a single line to return in each of your 200 different calls or for a line to return in any of them.

    You definitely want to do something in the sense of the canonical askTom wire

    select *
      from ( select a.*, rownum rnum
               from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
              where rownum <= MAX_ROWS )
     where rnum >= MIN_ROWS
    

    That said, it seems inconceivable that Tibco is unable to manage a cursor that returns more than a certain number of lines. You do a ton of work to return the data pages that are certainly not necessary. Unless you're saying that you somehow paralyzed your installation of Tibco giving him a ridiculously small amount of memory to process, something doesn't look good. A slider is just a pointer - it holds that no data - so the number of lines that you can extract a slider should have no impact on the amount of memory on the client application needs.

    As others have already pointed out, your exception handler is almost certainly do more harm than good. Return the error codes and error messages as from the OUT parameters, instead of simply allowing the exception to propagate deletes a ton of useful information (such as the mistake of the stack) and makes your process much less robust.

    Justin

  • sys_refcursor and Ref Cursor

    Hello

    I found this diffrence between ref and sys_refcursor slider.

    If you specify return_type, then the variables of type and slider REF CURSOR of this type are strong; If not,
    they are weak.
    The variables SYS_REFCURSOR and slider of this type are weak.

    my situation is that I must write a procedure stored so many reports entery pages. little enter pages use typed data groups and can't.

    so please tel me what is the best in terms of performance and maintainability above three conditions?

    Yours sincerely

    944768 wrote:

    my situation is that I must write a procedure stored so many reports entery pages. little enter pages use typed data groups and can't.

    Called stored procedures what and where?

    If, with a layer of app such as Java or .net, then they do not distinguish between weak and strong ref Cursor - because it is a concept of PL/SQL.

    And by using a ref cursor type in PL/SQL is intended to provide a mechanism to pass the handle of real cursor SQL cursor created in this session, the client (for example Java or .net). Nothing more. So, why even care that PL/SQL? a weak or strong Ref to the application layer slider

    so please tel me what is the best in terms of performance and maintainability above three conditions?

    I find always frustrating that there is this concept that some methods to create cursors, results in faster and better than other methods, the sliders. It is a concept of bs. All SQLs are analyzed as a SQL cursors. Each. Unique. One. By the SAME CBO.

    If the client code (Java, PL/SQL or other) you write for this SQL cursor DOES NOT change the source SQL.

    This therefore does not cause the CBO now compile a different SQL execution plan for her. The CBO does not care if your code uses a strong Ref Cursor or a weak Ref Cursor, or a slider DBMS_SQL, an explicit cursor, or whatever. Those are concepts of customer. And do not change the execution plan of cursor SQL on the server. Or its planned performance/cost.

    Yes, your client code (Java, PL/SQL, etc.) can use the SQL cursor on the server-side evil - and this can affect performance.

    But waiting for a weak Ref cursor will somehow cause a faster cursor or slower for the same SQL statement, that a strong Ref cursor is not understanding what SQL cursor is, and how the customer interacts with its data types, the classes of customers and its customer interfaces with this SQL cursor.

  • Ref Cursor as an out parameter.

    Hi all
    Please help me with this.

    It is a small procedure where the ref cursor is used as output parameter.
    create or replace
    PROCEDURE P_REFCURSOR_OUT 
    (P_DEPTNO    IN  EMP.DEPTNO%TYPE,
    P_RECORDSET OUT SYS_REFCURSOR) AS 
    BEGIN 
          OPEN P_RECORDSET FOR
          SELECT EMPNO,
          EMPNM,
          DEPTNO
          FROM   EMP
          WHERE  DEPTNO = P_DEPTNO
          ORDER BY EMPNM;
    END P_REFCURSOR_OUT;
    There is another procedure that calls the procedure above. But during the call, it is throwing an exception that ORA-01722. What's not here? Help, please.
    CREATE OR REPLACE PROCEDURE P_CALL_REFCURSOR_OUT AS
      L_CURSOR  SYS_REFCURSOR;
      L_EMPNM   EMP.EMPNM%TYPE;
      L_EMPNO   EMP.EMPNO%TYPE;
      L_DEPTNO  EMP.DEPTNO%TYPE;
    BEGIN
      P_REFCURSOR_OUT (P_DEPTNO    => 1000,
                  P_RECORDSET => L_CURSOR);
                
      LOOP 
        FETCH L_CURSOR
        INTO  L_EMPNM, L_EMPNO, L_DEPTNO;
        EXIT WHEN L_CURSOR%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(L_EMPNM || ' | ' || L_EMPNO || ' | ' || L_DEPTNO);
      END LOOP;
      CLOSE L_CURSOR;
    END P_CALL_REFCURSOR_OUT;
    Kind regards
    BS2012

    The cursor that you open selects the EMPNO and DEPTNO EMPNM in that order.
    When you retrieve the cursor, you get in L_EMPNM, L_EMPNO, L_DEPTNO.

    It would seem that the first two columns have been inverted in your FETCH statement. Assuming that EMPNO is a NUMBER EMPNM is a VARCHAR2, this means Oracle trying implicitly converted to the EMPNM in a NUMBER that is causing the error.

    If you change the order of the variables in your FETCH statement, the error should disappear

        FETCH L_CURSOR
        INTO   L_EMPNO, L_EMPNM, L_DEPTNO;
    

    Justin

  • The use of bind variables in dynamic query created for Ref Cursor

    Hello

    I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
    The application is currently using literals instead of bind variables.

    code snippet of the above is
    strSql: = "select * from emp where 1 = 1 and ().

    loop cursor1
    If cond is true then
    strSql = strSql | "ename = ' |" Cursor1.ColumnName;
    end loop;

    Open cursor2 for strSql;

    How to use links in the example above.

    sb92075 wrote:

    user13019948 wrote:
    Hello

    Here is the code I have my trying to change literal-based link to the base.

    What do you mean by "based bind?

    who, what, how determines the values to be 'bound '?

    He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.

    If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.

    This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of

    AND t_names(i) = t_values(i)
    

    for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of

    select description from attribute where attribute_id = :b1 and name = :b2
    

    by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).

    declare
       k_sql_base        constant varchar2(500) := 'select description from attribute';
    
       t_names           constant varchar2_t := varchar2_t('attribute_id',  'name');
       t_values          constant varchar2_t := varchar2_t('1012',          'ISIN');
    
       l_sql             varchar2(500) := k_sql_base;
       l_rows_fetched    integer := 0;
       l_value           varchar2(4000);
    
       l_cursor_handle   integer;
    
    begin
       -- Construct the SQL statement with column names and bind variables e.g.
       -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2'
       for i in t_names.first .. t_names.last loop
          l_sql := l_sql ||
             case i
                when t_names.first then ' where ' else ' and '
             end ||
             t_names(i) || ' = :b' || i;
       end loop;
    
       dbms_output.put_line('SQL statment = ' || l_sql); 
    
       -- Parse the statement we built above (the remaining steps require a parsed cursor):
       l_cursor_handle := dbms_sql.open_cursor;
       dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native);
    
       -- Associate the 1st column of output with variable l_value - required for SELECT statements:
       -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string -
       -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different.
       -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.)
       dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000);
    
       -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE)
       for i in t_values.first .. t_values.last loop
          dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i));
          dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i));
       end loop;
    
       -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result):
       l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle);
    
       -- 'Returns value of the cursor element for a given position in a cursor'
       -- Copy the value of column 1 to variable l_value (has to match
       -- dbms_sql.column_value(l_cursor_handle, 1, l_value);
       dbms_sql.column_value(l_cursor_handle, 1, l_value);
    
       dbms_output.put_line('Result = ''' || l_value || '''');
    
       dbms_sql.close_cursor(l_cursor_handle);
    end;
    

    Hope that helps...

  • Ref Cursor help

    Hello


    FOR REC V_LIST LOOPING
    INSERT INTO G_ID_TEMP_COMMON (TC_TYPE, TC_NUMBER_1_COL) VALUES ('T_ID_REPORT_PARM_VALUES', REC KEY);
    END LOOP;


    The above statement a part of the package.

    V_LIST is ref cursor,

    It returns a list of values,

    If place the statement above in the package, it shows error when compiling the package.

    Error:


    Error (17887,2): PL/SQL: statement ignored
    Error (17887,13): PLS-00221: 'V_LIST' is not a procedure or is not defined



    Kind regards
    Fame

    Try this:

    DECLARE
       l_key NUMBER;
    BEGIN
    ...
    LOOP
       FETCH v_list INTO l_key;
       --
       INSERT INTO G_ID_TEMP_COMMON(TC_TYPE,TC_NUMBER_1_COL) VALUES('T_ID_REPORT_PARM_VALUES', l_key);
       --
       EXIT WHEN v_list%NOTFOUND;
    END LOOP;
    ...
    
  • Ref cursor vs dbms_sql

    Hello

    What is the difference between dbms_sql and ref cursor.

    Thank you

    Smidreb wrote:

    What is the difference between dbms_sql and ref cursor.

    Client language interfaces of SQL cursors.

    All SQL are analyzed, stored and runs as sliders (including anonymous PL/SQL blocks). All cursors are equal. In other words, there is no such thing as a ref cursor or implicit cursor or cursor DBMS_SQL in the SQL engine. There are only cursors and they work all the same. There is a standard Oracle Call Interface to create and use and throw sliders.

    On the side of the customer's language (PL/SQL, Java, C/C++, etc.), there are usually a number of interfaces of client language by using the Oracle Call Interface for dealing with the sliders.

    In Delphi for example, there are different classes for different types of sliders (dynamic SQL statements, static SQL on a table, PL/SQL calls, etc.). In PL/SQL, there are also various interfaces in the language for using cursors.

    REF CURSOR is such an interface - with a specific feature to create and analyze the cursor using PL/SQL and then switch this slider handle to an external client language so he could use it.

    DBMS_SQL is a simplistic implementation of the actual Oracle Call Interface for cursors. Lower level stuff - this is basically how it works under the hood when dealing with a slider. Features are dynamic, binding and dealing with dynamically projection SQL cursors. This is widely used by applications such as Apex which deals really dynamic SQL and all aspects of it.

  • Converts the ref cursor effect of function table

    I have a function named fn_get_emp(), whose return type is sys_refcursor. When I select fn_get_emp of double; I get the output to the format of the cursor. I want to convert to the table like format so that I can use in my insert statements insert into foo select * from fn_get_emp();

    Please note that the columns in the output of the fn_get_emp() is not fixed.

    Published by: user10566312 on January 30, 2012 22:25

    Here are the steps in the package DBMS_SQL, you need to turn your Ref Cursor a cursor DBMS_SQL.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25788/d_sql.htm#CHDJDGDG

    and then the rest of the documentation of the DBMS_SQL package gives many examples of how to treat this a cursor dbms_sql.

    Here is an example to use the package dbms_sql to process a request and produce some projection of sql and the database is in the query to CSV file...

    As user sys:

    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    /
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /
    

    As myuser:

    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      --
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    

    This allows the header line and the data to write into files separate if necessary.

    for example

    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    
    PL/SQL procedure successfully completed.
    

    Output.txt file contains:

    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
    

    The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.

    Adapt to the exit of styles and different types of data are needed.

  • return ref cursor

    I want to return ref cursor based on explicit cursors


    create or replace procedure get_extract (in_val in varchar2, return_cursor to sys_refcursor)
    is
    cursor c1 is select * from jumbo.
    cursor c2 is select * from mumbo.

    rec_j jumbo % rowtype;
    rec_m mumbo % rowtype;

    Start

    If in_val = am' then

    Open c1;

    loop
    Fetch c1 in rec_m;
    When exit c1% notfound;
    end loop;

    Open return_cursor SELECT * from rec_m;
    Close c1;

    elsif in_val = 'J' then

    Open c2;

    loop
    extract the c2 in rec_j;
    When the exit c2% notfound;

    end loop;
    Open return_cursor SELECT * from rec_j;
    Close c2;

    on the other

    Open return_cursor select double null.

    end if;

    end;
    /

    When I compile the procedure above, I get the error

    LINE/COL ERROR
    -------- ---------------------------------------------------
    20/24 PL/SQL: statement ignored
    20/38 PL/SQL: ORA-00942: table or view does not exist
    32/24 PL/SQL: statement ignored
    32/38 PL/SQL: ORA-00942: table or view does not exist

    so its occurring in the open return_cursor for... statement, what is the problem with above?

    user650888 wrote:
    I wrote the above and it worked but instead of having a select into the body of the procedure, I love it in an explicit cursor

    You can't do that. The sliders don't work that way. On the closest you could get would be something like:

    SQL> select * from t;
    
            ID DESCR
    ---------- ----------
             1 T One
             2 T Two
    
    SQL> select * from t1;
    
            ID DESCR
    ---------- ----------
             1 T1 One
             2 T1 Two
    
    SQL> create or replace procedure get_extract(in_val in varchar2,
      2                               return_cursor out sys_refcursor) is
      3     l_cur_m varchar2(100) := 'select * from t';
      4     l_cur_j varchar2(100) := 'select * from t1';
      5  begin
      6     if in_val = 'M' then
      7        open return_cursor for l_cur_m;
      8     elsif in_val = 'J' then
      9        open return_cursor for l_cur_j;
     10     else
     11        open return_cursor for select null from dual;
     12  end if;
     13  end;
     14  /
    
    Procedure created.
    
    SQL> var cur refcursor;
    SQL> exec get_extract('M', :cur);
    
    PL/SQL procedure successfully completed.
    
    SQL> print cur
    
            ID DESCR
    ---------- ----------
             1 T One
             2 T Two
    
    SQL> exec get_extract('J', :cur);
    
    PL/SQL procedure successfully completed.
    
    SQL> print cur
    
            ID DESCR
    ---------- ----------
             1 T1 One
             2 T1 Two
    

    John

  • Ref Cursor and type

    Hi all

    I finally got the job of procedure stored Ref Cursor but am stuck on the following. I have this package body:

    CREATE OR REPLACE PACKAGE BODY PACK_MYCURSOR AS
    PROCEDURE REFCUR)
    theuserid IN OUT users.user_id%type,
    UserFirstName to users_TableRows) IS
    BEGIN
    OPEN FOR UserFirstName
    Select * from users
    Where user_id = theuserid
    ;
    END REFCUR;
    END PACK_MYCURSOR;
    /

    Now it works fine, but I need to have fields of explisit in the select statement, such as "select user_id from users", but when I do that then I would get the error messages of "expression is of the wrong type." Someone knows how to fix this?

    Thank you.

    Declare your as WEAK rather than STRONG type ref cursor. In other words, do not specify return rowtype % ROWTYPE in your statement in the specification.

    Declare that:
    TYPE users_TableRows IS REF CURSOR;

    Phil

  • CURSOR IS DIFFERENT FROM REF CURSOR?

    Hello
    Is the "cursor" and "ref cursor" both are different? What is the difference between them?

    Johan says:
    Yes, they are different, and the http://www.oracle.com/pls/db112/portal.all_books said all the differences.

    In fact, I'd say "Yes" and «»

    Ref Cursor and sliders are two pointers to a query as all queries are the sliders. They are both the same in this regard.
    However, how they are used, that is what makes them different. A single select statement is a slider that is implicitly opened, recovered and closed all in one action. A cursor defined in PL/SQL in contrast be implicitly open, recovered and closed (in the case of a loop FOR) or explicitly open, recovered and closed (in the case of an OPEN, FETCH... CLOSED... loop). A Ref Cursor is always explicitly open, closed and recovered, usually are opened within PL/SQL and then recovered and closed in another language such as .NET or Java. Very rarely a Ref Cursor would be used only in PL/SQL because there is really no need for them there. There are also sliders are defined using the package DBMS SQL which is very explicitly defined, parsed and executed (which is the same as OPEN) and then recovered and closed.

    All queries are the sliders, just how you access is different.

  • REF Cursor with search string

    Hello all,.

    I'm trying to implement a procedure that returns records in the hr.employees table when search strings are passed.

    Here is the package:
    create or replace package search_app 
    IS
    --
    TYPE emp_rec IS RECORD (last_name     hr.employees.last_name%TYPE
                                         ,first_name    hr.employees.first_name%TYPE
                                         ,job_id        hr.employees.first_name%TYPE
                                         ,salary        hr.employees.salary%TYPE
                                         ,dept          hr.departments.department_name%TYPE
                                         );
    --
    TYPE emp_curs  IS REF CURSOR RETURN emp_rec;
    --
    PROCEDURE  get_employees (p_last_name_search   IN  hr.employees.last_name%TYPE
                                             ,p_first_name_search  IN  hr.employees.first_name%TYPE
                                             ,p_job_id_search      IN  hr.employees.job_id%TYPE
                                             ,pr_emps              OUT emp_curs
                                             ,p_error              OUT VARCHAR2
                                             );
    --
    END search_app;
    /
    --
    create or replace package body search_app
    IS
    --
    PROCEDURE get_employees (p_last_name_search    IN  hr.employees.last_name%TYPE
                                            ,p_first_name_search  IN  hr.employees.first_name%TYPE
                                            ,p_job_id_search      IN  hr.employees.job_id%TYPE
                                            ,pr_emps              OUT emp_curs
                                            ,p_error              OUT VARCHAR2
                                            )
    IS
    --
      v_last_name_search       hr.employees.last_name%TYPE;
      v_first_name_search       hr.employees.first_name%TYPE;
      v_job_id_search             VARCHAR2(100);
      v_error_msg                  VARCHAR2(200);
    --
    BEGIN
    --
      OPEN  pr_emps FOR
    --
          SELECT e.last_name
                     ,e.first_name
                     ,e.job_id
                     ,e.salary
                     ,d.department_name as dept
          FROM hr.employees    e
                  ,hr.departments d
          WHERE (e.first_name LIKE p_first_name_search
                       AND
                     --OR   
                      e.last_name  LIKE p_last_name_search
                       AND 
                    --OR  
                       e.job_id     IN   p_job_id_search
                     )
          AND    d.department_id = e.department_id;
    --
        p_error := v_error_msg;
    --
    EXCEPTION
    --
    WHEN OTHERS THEN
       v_error_msg := SUBSTR(SQLERRM,1,200);
    END get_employees;
    --
    END search_app;
    /
    sho error
    
    ---
    here is the stub I am using to test.
    --
    set serveroutput on size 1000000
    spool search_app_OR.log
    --
    DECLARE
    --
      v_first_name_search     hr.employees.first_name%TYPE;
      v_last_name_search      hr.employees.last_name%TYPE;
      v_job_id_search           VARCHAR2(100);
      my_emps                    search_app.emp_curs;
    --
      v_first_name            hr.employees.first_name%TYPE;
      v_last_name             hr.employees.last_name%TYPE;
      v_job_id                  VARCHAR2(100);
      v_salary                   hr.employees.salary%TYPE;
      v_dept_name           hr.departments.department_name%TYPE;
      v_error_msg             VARCHAR2(200);
    --
      v_count                   PLS_INTEGER;
    --
    BEGIN
    --
        v_first_name_search := '%';
        v_last_name_search  := 'De%';
    --        v_job_id_search := '%';
        v_job_id_search     := chr(40)||chr(39)||'AD_VP'||chr(39)||','||chr(39)||'SH_CLERK'||chr(39)||chr(41);
    
    --
         search_app.get_employees(p_last_name_search   => v_last_name_search
                                 ,p_first_name_search  => v_first_name_search
                                 ,p_job_id_search      => v_job_id_search
                                 ,pr_emps              => my_emps
                                 ,p_error              => v_error_msg
                                  );
    --
         LOOP
    --
            FETCH my_emps INTO v_last_name, v_first_name,v_job_id, v_salary, v_dept_name;
                EXIT when my_emps%NOTFOUND;
    --
            DBMS_OUTPUT.PUT_LINE ('...last_name : '||v_last_name);
            DBMS_OUTPUT.PUT_LINE ('...first_name: '||v_first_name);
            DBMS_OUTPUT.PUT_LINE ('...job_id    : '||v_job_id);
            DBMS_OUTPUT.PUT_LINE ('...salary    : '||v_salary);
            DBMS_OUTPUT.PUT_LINE ('...dept      : '||v_dept_name);
            DBMS_OUTPUT.PUT_LINE ('...error_msg : '||v_error_msg);
    --
         END LOOP;
    --
         v_count := my_emps%ROWCOUNT;
    --
         CLOSE my_emps;
    --
            DBMS_OUTPUT.PUT_LINE ('v_last_name_search : '||v_last_name_search);
            DBMS_OUTPUT.PUT_LINE ('v_first_name_search : '||v_first_name_search);
            DBMS_OUTPUT.PUT_LINE ('v_job_id_search       : '||v_job_id_search);
            DBMS_OUTPUT.PUT_LINE ('num rec fetched      : '||v_count);
    --
     EXCEPTION
         WHEN OTHERS THEN
           v_error_msg := SUBSTR(SQLERRM,1,200);
           DBMS_OUTPUT.PUT_LINE ('error: '||v_error_msg);
    END;
    /
    spool off
    The results I get are as follows:

    When I OR in the request for get_employees for search parameters, 106 records are returned.

    When I AND in the application, not of records returned is 0. It should return 2 records. Why is it not return all records? Any suggestion on how this procedure should be applied?

    Thank you

    Raman

    Published by: rxshah on June 8, 2010 12:52 AM

    Hello

    The problem is that you try to implement a dynamic list in a static SQL statement:

    job_id IN '(''AD_VP'',''SH_CLERK'')'
    

    It will not work like that.

    Check out these links for some tips:
    http://tkyte.blogspot.com/2006/06/varying-in-lists.html
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:1242571115131928:P11_QUESTION_ID:110612348061

  • Return of the ref cursor of procedure where the cursor is defined in the specification

    Hello

    Here's pseudo-code

    create or replace package test
    as
    cursor c_emp (number cv_emp_id)
    is
    Select emp_name emp where emp_id = cv_emp_id;

    type ref_c is ref cursor;

    function get_emp_name (number p_emp_id) return ref_c;
    end test;
    /


    create or replace the test physics package
    as
    ref_c function get_emp_name (number p_emp_id)
    is
    ret_val ref_c;
    Start
    Open c_emp (p_emp_id);
    ret_val: = c_emp;
    return ret_val;

    end get_emp_name;
    end test;
    /

    Returns me "PLS-00382: expression is of the wrong type. I tried to use a strongly typed Ref cursor based on the cursor, but nothing helped.

    Clearly, I understand something... and if I can't assign as ' ret_val: = c_emp "and if there is another key way it so please let me know.

    Thank you

    Ralph

    Published by: user13024707 on May 5, 2010 04:43

    user13024707 wrote:
    Clearly the point of my question is being missed.

    Or maybe the question is not been clearly asked. ;)

    I want to set the cursor in the PACKAGE SPECIFICATION, and not in the package body. The issue of the bind variable and the string is neither here nor there because I pass parameters to the cursor.

    What you ask is to use a PL/SQL cursor (defined in the specifications of the package or elsewhere) and that convert a Ref Cursor. N ° cannot be done.
    PL/SQL cursors should be used in the PL/SQL code. REF CURSOR is primary used to pass back a reference to a cursor (and all queries are cursors) to a layer of application outside of PL/SQL for example .net, java, etc.. Once you start using the ref Cursor only really, you have the choice of opening it based on a (dynamic) or a fixed query string as in the examples given. You cannot open a cursor of a PL/SQL cursor definition Ref.

    The difference is that when you do:

      CURSOR cur_mycursor IS
        SELECT ...
    

    you declare a cursor in pl/sql definition, not actually a slider itself. The cursor itself is created when you issue an OPENING or a statement FOR etc. So a Ref Cursor (reference to a slider) cannot refer to the definition of the cursor because it is only a definition, not a cursor (i.e. it has not been sent engine sql and instantiated at that time here). Instead the Ref Cursor must reference a cursor (query), itself, and that may be presented as a string or as the query itself that is issued against the sql engine and then the ref cursor points

    Thus, slider ref and PL/SQL cursors are different concepts, both designed to manage cursors in a slightly different way of programming. You cannot mix them.

Maybe you are looking for

  • Fails to sync iPad Mini 2

    . For three days, I was unable to sync my iPad with iTunes. It is very important that I do now, I know, I get a new iPad for Christmas and I ant to be able to transfer all the data and applications. I plugged my iPad to the computer, and everything s

  • Why do I receive flag showing that I have a problem and insert the disc. but nothing shows

    Why do I get a red flaag showing I have a problem and to insert the blank disc aa, what I do, but the flag persists?

  • error when you try to upload photos on facebook

    In the Gallery of photos, when I click on the facebook icon and enter my Microsoft ID and password the next thing that happens is that a box appears on the screen with the following message: Could not load file or assembly 'System.web, Version = 4.0.

  • Webform planning activity log

    Hi allwhere can I find a journal that contains the activity to submit data through the Hyperion Planning webform?I already have SSAUDIT Setup for this application logs but you don't see any useful information there.Thanks for the help in advance!Kind

  • How to get table relationships in the Data Transformation Scripts shape 4.1 Custom DDL?

    HelloI work on a Transformation custom DDL Script and came across a problem.Because the documentation is not really good, I have not come again a response.When handling a table, it is possible to find the FK column and referenced table. It is also fa