Workaround for opening a strongly typed cursor using native dynamic SQL

Hi All,
In reading the PL/SQL documentation for Oracle 9i, I noted that the OPEN-FOR
statement with a dynamic SQL string only allows the use of weakly typed cursors.
I have verified this limitation with my own experimentation as follows:
DECLARE
type rec_type is record(
str     varchar2(40),
num     number(22)
type cur_type is ref cursor return rec_type;
my_cur     cur_type;
que     varchar2(100);
tab     varchar2(40);
BEGIN
tab := 'dynamic_table_name';
que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
open my_cur for que;
loop
if my_cur%found then
dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
exit;
end if;
end loop;
close my_cur;
END;
Running the above trivial example in an anonymous sql block yields the following
errors as expected:
ORA-06550: line 10, column 8:
PLS-00455: cursor 'MY_CUR' cannot be used in dynamic SQL OPEN statement
ORA-06550: line 10, column 3:
PL/SQL: Statement ignored
ORA-06550: line 13, column 54:
PLS-00487: Invalid reference to variable 'MY_CUR'
ORA-06550: line 13, column 7:
PL/SQL: Statement ignored
Is there a workaround to the situation? Since I do not know the table name at run
time, I must use Native Dynamic SQL. I have a long and complex record type
that I wish to return through JDBC using the REFCURSOR Oracle type in order to
avoid having to register an inordinate number of OUT parameters. Moreover, I
would like to return potentially one or more results in a ResultSet. Using the
standard method of registering native SQL types for the IN and OUT bindings
can only return one result. Hence the reason I would like to return a strong
cursor type. Also, the type of query I am doing is complex, and needs to be
executed in a PL/SQL procedure for performance reasons. Therefore simply
executing a SELECT query dynamically built up on the the JDBC client won't
do the trick.
If anybody has experience with a similar problem and would like to volunteer
information on their workaround, I would really appreciate it.
Best Regards,
J. Metcalf

We can use strongly-typed REF CURSORs in DNS, but the typing derives from a table e.g.
TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
so the problem is your use of "return rec_type" bit.
Forgive my bluntness but I think you have misunderstood strong and weak typing. You actually want to be using weakly-typed cursors. I mean this:
Moreover, I would like to return potentially one or more results in a ResultSet. suggests that the structure of your resultset may vary, which is precisely what a weakly-typed ref cursor allows us to do. Then we can use the JDBC metadata methods to interrogate the structure of the resultset, innit.
so try this:
DECLARE
type cur_type is ref cursor;
my_cur cur_type;
que varchar2(100);
tab varchar2(40);
BEGIN
tab := 'dynamic_table_name';
que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
open my_cur for que;
loop
if my_cur%found then
dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
exit;
end if;
end loop;
close my_cur;
END;
ras malai, APC
Cheers, APC

Similar Messages

  • Using Native Dynamic SQL in Forms

    Can Native Dynamic SQL be used in Forms 5.0 or Forms 6.0? (Database 8.1.6.0.0)
    I have tried the following code (examples below) from the PL/SQL User's Guide and Reference Release 8.1.6 and the Metalinks Note: 62592.1 and the trigger/procedure (in Forms) will not compile. I appreciate any help given.
    Example1:
    (I have a table named temp_jane with a column named companies and a value 'Hello'. When compiling, I receive the error: 'Error 103 at line 8, column 11 Encountered the symbol ''IMMEDIATE" when expecting one of the following :=.(@%; ')
    declare
    str varchar2( 200 );
    val varchar2( 20 );
    ret temp_jane%rowtype;
    begin
    str := 'select company from temp_jane where company = :b1';
    val := 'Hello';
    execute immediate str into ret using val;
    message('Value fetched from table: '| |ret.company);
    end;
    Example2:
    (Here is the real issue, I don't know what the select statement, so I need to be able to assign a variable. When compiling, I receive the error: 'Error 103 at line 28, column 21 Encountered the symbol "VSQLSTATEMENT" when expecting one of the following: select ').
    declare
    type ItemsControlCurTyp is ref cursor;
    ItemsCur ItemsControlCurTyp;
    ItemsRec Items%rowtype;
    vSQLStatement varchar2( 5000 );
    vExecuteSQL varchar2( 5000 );
    vNumRows integer;
    vValue varchar2( 2000 );
    vFirstOne varchar2( 1 ) := 'Y';
    vRetval varchar2( 2000 );
    begin
    -- Display the column prompts with the right text.
    set_item_property( 'ITEMS_AVAILABLE.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.AVAILABLE_LABEL );
    set_item_property( 'ITEMS_CHOSEN.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.CHOSEN_LABEL );
    -- Save the original version of CHOSEN_STRING in case the user reverts or cancels.
    :ITEMS_CONTROL.CHOSEN_STRING_ORIG := :ITEMS_CONTROL.CHOSEN_STRING;
    vSQLStatement := :ITEMS_CONTROL.SELECT_STATEMENT;
    vExecuteSQL := vSQLStatement;
    -- Open the cursor
    open ItemsCur for vSQLStatement;

    Hi JTaylor
    You cannot use NDS in Client side (Developer). You have to use DBMS_SQL only.
    Regards
    A K Srinivasan
    Oracle.

  • PLS-00455: cursor 'CUR_1' cannot be used in dynamic SQL OPEN statement

    create or replace function f_my_test_func
    return refcur_pkg.refcur_t1
    is
    cur_1  refcur_pkg.refcur_t1;
    begin
    open cur_1
    for
    'select * from dept';
    return cur_1;
    exception
    when others
    then
    insert into ddl_log (SQLTEXT)
    values
    ('fucntion error'); 
    end;

    I would suggest that cur_1 refcur_pkg.refcur_t1 is a stongly typed ref cursor i.e. it has RETURN dept%ROWTYPE or something similar in the declaration. You can't use strongly typed ref cursors with dynamic SQL in this way. The declaration should be weakly typed or just use sys_refcursor.
    DTYLER_APP@pssdev2> DECLARE
      2
      3      TYPE t_Strong   IS REF CURSOR RETURN dual%ROWTYPE;
      4
      5      lc_Strong       t_Strong;
      6
      7  BEGIN
      8
      9      OPEN lc_Strong FOR
    10      'SELECT * FROM dual';
    11
    12  END;
    13  /
        OPEN lc_Strong FOR
    ERROR at line 9:
    ORA-06550: line 9, column 10:
    PLS-00455: cursor 'LC_STRONG' cannot be used in dynamic SQL OPEN statement
    ORA-06550: line 9, column 5:
    PL/SQL: Statement ignored
    DTYLER_APP@pssdev2>
    DTYLER_APP@pssdev2> DECLARE
      2
      3      TYPE t_Weak   IS REF CURSOR;
      4
      5      lc_Weak       t_Weak;
      6
      7  BEGIN
      8
      9      OPEN lc_Weak FOR
    10      'SELECT * FROM dual';
    11
    12  END;
    13  /
    PL/SQL procedure successfully completed.
    DTYLER_APP@pssdev2> DECLARE
      2
      3      lc_Weak       sys_refcursor;
      4
      5  BEGIN
      6
      7      OPEN lc_Weak FOR
      8      'SELECT * FROM dual';
      9
    10  END;
    11  /
    PL/SQL procedure successfully completed.
    DTYLER_APP@pssdev2>HTH
    David

  • Workaround for opening GB 2.0.1 iOS in LP9?

    I have a compatibility issue between the latest GB for iOS and Logic Pro 9 on the Mac. LP 9 will not open the latest version of GB iOS. I cannot download LP 10 bc my 2007 MP is 32-bit EFI. I'm not comfortable w/ the hacks for getting Mavericks, etc. as I'm not computer savvy. I'm a songwriter who wants to write and record as simply as possible. My current set-up runs like a tank (except this one "little" compatibility issue!). GB iOS is great for getting ideas down when on the road. Then I flesh things out on the Mac in LP and add the audio tracks there as well.
    Anyone know a workaround for opening GB 2.0.1 iOS in LP9? I don't want the audio BTW, just the MIDI. I can find the audio by "show package contents", etc. but I can't see the MIDI info in the folder. Maybe my OSX won't recognize as I could possibly do this manually? When I unpack a pre-2.0.1 GB file on the Mac, I can see both the audio and the MIDI, but not on the new GB ".band" file. Any thoughts or ideas are welcomed. Thank you!
    Mac Pro 1,1 June 2007
    2x Quad Core 2.66 Ghz Intel Xeon
    16 GB RAM
    2 HD's
    Logic Pro 9.1.8
    Snow Leopard 10.6.8

    Hi Marian,
    Despite the Default Mappings table in the Oracle9i JDBC Developer's Guide and Reference, I have found that the only reliable mapping between any database table column with the NUMBER datatype (regardless of scale and/or precision) always maps correctly to the "java.math.BigDecimal" class.
    Personally, this mapping has not caused me any troubles -- and I have never had a requirement to use a different mapping. Is there some reason why you have to use "Float"?
    Remember, a PL/SQL parameter of type NUMBER must not have any scale or precision, so the only suitable java class is "java.math.BigDecimal". So I wouldn't call it a "bug", but of-course you are free to think what you want :-)
    Good Luck,
    Avi.

  • Alternative to native, dynamic sql to return a ref cursor to a client

    I'm on Oracle 8.0.4, and would like to pass a string of values like '1,2,7,100,104' that are the primary key for a table. Then use something like:
    procedure foo( MyCur RefCurType, vKey varchar2)
    begin
    open MyCur for
    'select names from SomeTable' | |
    ' where ID in (' | | vKey | | ')'
    end;
    This would return a recordset to (in this case) a Crystal Reports report.
    However, native dynamic SQL ain't available until 8.1.0. So can anyone think of a clever way to accomplish this, with a way to return a cursor? I can't figure out how to do this with DBMS_SQL, because open_cursor is just returning a handle, not a referene to a cursor that can be passed to a remote client.
    Thanks in advance.

    I'm on Oracle 8.0.4, and would like to pass a string of values like '1,2,7,100,104' that are the primary key for a table. Then use something like:
    procedure foo( MyCur RefCurType, vKey varchar2)
    begin
    open MyCur for
    'select names from SomeTable' | |
    ' where ID in (' | | vKey | | ')'
    end;
    This would return a recordset to (in this case) a Crystal Reports report.
    However, native dynamic SQL ain't available until 8.1.0. So can anyone think of a clever way to accomplish this, with a way to return a cursor? I can't figure out how to do this with DBMS_SQL, because open_cursor is just returning a handle, not a referene to a cursor that can be passed to a remote client.
    Thanks in advance.

  • Need Workaround for periodical autocommit in WebForms without using Timer

    Hi guys...
    I need to use autocommit in my form for say 1 min.
    As ther is a great performance degradation when i go for timers, i need a workaround to achieve the same functionality without using timers.
    Thanx & Regards
    Sriram

    <p>Get this zip file
    <br><br>
    unzip the file<br>
    copy the bean_timer.jar in your <forms_home>/java directory<br>
    update your formsweb.cfg configuration file<br>
    archive_jini=f90all_jinit.jar,...,bean_timer.jar<br><br>
    open, compile and run the beantimer.fmb sample demo
    <br>
    </p>
    Francois

  • Creating an OLAP cursor with a dynamic SQL

    The create sql cursor command
    SQL declare cursor_name cursor for Select col_name from table_name does not take a dynamic sql.
    Is there a way to execute a sql dynamically like
    SQL declare cursor_name cursor for 'Select col_name from table_name'
    I tried using the prepare statement command but i could not get the statement execution to the cursor. I am working on Oracle OLAP version 9.2.0.5.0
    Thanks in advance
    Ajesh A

    One method I'm familiar with is OPEN...FOR. You can do something like this (untested but should be close in any case):
    DECLARE
      tabname VARCHAR2(100) := 'mytable';
      colaval VARCHAR2(100);
      colbval VARCHAR2(100);
      colcval VARCHAR2(100) := 'somesearchval';
      TYPE MyCurTyp IS REF CURSOR;
      my_cur MyCurTyp;
    BEGIN
      OPEN my_cur
        FOR 'SELECT cola, colb FROM ' || tabname || ' WHERE colc=:1'
        USING colcval;
      LOOP
        FETCH my_cur INTO colaval, colvbal;
        EXIT WHEN my_cur%NOTFOUND;
        DBMS_OUTPUT.PUTLINE('cola: ' || colaval || ' colb: ' || colbval);
      END LOOP;
    END;
    /The PL/SQL User's Guide is invaluable when working in PL/SQL. Here's the section on ref cursors:
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1392
    For problems not covered by the documentation, you may find that for general SQL and PL/SQL programming advice not specifically related to OLAP that there will be more knowledge in some of the more general forums here.

  • Re: PLS-00455: cursor 'CUR_1' cannot be used in dynamic SQL OPEN statement

    create or replace package cognos_pk as /* Creates Package Header*/
    TYPE project_type IS record( /* A record declaration is used to */
    c1 NUMBER /* provide a definition of a record */
    ); /* that can be used by other variables*/
    TYPE project_type1 IS REF CURSOR  return project_type; /* Variable declaration */
    procedure conosg_sp (result1  out project_type1); /* SP declaration */
    end;
    CREATE OR REPLACE PACKAGE BODY cognos_pk AS /* Name of package body must be same as header */
    PROCEDURE conosg_sp(result1  OUT project_type1) IS
    countrow  number;
    BEGIN
    FOR X IN (SELECT TABLE_NAME
    FROM USER_TAB_COLUMNS
    WHERE COLUMN_NAME='PROC_STAT_CODE' AND TABLE_NAME LIKE 'INPT%')
    LOOP
    execute immediate 'select count(*)   from '||X.TABLE_NAME ||' WHERE PROC_STAT_CODE &lt;&gt;10 ' into countrow;
    --result1 := X.TABLE_NAME|| ROW_CNT;
    -- dbms_output.put_line(result1 );
    OPEN result1 for countrow;
    END loop;
    END;
    end;
    /This is my requirement ...
    I want to count the table starting with Inpt and and proc stat _code =10 which is the column name in all the table.
    i wan to return the count and the table name to be used in my cognos report.
    Edited by: BluShadow on 10-May-2013 09:22
    added {noformat}{noformat} tags around the code/data for readability (no accounting for OP's lack of formatting)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    1005181 wrote:
    create or replace package cognos_pk as /* Creates Package Header*/
    TYPE project_type IS record( /* A record declaration is used to */
    c1 NUMBER /* provide a definition of a record */
    ); /* that can be used by other variables*/
    TYPE project_type1 IS REF CURSOR  return project_type; /* Variable declaration */
    procedure conosg_sp (result1  out project_type1); /* SP declaration */
    end;
    CREATE OR REPLACE PACKAGE BODY cognos_pk AS /* Name of package body must be same as header */
    PROCEDURE conosg_sp(result1  OUT project_type1) IS
    countrow  number;
    BEGIN
    FOR X IN (SELECT TABLE_NAME
    FROM USER_TAB_COLUMNS
    WHERE COLUMN_NAME='PROC_STAT_CODE' AND TABLE_NAME LIKE 'INPT%')
    LOOP
    execute immediate 'select count(*)   from '||X.TABLE_NAME ||' WHERE PROC_STAT_CODE &lt;&gt;10 ' into countrow;
    --result1 := X.TABLE_NAME|| ROW_CNT;
    -- dbms_output.put_line(result1 );
    OPEN result1 for countrow;
    END loop;
    END;
    end;
    /This is my requirement ...
    I want to count the table starting with Inpt and and proc stat _code =10 which is the column name in all the table.
    i wan to return the count and the table name to be used in my cognos report.The execute immediate statement you have, is doing the actual count and returning the count into the variable "countrow".
    The subsequent OPEN statement for the ref cursor is trying to open a cursor, and is expecting an SQL query to do that, but you are passing it your numeric value instead.
    All you need to open a ref cursor is:
    e.g.
    OPEN result1 for 'select count(*) from '||x.table_name||' where proc_stat_code != 10';However, your code is so seriously flawed in many ways.
    a) you don't need to declare a type of "REF CURSOR" yourself. Oracle provides a type called "SYS_REFCURSOR" that you can use already.
    b) Your procedure is supplying a single ref cursor as an OUT variable, yet it tries to loop through multiple tables and re-use the same ref cursor over and over. That's not going to work. You can only pass one thing out in your OUT parameter.
    I don't know how congos expects it's results, but I assume a ref cursor is acceptable to it, so what you're actually looking for is to pass back a single ref cursor that is based on a query that can give the results for all your tables in one go.
    There are various queries that can be used to count records on multiple tables e.g.
    (ref. Laurent Schneider's blog: http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html )
    SQL> select
      2    table_name,
      3    to_number(
      4      extractvalue(
      5        xmltype(
      6 dbms_xmlgen.getxml('select count(*) c from '||table_name))
      7        ,'/ROWSET/ROW/C')) count
      8  from user_tables
      9 where iot_type != 'IOT_OVERFLOW'
    10 or    iot_type is null;
    TABLE_NAME                      COUNT
    DEPT                                4
    EMP                                14
    BONUS                               0
    SALGRADE                            5You could therefore open your refcursor using a single query based on the above (adapting it for your own needs and restrictions).

  • Can I test for open or shorted accelerome​ters using an NI9234 module?

    I'm using multiple NI9234 modules to acquire data from accelerometers.  Is there anyway in LabVIEW to test the health of the accelerometers?  I'm looking for either open or shorted accelerometers.
    THANKS

    Hi NI_1424,
    From LabVIEW, we just read the voltages that are on the NI 9234. If you are expecting a voltage from an accelerometer but it is reading 0 V, it could be shorted or open. So, the short answer is "no". But you can deduce faulty accelerometers if you understand your setup and are seeing unexpected values.
    Jeff Munn
    Applications Engineer
    National Instruments

  • New page not being opened in new window when using a dynamic menu

    I have read an earlier post about this but I didn't really see a solution I could implement there. I have a dynamic menu, and I want one item on it to open a new frame. Here is the module code from the template.
    {module_menu, version="2", menuId="901683", moduleTemplateGroup="Default"}
    It is the main template menu from the Tribeca site template.
    I have tried inserting (_blank) into the appropriate target frame, and still it opens in the same window.  I gathered from the previous post that it was a version issue, but as you can see, the code says "version 2"... or am I mis-reading that?
    I couldn't find where to make changes. The previous post suggested I look for the CSS on the home template, but I am not using a home template.
    Any thoughts?
    Chuck

    Thanks Liam, it worked. I need a clarification if you can... I don't need all the items in the menu to open in a new window, so under the menu itself, under the individual items, I would set the target frame to "_self" for the items I need to remain in the same window? Or is it an all or none thing?
    I really have appreciated the help you've given me.
    Chuck

  • Schema for File with Multiple Fixed Records using Native Schema builder

    Hi All:
    The below is the sample file format which i need to read through file adapter
    HeaderReacord
    FailureOrderRecord
    ChildFailureRecord
    ChildFailureRecord
    SuccessOrderRecord
    SuccessOrderRecord
    HeaderReacord
    FailureOrderRecord
    ChildFailureRecord
    In the above file, totally three records are repeatedly present with fixed length eg. HeaderReacord length is 50, SuccessOrderRecord and FailureOrderRecord length is 100, ChildFailureRecord length is 25. The file may have more than one header group i.e. A single header group contain one HeaderReacord, more than one SuccessOrderRecord, more than one FailureOrderRecord and more than one ChildFailureRecord after each FailureOrderRecord.
    I have created the below xsd for this scenario and get the below output. Kindly tell how to do this in Native builder using fixed length type for different fixed records options
    <xsd:element name="BatchOrder">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="OrderGroupCollection" type="OrderGroup" minOccurs="1" maxOccurs="unbounded"
    nillable="false"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:complexType name="OrderGroup">
    <xsd:sequence>
    <xsd:element name="HeaderRecord" type="xsd:string" minOccurs="1" maxOccurs="1"
    nillable="false"/>
    <xsd:element name="RecordList" type="RecordList" minOccurs="1" maxOccurs="unbounded"
    nillable="false"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="RecordList">
    <xsd:sequence>
    <xsd:element name="OrderRecord" type="xsd:string" minOccurs="1" maxOccurs="1"
    nillable="false"/>
    <xsd:element name="ChildErrorRecord" type="xsd:string" minOccurs="0"
    maxOccurs="unbounded" nillable="true"/>
    </xsd:sequence>
    </xsd:complexType>
    Output:
    =======
    <BatchOrder>
    <OrderGroupCollection>
    <OrderGroup>
    <HeaderRecord>HeaderReacord</HeaderRecord>
    <RecordList>
    <OrderRecord>FailureOrderRecord</OrderRecord>
    <ChildErrorRecord>ChildFailureRecord</ChildErrorRecord>
    <ChildErrorRecord>ChildFailureRecord</ChildErrorRecord>
    <ChildErrorRecord>SuccessOrderRecord</ChildErrorRecord>
    <ChildErrorRecord>SuccessOrderRecord</ChildErrorRecord>
    <ChildErrorRecord></ChildErrorRecord>
    <ChildErrorRecord>HeaderReacord</ChildErrorRecord>
    <ChildErrorRecord>FailureOrderRecord</ChildErrorRecord>
    <ChildErrorRecord>ChildFailureRecord</ChildErrorRecord>
    </RecordList>
    </OrderGroup>
    </OrderGroupCollection>
    </BatchOrder>

    you cant acheive this heirarchy using the file adapters cont. conv, cos it supports only to a single level.
    Maybe you can have a module or use the conversion agent !!
    Some good reads on the Conv. agent!!!
    /people/william.li/blog/2006/03/17/how-to-get-started-using-conversion-agent-from-itemfield
    /people/paul.medaille/blog/2005/11/18/conversion-agent-a-free-lunch
    /people/alexander.bundschuh/blog/2006/03/14/integrate-sap-conversion-agent-by-itemfield-with-sap-xi
    /people/paul.medaille/blog/2005/11/17/more-on-the-sap-conversion-agent-by-itemfield

  • How to use a dynamic SQL data as the header ?

    I'm using BO XI Rel 2. I have hard coded the report headers, but i do have a table wherein the header data is available. I like to fetch the HEADER information from the table, rather than hard coding. How to go about it?
    Example: "Statement of Closing" is the header.
    The above output can be retrieved by using the below query!
    Select Form_desc from TBS_FORMS where form_id = 'tbs1a';
    form_id is a common link between tables!! Since the actual report data has multiple value as output, just by plugging the query in the header, i'm getting #multivalue error!!!!
    In oracle reports, i have something called place holder to achieve the above objective. In BO, how to go about it?
    Edited by: Karthik  Ganesan on Dec 28, 2008 1:22 PM

    Sorry, that doesn't solve my problem. Please read the question more closely - I want my USERS to be able to do this without changing their configurations. My users are public school elementary teachers and parents. I can't ask them to toggle any settings - I'm looking for a way that my users can do this on their own.
    Thanks

  • Create table using a dynamic SQL returns error.

    DBMS_UTILITY.exec_ddl_statement (
    'create table test_table as select column_names from table_name@dblink
    where condition' )
    i am using the above statement in a pl/sql procedure.
    It throws an error saying
    "Exact fetch returns more than requested no. of rows"
    can any one help me on this please!!!
    Very Urgent
    Thanks in Advance.
    Bala.

    Works for me. But the more important question would be the need to have this run within PL/SQL? Why do you want to do that? what is the requirement? can you not do this one time at SQL*Plus prompt and be done with it?
    SQL> drop table emp ;
    Table dropped.
    SQL>
    SQL>
    SQL> exec dbms_utility.exec_ddl_statement('create table emp as select * from [email protected] where deptno = 10') ;
    PL/SQL procedure successfully completed.
    SQL> select count(*) from emp ;
      COUNT(*)
             3
    1 row selected.
    SQL> select count(*) from [email protected] ;
      COUNT(*)
            14
    1 row selected.
    SQL> select count(*) from [email protected] where deptno = 10 ;
      COUNT(*)
             3
    1 row selected.
    SQL>Message was edited by:
    Kamal Kishore

  • Using a Variable for Table Name  with a cursor

    Hello All
    Is it possible to use a Parameter passed to a procedure as the table name
    in a cursor selection statment. I thought the below would work but I get
    a error. Does anyone have any ideas?? The Error is listed below to.
    Here's the code I just complied
    CREATE OR REPLACE PROCEDURE Dup_Add(NEWQATABLE IN VARCHAR2) IS
    CURSOR c1 IS SELECT MUNI,PROV FROM NEWQATABLE GROUP BY MUNI, PROV;
    c1rec c1%ROWTYPE;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO c1rec;
    EXIT WHEN c1%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(c1rec.MUNI);
    END LOOP;
    CLOSE c1;
    END;
    Here is the errors
    LINE/COL ERROR
    3/8 PLS-00341: declaration of cursor 'C1' is incomplete or malformed
    3/15 PL/SQL: SQL Statement ignored
    3/38 PLS-00201: identifier 'NEWQATABLE' must be declared
    5/7 PL/SQL: Item ignored
    10/3 PL/SQL: SQL Statement ignored
    10/17 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    12/3 PL/SQL: Statement ignored
    12/24 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    LINE/COL ERROR
    Thanks
    Peter

    If you are going to have a table name or a column name as a parameter, then you have to open the cursor dynamically. The following example uses Native Dynamic SQL (NDS) to open a ref cursor dynamically. I also eliminated the group by clause, since it is intended for use with aggregate functions and you weren't using an aggregate function. Also notice that there are some other differences in terms of defining variables and fetching and so forth.
    SQL> CREATE TABLE test_table
      2  AS
      3  SELECT deptno AS muni,
      4         dname  AS prov
      5  FROM   dept
      6  /
    Table created.
    SQL> CREATE OR REPLACE PROCEDURE Dup_Add
      2    (newqatable IN VARCHAR2)
      3  IS
      4    TYPE cursor_type IS REF CURSOR;
      5    c1 cursor_type;
      6    c1muni NUMBER;
      7    c1prov VARCHAR2 (20);
      8  BEGIN
      9    OPEN c1 FOR 'SELECT muni, prov FROM ' || newqatable;
    10    LOOP
    11      FETCH c1 INTO c1muni, c1prov;
    12      EXIT WHEN c1%NOTFOUND;
    13      DBMS_OUTPUT.PUT_LINE (c1muni || ' ' || c1prov);
    14    END LOOP;
    15    CLOSE c1;
    16  END;
    17  /
    Procedure created.
    SQL> SHOW ERRORS
    No errors.
    SQL> SET SERVEROUTPUT ON
    SQL> EXECUTE dup_add ('test_table')
    10 ACCOUNTING
    20 RESEARCH
    30 SALES
    40 OPERATIONS
    PL/SQL procedure successfully completed.

  • Using dynamic SQL (native) in triggers.

    Hi All:
    As a part of client requirement, I need to capture all column data from tables when rows get deleted. I am using a single table to capture deleted column data (not concatenated but one column data per row).
    I am using native dynamic SQL as I need to get the most recent column list for any table from USER_TAB_COLUMNS table. Somehow, Oracle does not allow me to use :old.xxx syntax when doing a EXECUTE IMMEDIATE insert_statment;
    Can't I use native dynamic SQL in triggers to refer to :old and :new values?
    Thanks,
    Sankar.

    No, you cannot use NDS to refer to the :old values. You can use the data dictionary to automate the writing of the audit trigger code itself though. Hi Todd,
    Can you please explain your comment about using the data dictionary to automate writing the audit trigger code..
    Thanks.

Maybe you are looking for

  • Freight charges among stock items

    how can to configure freight charges among the stock items. i have configuration where freight charges taken into freight A/c.I want it among the stock A/c. pls Help

  • Payment Advise

    Hi Friends, Could anybody please tell me the procedure for configuring an incoming payment's payment advise. Helpful answers will be definately rewarded. Thanks and Regards, Suraj

  • Dissapearing letters in forms fields

    After creating a multi-record block displaying 12 records I added a text item that only displays one item per record. If an item (the text item in my case) has a different number of records displayed as defined within the block properties (block = 12

  • Re-formating iPod from Windows to MAc

    How do I, if possible, reformat my iPod that I use to connect to a Windows based PC to a MAC? Also can I do it without wiping out music libary on the iPod?

  • Order type & Item Category

    Dear SAPers, i used to work with the standard Order Type and Item Category. Now i decided to copy and change them. By raising the sales order (with my order type 9OR) i don't get the item category 9TAN that i created. How can i solve that. Thanks