Open cursor for ...using...

Hi all
1 general question- can someone explain me how 'using keyword in 'open cursor for ...' statement works.
Does it replace where clause and how?
open cur_xx for qry_xxx using text_xxx
where 'text_xxx' is going to be my codition in select statement
Tahnks everyone

http://oraclesvca2.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems35.htm

Similar Messages

  • PDE-PLI038 Cannot open file for use as a PL/SQL library

    Hi,
    We are using oracle 12 .0.4 on RHAS 4
    I am trying to compile a .pll file with the following code
    frmcmp_batch module=$AP_TOP/patch/115/sql/apacrndb.pls userid=apps/apps module_type=LIBRARY;
    but it's returning the error
    PDE-PLI038 Cannot open file for use as a PL/SQL library
    Thanks
    Umair

    Umair,
    What is the issue about?
    Usually, it would be required to run the pls files to recreate certain objects (mainly packages) in the database, and you run the pls file from SQL*Plus as apps/applsys user.
    Please update the SR and confirm with Oracle Support what the action plan you need to follow to resolve the issue.
    Regards,
    Hussein

  • Open cursor for a dynamic query

    Hi,
    I'm using forms6i and db 10g
    I want to create a procedure like below
         PROCEDURE pop_cursor (generic_cur IN OUT gencurtyp, querystring varchar2) IS
         BEGIN
              OPEN generic_cur FOR querystring;
         END;where generic_cur is a Ref Cursor and querystring will contain a query statement like 'select col1... from table1'
    The above way i'm not able to do that, i'm getting error
    Encountered the symbol 'QUERYSTRING' when expecting on of the following:
    select
    Is there any alternative??
    Please help

    You can only use that sort of dynamic sql in the database. maybe you can return the ref cursor to the form from a db-function, i don't know if it works in forms 6i.
    But you could tell us your requirement, maybe you can implement it without these dynamic things.

  • Open cursor for internal table

    Hi folks,
    I have a tricky question concerning the cursor function and internal tables. First of all, it is not possible to create a view. Instead I've to use a function module for extracting some data to the BI system.
    Actually most of the time I work with SELECT (for outer joins) and internal tables. At the end I have a internal table and must open an cursor. As fact, I can't open a cursor for an internal table - only database tables are allowed.
    OPEN CURSOR WITH HOLD s_cursor FOR SELECT * FROM lt_temp.
    Does someone have a clue how to solve my problem? Obviously I have to use a db table for a open cursor statement but on the same way I have to use a internal table for all my previous SELECT-statements.
    Thanks in advance for your help.
    Regards,
    Mrcl

    Why don't you use EXEC and ENDEXEC
    Check this link
    http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3b8b358411d1829f0000e829fbfe/content.htm

  • How to analyse the number of open cursors being used by each program?

    Hi,
    I am getting an error "ORA:1000 Maximum Open Cursors Exceeded" in my
    application. I want to analyse and monitor that how many cursors are
    being used  by each program running in a particular session. I have
    already set the Open Cursors Count double of the recommended for my
    application, yet I am getting this error.
    Is there any tool to analyse and monitor the number of cursors being
    used by each DB call?
    I have installed SAP NW 7.0 and Using Oracle 10g as DB.
    Your immediate help will be greatly appreciated.
    Best Regards,
    Smriti.

    You can list the open cursors per session and check which one uses the most with sqlplus:
    SQL> select a.value, s.username, s.sid, s.serial#
    from v$sesstat a, v$statname b, v$session s
    where a.statistic# = b.statistic#  and s.sid=a.sid
    and b.name = 'opened cursors current';
    Values over 300 are unusual.
    It is quite possible, that you see several workprocesses using a lot, because workprocesses are kind of shared sessions.
    Cheers Michael
    Edit: ah, our posts crossed, obviously there is no workprocess in the java world

  • Open cursor for and bind variables

    Hello all,
    how can I assign values to a bind variable before opening a cursor?
    example code:
    DECLARE
       TYPE ref_cur_t IS REF CURSOR;
       l_ref_cur   ref_cur_t;
       l_query VARCHAR2 (100)
             := 'select * from table t1 where ndx= :var_index' ;
    BEGIN
       -- assign a value to :var_index
       OPEN l_ref_cur FOR l_query;
    END;Thanks!

    Something like this ->
    scott@ORCL>
    scott@ORCL>DECLARE
      2     l_ref_cur   sys_refcursor;
      3     l_query VARCHAR2 (100) := 'select * from emp where empno = :var_index';
      4     l_empno  number(4);
      5  BEGIN
      6     l_empno := &emno;
      7     -- assign a value to :var_index
      8     OPEN l_ref_cur FOR l_query using l_empno;
      9  END;
    10  /
    Enter value for emno: 7698
    old   6:    l_empno := &emno;
    new   6:    l_empno := 7698;
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:19.78
    scott@ORCL>Regards.
    Satyaki De.

  • Open Cursor for insert actually inserts

    Have been using code similar to this to prepare an SQL insert
    statement before entering a loop to perform the inserts. Find
    that the open actually performs an insert when it is executed,
    so the table always has an extra row of garbage.
    Is there some way to stop this behaviour? ProC compiler option
    or open parameter. Currently I am doing a ROLLBACK after the
    open to clear it.
    Using the prepare because the table name is not known at compile
    time.
    EXEC SQL AT DB_1 PREPARE insert_cust FROM :szSqlInsertCustomer;
    EXEC SQL AT DB_1 DECLARE insert_cust_cursor CURSOR FOR insert_cust;
    EXEC SQL AT DB_1 OPEN insert_cust_cursor USING :customerId;
    for ( ....)
    customerID = ...;
    EXEC SQL AT DB_DCMS EXECUTE insert_cust;
    Also tried passing in the tablename as a host variable
    EXEC SQL INSERT INTO :szTableName (CUSTOMER_ID) VALUES (:customerId);
    ProC compiler gives the following error:
    INSERT INTO :szTableName (CUSTOMER_ID) VALUES (:customerId);
    ........................1
    PCC-S-02201, Encountered the symbol ":" when expecting one of the following:
    ( an identifier, a quoted string, date, table, count,
    extract, interval, multiset, the, time, timestamp, treat,
    trim, avg, max, min, sum, stddev, variance,
    Thanks

    You don't DECLARE and OPEN an insert statement (just selects). Just use EXECUTE ... USING ...

  • Open cursor for string and select from partition (cannot bind)

    Hi,
    i don't manage to use a bind variable for a select ... from ... PARTITION(...).
    It doesn't work to use something like
    open cur for 'select ... from ... PARTITION(:1) where ...' using 'NDAY_20120301';So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    Doesn't that prevent from re-use in library_cache?
    best regards,
    Frank

    >
    So i have to create the cursor string with string functions each time i change the partition.
    But that means, that the string changes each time.
    >
    Yes it does.
    Doesn't that prevent from re-use in library_cache?
    >
    Yes it does.
    So why do you care? Unless you have large numbers of partitions what difference does it make? Bind variables are useful to keep Oracle from doing hard parses of queries that are basically the same but use different filter values. Such as an INSERT statement that uses different values FOR EACH ROW rather
    You are just constructing the main (non-filter) part of the query one time and need a single value for the entire query regardless of how many rows - that isn't really a use case for bind variables and isn't going to provide any real benefit.
    So the real question is why do you even care about something that wouldn't provide any benefit to you even if you could do it?
    Looks like you just want to 'roll your own' parallel processing rather that use, and pay for, Oracle's parallel functionality.
    If each partition uses its own tablespace you could filter on the FILE Id of the ROWIDs since the file number will be different for each tablespace and datafile.
    1. Determine the list of file numbers for each partitions tablespace.
    2. Use a WHERE DBMS_ROWID.ROWID_RELATIVE_FNO (ROWID) = :n filter (or use IN (:n1, :n2))to filter rows based on file number(s) for the partition you want
    See DBMS_ROWID.ROWID_RELATIVE_FNO in the PL/SQL Packages and Types doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_rowid.htm#i1004259

  • Open cursor for PLSQL table of records

    Is it possible to open a cursor for all data in a PLSQL table of records?
    something like
    cursor c (p1 number) is select * from <plsqltab>
    where <plsqltab>.col = p1

    There is no such thing as a PL/SQL table. Yes, I know that many calls this structure in PL/SQL a table. And that is exactly where all this confusion stems from.. and trying to treat such a "table" as an Oracle table using SQL.
    The correct terms are dynamic array (indexed by integer) or dynamic associative array (indexed by varchar). And an array is nothing like a table ito RDBMS processing.
    Yes, you can run SQLs against arrays. But it is "expensive". Why? Because the data sits inside PL/SQL Engine. Not in the SQL Engine. The data is in a PL/SQL defined structure. Not a SQL defined structure.
    So.. the data needs to be shipped from the PL/SQL Engine to the SQL Engine and converted into a format that the SQL Engine can understand and use.
    Also, once shipped and converted the SQL structure is not indexed. Which means that the only option is a full table scan of that structure.
    So you need to ask yourself why do you want to use SQL against a PL/SQL array? As soon as you do that, you are saying "Hey, this PL/SQL table ain't good enough and I need to process it using SQL".
    So why then does that data sit inside a PL/SQL array and not in a SQL table?
    Oracle provides you with the ability to create temporary session tables. These can be indexed. SQL can be run against them without all the "expenses" that are associated with running SQL against a PL/SQL array.
    PL/SQL arrays is a great tool. But only when it is the right tool to use. When someone says he/she needs SQL to use this tool, then I question the choice of the tool. Make sure you use the right tool for the job.

  • OPEN cursor for large query

    OPEN cursor
    When you OPEN a cursor for a mult-row query, is there a straightforward way that you can have it only retrieve a limited number of rows at a time and then automatically delete those rows as you do the FETCH against them? I'm thinking of setting up multiple sequential cursors, and opening and closing them as the rows are processed. But I'm hoping there might be a better way.
    The problem is that I'm running out of TEMPORARY during the OPEN cursor stage.
    The application I am working on needs to work in Standard Edition and Personal Edition versions of Oracle.
    Thank you.

    Thanks - I had read the documentation before, but interpreted it differently.
    What I had read was in:
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#i45288
    The extract of interest was:
    Opening a Cursor
    Opening the cursor executes the query and identifies the result set, which consists of all rows that meet the query search criteria. For cursors declared using the FOR UPDATE clause, the OPEN statement also locks those rows. An example of the OPEN statement follows:
    DECLARE
    CURSOR c1 IS SELECT employee_id, last_name, job_id, salary FROM employees
    WHERE salary > 2000;
    BEGIN
    OPEN C1;
    Rows in the result set are retrieved by the FETCH statement, not when the OPEN statement is executed.
    My interpretation was that the result of the query was put into the temporary tablespace and then retrieved into the program during the FETCH.
    Assuming I was wrong, what I'm wondering now is how I can possibly be running out of temporary space during this OPEN cursor process.

  • Open cursor for dynamic sql

    Hi
    I am using oracle 8.1.7 on solaris.
    I have created
    SQL> CREATE OR REPLACE PACKAGE TEST_PKG AS
    2 TYPE row_cursor IS REF CURSOR RETURN TEMP_TAB%ROWTYPE;
    3 PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor);
    4 END TEST_PKG;
    5 /
    Package created.
    now i am trying to create the procedure Return_Columns_proc by
    CREATE OR REPLACE PACKAGE BODY TEST_PKG AS
    PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor) AS
    QUERY_STR VARCHAR2(850);
    x number ;
    BEGIN
    x:=1;
    QUERY_STR :='SELECT * FROM temp_tab where order_line_id = '||x;
    OPEN c_return FOR QUERY_STR;
    END Return_Columns_proc;
    END TEST_PKG;
    I am getting following error.
    SQL> show error
    Errors for PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    8/4 PL/SQL: Statement ignored
    8/9 PLS-00455: cursor 'C_RETURN' cannot be used in dynamic SQL OPEN
    statement
    any help for this error.

    The error says it all. You have defined a strong ref cursor and it cannot be used with dynamic sql. However, that does not mean you cannot use the query directly in the OPEN clause
    OPEN c_Return FOR SELECT * FROM temp_tab where order_line_id = X ;

  • Procedure Problem - Open Cursor for SQL

    in my form I added a procedure. this is working fine in SQL but when I try to run through form it gives error.
    Code of Procedure:-
    PROCEDURE Proc_Purchase_all IS
    BEGIN
      declare
         v_sql varchar2(4000);
         v_user varchar2(30);
         v_sep varchar2(20);
         v_cur SYS_REFCURSOR;
       pur_rec    purchase%ROWTYPE;
       begin
         for u in (SELECT * FROM ALL_TABLES WHERE OWNER LIKE 'BMP%' and table_name ='PURCHASE') loop
           v_sql := v_sql || v_sep || 'SELECT * from '||u.owner||'.purchase';
          v_sep := ' UNION ALL ';
        end loop;
        open v_cur for v_sql;
      Loop
      Fetch v_cur into pur_rec;
      Exit when v_cur%NOTFOUND;
      --DBMS_OUTPUT.PUT_LINE (PUR_REC.S_CODE||' '||Pur_rec.s_name);
      End Loop;
        close v_cur;
    end;
    END;Error Line
    * open v_cur for v_sql;*
    Error is :-
    Encountered the symbol 'V_SQL' when expecting one of the following.
    select
    Encountered the symbol END when expecting one of the following.
    Begin function package pragma procedure external

    I changed my code ALSO Showing SAME error .
    SQL> Declare 
      2    v_sql varchar2(4000);
      3       v_user varchar2(30);
      4       v_sep varchar2(20);
      5    TYPE R_CURSOR IS REF CURSOR RETURN purchase%ROWTYPE;
      6       C_Pur R_CURSOR;
      7       ER C_pur%ROWTYPE;
      8       BEGIN
      9    for u in (SELECT * FROM ALL_TABLES WHERE OWNER LIKE 'BMP%' and table_name ='PURCHASE') loop
    10         v_sql := v_sql || v_sep || 'SELECT * from '||u.owner||'.purchase';
    11        v_sep := ' UNION ALL ';
    12      end loop;
    13   OPEN C_Pur FOR V_sql;
    14       LOOP
    15       FETCH C_Pur INTO ER;
    16      EXIT WHEN C_Pur%NOTFOUND;
    17    
    18      END LOOP;
    19      CLOSE C_Pur;
    20     END; 
    21  /
    OPEN C_Pur FOR V_sql;
    ERROR at line 13:
    ORA-06550: line 13, column 7:
    PLS-00455: cursor 'C_PUR' cannot be used in dynamic SQL OPEN statement
    ORA-06550: line 13, column 2:
    PL/SQL: Statement ignoredEdited by: Ahmed on Jan 13, 2011 1:58 AM

  • Open cursor for existing procedure

    Is it possible to open a refcursor for an existing procedure as apposed to opening a refcursor for a standard select statement. For example:
    Standard select:
    OPEN refcursor FOR
    select * from my_table;
    RETURN the_cursor;
    Based on an existing procedure:
    OPEN refcursor FOR
    my_package.my_procedure();
    RETURN the_cursor;
    Note: my_procedure returns a table of record type rows defined by myself in the package spec.
    Any help is much appreciated
    Regards
    Tony

    Hi Sven
    Thank you for that information however I am still a little unsure as to how to call the procedure including the necessary parameters. The procedure in question has the following IN parameters with one OUT parameter.
    my_procedure (p_context_id in number,
    p_username in varchar2,
    p_mdata out mtab)
    As you stated, if it is a procedure, which it is, then use the following:
    my_package.my_procedure(the_cursor);
    However if I need to pass parameters in the call that kind of conflicts where 'the_cursor' is?
    Any ideas?
    Tony

  • Open cursor for a nested table

    Hi,
    I want to open a cursor like:
    open c1 for select * from emp;
    BUT
    I what the cursor results to be populated with contents of a nested table or associative array..
    How can this be done???
    Thanks in advance,
    teo

    Well, given a variable YOUR_EMP of nested table type EMP_NT it could be as simple as
    open c1 for select * from TABLE( CAST(your_emp AS emp_nt));Cheers, APC

  • SELECT DISTINCT With OPEN cursor FOR

    Hello.
    I have the following procedure. All it does is open a cursor for an SQL string passed into it, and return the open cursor.
    PROCEDURE sp_execute_dynamic (hold_input_string IN CLOB,
    hold_cursor OUT hold_cursor_type) IS
    BEGIN
    OPEN hold_cursor FOR TO_CHAR(hold_input_string);
    END sp_execute_dynamic;
    It works fine except when I perform SELECT DISTINCT. I get the following error.
    SQL> declare
    2 TYPE hold_cursor_type IS REF CURSOR;
    3 hold_cursor hold_cursor_type;
    4 hold_object_name VARCHAR2(1024);
    5 hold_object_type VARCHAR2(1024);
    6 begin
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    10 exit when hold_cursor%NOTFOUND;
    11 dbms_output.put_line('Object Name = '||hold_object_name||' Object Type = '||hold_object_type);
    12 end loop;
    13 end;
    14 /
    declare
    ERROR at line 1:
    ORA-01007: variable not in select list
    ORA-06512: at line 9
    It does the same thing with SELECT UNIQUE or SELECT with a GROUP BY. Can anyone tell me why this happens and what I could to to work around it?
    Thanks
    Chris

    see at line 7 you are selecting only one column and at line 9you are fetching into two variables
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    HTH

Maybe you are looking for