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

Similar Messages

  • 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

  • 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 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 in a procedure

    Hi to all,
    my problem is to open a cursor into a procedure.
    The code is the following:
    PROCEDURE p_selection_customer
    IS
         CURSOR cursor_customer IS
              SELECT
              c_u.id_customer
              FROM
              customer_unified_a c_u;
         BEGIN
              FOR record_customer IN cursor_customer LOOP
                   ROLLBACK;
              END LOOP;
    END p_selection_customer;
    The error is :
    Errore(55,3): PL/SQL: SQL Statement ignored
    Errore(58,3): PL/SQL: ORA-06552: PL/SQL: Compilation unit analysis terminated ORA-06553: PLS-320: the declaration of the type of this expression is incomplete or malformed
    This procedure is defined in the spec. Then I suppose that my problem is that I can't open a cursor into my schema. Do I verify this hypotesys in my schema? Do I have some queries? My schema don't have the dba and sys grants.
    Thank'you very match!

    Hi Alex,
    this is the complete script used to generate the table.
    Me too, I knew that the partition was transparent to the Cursor statement.
    Thank'you very match!
    CREATE TABLE "SSVILCID"."TW_E_CUSTOMER_UNIFIED_A"
       (     "ID_CUSTOMER_UNIFIED" VARCHAR2(27 BYTE) NOT NULL ENABLE,
         "START_VALIDITY_DATE" DATE NOT NULL ENABLE,
         "START_ASINC_DATE" DATE NOT NULL ENABLE,
         "END_ASINC_DATE" DATE,
         "CUSTOMER_STATUS" VARCHAR2(255 BYTE),
         "TERMINATION_DATE" DATE,
         "CUSTOMER_DOMAIN" VARCHAR2(255 BYTE),
         "CUSTOMER_CLUSTER" VARCHAR2(255 BYTE),
         "CUSTOMER_SENIORITY" DATE,
         "ACTIVATION_DATE" DATE,
         "ACQUISITION_DATE" DATE,
         "ACQUISITION_CHANNEL" VARCHAR2(255 BYTE),
         "SUB_ACQUISITION_CHANNEL" VARCHAR2(255 BYTE),
          CONSTRAINT "TW_E_CUSTOMER_UNIFIED_A_PK" PRIMARY KEY ("START_ASINC_DATE", "ID_CUSTOMER_UNIFIED", "START_VALIDITY_DATE")
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "SYSTEM"  ENABLE
       ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
      PARTITION BY RANGE ("START_ASINC_DATE")
      SUBPARTITION BY LIST ("END_ASINC_DATE")
    (PARTITION "M200909"  VALUES LESS THAN (TO_DATE(' 2009-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
    ( SUBPARTITION "M200909_N"  VALUES (NULL)
       TABLESPACE "DATI",
      SUBPARTITION "M200909_NN"  VALUES (DEFAULT)
       TABLESPACE "DATI") ,
    PARTITION "M200910"  VALUES LESS THAN (TO_DATE(' 2009-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
    ( SUBPARTITION "M200910_N"  VALUES (NULL)
       TABLESPACE "DATI",
      SUBPARTITION "M200910_NN"  VALUES (DEFAULT)
       TABLESPACE "DATI") ,
    PARTITION "M200911"  VALUES LESS THAN (TO_DATE(' 2009-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
    ( SUBPARTITION "M200911_N"  VALUES (NULL)
       TABLESPACE "DATI",
      SUBPARTITION "M200911_NN"  VALUES (DEFAULT)
       TABLESPACE "DATI") ,
    PARTITION "M200912"  VALUES LESS THAN (TO_DATE(' 2010-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
    ( SUBPARTITION "M200912_N"  VALUES (NULL)
       TABLESPACE "DATI",
      SUBPARTITION "M200912_NN"  VALUES (DEFAULT)
       TABLESPACE "DATI") ,
    PARTITION "M201001"  VALUES LESS THAN (TO_DATE(' 2010-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
    ( SUBPARTITION "M201001_N"  VALUES (NULL)
       TABLESPACE "DATI",
      SUBPARTITION "M201001_NN"  VALUES (DEFAULT)
       TABLESPACE "DATI") ,
    PARTITION "M201002"  VALUES LESS THAN (TO_DATE(' 2010-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
    ( SUBPARTITION "M201002_N"  VALUES (NULL)
       TABLESPACE "DATI",
      SUBPARTITION "M201002_NN"  VALUES (DEFAULT)
       TABLESPACE "DATI") ,
    PARTITION "FUTURE"  VALUES LESS THAN (MAXVALUE)
    PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
      STORAGE(
      BUFFER_POOL DEFAULT)
      TABLESPACE "DATI"
    ( SUBPARTITION "M210001_N"  VALUES (NULL)
       TABLESPACE "DATI",
      SUBPARTITION "M210001_NN"  VALUES (DEFAULT)
       TABLESPACE "DATI") )  ENABLE ROW MOVEMENT ;

  • 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 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 ;

  • 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

  • Ref cursors for stored procedure

    Hi every body,
    I am new one,I am in learning stage.
    My java developer was ask me give set of results.
    i am using in my code sys_refcursor, my questions are.
    SQL> create or replace procedure sysref(p_out out sys_refcursor) is
    2 begin
    3 open p_out for select empno,ename from employee;
    4 end;
    5 /
    I am using the procedure like above procedure.
    1) How to use ref cursors in procedure. what is the main use.
    2) How to close ref cursors in procedure.If it is need.
    3) How to use exceptions in procedures for ref cursors.
    Give me one example with complete structure.
    Please help me
    new one
    Edited by: subba on Aug 19, 2010 12:08 AM
    Edited by: subba on Aug 19, 2010 12:09 AM

    subba wrote:
    1) How to use ref cursors in procedure. what is the main use.All SQL in Oracle are parsed as cursors in the Shared Pool. The client code (be that PL/SQL or Visual Basic or Java) gets a handle or reference to this SQL cursor on the server.
    Using this handle, the client can fetch rows using the cursor (the cursor is like a program - the executable binary version of the source SQL code).
    Clients implement their interfaces with this SQL cursor handle in different ways. PL/SQL alone supports:
    - implicit cursor handles
    - explicit cursor handles
    - DBMS_SQL cursor handles
    - reference cursor handles
    Why so many? Different tools for different jobs. Each has its pros and cons and each is suited for specific (and different) types of problems.
    A ref cursor is special in that PL/SQL can pass this SQL cursor reference handle to an external client to use - like Java.
    Why?
    The basic concept is that of abstraction. Removing the complexities of SQL and the database design and SQL optimisation from the Java code. Instead, Java calls a PL/SQL proc. This proc creates the SQL cursor, and uses a reference cursor variable to store the SQL cursor handle. It can then pass this to Java. This means that the entire SQL is encapsulated in the PL/SQL proc. We can now modify it, optimise it, support data models changes in the database via the PL/SQL proc... all without even having to recompile the Java code that makes the call and consumes the ref cursor the PL/SQL proc gives it.
    2) How to close ref cursors in procedure.If it is need.Yes. A very important factor - well spotted.
    As PL/SQL can pass ref cursors to external clients. it does not automatically close these cursors. It does not know when the client has consumed the cursor. It will only close it when the cursor is still open, when the Oracle server session is terminated.
    So it is important that the client (Java in this case) closes the cursor when done. If not, the cursor will remain open, will continue to occupy server resources... and if the client opens more and more of these cursors, the server process will run out of resources.
    Cursor leakage by Java developers are common - and can simply be avoided by closing the cursor once the Java code has consumed it.
    3) How to use exceptions in procedures for ref cursors.No. Why? Why would you want to deal with the exception in a PL/SQL proc? The Java code wants to open that cursor. It knows why. It knows what to do when that cursor fails or is empty. It interacts with the user. How is the PL./SQL proc, whose only function is to construct the SQL and pass the cursor handle to Java, to know any of this?
    Exceptions in this regard should typically be handled in Java. Not in PL/SQL.
    Of course, if that PL/SQL proc has parameters, it also needs to validate these and it needs to raise application exceptions to inform the Java caller when these parameters are invalid.
    But actually catching exception in this case... does not make much sense. As what can the PL/SQL do about the error when it is a "server" and Java is the "client"?
    It is like saying that the Oracle Server should handle all exceptions when TOAD is used and incorrect SQL is passed to it. How does it make sense for Oracle to process SQL errors and the TOAD client not getting any results from a wrong SQL and not knowing that there was even an error with that SQL?

  • Extending a Cursor (for stored procedure)

    (Embedded image moved to file: PIC19643.PCX) Dan Christopher @ SUNLIFE
    03-13-97 04:39 PM
    I receive the following message when I try to extend a cursor for an
    execute of a stored procedure. I believe my problem has to do with using
    ODBC as my driver (to attach to a MS-SQL Server 6.5 database) , but does
    anyone have any other insight to what my problem may be.
    SYSTEM ERROR: Invalid state transition from FETCH to EXTENDED for statement of
    type qqdb_OdbcCursor.
    Class: qqdb_UsageException with ReasonCode: DB_ER_INVALIDSTATE
    Error #: [801, 152]
    Detected at: qqdb_Statement::ValidTransition
    Last TOOL statement: method w_connect.ExecStoredProc, line 53
    Error Time: Thu Mar 13 13:55:59
    Exception occurred (remotely) on partition "Dan_Connect_CL0_Part1",
    (partitionId = 210EC99B-811A-11D0-8D72-82F2A190AA77:0x22f:0x20, taskId =
    [210EC99B-811A-11D0-8D72-82F2A190AA77:0x23d:0x3.25]) in application
    "Forte
    Runtime", pid 314 on node 543SZAD in environment dusgroup.
    Here is a example of my code.
    constant NUM_ROWS_FETCH = 2; //default to fetch 50 rows
    //at a time.
    l_inputDataSet :DBDataSet = new; //input parameters for
    Forte
    l_statementtype :integer;
    l_return :integer; //return value for
    open/extend
    //cursor functions
    l_numRows :integer; //the number of rows fetch
    l_DBStatement :DBStatementHandle; //statement handle for
    sp
    l_statementtype = DB_CV_EXECUTE ;
    l_DBStatement = p_dbsession.Prepare(
    commandString = p_exec,
    inputDataSet = l_inputdataset,
    cmdType = l_statementtype);
    // fill in the parameter values
    for i in 1 to p_parameters.items do
    //integer parameter
    if (p_parameters.GetParmIndicator() = 'I') then
    l_inputdataset.SetValue(position = i,
    Value = p_parameters[i].GetParmValue().integervalue);
    else
    l_inputdataset.SetValue(position = i,
    Value = p_parameters[i].GetParmValue());
    end if;
    end for;
    //open the cursor
    l_return = p_dbsession.OpenCursor(
    StatementHandle = l_DBStatement,
    inputDataSet = l_inputdataset,
    resultDataSet = p_outputdataset);
    // Continue to Fetch and Extend the Cursor untill all rows have been
    retrieved.
    while (l_return != DB_RS_NONE) do
    l_numRows = p_dbsession.FetchCursor(
    StatementHandle = l_DBStatement,
    resultDataSet = p_outputdataset,
    maxRows = NUM_ROWS_FETCH);
    if (l_numRows = NUM_ROWS_FETCH) then //extend the cursor
    l_return = p_dbsession.ExtendCursor(
    StatementHandle = l_DBStatement,
    resultDataSet = p_outputdataset);
    else
    exit;
    end if;
    end while;
    //close the cursor
    p_dbsession.CloseCursor(statementHandle = l_DBStateMent);
    return l_numRows;

    Hi Dan,
    Thanks for the Calrification on Cursors, We solved it here.
    As for your Extend problem goes the Fetch should go outside the while
    loop I think.
    You first fetch and then get the next data set in a loop. I feel
    that this should solve your problem.
    Thankx
    Bala
    [email protected]
    Sage Solutions
    353 Sacramento
    Suite 1360
    San Francisco
    CA 94111.

  • 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

  • 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.

Maybe you are looking for

  • 9i installation problem on Fedora 5

    Hi, I am having some difficulties when installing Oracle 9i on Fedora 5 using the article from http://ivan.kartik.sk/oracle/install_ora9_fedora.html. Specifically, it is when "switching the GCC3 compiler binary with GCC2 compiler binary as following"

  • Quarter Patch Confusion

    Hi All, Client has requested to apply a second quarter patch. However the quarter patch is yet released now. As per the oracle doc, The quarter patches dates are following. From the below patches which one is the 2nd quarter patches. 17 July 2012 16

  • How Can I Download os 5 (NON Carrier) for my blackberry 8520

    Hi Im new here so i was just wondering like how can i download the os 5 for my blackberry curve 8520 because im reloading it using BBSAK But the only problem is that i dont know where can i download a non carrier os like the original one that came wi

  • Die Excise duty Amortization Pricing procedure

    Hi, M faceing a problem in defining pricing procedure for Excise duty amortization for Die. The requirement is as follows: Sr.No.     Conditions     Result                                     Remark 1     Rate – Discount + Pakg & Forwarding     Basic

  • 10.7.5/Time Machine Sloooow backups

    I've got 3 (2007 and 2008) Macbooks (Lion 10.7.5) and have been backing them up for at least 3 years to a 1TB Time Capsule. The other day one of the Macbooks had a harddrive fail and it was replaced by a brand new 320GB WD Caviar Blue. The restore of