Dynamic SQL statements

Hi
Here is an interesting question for all. My application has to support 5 markets. For that I created a report based on querying a view. That report is based on some search criteria which comes through a form. Right now the report is perfectly working as I have queried it as
select * from portland.rsu_inventory where ne = :ne_no
But we have some more markets apart from PORTLAND. For that we want to use the same application. So we have to be able to pass the market name dynamically. I am able to capture the market name in the search croteria form. But how can I send the market name to the Report SQL statement like
select * from | |MarketName| |.rsu_inventory where ne = :ne_no
Here the "MarketName" should be the market name that I would dynamically pass.
How can I acieve this. Thanks for any kind of suggession.
venu

According to the metalink, the new version of OracleAs Portal is no longer support the query statement passing to this wwv_render_report.show procedure but however you can pass the cursor handle to this procedure instead. Here is the sample code to call this procedure:
declare
v_qry_stmt varchar2(32767) ;
v_cur_hdl int;
begin
v_cur_hdl := dbms_sql.open_cursor; -- open cursor
v_qry_stmt := '<your query>';
--Example query:
--v_qry_stmt := 'select empno,ename from scott.emp';
dbms_sql.parse(v_cur_hdl, v_qry_stmt, dbms_sql.native);
PORTAL30.wwv_render_report.show(p_table_border=>'1',
p_heading_bgcolor=>'#FFFFF0',
p_heading_font_face=>'Arial',
p_heading_font_size=>'13',
p_table_bgcolor=>'#FFFFFF',
p_font_face=>'Arial',
p_font_size=>'10',
p_query=>to_char(v_cur_hdl),
p_col_headings=>PORTAL30.wwv_standard_util.string_to_table2('Employee Number:Employee Name')
end;
Thanks
-Krishnamurthy

Similar Messages

  • 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

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

  • 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

  • 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

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

  • 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

  • Comparintg times  in a dynamic sql statement

    I am working on a coversion procedure from one database to another. I have a move procedure that calls functions and the like .
    I am trying to use dynamic sql and my where clause is giving me errors. What am I missing here ? TIA....
    DEFINE DATECUTOFF ='11-JAN-05' of type date
    DES_DATE is a date column in the 2nd database .... type date
    I am building strings to do a create table from the 2nd database ...
    Testwhere := q'[where to_char("des_date", 'DD-MM-YY') < '01-JAN-05]'; === works but I want to pass in date variable
    Teststring := 'Create table '|| table_name || ' as select * from '|| second_table||'@'Linkname
    execute immediate teststring || ''|| testwhere;
    Testwhere := q'[where to_char("des_date", 'DD-MM_YY') <  to_char(DATECUTOFF, 'DD-MON-YY')]; gives me errors like invalid number, or invalid type depending on where the quotes are or how I define DATECUTOFF
    Any ideas of what I am doing wrong in comparing the two dates ?
    Thanks.

    Sorry if I confused anyone ... we're working a duo effort here and get confused ourselves. Here's a summary of the effort.
    We're on 11G Linux.
    We're writing scripts, procedures and functions that will help us transition from a remote database (Ingres) to oracle. We plan to do this for many dbs, so we are using variables for the table names, links, etc ....
    The Where clase that we are developing is pretty
    complex, so our initial attempts to build it is
    to make it into two sections as a "literal" , join them and do a execute immediate. A date fields seem to be the issue...
    Our main procedure calls a datamove function to do the select from the remote data base....
    DATECUTOFF is date;
    TESTWHERE is varchar2(600);
    TESTSTRING varchar2(600);
    TestString := 'Create table '|| table_name_temp|| as select * from '||remote_table_name||'@'Linkname;
    TestWhere :=q'[ Where ||des_date < 'DATECUTOFF'];
    execute immediate Teststring || '' ||Testwhere;
    Can I do this in dynamic plsql ? the des_date is the column from the remote database. DATACUTOFF comes from the main procedure passed in.
    I do a DBMS_OUTPUT.Put_Line{teststring);
    DBMS_OUPUT.Put_Line(testwhere);
    and get the following on my screen
    Create Table AC_KEY_TEMP as select * from ACK_KEY2@DBLINK2
    where "des_date" = 11-Jan-05
    DECLARE
    Error at line 1;
    ORA-00904 "JAN" invalid identfier
    ORA- 06512 at datamove.datamove, line 146
    ORA-06512 at line 49, which is the line for
    the TestWHERE string.
    so in the procedure, if DBMS_OUTPUT is correct, the execute immediate is operating on the where clause and it
    thinks the JAN field is incorrect. I have put single quotes around it as well ...

  • Creating a dynamic sql statement

    hi,
    I am having a query
    select w.id, w.cr_dt, w.cc_cor_addr_id, w.cc_cee_addr_id,
    w.ttl_pkgs, w.chrg_wt, wf.wb_bkg_chgd_amt + wf.wb_bkg_chgd_amt_st
    from ops_waybl_fin wf, ops_waybl w
    where wf.id = w.id
    and cre_bill_batch_dtls_id in (select get_bill_batch(1) from dual);
    the bold part is a function returns a select query.
    if the sql statement is run then we get data based on which the parent query returns data.
    how we should use a function that returns select query.
    Please advice..

    *** not tested *** Sven probably had in mind something like
    with
    v_count_cust_no as
    (select count(orr.param_val) the_count
       from ops_report_req orr
      where orr.id = :p_req_id
        and orr.param_nm = 'CUST_ID'
    v_count_cust_cntr as
    (select count(orr.param_val) the_count
       from ops_report_req orr
      where orr.id = :p_req_id
        and orr.param_nm = 'CUST_CNTR_ID'
    variant as
    (select case when (select the_count from v_count_cust_no) > 0
                 then case when (select the_count from v_count_cust_cntr) > 0
                           then 1
                           else 2
                      end
                 else case when (select the_count from v_count_cust_cntr) > 0
                           then 3
                           else 4
                      end
            end the_type
       from dual
    select w.id,w.cr_dt,w.cc_cor_addr_id,w.cc_cee_addr_id,w.ttl_pkgs,w.chrg_wt,wf.wb_bkg_chgd_amt + wf.wb_bkg_chgd_amt_st
      from ops_waybl_fin wf,ops_waybl w
    where wf.id = w.id
       and cre_bill_batch_dtls_id in (select to_number(b.id)
                                        from ops_bill_batch_dtls b,ops_cust_cntr cc
                                       where b.cust_cntr_id = cc.id
                                         and b.bill_batch_id = f1(1)
                                         and b.status_lid = 255
                                         and (((select the_type from variant) = 1
                                               and cc.cust_no in (select param_val
                                                                    from ops_report_req
                                                                   where id = :p_req_id
                                                                     and param_nm = 'CUST_ID'
                                               and cc.ID in (select param_val
                                                               from ops_report_req
                                                              where id = :p_req_id
                                                                and param_nm = 'CUST_CNTR_ID'
                                           or ((select the_type from variant) = 2
                                               and cc.cust_no in (select param_val
                                                                    from ops_report_req
                                                                   where id = :p_req_id
                                                                     and param_nm = 'CUST_ID'
                                           or ((select the_type from variant) = 3
                                               and cc.ID in (select param_val
                                                               from ops_report_req
                                                              where id = :p_req_id
                                                                and param_nm = 'CUST_CNTR_ID'
                                           or ((select the_type from variant) = 4
                                     ) Regards
    Etbin

  • Dynamic SQL Statements with an JDBC Adapter

    Hello,
    i have a simple scenario:
    A WebService calls SAP XI and XI has convert this request into an dynamic SQL for a particular DB-Table.
    Two Questions:
    1. Can this done with an JDBC-Receiverchannel or do i have to write a Java Server-Proxy?
    2. How do i bring dynamic SQL Stratement into the JDBC Receiver-Adapter?
    Regard
    Gunnar

    I think you should be able to achieve this using the SQL_QUERY / SQL_DML action in the JDB receiver adapter...
    The SQL string can be dynamically created....
    see the help link on different document types with JDBC receiver adapater....look for statement6...
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm
      <StatementName6>
    <anyName action=” SQL_QUERY” | “SQL_DML”>
    <access>SQL-String with optional placeholder(s)</access>
    <key>
      <placeholder1>value1</placeholder1>
      <placeholder2>value2<placeholder2>    
    </key>
    </anyName > 
      </StatementName6>
    Thanks,
    Renjith

  • Report for a dynamic SQL Statement

    Hi,
    I have a dynamic generated SQL query and I want to report the result in a report region like a regular (standard) report.
    Is there a PL/SQL package function where I can put the parameters in (like SQL query etc) and outputs me the the HTML Code which I can put with htp.p?
    regards
    voidy
    PS: hope you understand what I mean

    Hi Denes (and all the others ;),
    well, I was too busy on my Apex projects lately ;). Actually quite an interesting application. Currently I build a high availability solution for 4.500 users, maybe 2.000 using it at the same time.
    And I have just recently become a father of a beautiful daughter:
    http://www.flickr.com/photos/13993868@N00/sets/72157594266133338/detail/
    http://www.flickr.com/photos/13993868@N00/sets/72157594266133338/show/
    These things have kept me quite busy lately ...
    Greetinx,
    ~Dietmar.

  • Variables & dynamic sql statements in PL/SQL

    Hi All,
    I'm sure I am missing something really simple, but I can't figure it out...
    In a procedure, I'm trying to 'build' a sequence name from a parameter (table name), and then select the nextval into another variable to be used later. But I don't seem to be doing it correctly...
    First I created a var to hold the full sequence name (table_name_seq.nextval) like this:
    v_Sequence_Name := '"'||param_table_name||'_Seq".nextval';This seems to work correctly as I have output the value and I get what I am expecting. Next I try to use the new variable in a select statement like so:
    -- I've tried many variations here, but none have worked
    select v('v_Sequence_Name') into v_Sequence_ID from dual;I end up with a Null I think (because I insert the value into a test table).
    Any ideas what I am doing wrong?
    TIA,
    Corey

    dynamic query in pl/sql needs to be executed using exec. immediate statement or the dbms_sql package.
    here's what you can do :
    execute immediate 'select '|| v_sequence_name ||' from dual' into v_sequence_id;

  • Dynamic SQL statement to select the tables which are updated today...

    Hi Guys,
    I need to find the names of all the tables which contain rows that are inserted/updated in a given time stamp...
    Below statement gives me the list of all the tables in the database...
    select t.table_name from all_tables t;All these tables in the database have a column called rowversion which gives the updated/inserted date of a record. I need to write a select statement (probably dynamic) which will give me the table names which contain the rowversion value 24-01-2013....
    Any help is very much appreciated...

    Napster wrote:
    Hi Karthick,
    Thanks for your reply...
    But when I execute your select statement I am getting an error saying table SYS.DBMS_XMLGEN does not exist.
    Probably something wrong in my environment?Yes you can, here is a quick untested code
    declare
      my_filter date := to_date('24-01-2013', 'dd-mm-yyyy');
      my_count integer;
    begin
      for i in (select table_name from user_tables)
      loop
         execute immediate q'[select count(*) from ]' || i.table_name || q'[ where rowversion = :1]'
         using my_filter
         into my_count;
         if my_count > 0 then
             dbms_output.put_line(i.table_name);
         end if;
      end loop;
    end; 
    /

Maybe you are looking for

  • Lost messages in PI

    Hi, messages are sent by ABAP PRoxy from IS-U to PI, but they do not come. It happend just now, before communication worked nicely. At PI smq1,smq2, sm58 are clean. at IS-U log of proxy says messages were sent, and sm58 also has no errors. Any ideas?

  • WAP4410N SSLv3 no longer supported in Chrome, Firefox

    Hello all I have a Cisco WAP4410N servicing a small office for drop-in technicians to connected to our LAN, no heavy traffic or fancy management set up, they just see it as a wireless access point they can connect to for internet and access some Samb

  • Programatic control of float array precision?

    Using LV6.1, I can't figure out how to control the array precision similar to the attached example's control of a simple float control.  Can it be done? Attachments: Untitled.vi ‏20 KB

  • Adobe content viewer "error during download, please try again"

    I'm experiencing some strange behavior in the new version of adobe content viewer. When Launching the viewer app for the first time on an ipad I will get the login screen, enter credentials and then be presented with the home page, with an Icon for m

  • Battery menubar status not updating

    Hello, My battery menubar status indicator does not change while my powerbook is plugged in. It will stay at the same charge % and the time remaining stays on "calculating". Any suggestions would be appreciated. Thank you