Using Dynamic SQL in OWB maps

Hi,
Is there any way that we can write dynamic SQL in OWB.As per my requirement i want to change the where clauses dynamically on need basis.
Thx

David,
I want to change the where clause dynamically.Our objective is to make the map in a generic way so that if there is a change in where clause (i.e. adding more conditions in where clause) i dont have to change the map.I can change the values(if used, say emp_no=20) however i'm facing problem changing the whole condition i.e. even the column name.
Thx

Similar Messages

  • Can we use Dynamic SQL in Oracle Reports ?

    Hi ,
    Can we use Dynamic SQL in Oracle Reports ?
    If yes please give some examples .
    Thanx
    srini

    I believe the built-in package SRW.Do_Sql is what you are looking for
    Example from the document:
    /* Suppose you want to create a "table of contents" by getting the
    ** first character of a columns value, and page number on which its
    ** field fires to print. Assume that you want to put the "table of
    contents"
    ** into a table named SHIP. You could write the following construct:
    DECLARE
    PAGE_NO NUMBER;
    PAGE_FOR INDEX NUMBER;
    SORT_CHAR CHAR(1);
    CMD_LINE CHAR(200);
    BEGIN
    SORT_CHAR := :SORT_NAME ;
    IF :CALLED = Y THEN
         SRW.GET_PAGE_NUM(PAGE_FOR_INDEX);
         SRW.USER_EXIT(RWECOP PAGE_FOR_INDEX
         P_START_PAGENO);
         SRW.MESSAGE(2,TO_CHAR(:P_START_PAGENO));
    END IF;
    SRW.GET_PAGE_NUM(PAGE_NO);
    CMD_LINE := INSERT INTO SHIP VALUES
                          (||SORT_CHAR||,||TO_CHAR(PAGE_NO)||);
    SRW.MESSAGE(2,CMD_LINE);
    SRW.DO_SQL(CMD_LINE);
    COMMIT;
    EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
            NULL;
      WHEN SRW.DO_SQL_FAILURE THEN
            SRW.MESSAGE(1,FAILED TO INSERT ROW INTO SHIP TABLE);
      WHEN OTHERS THEN
           COMMIT;
    END;

  • How to Use Dynamic SQL

    Can anybody please send me a small program on How to Use Dynamic SQL.
    How to execute and run give details.
    Thanks
    null

    You can certainly use the INTO (and USING) clauses of EXECUTE IMMEDIATE to pass in and return data, i.e.
    EXECUTE IMMEDIATE sqlStmt
      USING variable1, variable2
       INTO output1, output2The more complex the statement, however, the more appropriate DBMS_SQL is. DBMS_SQL also has the potential to allow you to use bind variables rather than reparsing the statement many times.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Getting error while using DYNAMIC SQL

    Hi Team,
    I am Oracle DBA. I have limited knowledge on PL/SQL. I used below PL/SQL code to drop 50 partitons from one of the table.
    I used Dynamic SQL EXECUTE IMMEDIATE to drop partions. But error occured. If I commented EXECUTE IMMEDIATE, procedure executed successfully.
    Please suggest me, where i did the mistake. Also please suggest for better code than my code. please find below code and error details.
    SQL> ed
    Wrote file afiedt.buf
    1 DECLARE
    2 CURSOR DROP_PARTITON IS select partition_name from user_tab_subpartitions where PARTITION_NAME<='ABCD_2011_04';
    3 BEGIN
    4 for curr IN DROP_PARTITON LOOP
    5 DBMS_output.put_line(curr.partition_name);
    6 execute immediate(Alter table Table_Name drop partition curr.partition_name);
    7 end loop;
    8* END;
    SQL> /
    execute immediate(Alter table BILLCHRG drop partition curr.partition_name);
    ERROR at line 6:
    ORA-06550: line 6, column 19:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    ( - + case mod new not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set specification>
    <an alternative
    SQL> ed
    Wrote file afiedt.buf
    1 DECLARE
    2 CURSOR DROP_PARTITON IS select partition_name from user_tab_subpartitions where PARTITION_NAME<='ABCD_2011_04';
    3 BEGIN
    4 for curr IN DROP_PARTITON LOOP
    5 DBMS_output.put_line(curr.partition_name);
    6 --execute immediate(Alter table TABLE_NAME drop partition curr.partition_name);
    7 end loop;
    8* END;
    SQL> /
    ABCD_2009_06
    ABCD_2009_06
    ABCD_2009_06
    BILLCHRG_2011_04
    PL/SQL procedure successfully completed.

    PL/SQL code runs on the server, inside an Oracle process - thus PL/SQL code cannot dynamically write and display messages to the client. That server process is not connected to any keyboard, mouse or display.
    DBMS_OUTPUT can be used. This is a PL/SQL buffer area in that server process that code can write lines of text too. When the server process informs the client that it has completed, the client can now request the contents of the DBMS_OUTPUT buffer and the client can display it on the client device.
    This is what set serveroutput on in SQL*Plus does - tell the sqlplus client to request the DBMS_OUTPUT buffer after each Oracle server call made and to display the contents locally.
    So to display the SQL command can be done using DBMS_OUTPUT. E.g.
    declare
      dropPart varchar2(32767);
    begin
      for c in (select...) loop
        dropPart := 'alter table my_tab drop partition '||c.partition_name';
        --// write the SQL command to DBMS_OUTPUT
        DBMS_OUTPUT.put_line( dropPart );
        --// execute the SQL using a begin..end block in order to catch error
        begin
          execute immediate dropPart;
          DBMS_OUTPUT.put_line( 'command completed successfully' );
        exception when OTHERS then
          DBMS_OUTPUT.put_line( 'command failed with: '||SQLERRM(SQLCODE) );
        end;
      end loop;
    end;So after this code block has been executed and partitions dropped, sqlplus will display the DBMS_OUTPUT generated by this code block.

  • Delcare Cursor using Dynamic SQL using PL/SQL in Oracle 7.3.4

    In Oracle 7.3.4, can I declare a cursor at run time using Dynamic SQL. From the sample code in this website, it seems that Oracle 8 support this function. Please help. Thanks a lot.
    If I can do this on Oracle 7.3.4, could you give me some sample codes? Thanks.
    Regards,
    Raymond

    Hi,
    Try using the the following code where you can dynamically build the Valid Select stmt. and call that where ever you want.
    declare
    Type Cur_ref Is Ref Cursor;
    C_ref Cur_ref;
    V_Str Varchar2(100);
    V_Name Varchar2(100);
    Begin
    V_Str := 'Select Ename from Scott.emp Where empno = 7369';
    Open C_Ref for V_Str;
    Fetch C_ref Into V_Name;
    close C_Ref;
    dbms_output.put_line(V_Name);
    End;
    regards
    gaurav
    null

  • Using Dynamic SQL in Forms

    Does anyone know anything about Dynamic SQL not being available in Forms v. 6.0.8.11.3? I trying to use Dynamic SQL for the first time and am having some difficulty. When I try to put my SQL in a function and run it straight into the database through SQLPlus, it works fine, but when trying to compile the code in Forms Builder (in a library), I get compiler errors. Any help would be appreciated...
    Thanks!
    Vanessa

    When I tried to compile the following code in Forms, the compiler error I got was Encountered the symbol "STMT_STR" when expecting one of the following: select. However, when I run it in SQLPlus, it creates the function without any errors.
    FUNCTION my_func
    return number
    is
    TYPE DiaryCurTyp IS REF CURSOR;
    cur DiaryCurTyp;
    stmt_str VARCHAR2(200);
    dmonth NUMBER;
    dday NUMBER;
    BEGIN
    stmt_str := 'SELECT dmonth, dday FROM p2_diary
    WHERE dmonth = :1';
    OPEN cur FOR stmt_str USING '12';
    LOOP
    FETCH cur INTO dmonth, dday;
    EXIT WHEN cur%NOTFOUND;
    -- <process data>
    END LOOP;
    CLOSE cur;
    END;

  • Using dynamic sql in triggers with :OLD values

    i need to record all deleted rows from an entire schema in a single table. for that matter i created a function that receives a table name and generate an insert command according to it's primary key columns. i call this function in the table triggers. in order to insert the old values before the delete i use :OLD with "execute immediate" as followed :
    create or replace trigger trg_some_tbl_bd
    before delete on some_tbl
    for each row is
    declare
    v_sql varchar2(4000);
    begin
    v_sql := generate_insert_command('some_table');
    execute immediate v_sql;
    end;
    the return value from "generate_insert_command" function is the string:
    insert into deleted_table (table_name , date , pk1 , pk2) values
    ('some_table' , sysdate , :OLD.pk1 , :OLD.pk2)
    the execute immediate command notice the :OLD and looks for bind variables.
    i need to know i can i bypass that. i tried looking for escape characters but couldent find any...
    i would appriciate any help , it's kynda urgent
    Thanks !

    I don't believe this is going to work. Even if you could get around the fact that :old looks like a bind variable, the :old values are not visible to the dynamic SQL statement, they're like local variables in that respect.
    If you wanted to pass old values in, those values would have to be passed in as bind variables, i.e.
    EXECUTE IMMEDIATE v_sql USING :old.pk1, :old.pk2which defeats the purpose of using dynamic SQL.
    Since you have to create a trigger for each table, I don't see why you would bother with dynamic SQL inside the trigger-- your table structure is fixed when the trigger is created. You could write dynamic SQL that generated the triggers in the first place, but the code inside the trigger should be dynamic.
    As an aside, you realize that logging every audit record into a single table creates rather massive contention issues, right? And have you considered how painful it is to query this sort of table? Have you considered other options for maintaining history like Workspace Manager? Or at least separate history tables for each table?
    Justin

  • ORA-01006 using Dynamic SQL

    Hello,
    I'm trying to create a function utilizing Dynamic SQL. The function compiles fine, but when I go to call it using the select staement below, I get :
    ORA-01006: bind variable does not exist
    ORA-06512: at "ICIM.PROD_SALES_DATA", line 24
    select prod_sales_data('09','I',2009,'Awning')
    from dual;
    CREATE OR REPLACE FUNCTION prod_sales_data
    (p_ahl1 IN VARCHAR2, p_phl1 IN VARCHAR2, p_fisyr IN NUMBER,
    p_prod_str IN VARCHAR2)
    RETURN NUMBER IS
    v_return NUMBER;
    query_str VARCHAR2(10000);
    BEGIN
    query_str :='select sum(a.qsh*a.unitcnt)'||chr(13)
    ||'from sh_units a, sh_product_desc b, sh_ad_glass c'||chr(13)
    ||'where a.unittype = b.unittype'||chr(13)
    ||'and a.sh_id = c.sh_id(+)'||chr(13)
    ||'AND a.ahl1 = '||chr(39)||p_ahl1||chr(39)||chr(13)
    ||'AND a.phl1 = '||chr(39)||p_phl1||chr(39)||chr(13)
    ||'AND a.fisyr ='|| p_fisyr||chr(13)
    ||'AND UPPER(b.descrip) = UPPER('||chr(39)||p_prod_str||chr(39)||')'||chr(13)
    ||'AND a.invdt between b.eff_beg and b.eff_end'||chr(13)
    ||'and a.parts_flag <>'||chr(39)||'Y'||chr(39)||chr(13)
    ||'and a.unittype <>'||chr(39)||'OTHE'||chr(39)||chr(13)
    ||'and icim.sh_rept_chk_ortp(a.ortp) = 1'||chr(13)
    ||'and A.REPT_RELEASE_DT is not null';
    DBMS_OUTPUT.PUT_LINE(query_str) ;
    EXECUTE IMMEDIATE query_str
    INTO v_return
    USING p_ahl1,p_phl1,p_fisyr,p_prod_str;
    RETURN v_return;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    END prod_sales_data ;
    Any help as to what is going wrong would be greatly appreciated.
    Thanks,
    Tyler

    Hello,
    >
    I'm trying to create a function utilizing Dynamic SQL. But why?
    Whenever you turn towards dynamic SQL, ask yourself why?
    I bet for a couple of years you aren't able rto come up with an answer. Meaning you shouldn't.
    Even if you do come up with an answer, think again. The answer may very well be wrong.
    Wouldn't it be nice if your function was as simple as:
    CREATE OR REPLACE FUNCTION prod_sales_data
       ( p_ahl1      IN VARCHAR2
       , p_phl1      IN VARCHAR2
       , p_fisyr     IN NUMBER,
         p_prod_str  IN VARCHAR2)
    RETURN NUMBER
    IS
       v_return NUMBER;
    BEGIN
        select sum(a.qsh*a.unitcnt)
          into v_return
          from sh_units a
             , sh_product_desc b
             , sh_ad_glass c
         where a.unittype = b.unittype
           and a.sh_id = c.sh_id(+)
           and a.ahl1 =  p_ahl1
           and a.phl1 =  p_phl1
           and a.fisyr = p_fisyr
           and upper(b.descrip) = upper(p_prod_str)
           and a.invdt between b.eff_beg and b.eff_end
           and a.parts_flag != 'Y'
           and a.unittype != 'OTHE'
           and icim.sh_rept_chk_ortp(a.ortp) = 1
           and a.rept_release_dt is not null;
    RETURN v_return;
    EXCEPTION
       WHEN NO_DATA_FOUND THEN
          RETURN NULL;
    END prod_sales_data ;
    /Now using proper bind variables, plain static pre-compiled SQL. And even works properly WITH NO DATA FOUND.
    I know it's dangerous to use words as always and never, but i dare say
    Always (Whenever you can) use static SQL. Never (Unless you must) use dynamic SQL (When you can use static).
    Regards
    Peter

  • Should I use dynamic SQL for simple updates?

    Please tell me, out of the two options given below, which option should i use to update columns in a table and why?
    what will be the performance difference between the two approaches?
    Please note: The options given below is just for an example
    procedure proc1(var1 varchar2)
    is
    begin
    update tab1 set col1 = var1;
    commit;
    end;
    procedure proc1(var1 varchar2)
    is
    sqlstr varchar2(1000);
    begin
    sqlstr := 'update tab1 set col1 = :v1';
    execute immediate sqlstr using var1;
    commit;
    end;
    Thanks
    Arun

    Arun G Nath wrote:.
    Should I use dynamic SQL for simple updates? No way, not a chance.
    Performance is not the issue (as long as you are using bind variables).
    But with dynamic SQL, you loose compile time checking; you do not know until runtime if the SQL is valid.
    You also loose the dependency between proc1 and tab1, which can be found only if you search user_source.
    (And in either case, you probably want to remove the commit)
    Regards
    Peter

  • How to implement dynamic sql in owb

    Hi everybody,
    I am new to OWB and hence i want to know how i can implement the following dynamic sql statement in owb...
    Declare
    Cursor C_tab_col is
    Select cat from tbl_cat_edesc_1 ;
    Vcat varchar2(240);
    Cursor C_edesc_col is
    Select edesc from tbl_cat_edesc_1 ;
    Vedesc varchar2(240);
    V_Command varchar2(30000);
    Begin
    Open C_Tab_col;
    Fetch C_tab_col into vcat;
    Open C_edesc_col;
    Fetch C_edesc_col into vedesc;
    loop
    V_Command := 'update upd_catseg_1 c set c.'||vcat||'=';
    V_Command := V_Command||'(select d.sales from TEST_catseg d' ;
    V_Command := V_Command||' where edesc = '||''''||vedesc||''''||' and c.cardno=d.cardno)';
    dbms_output.put_line('10 '||V_command);
    Execute immediate v_command;
    Fetch C_tab_col into vcat;
    Exit when c_tab_col%notfound;
    Fetch C_edesc_col into vedesc;
    Exit when c_edesc_col%notfound;
    end loop;
    commit;
    end;
    Thanks a many

    Hi,
    first i have created a procedure witht he following code in the code editor...
    BEGIN
    Declare
    Cursor C_brand_col is
    Select cat from TBL_CAT_EDESC_BRAND ;
    Vbrand varchar2(240);
    Cursor C_bredesc_col is
    Select EDESC_BRAND from TBL_CAT_EDESC_BRAND;
    Vbredesc varchar2(240);
    V_Command varchar2(30000);
    Begin
    Open C_brand_col;
    Fetch C_brand_col into vbrand;
    Open C_bredesc_col;
    Fetch C_bredesc_col into vbredesc;
    loop
    V_Command := 'update sav_fc_sa_pc c set c.'||vbrand||'=';
    V_Command := V_Command||'(select d.fc_brands_sa from TEST_brand d' ;
    V_Command := V_Command||' where d.brand_edesc = '||''''||vbredesc||''''||' and c.cardno=d.cardno)';
    dbms_output.put_line('10 '||V_command);
    Execute immediate v_command;
    Fetch C_brand_col into vbrand;
    Exit when c_brand_col%notfound;
    Fetch C_bredesc_col into vbredesc;
    Exit when c_bredesc_col%notfound;
    end loop;
    commit;
    end;
    END;
    then i validate it and deply it..
    after that i create a mapping and in that mapping i first import the table TBL_CAT_EDESC_BRAND and drag and drop it into the mapping and again the i put the procedure into a transformation operator and connect the inoutgrp of the table to the transformation operator ingrp deploy it and run it...this is taking a lot of time .... so i am not sure whether i am doing the right thing...for this dynamic sql i dont need to pass any parameters. can i juz execute this procedure or should i create a mapping ???? i am totally confused... could you please help me.....how to proceed........
    if i juz execute the dynamic sql it takes only 5 min in sql but i am not sure how ti implement it in owb... can you please help...
    Thanks a many

  • Transformations not occuring properly using PIVOT operator in OWB mapping.

    Hi ,
    In our project we have a OWB Map UII_D_MAP_SPC_CUST_FAULT_NATTR which is used to populate UII_CUSTOMER_FAULT table in our target side.
    The source table which populate UII_CUSTOMER_FAULT is SR_S_TABLE_N_ATTRIBUTEVALUE (a materialized view in another External Db)
    This Mview has 2 columns: S_N_STRINGVALUE & N_NAME.
    When N_NAME is 'FAULT_REPORT_CODE' the corresponding S_N_STRINGVALUE value should populate the REPORT_CODE field in UII_CUSTOMER_FAULTin the target sde.
    This source to target transformations is being done by using UNPIVOT operator in this mapping UII_MAP_SPC_CUST_FAULT_NATTR.
    In ideal case when S_N_STRINGVALUE is NOT NULL, REPORT_CODE value should be populated with the value of source field value (ie the value of S_N_STRINGVALUE) and when S_N_STRINGVALUE is NULL , REPORT_CODE should be populated with 'XX'.
    But in some cases REPORT_CODE value in UII_CUSTOMER_FAULT table is populated as NULL when S_N_STRINGVALUE is NOT NULL
    which should not happen.
    We suspect that there is some prpblem in the UNPIVOT operator, but we are not able to track down the exact location where it is failing. Can you please help in resolving this problem?
    Shall we remove Unpivot operator and use CASE statement in some package that will be called through Expression operator?
    Please advise.
    Regards
    Arinjit Dhar

    Arinjit,
    Have got any solution forthis. Today I ran into exactly the same problem. If you have got the solution, can you please post it in the forum.
    Ott Karesz,
    I have posted my SQL which got generated. The problem is when I am running the SQL just for the particular data set, it is giving the output properly. But what confuses me more is, when I run the mapping just for few records, it is populating the values correctly, but when running the mapping for all the records, then it populates null values for those records.
    Generated SQL:
    INSERT
    INTO
    "TB_PIPE_1"
    ("ASSETNUM",
    "SITEID",
    "TYPE",
    "STATUS",
    "YEARLAID",
    "MATERIALCODE",
    "PRESSURECODE",
    "DIAMETER",
    "METHODLAID",
    "JOINTTYPE",
    "SDRCOL",
    "LENGTHLAID",
    "LENGTHDIGITISED",
    "MEASUREUNITID")
    SELECT
    "UNPIVOT"."ASSETNUM" "ASSETNUM$1",
    "UNPIVOT"."SITEID" "SITEID$1",
    "UNPIVOT"."CLASSIFICATIONID" "CLASSIFICATIONID$1",
    "UNPIVOT"."STATUS" "STATUS$1",
    "UNPIVOT"."YEAR_LAID" "YEAR_LAID$1",
    "UNPIVOT"."MATERIAL" "MATERIAL$1",
    "UNPIVOT"."PRESSURE" "PRESSURE$1",
    "UNPIVOT"."DIAMETER" "DIAMETER$1",
    "UNPIVOT"."METHODLAID" "METHODLAID$1",
    "UNPIVOT"."JOINTTYPE" "JOINTTYPE$1",
    "UNPIVOT"."SDR" "SDR$1",
    "UNPIVOT"."LENGTHLAID" "LENGTHLAID$1",
    "UNPIVOT"."LENGTHDIGITESED" "LENGTHDIGITESED$1",
    "UNPIVOT"."MESUREUNIT" "MESUREUNIT$1"
    FROM (SELECT
    "ASSETNUM" "ASSETNUM",
    "SITEID" "SITEID",
    "STATUS" "STATUS",
    "YEAR_LAID" "YEAR_LAID",
    "CLASSIFICATIONID" "CLASSIFICATIONID",
    MIN(CASE WHEN "ASSETATTRID" = 'MATERIAL' THEN "ALNVALUE" ELSE NULL END) "MATERIAL",
    MIN(CASE WHEN "ASSETATTRID" = 'PRESSUREREGIME' THEN "ALNVALUE" ELSE NULL END) "PRESSURE",
    MIN(CASE WHEN "ASSETATTRID" = 'DIAMETER' THEN "NUMVALUE" ELSE NULL END) "DIAMETER",
    MIN(CASE WHEN "ASSETATTRID" = 'METHODLAID' THEN "ALNVALUE" ELSE NULL END) "METHODLAID",
    MIN(CASE WHEN "ASSETATTRID" = 'JOINTTYPE' THEN "ALNVALUE" ELSE NULL END) "JOINTTYPE",
    MIN(CASE WHEN "ASSETATTRID" = 'SDR' THEN "ALNVALUE" ELSE NULL END) "SDR",
    MIN(CASE WHEN "ASSETATTRID" = 'LENGTHLAID' THEN "NUMVALUE" ELSE NULL END) "LENGTHLAID",
    MIN(CASE WHEN "ASSETATTRID" = 'LENGTHDIGITISED' THEN "NUMVALUE" ELSE NULL END) "LENGTHDIGITESED",
    MIN(CASE WHEN "ASSETATTRID" = 'DIAMETER' THEN "MEASUREUNITID" ELSE NULL END) "MESUREUNIT"
    FROM (SELECT
    "MV_PIPE"."ASSETNUM" "ASSETNUM",
    "MV_PIPE"."SITEID" "SITEID",
    "MV_PIPE"."STATUS" "STATUS",
    "MV_PIPE"."YEAR_LAID" "YEAR_LAID",
    "MV_PIPE_SPEC"."ASSETATTRID" "ASSETATTRID",
    "MV_PIPE_SPEC"."NUMVALUE" "NUMVALUE",
    "MV_PIPE_SPEC"."ALNVALUE" "ALNVALUE",
    "MV_PIPE_SPEC"."MEASUREUNITID" "MEASUREUNITID",
    "MV_PIPE"."CLASSIFICATIONID" "CLASSIFICATIONID"
    FROM "MV_PIPE_SYN" "MV_PIPE",
    "MV_PIPE_SPEC_SYN" "MV_PIPE_SPEC" WHERE "MV_PIPE"."ASSETNUM" in ('466651706','606703143') and ( "MV_PIPE"."ASSETNUM" = "MV_PIPE_SPEC"."ASSETNUM" )) "OUTGRP1"
    GROUP BY
    "ASSETNUM", "SITEID", "STATUS", "YEAR_LAID", "CLASSIFICATIONID") "UNPIVOT"

  • Using Dynamic SQL to populate ALV

    Hi,
    Does anyone know if it is possible to use the Runtime Type Services to obtain the structure definition for the results a dynamic select statement?
    I am looking to create a simple web dynpro app that that will populate an ALV grid with the results of a SQL Select statement that has been manually typed in by a user. Is there an easy way to do this without having to pull apart the relevant details from (column_syntax), (from_syntax) etc.. in order to create a dynamic type that the ALV Data Node will be mapped to?
    Kind Regards
    Simon

    Hi Clemens,
    Thanks for your reply.
    It is the result table that I am actually interested in. I know how to build the actual SELECT statement from user input but I'm struggling to capture the results into a table without having to define the result table structure first (i.e. in order to implement the 'INTO CORRESPONDING FIELDS OF TABLE' clause). If I could somehow capture the results into a generically defined table and then use CL_ABAP_TABLEDESCR to get the actual line structure, I could then build the Context Node that will be mapped to the ALV Data interface node.
    What I am trying to avoid, if at all possible, is having to deconstruct the actual SQL statement in order to pull out the parts that I would have to use to get RTTS to manually create a custom descriptionfor the results table.
    Is this possible?
    I have also come across classes in the SDB_ADBC package which look that they could possibly do the job. However, my understanding is that these use Native SQL rather then Open SQL.

  • How to use dynamic SQL in this case for best performance

    I have the table with following columns
    ID NUMBER,
    DATA LONG,
    TAG VARCHAR2(255)
    Records in this table will be like following
    1 this is an abstract ABSTRACT
    1 this is author AUTHOR
    1 100 PRICE
    2 this is an abstract ABSTRACT
    2 this is author AUTHOR
    3 contract is this CONTRACT
    Basically all the records with the same number constitute 1 record for another table. Tag in the above table indicates that what column it is and DATAwill have the actual data for that column. I need to populate the second table based an the above table but will not get the same number of TAGS all the time. I need to insert the values only for the columns provided in the TAG field. How will I accomplish this by dynamic sql. Do I create a loop and create two strings one with columns and one with values and then combine them and use execute immediate to insert into table? Is there an easier way to do this??
    Please respond quickly.
    Thanks
    Bhawna
    null

    > so which collection should i use to perform it..
    so that performance is best......
    Program to interfaces. That way, you can switch out implementations and test for yourself which performance is best in an actual production context. But first, write your program so that it works. Worry about refactoring for performance once your program is written and it works.
    > plz send me the logic....
    Give it a shot on your own first; we can help if you get stuck.
    ~

  • Doubt & Error Using Dynamic SQL

    Hello,
    According to oracle documentation for Dynamic SQL using ' Method 2 ' ... which says ...
    Method 2
    This method lets your program accept or build a dynamic SQL statement, then process it using the PREPARE and EXECUTE commands. The SQL statement must not be a query. The number of placeholders for input host variables and the datatypes of the input host variables must be known at precompile time. For example, the following host strings fall into this category:
    'INSERT INTO EMP (ENAME, JOB) VALUES (:emp_name, :job_title)'
    'DELETE FROM EMP WHERE EMPNO = :emp_number'
    Now for trying this method i created a procedure .. named .. 'aj_proc_1'
    CREATE OR REPLACE PROCEDURE aj_proc_1(p_id IN NUMBER)
    IS
    BEGIN
         EXECUTE IMMEDIATE 'delete from aj_test_1 where id = :p_id';
    END aj_proc_1;
    And the table which m using in this procedure is ...
    SQL> select * from aj_test_1;
    ID NAME
    1 aijaz
    2 melwin
    3 aasim
    4 satish
    5 ashok
    So now whn m calling this Procedure & wanted to delete the record with id '2' ... m getting an Error...the way m executing this procedure is ...
    SQL> execute aj_proc_1(2);
    BEGIN aj_proc_1(2); END;
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at "FA.AJ_PROC_1", line 4
    ORA-06512: at line 1
    Please Help me .. As i have no idea ..wats goin wrong over here...

    Now whats Wrong with this 1 ....
    CREATE OR REPLACE PROCEDURE aj_proc_1(p_id IN NUMBER)
    IS
         val_name varchar2(34);
    BEGIN
         EXECUTE IMMEDIATE 'select name into '||val_name||' from aj_test_1 where id = :p_id'
                        USING p_id ;
              dbms_output.put_line(val_name);
    END aj_proc_1;
    SQL> exec aj_proc_1(2);
    BEGIN aj_proc_1(2); END;
    ERROR at line 1:
    ORA-00936: missing expression
    ORA-06512: at "FA.AJ_PROC_1", line 5
    ORA-06512: at line 1
    -----------------------------------------------------------------------------------

  • Convert a trigger format into a  stored procedure using Dynamic Sql

    Hi everyone,
    ihave table
    Table_NAME_ABCD contains
    i have a trigger Table_NAME_ID,ROW_CREATED_DATE,ROW_CREATED_BY,ROW_CHANGED_DATE,ROW_CHANGED_BY,UNQ columns
    i am populating Table_NAME_ID(primary_key) using sequencer in the below mentioned trigger.
    and for this table i have created IU trigger for inserting or updating trigger will fire
    create or replace
    TRIGGER "Table_NAME_IU_TRG" BEFORE INSERT OR UPDATE ON Table_NAME_ABCD FOR EACH ROW
    BEGIN
    If inserting then
    If :new.Table_NAME_ID is NULL THEN
    SELECT Table_NAME_ID_ABCD_SEQ.NEXTVAL INTO :NEW.Table_NAME_ID FROM DUAL;
    end if;
    if :new.ROW_CREATED_DATE is NULL then
    :new.ROW_CREATED_DATE := SYSDATE;
    end if;
    if :new.ROW_CREATED_BY is NULL then
    :new.ROW_CREATED_BY := USER;
    end if;
    if :new.ROW_CHANGED_DATE is NULL then
    :new.ROW_CHANGED_DATE := SYSDATE;
    end if;
    if :new.ROW_CHANGED_BY is NULL then
    :new.ROW_CHANGED_BY := USER;
    end if;
    if :new.UNQ is NULL then
    :new.UNQ := SYS_GUID():
    end if;
    end if;
    If updating then
    :new.ROW_CHANGED_DATE := SYSDATE;
    :new.ROW_CHANGED_BY := USER;
    end if;
    END;
    above mentioned table along with trigger is same format for ~100 different tables i have been created.
    i want a stored procedure in side it above mentioned trigger (i.e., for inserting or updating )code should be written with Dynamic Sql so that when ever i am passing Tablename as a parameter it should work.
    please suggest me.

    What is new since this thread?
    Stored procedure instead of Trigger

Maybe you are looking for

  • 10.5.8 won't show UPS battery level

    I just installed an APC Smart UPS 1000 VA UPS to my Mac Pro server.  The USB cable is plugged in and the UPS battery is fully charged according to the display on the UPS itself.  The Energy Saver control panel is the APC preferred control method (the

  • Text module constrained to single page?

    I have added a page to the "standard" smart form for purchase order printing. The purpose is to print standard terms and conditions, which are stored in a text module. This should be a piece of cake I thought, but apparently not... A command to go to

  • Change DNS settings in Solaris 11

    Where do I need to go to change the DNS settings on a Solaris 11 server?

  • Upgrade from Adobe Reader LE 2.0 2006

    I have an AT&T Tilt smart phone made by HTC that has the above Adobe reader on it V2.00.288531. I have noticed that it will not read PDF files made on newer versions of a Xerox Copier. It does open the ones made on older Xerox machines. However those

  • IPad Mail app crashing upon launch

    Have tried restarting multiple times but Mail keeps crashing instantly upon launch.