Concatenate problem for Dynamic SQL statements

Hi Experts ,
I am building Dynamic SQL statements depending on the values which the user enters into the select option parameters .This dynamic query is passed to cl_sql_connection object for querying from another databasse
So i wrote dynamic values for one select option spointof for the database field ppointofdelivery.
loop at spointof.
CONCATENATE ' pointofdelivery between ''' spointof-low''''
' AND ''' spointof-high''''
INTO where_clause .
endloop.
The whereclause has value pointofdelivery between '123' and '124'.(if the user has entered 123 and 124 as values)
This works fine . But my problem is I have to pass the fieldnames and operator dynamically into where_clause depending on User input.
when i am writing code like the below
field_name = ' pointofdelivery '.
operator = '='.
CONCATENATE field_name operator '''spointof-low''' INTO where_clause .
the where_clause contains value
pointofdelivery = ' spointof-low '
and not pointofdelivery = ' 123 ' as expected .
Do you know why this is haapening as it is not taking the value.
Thanks
Arshad

Hi,
there are lot of function modules..available...to build a where clause based on the select-options..
check the FM FREE_SELECTIONS_RANGE_2_WHERE
Thanks
Naren

Similar Messages

  • How can I open a cursor for dynamic sql statement

    Hi,
    I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
    CREATE OR REPLACE FUNCTION DEMO
    (MN_I in VARCHAR)
    return AB_OWNER.ABC_Type.NonCurTyp is
    RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
    sql_stmt VARCHAR2(4000);
    BEGIN
    sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
    OPEN RESULT1 FOR sql_stmt;
    END IF;
    return RESULT1;
    END DEMO;
    What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.

    Gangadhar Reddy wrote:
    I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
    Because this is what will happen when it runs a lot.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
    http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
    And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
    Flushing Shared Pool regularly
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
    >
    Ok, this is an easy one to diagnose.
    You are not using bind variables. This is terrible. Flushing the shared pool is a bad
    solution -- you are literally killing the performance on your box by not using them.
    If I was to write a book on how to build “non scalable applications in Oracle”, this
    would be the first and last chapter. This is a major cause of performance issues and a
    major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
    important shared memory data structure) operates is predicated on developers using bind
    variables. If you want to make Oracle run slowly, even grind to a total halt – just
    refuse to use them.
    >
    But, please feel free to go ahead with this successful implementation.
    I just hope anyone else who reads this doesn't make the same mistake.

  • Preparing Dynamic SQL statement for inserting in Pro*C

    Hi Friends,
    From quite some time i am struggling writing Dynamic SQL statement for dynamic insert and update in Pro*C.
    Can somebody go through my code and suggest me the rigth way of doing.
    Right now it throws an error saying " Error while updating ORA-00904: invalid column name "
    Please help me.
    Girish.
    int main()
    EXEC SQL BEGIN DECLARE SECTION;
    char *uid ="scott/tiger";
    static char sqlstmt[129];
    struct /* DEPT record */
    int dept_num;
    char dept_name[15];
    char location[14];
    } dept_rec;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL WHENEVER SQLERROR DO sql_error();
    EXEC SQL CONNECT :uid;
    dept_rec.dept_num = 50;
    strcpy(dept_rec.dept_name,"ADMIN");
    strcpy(dept_rec.location,"IN");
    strcpy(sqlstmt,"UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num");
    EXEC SQL EXECUTE IMMEDIATE:sqlstmt;
    EXEC SQL COMMIT;
    exit(0);
    void sql_error()
    printf("\nError while updating %s",sqlca.sqlerrm.sqlerrmc);
    EXEC SQL ROLLBACK;
    }

    A bit rusty here but this is how I see it.
    Think of it this way ..
    all Oracle is going to see is:
    UPDATE dept set DNAME = dept_rec.dept_name where DEPTNO = dept_rec.dept_num
    Its NOT going to know what dept_rec.dept_name is or dept_rec.dept_num is ..
    it doesnt go back and fill in those values.
    You need something like
    strcpy(sqlstmt,"UPDATE dept set DNAME = \"");
    strcat(sqlstmt,dept_rec.dept_name);
    strcat(sqlstmt,"\" where DEPTNO = ");
    strcat(sqlstmt,dept_rec.dept_num);
    printf(sqlsmt); # Just to be sure the update statement look right during testing.

  • DB2 problems with Dynamic SQL

    Does anyone out there use dynamic SQL with DB2? If so, are the sql statements causing a PreparedStatement to be executed on DB2. I posted this question similarly before, but never resolved it, and it is killing me. I have to resolve this ASAP!
    Here is the problem: My DB2 Admin says that EVERY TIME I access the database, my Java app is causing the database to create a PreparedStatement. However, I'm using Statement objects exclusively, with dynamic SQL. He says that DB2 needs an "access path" for the client, and that it converts the Statement to a PreparedStatement, as this is the only way to get this "access path". He says the only solution is either stored procedures or SQLJ, which will do the binding in advance, and increase performance tremendously. However, I am STRONGLY opposed to using SQLJ, and if we do stored procedures, we'd have to write one for every possible SQL statment! I KNOW there is a better solution.
    Is anyone out there having these problems with JDBC and DB2? Surely someone out there uses DB2 and JDBC and either has these problems or can confirm that something is incorrectly configured on the database side.
    Any help would be great. Thanks, Will

    Now I'm wondering if maybe the PreparedStatements are ONLY being called on the database when I call getConnection(), and not when I call executeQuery() or executeUpdate() from the Statement object. I just can't see why the database would have to make an access path for every SQL statement executed, but I could see it creating an access path for every connection requested. Any thoughts on that theory?

  • Help required in changing to str for dynamic sql

    Hi
    I am trying to make this to string for dynamic sql, this is a part of the sql which is giving problem with p_..as parameters from proc. Help me in this , iam also seeing dbms _output but stil unable to format it to required error free string.
    || ' AND ( po.abbreviationprojectopportid LIKE '
    || '%'
    || 'NVL'
    || '('
    || p_opp_code
    || ', ''NULL'')'
    || '%'
    || ' OR co.companyname LIKE '
    || '%'
    || 'NVL'
    || '('
    || p_client_name
    || ', '' NULL'')'
    || '%'
    || ' OR le.line_item_amount = NVL '
    || ' ('
    || p_booking_amt
    || ', -0.197) '
    || 'OR po.dealcurrency = NVL '
    || '('
    || p_currency
    || ',''NULL'')'
    || 'OR be.booking_entry_id LIKE '
    || '%'
    || 'NVL ('
    || p_entry_id
    || ',''NULL'')'
    || '%'
    || ' OR le.line_item_id LIKE '
    || '%'
    || 'NVL ('
    || p_line_item
    || ',''null'')'
    || '%'
    || ' OR be.ticket_num LIKE '
    || '%'
    || 'NVL ('
    || p_ticket_num
    || ',''NULL'')'
    || '%'
    || ' OR be.updatedby LIKE '
    || '%'
    || 'NVL ('
    || p_user_name
    || ',''NULL'')'
    || '%'
    || ' OR credittransaction.acct_code ='
    || 'NVL ('
    || p_gl_account
    || ','
    || '-0.197)'
    || 'OR debittransaction.acct_code ='
    || 'NVL ('
    || p_gl_account
    || ', '
    || '-0.197) '
    || 'OR credittransaction.profit_ctr_code ='
    || 'NVL ('
    || p_profit_center
    || ','
    || ' -0.197)'
    || 'OR debittransaction.profit_ctr_code ='
    || 'NVL ('
    || p_profit_center
    || ','
    || '-0.197)'
    || ' OR le.sap_posting = NVL ('
    || p_sap_posting
    || ',''$'')'
    || 'OR cmis.cmis_code = NVL ('
    || p_cmis_nominal
    || ','' -0.197)'
    || 'OR sa.sap_code = NVL ('
    || p_sap_booking_entity
    || ', -0.197)'
    || ' OR (be.booking_date BETWEEN '
    || v_booking_date_from
    || 'AND '
    || v_booking_date_to
    || ')'
    || ' )'
    || 'ORDER BY '
    || p_sort_by
    || ' '
    || p_order;

    some errors.. Try this...
    ' SELECT be.booking_date bookingdate, '
    || ' be.booking_entry_id entryid, le.line_item_id itemid,'
    || ' po.abbreviationprojectopportid opportunitycode,'
    || ' co.companyname clientname, '
    || ' le.line_item_amount bookingamount,'
    || ' be.ticket_num ticketnum, po.dealcurrency currency,'
    || ' cmis.cmis_code cmis_nominal,'
    || ' sa.sap_code sap_booking_entity,'
    || ' (SELECT full_name '
    || ' FROM iba_employee '
    || ' WHERE TO_CHAR (employeeid) = be.updatedby) updatedby,'
    || ' be.updateddate updateddate, '
    || ' (SELECT le.line_item_amount * rate '
    || ' FROM iba_currencyconversion '
    || ' WHERE tocurrencycd = '
    || 'USD'
    || ' AND currencycd = po.dealcurrency '
    || ' AND conversiondate = be.booking_date) amountusd,'
    || 'debittransaction.acct_code debitglaccount,'
    || ' credittransaction.acct_code creditglaccount,'
    || ' debittransaction.profit_ctr_code debitprofitcenter,'
    || ' credittransaction.profit_ctr_code creditprofitcenter,'
    || ' debittransaction.amt debitamount,'
    || ' credittransaction.amt creditamount'
    || ' FROM rb_booking_entry be, '
    || ' rb_line_item le, '
    || ' rb_booking_period bp,'
    || ' rb_cmis_gl_account cmisgl,'
    || ' rb_cmis_account cmis,'
    || ' iba_projectopportunity po,'
    || ' iba_company co,'
    || ' rb_sap_account sa,'
    || ' (SELECT acctr.line_item_id line_item,'
    || ' sapgl_acc.account_code acct_code,'
    || ' acctr.amount amt,'
    || ' sappr.profit_center_code profit_ctr_code'
    || ' FROM rb_account_transaction acctr,'
    || ' rb_sap_profit_center sappr,'
    || ' rb_sap_gl_account sapgl_acc'
    || ' WHERE acctr.profit_center_id = sappr.profit_center_id '
    || ' AND acctr.gl_account_id = sapgl_acc.gl_account_id '
    || ' AND acctr.transaction_type = ''D'') debittransaction,'
    || ' (SELECT acctr.line_item_id line_item,'
    || ' sapgl_acc.account_code acct_code,'
    || ' acctr.amount amt,'
    || ' sappr.profit_center_code profit_ctr_code '
    || ' FROM rb_account_transaction acctr, '
    || ' rb_sap_profit_center sappr, '
    || ' rb_sap_gl_account sapgl_acc '
    || ' WHERE acctr.profit_center_id =sappr.profit_center_id '
    || ' AND acctr.gl_account_id = sapgl_acc.gl_account_id '
    || ' AND acctr.transaction_type = ''C'') credittransaction '
    || ' WHERE po.projectopportunityid = be.projectopportunityid '
    || ' AND be.booking_entry_id = le.booking_entry_id '
    || ' AND po.companyid = co.companyid '
    || ' AND bp.booking_period_id = be.booking_period_id '
    || ' AND cmis.cmis_id = cmisgl.cmis_id '
    || ' AND le.sap_id = sa.sap_id '
    || ' AND le.cmis_id = cmis.cmis_id '
    || ' AND debittransaction.line_item(+) = le.line_item_id '
    || ' AND credittransaction.line_item(+) = le.line_item_id '
    || ' AND ( po.abbreviationprojectopportid LIKE ' || '''%' || NVL(p_opp_code,'NULL') || '%'''
    || ' OR le.line_item_id LIKE '
    || '''%'
    || NVL (
    || p_line_item
    || ,'null')
    || '%'''
    | ' OR le.line_item_amount = '
    ||NVL(|| p_booking_amt, -0.197)
    || ' OR po.dealcurrency ='
    || NVL(p_currency,'NULL')
    || ' OR be.booking_entry_id LIKE '
    || '''%'
    || NVL (p_entry_id,'NULL')
    || '%'''
    || ' OR be.ticket_num LIKE '
    || '''%'
    || NVL (p_ticket_num,'NULL')
    || '%'''
    || ' OR be.updatedby LIKE '
    || '''%'
    || NVL (p_user_name,'NULL')
    || '%'''
    || ' OR credittransaction.acct_code ='
    || NVL (p_gl_account,-0.197)
    || ' OR debittransaction.acct_code ='
    || NVL (p_gl_account,  -0.197)
    || ' OR credittransaction.profit_ctr_code ='
    || NVL (p_profit_center, -0.197)
    || ' OR debittransaction.profit_ctr_code ='
    || NVL (p_profit_center, -0.197)
    || '  OR le.sap_posting = '
    ||NVL (p_sap_posting,'$')
    || ' OR cmis.cmis_code = '
    ||NVL (p_cmis_nominal, -0.197)
    || ' OR sa.sap_code = '
    || NVL (p_sap_booking_entity, -0.197)
    || '  OR (be.booking_date BETWEEN to_date('''
    || v_booking_date_from
    || ''') AND  to_date('''
    || v_booking_date_to
    || ''')'
    || ' OR co.companyname LIKE '
    || '''%'
    || NVL(p_client_name,'NULL')
    || '%'''
    || ' )'
    || 'ORDER BY  ' || p_sort_by || ',' || p_order;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help With SUBSTR in dynamic SQL statement

    Following is the dynamic SQL statement.
    EXECUTE IMMEDIATE 'UPDATE table_name pml
    SET pml.'|| con_fields.field ||' = SUBSTR(pml.'||con_fields.field||' ||'' ''||
    (SELECT pml1.'||con_fields.field||'
    FROM table_name pml1
    WHERE pml1.grp_id = '||los_concats.grp_id ||'
    AND pml1.row_id = '||los_concats.row_id||'
    AND pml1.loser_flg = ''Y''),1, '||con_fields.max_length||')
    WHERE pml.grp_id = '||los_concats.grp_id ||'
    AND pml.loser_flg IS NULL ';
    what it does is that it updates a particular field. This field is concatenated by a field of a similar record.
    My problem is with SUBSTR function. Since I am concatenating fields I do not want the field to be updated greater than max_length on that field, the reason why I use SUBSTR. the select query inside SUBSTR works alright with one of the AND condition in a WHERE clause not present. When I add that additional condition it gives me this error.
    ORA-00907: missing right parenthesis.
    Is there any way to get around this problem. Does SQL has other than SUBSTR function which can limit the character length.
    Appreciate it.

    The other alternative I thought about was to do this first
    EXECUTE IMMEDIATE 'SELECT pml.'||con_fields.field||'
    FROM table_name pml
    WHERE pml.grp_id = '||los_concats.grp_id||'
    AND pml.row_id = '||los_concats.row_id||'
    AND pml.loser_flg = ''Y''
    ' INTO v_concat_field;
    write into the variable v_concat_field and then use it into the previous script.
    But on this I get SQL Command not properly terminated, I don't get it Why?
    Donald I tried with your suggested script. It works fine with one of the conditions eliminated. I don't understand what the error trying to say?
    Thanks

  • How can I execute Dynamic SQL statement in Forms?

    Hi All,
    I have to execute dynamic SQL statement from Forms
    Below statement I have to execute
    "EXECUTE IMMEDIATE v_stmt INTO v_return;".
    Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
    Can any one help me..
    Thanks,
    Madhu

    So in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
    Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
    And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
    In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
    cheers

  • The number of reloads for the SQL statements

    Hi,
    in 10g R2, how to see the number of reloads for the SQL statements ? Any query ? Which value is high ? Which valu is low ?
    Thanks.

    thanks all.
    It was a test question for 1Z0-042 exam as follows :
    The users on your SALESDB are complaining of slow response to their queries. Using the SQL Tuning Advisor, you determine
    that the SQL statements are using the best optimization plan. Querying the dynamic views, you see that the number of reloads
    for the SQL statements is high, which can cause performance degradation.
    Which component of the SGA should you resize to reduce the number of reloads of the SQL statements?
    Answer :
    shared poolThen I wonder how to see the number of reloads for the SQL ?

  • Escaping "curly apostrophe" for a sql statement

    Hi,
        I'm trying to escape the curly apostrophe for a sql statement, i.e.,
    Bob’s . I tried using the following
    string str = inputStr.Replace("'","''");
    Of course, this doesn't work.
    Thanks!

    Replace has 2 overloads.  One uses 2 strings while the other uses 2 char parameters.  Run this code on text pasted from each application.
    static string ReplaceString()
    string input =
    "O'Hara";
    foreach ( Char c
    in input )
    Console.WriteLine(c.ToString() +
    " = " + Convert.ToInt32(c).ToString());
    return input.Replace("'",
    String.Empty);
    Compare the values returned for the character.  Then use the char value from Word and replace it with the char value from Notepad in the other overload that takes 2 char parameters.
    Are you using a TextBox or a RichTextBox?
    Mark the best replies as answers. "Fooling computers since 1971."
    http://rudedog2.spaces.live.com/default.aspx

  • Looking for a SQL statement

    Looking for a sql statement that returns me one row which is made up of data of two rows but display it side by side instead of one row followed by other row.
    e.g
    Col1
    1
    2
    2 Rows selected
    How can i display it as
    Col1
    1 2
    1 Row selected
    Appreciate any responses.
    TIA
    DS
    null

    How to find the last sql statement executed in oracle .
    thanks
    B.B.Padhi
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by SANJAY KUMAR ([email protected]):
    i have table san with column rl having values 11, 12. Then write the SQL as:
    select a.rl, n.rl from san a,( select b.rl from san b where b.rl in (select rl from san) ) n
    where a.rl < n.rl;
    It will give u approprate result.
    Thanks!<HR></BLOCKQUOTE>
    null

  • Need to wite pl sql procedure for dynamic select statement

    Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
    select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;

    I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
    TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM'))

  • Dynamic SQL statement in a Procedure

    Hi,
    is it possible to use a variable in place of a column name in a sql statement inside a procedure. Or to create the whole statement as a sql statement and execute it (preferrably with parameters - rather than concatinating the values).
    Thanks for any help or direction
    Elliot

    Turns out you can do the following very nicely (dynamic sql with parameterized values)
    Declare
    id number(10,0);
    sql_stmt varchar2(300);
    fieldName varchar2(30);
    fieldValue varchar2(100);
    id := 30;
    fieldName := 'somecolumn';
    fieldValue := 'some value';
    sql_stmt := 'UPDATE myTable SET ' || fieldName || ' = :1 WHERE id = :2';
    EXECUTE IMMEDIATE sql_stmt USING fieldValue, id;

  • Execute Dynamic SQL statement using procedure builder

    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks

    Hi,
    You can very well use DBMS_SQL Package supplied by Oracle for doing this.
    Search for DBMS_SQL in OTN. You will get all info regarding this.
    Regards.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by itslul:
    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks<HR></BLOCKQUOTE>
    null

  • Dynamic SQL Statement with table name

    Dear all
    i like to have a SQL statement with a dynamic tablename. Is this possible? If yes, how?
    should be something like "select * from <mytablename>"
    Thank you
    Herbert

    Yes this is possible. use the below reference code for this.
    data: g_tablename type w_tabname,
            gv_dref TYPE REF TO data.
    FIELD-SYMBOLS: <g_itab> TYPE STANDARD TABLE.
    gv_tabname = p_tablename (take table name form selection screen or as per ur requirement)
    CREATE DATA gv_dref TYPE TABLE OF (g_tabname).
    ASSIGN gv_dref->* TO <g_itab>.
    now use the below select query to fetch the data
      SELECT * FROM (gv_tabname) INTO TABLE <g_itab>.
    Hope this will help

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

Maybe you are looking for