Dynamic Column in SQL-Statement

Hello,
can i do something like this?
SELECT :P101_Lang FROM LANGUAGE where NAME = 'P5_REPORT'
Many thanks in advance

I have a similar situation, but rather than a select statement, it's an update statement. I'm still VERY new to APEX and Oracle SQL. I'm used to using MS Access & VBA, but the project that was handed to me is APEX, so I'm doing my best to learn it.
Page Items:
P4_COLUMN_NAMES (Listbox)
P4_TEXT ENTRY (text field)
P4_ITEM_ENTRY (List management)
The process that should happen is this: User picks several items from ITEM_ENTRY, then chooses which column to update in COLUMN_NAMES to whatever is in TEXT_ENTRY.
Using the APEX function to cycle through the ITEM_ENTRY results, I've tried SEVERAL ways, all of which resulted in multiple errors. I've spent over a week, off and on, on this issue. Here is the most basic version.
declarev_p1_x_arr apex_application_global.vc_arr2;
begin
v_p1_x_arr := apex_util.string_to_table(:P4_ITEM_ENTRY);
for i in 1..v_p1_x_arr.count loop
UPDATE SMT SET :P4_COLUMN_NAMES = :P4_TEXT_ENTRY
end loop;
end;>
I've tried this as an app process and a page process. Until I found this thread, I didn't even know there was a PL/SQL region. ((told ya I'm a newbie)) It seems like the solution you provided to the other person is pretty close to what I'm looking for. However, I don't know how to implement it with the APEX function above.
Any help would be GREATLY appreciated!
Thanks,
-- Matt

Similar Messages

  • Dynamic column name sql?

    I need to do a select statement using dynamic column names. Can it be done WITHOUT building a string to execute the sql?
    In other words, I want to use a variable name in the SELECT part of a statement.
    Thanks

    Properly done, there shouldn't be a great difference in the performance of static and dynamic SQL. Of course, dynamic SQL is a whole lot more complicated to get right. It's also rather at odds with your requirement that column names get passed in dynamically-- if you don't know what columns you're going to select at compile time, you can't use static SQL.
    That said, there are a handful of tricks around using Oracle's built-in XML processing functionality to simulate dynamic SQL. This is almost certainly less efficient than doing dynamic SQL in your case, and a whole lot more complicated, but it's technically not dynamic SQL.
    The proper response, though, is almost certainly to either
    1) figure out how to design the application so that column names need not be passed in at runtime or
    2) use dynamic SQL.
    If at all possible, option 1 is generally preferable. While there are situations where dynamic SQL is necessary, those tend to be rather rare.
    Justin

  • Output fields dynamically from an SQL statement

    I'm trying to build an SQL statement that uses the values from one table to form the field names to output in the select statement. I have two tables, pjl_test contains the field names and bp_objects contains the data I want the sql to return... the tables look like this:
    pjl_test table:
    field_name
    OBJECT_TYPE
    SHORT_DESCRIPTION
    OBJECT_ID
    bp_objects table:
    object_id, object_type, short_description
    275 TS Establish Contract
    276 TS Enter contract details
    277 TS Review & amend Contract details as required
    278 TS Enter/update contractor details
    The select statement I'm toying with looks like this:
    SELECT (
    SELECT field_name
    from (SELECT ROWNUM as MyNo, field_name from pjl_test)
    where myno = 1) as Name FROM BP_OBJECTS
    The problem is that the sql is using the returned field name as a display value instead of a column name and thus outputs the following:
    OBJECT_TYPE
    OBJECT_TYPE
    OBJECT_TYPE
    OBJECT_TYPE
    I'm sure there must be a way to do this in an single sql statement, is anyone able to advise.
    Thanks in advance

    I'm sure there must be a way to do this in an single sql statement, is anyone able to advise.No, there is no simple way to get the column name then select those ones in one statement.
    Dynamic sql will do that. But not a single statement.
    Or maybe some XML package. Then you have to tell about your db vwersion.
    Nicolas.

  • How to dynamically execute generated SQL statements using 11gR2 ?

    Hello,
    I'd like to know if it is possible to do what the following statement intended to do:
    select * from (select replace('select empno from emp',
                                 '') from dual);in other words, is it possible to dynamically generate and execute a select statement in a from clause ?
    thank you for your help,
    John
    Edited by: 440bx on Jul 16, 2010 3:57 PM changed "generate" to "generated" in subject

    Hello Aketi,
    That is totally WICKED !!
    I've been playing with the code you posted, pretty much since you did, trying to figure out how it works. I have some idea of how it works now but, I cannot figure out why I get the set of results, not once but TWICE.
    When I run the query you posted above, this is what I get:
    SQL> @getxml2
    TABLE_NAME                          count
    CLOB_EXAMPLE                            1
    D42                                     1
    DEPT                                    4
    DEPT_2                                  0
    DEPT_ACCIDENTS                          6
    DEPT_EAST                               2
    ... some tables deleted to shorten the output
    T1                                      1
    T10                                    10
    T100                                    0
    22 rows selected.
    TABLE_NAME                          count
    CLOB_EXAMPLE                            1
    D42                                     1
    DEPT                                    4
    DEPT_2                                  0
    DEPT_ACCIDENTS                          6
    DEPT_EAST                               2
    ... some tables deleted to shorten the output
    T1                                      1
    T10                                    10
    T100                                    0
    22 rows selected.
    SQL>The result is shown TWICE. I cannot figure out why. Any ideas as to why the result is shown twice ? (I ran the statement from SQL*Plus and started a fresh instance of SQL*Plus to ensure that no settings from previous scripts would be the cause).
    Thank you for your help, great little piece of code!
    John.
    Edited by: 440bx on Jul 16, 2010 5:30 PM
    Edited by: 440bx on Jul 16, 2010 5:31 PM - corrected name in Hello greeting
    Edited by: 440bx - 11gR2 on Jul 17, 2010 2:55 AM - corrected misspelling
    Edited by: 440bx - 11gR2 on Jul 17, 2010 2:56 AM - corrected another misspelling

  • SSIS Dynamic Columns in SQL

    Hi All
    I have an unusual issue and wondered if someone could assist. have a table which contains a list of columns which i need to feed into the query. I have written some dynamic SQL as shown:
    Declare @KeyString varchar(100)
    Declare @SQL1 nvarchar(max)
    Set @KeyString=(Select STUFF((SELECT '+' + Attr FROM ave_control.ETL.Source inner JOIN [DM_AVE2].[Reference].[CRKAttr] on client = sourcename COLLATE DATABASE_DEFAULT where Client = 'Brampton' Order by AttrOrder FOR XML PATH('')),1,1,'') AS KeyString)
    Set @SQL1 ='WITH CLAIMDATA AS(
    Select
    DB_NAME() AS DBName,
    Convert(Varchar,UK.KMPONO) + ''/'' + Convert(Varchar,UK.KMPOSQ) + ''/'' + Convert(Varchar,UK.KMUGYR) + ''/'' + Convert(Varchar,UK.KMDANO) AS [POLICYREF],
    Convert(Varchar,UK.KMPONO) + ''/'' + Convert(Varchar,UK.KMPOSQ) + ''/'' + Convert(Varchar,UK.KMUGYR) + ''/'' + Convert(Varchar,UK.KMDANO) + ''/'' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
    left(19000000+KMLODT,4) as [LOSSYEAR],
    UK.KMLOCD AS [LOSSCODE],
    CASE WHEN KMLOCD = '''' then COALESCE(UC.LOLODS,'''') ELSE UC.LOLODS END AS LOSSDESCRIPTION,
    UK.KMEVCD AS [EVENTCODE],
    KMCMDS AS [CLAIMDESCRIPTION],
    CASE WHEN LEFT(KMCMDS,1) = ''@'' THEN ''Y'' ELSE ''N'' END AS [STATICRESERVEREVIEW],
    CASE WHEN UCE.EVEVDS IS NULL then COALESCE(UCE.EVEVDS,'''') ELSE UCE.EVEVDS END AS [EVENTCODEDESCRIPTION]
    FROM UKKMREP UK
    LEFT JOIN UCLOREP UC ON UK.KMLOCD = UC.LOLOCD
    LEFT JOIN UCEVREP UCE ON UK.KMEVCD = UCE.EVEVCD),
    COGDATA AS(
    SELECT TOP 100 PERCENT
    CONVERT(Varchar,POLICY)+''/''+CONVERT(Varchar,CO.SEQ)+''/''+CONVERT(Varchar,CO.[YEAR])+''/''+CONVERT(Varchar,CO.[DEC])+''/''+CONVERT(Varchar,CO.CLAIM) AS [CLAIMREF],
    [Type],
    SUM(isnull(CO.KCR,0)+isnull(CO.ACR,0)+isnull(CO.[OCR],0)+isnull(CO.[EXP],0)+isnull(Co.[LOC],0)) AS OLR
    FROM COG626A CO
    Group by CONVERT(Varchar,POLICY)+''/''+CONVERT(Varchar,CO.SEQ)+''/''+CONVERT(Varchar,CO.[YEAR])+''/''+CONVERT(Varchar,CO.[DEC])+''/''+CONVERT(Varchar,CO.CLAIM), [Type]
    ORDER BY CLAIMREF
    CLAIMRCData AS(
    Select distinct
    DB_NAME() As DBNAME,
    Convert(Varchar,UK.KMPONO) + ''/'' + Convert(Varchar,UK.KMPOSQ) + ''/'' + Convert(Varchar,UK.KMUGYR) + ''/'' + Convert(Varchar,UK.KMDANO) + ''/'' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
    Convert(varchar,isnull(pocscd,'''')) as POCSCD,
    Convert(varchar,isnull(pomkrf,'''')) AS PMKRF,
    Convert(varchar,isnull(poplcd,'''')) AS POPLCD,
    Convert(varchar,isnull(poqdfg,'''')) AS POQDFG,
    Convert(varchar,isnull(pougty,'''')) AS POUGTY,
    Convert(varchar,isnull(pogucd,'''')) AS POGUCD,
    Convert(varchar,isnull(kmbhcd,'''')) AS KMBHCD,
    Convert(varchar,isnull(kmcccd,'''')) AS KMCCCD,
    Convert(varchar,isnull(kmdpdv,'''')) AS KMDPDV,
    Convert(varchar,isnull(kmevcd,'''')) AS KMEVCD,
    Convert(varchar,isnull(kmimcd,'''')) AS KMIMCD,
    Convert(varchar,isnull(kmiycd,'''')) AS KMIYCD,
    Convert(varchar,isnull(kmlocd,'''')) AS KMLOCD
    from UPPOREP UP Left join UKKMREP UK on UP.POPONO = UK.KMPONO AND UP.POPOSQ = KMPOSQ AND UP.POUGYR = UK.kmugyr AND UP.PODANO = UK.KMDANO)
    Select distinct
    C1.DBName,
    C1.POLICYREF,
    C1.CLAIMREF,
    C1.LossDescription,
    C1.LOSSCODE,
    C1.LOSSYEAR,
    C1.EventCode,
    C1.ClaimDescription,
    C1.StaticReserveReview,
    C1.EventCodeDescription,'
    + @KeyString + ' AS ClaimKey,
    Round(CG1.OLR,2) as [OLR],
    CASE WHEN CG1.OLR <> 0 THEN ''OPEN'' ELSE ''CLOSED'' END AS [ClaimStatus]
    FROM CLAIMDATA C1
    LEFT JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
    LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
    UNION
    Select distinct
    C1.DBName,
    C1.POLICYREF,
    SUBSTRING(CG1.ClaimRef,1,Len(CG1.ClaimRef)-2) + ''/0'',
    '''' AS LossDescription,
    '''' AS LossCode,
    1912 AS LossYear,
    '''' AS EventCode,
    '''' AS ClaimDescription,
    '''' AS StaticReserveReview,
    '''' AS EventCodeDescription,'
    + @KeyString + ' AS ClaimKey,
    0 AS OLR,
    ''CLOSED'' AS CLAIMSTATUS
    From CLAIMDATA C1
    INNER JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
    LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
    Order by C1.POLICYREF'
    Select @SQL1
    I always want to output @Keystring using a DFT but depending on the client the Keystring is set to a different group of columns and selects a different set of columns from the CLAIMRCData loop.
    I tried inserting it as dynamic SQL as a variable but cannot get it to parse - does anyone know how to achieve this?
    Here is the output from the Select @SQL1 which always returns the value I want and if i execute this and change the clientname it successfully returns the right claimkey each time - i.e. another client has 3 columns and these are successfully parsed
    - i just dont know how to get it into SSIS. Output as shown:
    WITH CLAIMDATA AS(
    Select
    DB_NAME() AS DBName,
    Convert(Varchar,UK.KMPONO) + '/' + Convert(Varchar,UK.KMPOSQ) + '/' + Convert(Varchar,UK.KMUGYR) + '/' + Convert(Varchar,UK.KMDANO) AS [POLICYREF],
    Convert(Varchar,UK.KMPONO) + '/' + Convert(Varchar,UK.KMPOSQ) + '/' + Convert(Varchar,UK.KMUGYR) + '/' + Convert(Varchar,UK.KMDANO) + '/' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
    left(19000000+KMLODT,4) as [LOSSYEAR],
    UK.KMLOCD AS [LOSSCODE],
    CASE WHEN KMLOCD = '' then COALESCE(UC.LOLODS,'') ELSE UC.LOLODS END AS LOSSDESCRIPTION,
    UK.KMEVCD AS [EVENTCODE],
    KMCMDS AS [CLAIMDESCRIPTION],
    CASE WHEN LEFT(KMCMDS,1) = '@' THEN 'Y' ELSE 'N' END AS [STATICRESERVEREVIEW],
    CASE WHEN UCE.EVEVDS IS NULL then COALESCE(UCE.EVEVDS,'') ELSE UCE.EVEVDS END AS [EVENTCODEDESCRIPTION]
    FROM UKKMREP UK
    LEFT JOIN UCLOREP UC ON UK.KMLOCD = UC.LOLOCD
    LEFT JOIN UCEVREP UCE ON UK.KMEVCD = UCE.EVEVCD),
    COGDATA AS(
    SELECT TOP 100 PERCENT
    CONVERT(Varchar,POLICY)+'/'+CONVERT(Varchar,CO.SEQ)+'/'+CONVERT(Varchar,CO.[YEAR])+'/'+CONVERT(Varchar,CO.[DEC])+'/'+CONVERT(Varchar,CO.CLAIM) AS [CLAIMREF],
    [Type],
    SUM(isnull(CO.KCR,0)+isnull(CO.ACR,0)+isnull(CO.[OCR],0)+isnull(CO.[EXP],0)+isnull(Co.[LOC],0)) AS OLR
    FROM COG626A CO
    Group by CONVERT(Varchar,POLICY)+'/'+CONVERT(Varchar,CO.SEQ)+'/'+CONVERT(Varchar,CO.[YEAR])+'/'+CONVERT(Varchar,CO.[DEC])+'/'+CONVERT(Varchar,CO.CLAIM), [Type]
    ORDER BY CLAIMREF
    CLAIMRCData AS(
    Select distinct
    DB_NAME() As DBNAME,
    Convert(Varchar,UK.KMPONO) + '/' + Convert(Varchar,UK.KMPOSQ) + '/' + Convert(Varchar,UK.KMUGYR) + '/' + Convert(Varchar,UK.KMDANO) + '/' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
    Convert(varchar,isnull(pocscd,'')) as POCSCD,
    Convert(varchar,isnull(pomkrf,'')) AS PMKRF,
    Convert(varchar,isnull(poplcd,'')) AS POPLCD,
    Convert(varchar,isnull(poqdfg,'')) AS POQDFG,
    Convert(varchar,isnull(pougty,'')) AS POUGTY,
    Convert(varchar,isnull(pogucd,'')) AS POGUCD,
    Convert(varchar,isnull(kmbhcd,'')) AS KMBHCD,
    Convert(varchar,isnull(kmcccd,'')) AS KMCCCD,
    Convert(varchar,isnull(kmdpdv,'')) AS KMDPDV,
    Convert(varchar,isnull(kmevcd,'')) AS KMEVCD,
    Convert(varchar,isnull(kmimcd,'')) AS KMIMCD,
    Convert(varchar,isnull(kmiycd,'')) AS KMIYCD,
    Convert(varchar,isnull(kmlocd,'')) AS KMLOCD
    from UPPOREP UP Left join UKKMREP UK on UP.POPONO = UK.KMPONO AND UP.POPOSQ = KMPOSQ AND UP.POUGYR = UK.kmugyr AND UP.PODANO = UK.KMDANO)
    Select distinct
    C1.DBName,
    C1.POLICYREF,
    C1.CLAIMREF,
    C1.LossDescription,
    C1.LOSSCODE,
    C1.LOSSYEAR,
    C1.EventCode,
    C1.ClaimDescription,
    C1.StaticReserveReview,
    C1.EventCodeDescription,pogucd+pougty AS ClaimKey,
    Round(CG1.OLR,2) as [OLR],
    CASE WHEN CG1.OLR <> 0 THEN 'OPEN' ELSE 'CLOSED' END AS [ClaimStatus]
    FROM CLAIMDATA C1
    LEFT JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
    LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
    UNION
    Select distinct
    C1.DBName,
    C1.POLICYREF,
    SUBSTRING(CG1.ClaimRef,1,Len(CG1.ClaimRef)-2) + '/0',
    '' AS LossDescription,
    '' AS LossCode,
    1912 AS LossYear,
    '' AS EventCode,
    '' AS ClaimDescription,
    '' AS StaticReserveReview,
    '' AS EventCodeDescription,pogucd+pougty AS ClaimKey,
    0 AS OLR,
    'CLOSED' AS CLAIMSTATUS
    From CLAIMDATA C1
    INNER JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
    LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
    Order by C1.POLICYREF
    any help would be greatly appreciated - oh version is SQL 2014 SSIS
    Thanks
    James

    When you say not able to parse, can you give the expression itself?
    And in what SSIS component do you run this query?
    And what error do you get?
    My cursory look (too much code to digest frankly) says you need to wrap it into a stored procedure.
    Arthur
    MyBlog
    Twitter

  • How to Generate Dynamic Columns from SQL

    Hi Friends,
    I want to create a data fromat like This
    Showroom / date    01-01-09        02-01-09     03-01-09     04-01-09      05-01-09     06-01-09     07-01-09   
    S1                           20                      10              09            90             90                  10            100
    S2                           10                       1                1              2               6                    2             10
    S3                            5                        7                 9             1               2                    3             12This Data is Just like Matriz Reports....................................
    Here i Want to Generate Date column value Dynamically.....................is it possible through SQL
    the values are Sales value for each showroom for diffrent date value
    all sale,showroom and Date Column are in one Table......................
    It should Generate date Dynamically depending on User VAlues./..............
    Thanks in Advance

    something to play with (not tested as I don't have database access)
    declare
    /* assuming table showroom_sales has columns a_showroom,a_date,a_sale */
      the_sql varchar2(32000) := 'select a_showroom';
      day_from date := to_date('20090101','yyyymmdd');
      day_till date := to_date('20090107','yyyymmdd');
    begin
      for d in (select a_date from showroom_sales where a_date between day_from and day_till)
      loop
        the_sql := the_sql ||
                   ',max(decode(a_date,to_date('''||to_char(d.a_date,'yyyymmdd')||''',''yyyymmdd''),a_sale,null)) "'||to_char(d.a_date,'dd-mm-rr')||'"'
      end loop;
      the_sql := the_sql || ' from showroom_sales group by a_showroom order by a_showroom ';
      dbms_output.put_line(the_sql);  /* to verify if query is correct or not */
    end;the code above should generate something like (provided all those dates appear in your showroom_sales table)
    select a_showroom,
           max(decode(a_date,to_date('20090101','yyyymmdd'),a_sale,null)) "01-01-09",
           max(decode(a_date,to_date('20090102','yyyymmdd'),a_sale,null)) "02-01-09",
           max(decode(a_date,to_date('20090103','yyyymmdd'),a_sale,null)) "03-01-09",
           max(decode(a_date,to_date('20090104','yyyymmdd'),a_sale,null)) "04-01-09",
           max(decode(a_date,to_date('20090105','yyyymmdd'),a_sale,null)) "05-01-09",
           max(decode(a_date,to_date('20090106','yyyymmdd'),a_sale,null)) "06-01-09",
           max(decode(a_date,to_date('20090107','yyyymmdd'),a_sale,null)) "07-01-09"
      from showroom_sales
    group by a_showroom
    order by a_showroom to be executed to get the result as required
    Regards
    Etbin

  • How to dynamic create Select SQL statements.

    Hi frnds,
    I want to make a SELECT statement in which all values I will get dynamically. Like i have two fields on selection screen, one for table name and one for field name. Now I need to make my ITAB according to the table selected and field name selected. So finally my ITAB will be having the field which I chosen from selection screen.
    Now how can I make a dynamic ITAB and how to create a dynamic SELECT statement?
    It wud be great if you can help me.
    Thanks
    Arpit

    Here is a sample program....
    This will get you started in programming a dynamic internal table as well as dynamic select.
    report zrich_0002.
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: alv_fldcat type slis_t_fieldcat_alv,
          it_fldcat type lvc_t_fcat.
    type-pools : abap.
    data : it_details type abap_compdescr_tab,
           wa_details type abap_compdescr.
    data : ref_descr type ref to cl_abap_structdescr.
    data: new_table type ref to data,
          new_line  type ref to data,
          wa_it_fldcat type lvc_s_fcat.
    selection-screen begin of block b1 with frame title text .
    parameters: p_table(30) type c.
    selection-screen end of block b1.
    * Get the structure of the table.
    ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
    it_details[] = ref_descr->components[].
    loop at it_details into wa_details.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = wa_details-name .
      wa_it_fldcat-datatype = wa_details-type_kind.
      wa_it_fldcat-intlen = wa_details-length.
      wa_it_fldcat-decimals = wa_details-decimals.
      append wa_it_fldcat to it_fldcat .
    endloop.
    * Create dynamic internal table and assign to FS
    call method cl_alv_table_create=>create_dynamic_table
                 exporting
                    it_fieldcatalog = it_fldcat
                 importing
                    ep_table        = new_table.
    assign new_table->* to <dyn_table>.
    * Create dynamic work area and assign to FS
    create data new_line like line of <dyn_table>.
    assign new_line->* to <dyn_wa>.
    * Select Data from table.
    select * into corresponding fields of table <dyn_table>
               from (p_table).
    * Write out data from table.
    loop at <dyn_table> into <dyn_wa>.
      do.
        assign component  sy-index  of structure <dyn_wa> to <dyn_field>.
        if sy-subrc <> 0.
          exit.
        endif.
        if sy-index = 1.
          write:/ <dyn_field>.
        else.
          write: <dyn_field>.
        endif.
      enddo.
    endloop.
    Regards,
    Rich Heilman
    Message was edited by: Rich Heilman

  • Dynamic Conversion of SQL Statement for a particular Schema

    Hi,
    Please suggest me a best method for my following scenerio,
    user1 - Owner of table A (no number, name varchar2, location varchar2, age char(2) )
    user2 - A normal database user
    user2 has access to table A
    Now, even if user2 executes " select * from A; " he should not get all the columns displayed, i.e for example the query "select * from A " should be dynamically converted to "select no, name from A ".
    Like that the user1 should restrict the display of particular columns to particular users in database.
    Please do help me out
    Thanks

    Of course I can create a view but the thing is user2 needs to access the parent table A itselfWell, really they just need to think they're accessing parent table A.
    The proper approach for that is a combination of views and synonyms and no direct visibility of the base table to the other user.
    The other option is some element of VPD column masking - that will hide the data but not the column definition.

  • How to set Query SQL Statement parameter dynamically in Sender JDBCAdpter

    Hi All,
    I have one scenario in which we are using JDBC Sender Adapter.
    Now in this case,we need to set Query SQL Statement with a SELECT statement based on some fields.
    This SQL statement is not constant, it would need to be changed.
    Means sometimes receiver will want to execute SQL statement with these fields and sometimes they will want to execute it with different fields.
    We can create separate channels for each SQL statement but again that is not an optimum solution.
    So ,I am looking out for a way to set these parameters dynamically or set SQL statement at Runtime.
    Can you all please help me to get this?

    Shweta ,
    <i>Sometimes receiver will want to execute SQL statement dynamically</i>....
    How you will get the query dynamically? Ok Let me assume, consider they are sending the query through file, then its definitely possible. But u need BPM and also not sender JDBC receiver adapter instead, receiver JDBC adapter.
    SQL Query File ->BPM>Synchronous send [Fetch data from DB]--->Response -
    >...............
    Do u think the above design will suit's ur case!!!!
    Best regards,
    raj.

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

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

  • Dynamic select sql statement

    Hi currently i have a problem with the sql statement.
    The field name and the table name of the sql statement will depend on what the user input. We need to find out what records is in tableA columnA and not in tableB columnB.
    Below is my sql statement:
    SELECT * FROM (TABLEA) INTO TABLE ITABA
    WHERE (COLUMNA)
    NOT IN ( SELECT (COLUMNB) FROM (TABLEB) ).
    =============================================
    ColumnA = "the user input the field name"
    TableA = " the user input the table name"
    TableB = " the user input the table name"
    The problem lies at the WHERE clause. The system generate a sql error which says "unable to find the field name".

    Hi,
    Check the following code:
    For dynamic table name....
    REPORT demo_select_dynamic_database .
    DATA wa TYPE scarr.
    DATA name(10) TYPE c VALUE 'SCARR'.
    SELECT *
    INTO wa
    FROM (name) CLIENT SPECIFIED
    WHERE mandt = '000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDSELECT.
    For dynamic field list
    REPORT demo_select_dynamic_columns .
    DATA: itab TYPE STANDARD TABLE OF spfli,
                wa LIKE LINE OF itab.
    DATA: line(72) TYPE c,
    list LIKE TABLE OF line(72).
    line = ' CITYFROM CITYTO '.
    APPEND line TO list.
    SELECT DISTINCT (list)
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM spfli.
    IF sy-subrc EQ 0.
    LOOP AT itab INTO wa.
    WRITE: / wa-cityfrom, wa-cityto.
    ENDLOOP.
    ENDIF.
    Regards,
    Bhaskar

  • Apex 4.0 display image item :BLOB column returned by SQL statement

    Hello
    I'm creating an display image item in apex 4.0. The source is a BLOB column returned by SQL statement.
    When I'm issuing an sql statement like this:
       select lado.blob_content
       from   large_documents      lado
       ,        large_doc_headers    ladh
       where lado.ladh_nr = ladh.nr
       more criteriait works fine.
    When I create a function inside a package with the same query (in a cursor)
    function get_image(some parameters in) return blob
    Following in apex by:
    select get_image(some parameters) from dualI get a
    ORA-06502: PL/SQL: numeric or value error: character string buffer too smallAnybody any idea why this does not work?
    Regards Erik

    Hi Eric,
    the environment assumes varchar2-output by default, which will be limited to 32767 characters and may have problems with binary formats. You could define a blob-variable to select the value into.
    DECLARE
      l_blob BLOB;
    BEGIN
      SELECT get_image(some parameters)
        INTO l_blob
        FROM dual;
    END;
    /If you expect the BLOB-Content to be text (you should consider CLOB then), you may use UTL_RAW.CAST_TO_VARCHAR2 to convert the content. If your object is larger than the maximum varchar2 size, or you want to convert BLOB to CLOB, you might be interested in some converter like described here: {message:id=559749}
    Hope this is what you were searching for.
    -Udo

  • The column name "PERNR" has two meanings. ABAP/4 Open SQL statement.

    Hi All,
    Could anyone advise on what are the error I encountered at below code.
    I get the error in " The column name "PERNR" has two meanings. ABAP/4 Open SQL statement." . This errors happen to all the key fields I have selected in below code (eg: pernr, subty, objps, sprps, begda, endda, seqnr).
    The field zeih also encountered error in "Unknown column name "ZEIH". not determined until runtime, you cannot specify a field list."      
      SELECT  pernr
                   subty
                   objps
                   sprps
                   begda
                   endda
                  seqnr
                  zlsch
                  ZEIH
      SELECT * INTO CORRESPONDING FIELDS
              OF TABLE  i_pa0009
              FROM pa0001 INNER JOIN pa0009
              ON pa0001pernr = pa0009pernr
              WHERE bukrs IN s_code AND
              banks NE space.

    Hi,
    In this query
    SELECT pernr
    subty
    objps
    sprps
    begda
    endda
    seqnr
    zlsch
    ZEIH
    if you have used joins and if both the database pa0001, pa0009 has the above mentioned fields you will get the error message as the control gets confused as to which table of the field you are referring to..., instead use them in this way
    SELECT pa0001~pernr
    for each field mention to which table it belongs and ~ before the field name in the above fashion, this will remove the error
    Regards,
    Siddarth

  • 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

Maybe you are looking for

  • Regarding web analysis data export issue

    Hi all, Iam new to web analysis we had a issue on one of the report I can open the report and i can work perfectly on the report but when i export the data to excel its showing up as fallowing error FATAL ERROR: gui report is inccorect In the same ap

  • Displaying image from database in report

    I need to include a picture (company logo) in numerous reports. This logo will be stored in an MS SQL Image field in a table (this bit I have already sorted out). What I'm wondering is, what is the best way to retrieve this image from the database? D

  • Clearing account code FR3

    hi, 1) may i know what tcode i can see the custom clearing or freight clearing account posted during GR? If obyc, then what is the transaction code column? for example, custom clearing FR3, I do not see FR3 in M/06. so where is the link for FR3? 2) a

  • "Create Archive of" file destination

    Very strange- on my computer, when I control-click a folder and choose "Create Archive of-", the resulting .zip file ends up in the same folder as the original. I've just been helping my girlfriend archive some old files, and on her computer, the .zi

  • Defining events on a graph like "onclick"

    Hi All, I have a graph(say a guage) embedded in a dashboard in OBIEE 11g. How do i define onclick events on the graph so that when user clicks on the graph, the corresponding data is displayed in a new browser tab(like the table used to plot the grap