How to implement Dynamic SQL in DataService ??

Hi,
Is there any way in ALDSP to implement Dynamic SQL in Dataservice ?
My scenario is "based on set of optional fields i need to join different tables.If the optional field is not there then i don't have to join with the corresponding table."
Thanks

Ah yes, I thought that looked familiar. It's same question from July 12.
There is no way to generate Dynamic SQL in DSP XQuery. There is one query plan for each query. The query plan does not change based on the inputs.
Using a FilterXQuery on top of a query actually generates a new query. You can play with that if you like, but it is not particularly suited to changing joins. Go with the ad hoc query.

Similar Messages

  • 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

  • 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

  • How to implement Dynamic Sort to an SQL classic report?

    Hi,
    I'm trying to implement dynamic sort to my working sql classic report, when user selects order by column from select item(action as submit page), the report should be refreshed and display with the selected column sort order.
    But not able to do so.
    Report Query:
    Select a, b, c from sample order by :P1_ORDER_BY
    P1_ORDER_BY - Select Item:
    STATIC2: Column 1;a, Column 2;b, Column 3;c
    Running page, report doesnt sorts in any of the column priority.
    Kindly guide.
    Regards,
    Krishna

    Of course the select item is in use.
    It should submit the the page on select so you can retrieve the current value in you report select statement.
    look here:
    http://apex.oracle.com/pls/apex/f?p=21296:2:
    table:
    create table sample
      a varchar2(30)
    , b varchar2(30)
    , c varchar2(30)
    insert into sample values('a','z','k');
    insert into sample values('b','y','d');
    insert into sample values('c','x','a');
    insert into sample values('d','w','b');
    commit;
    Select List:
    P2_ORDER_BY
    STATIC:Order by A;A,Order by B;B,Order by C;C
    Report select:
    select
    a,b,c
    from sample
    order by
      decode(:P2_ORDER_BY,'A',a,null)
    , decode(:P2_ORDER_BY,'B',b,null)
    , decode(:P2_ORDER_BY,'C',c,null)Marc
    Edited by: telemat on Aug 24, 2012 1:50 PM

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

  • How to implement Dynamic lookup in OWB mappings(10g)

    Hi,
    Iam using OWB 10g version for developing the mappings.
    Now I need to implement the Dynamic lookup in the mapping.Is there any transformations available in OWB to achieve this.
    Please give me some information about the same.
    Thanks in advance...

    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

  • How to implement Dynamic form validation

    Hello,
    I've been reading up on the forums about using the htmldb.item package to dynamically create form elements using a SQL query. Assuming I can generate the form dynamically, what approaches/options are available for implementing dynamic validation of the form elements themselves?
    Thanks in advance

    You could write a page-level 'PL/SQL Function Body returning error text' validation where you loop over your dynamic form elements (htmldb_application.g_fnn), check the values and raise errors as needed.

  • How to Implement Dynamic Modification Rule for Material & multiple vendor Combination

    Hi Team,
         In dynamic modification rule for Material &  vendor combination, i have maintained material & vendor in Inspection plan at Material Assignments
    1.If i purchase same material from different vendors then how to implement ?

    Hi Balaji,
    I am not sure if i have followed your requirement.
    What do you want to do with Vendor Z? Do you want to inspect each lot from Z?
    If yes:
    Then Create 2 Inspection plans with same Operations and Same MICs, In Material Assignment, mention Vendor as Z so that 1st inspection plan will only be for Vendor Z. Do not enter DMR in Header.
    In 2nd inspection plan Enter DMR and do not mention any vendor so this plan will be applicable for all vendors except Z.
    If No:
    Then create Qm info record for vendor Z with "No inspection" set in QI06.
    Amol.

  • How to implement Dynamic Context Node Mapping between Components

    Hey genuis:
               I am looking for how to implement context mapping bwteen two components. I read some threads, and try to use external context mapping. The example works fine. However, my requirement is more than that.
    I have a context node in Component B, and the attributes in it are dynamically generated. Component A is the main component which use Component B's function. Both A and B work fine by theirselves. 
    When I assemble A and B (external mapping), the system gives me a exception:com.sap.tc.webdynpro.progmodel.context.ContextException: MappedNodeInfo(T8UploadCompInterface.data): cannot create nodes, no mapping defined yet.
    Please give me some suggestion?
    Any responses are appreciated.

    I miss this thread.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6fdae690-0201-0010-a580-d104b459cb44
    This is almost the right solution for my problem.

  • How to run dynamic SQL from an ODI procedure step

    I am on ODI 11.1.1.6.4. From within an ODI IKM step I have no problem running a procedure step like the following which calls a pl/sql procedure to get SQL text then later runs that code. Is there anyway to do the same from within an ODI procedure? I've tried a couple of variations and can not seem to get the parsing levels to resolve within a procedure like they resolve from within a KM step.
    <@
    /* Setup Java variables */
    String out_SQL = "";
    try
    java.sql.Connection sourceConnection = odiRef.getJDBCConnection("SRC");
    String sqltxt = "{call set_sql(?)}";
    java.sql.CallableStatement pstmt = sourceConnection.prepareCall(sqltxt);
         try
         pstmt.registerOutParameter( 1, java.sql.Types.VARCHAR);
         pstmt.execute();
    out_SQL = pstmt.getString(1);
         catch(java.sql.SQLException ex)
              errMessage = ex.getMessage();
              errMessage = errMessage.replace("'","");
         finally
              pstmt.close();
    catch(java.lang.Exception e)
         errMessage = e.getMessage();
         errMessage = errMessage.replace("'","");
    @>
    BEGIN
    -- The SQL that I want to run
    <@
    out.println(out_SQL);
    @>
    -- Error handling
    <@ if ( out_SQL.length() ==0 ) { @>
         raise_application_error(-20101, '<@=errMessage@>');
    <@ } else { @>
         dbms_output.put_line('Successful.');
    <@ } @>     
    END;
    ------

    Please understand that I know that I can do this all within PL/SQL -- I am explicitly doing it the way I have outlined because I want to better understand the parsing levels/behavior within ODI procedures and I want to understand why KMs steps behave differently.
    Another observation -- putting this all within a pl/sql block prevents ODI from properly capturing insert/update/delete row counts like it would if it were running a SQL statement.
    So the question remains -- is there a way to run a dynamic SQL statement in an ODI procedure where the SQL statement is generated from within an Oracle procedure call and then run as SQL within an ODI procedure step? Best would be if there is an example of how this can be done.

  • How to rewrite dynamic SQL built using IF clauses, as static SQL?

    Hi folks
    I have some Dynamic SQL that I would like to rewrite as static.
    The original PL/SQL code contains a number of IF clauses that I would normally replace with CASE statements in the static code, but I am wondering if I'm doing it the best way as although it works, I am not that happy with it for reasons described below.
    [Please excuse any remaining syntax errors, I have tried to reduce them but we have no Oracle on our internet network and I can't CutnPaste from the dev network.]
    So...
    An example of what I would normally do.
    A silly example, I admit, but it's just for demo.
    Original Dynamic Code:
    PROCEDURE GET_EMP_NAMES(p_job_title  IN VARCHAR2 := NULL
                           ,p_car_class  IN NUMBER   := NULL
                           ,p_REF_CURSOR OUT CURVAR)
      Purpose: Provide names of all employees.  But if MANAGERS only is requested,
      then limit the result set to those employees with the car class specified.
      Fields in table emp: first_name, fam_name, car_class(NUMBER)
    AS
      v_str VARCHAR2(1000);
    BEGIN
      v_str := 'select e.first_name, e.fam_name FROM emp e WHERE 1=1 ';
      IF p_job_title = 'MANAGER' and p_car_class IS NOT NULL THEN
          v_str :=  v_str || ' AND e.car_class = ' || p_car_class;
      END IF;
      OPEN p_REF_CURSOR FOR v_str;
    END;My usual rewrite:
    BEGIN
      OPEN p_REF_CURSOR FOR
        SELECT e.first_name, e.fam_name
          FROM emp e
         WHERE e.car_class =
                          CASE WHEN p_job_title = 'MANAGER' AND p_car_class IS NOT NULL
                                 THEN p_car_class
                               ELSE e.car_class
                           END;
    END;My problem with this is that some employees may have an e.car_class of NULL.
    In this case the WHERE clause will evaluate to NULL = NULL, and so they will not be included in the result set.
    So I usually defend with NVL() and some fictive constant for the NVL result, ie:
    AS
      k_dummy_val CONSTANT NUMBER(20) := 56394739465639473946;
    BEGIN
      OPEN p_REF_CURSOR FOR
        SELECT e.first_name, e.fam_name
          FROM emp e
         WHERE NVL(e.car_class,k_dummy_val) =
                        CASE WHEN p_job_title = 'MANAGER' AND p_car_class IS NOT NULL
                               THEN p_car_class
                             ELSE NVL(e.car_class,k_dummy_val)
                         END;
    END;But now I have had to decide what to use for k_dummy_val. I need to choose some fictive number that is not and will not EVER be used as a car class. This is a problem as I do not know this.
    So this makes me think that my technique is incorrect.
    Do you have any suggestions?
    Many thanks
    Assaf
    Edited by: user5245441 on 03:55 24/04/2011

    Hi,
    Assaf wrote:
    ... if I were to do the following then it would be a mess, right? Barckets are needed and if I have many such conditions and make a mistake with the brackets, then... :(Brackets may be needed, but they're a good idea even if they are not needed.
    WHERE     p_job_title     != 'MANAGER'
         OR     'X' || TO_CHAR (car_class)     
               = 'X' || TO_CHAR (p_car_class)
    AND   p_yet_another_param != 'SOMETHING ELSE'
         OR     'X' || TO_CHAR (another_field)     
               = 'X' || TO_CHAR (p_another_param)What do you think?Using parenetheses, that would be:
    WHERE     (   p_job_title     != 'MANAGER'
         OR     'X' || TO_CHAR (car_class)     
               = 'X' || TO_CHAR (p_car_class)
      AND   (   p_yet_another_param != 'SOMETHING ELSE'
         OR     'X' || TO_CHAR (another_field)     
               = 'X' || TO_CHAR (p_another_param)
         )I find this clearer than CASE expressions, but I won't be maintaining your code.
    This is one place where implicit conversions won't hurt you. Both operands to || have to be strings. If you use a NUMBER as an operand to ||, then it will be implicitly converted to a string. Usually, it's better to make this clear by using TO_CHAR, and converting the NUMBER to a string explicitly, but in this case you might gain clarity by not using TO_CHAR.
    Put comments in your code where you think they'll help someone to read and understand it.
    WHERE
         -- p_car_class only applies to MANAGERs
         (   p_job_title     != 'MANAGER' 
         OR     'X' || car_class
               = 'X' || p_car_class
      AND   (   p_yet_another_param != 'SOMETHING ELSE'
         OR     'X' || another_field
               = 'X' || p_another_param
    ... I avoid dynamic whenever possible, leaving it for use only in situations where things such as Table Names are unknown at compile time. I find it complex and error prone, and especially difficult for another developer to support at a later date.I agree. I agree especially with being concerned about the developer who has to modify or debug the code in the future, regardless of whether it's you or another.

  • How to implement dynamic form?

    Hi, all
    Currently, I am using XPAAJ to merge xml data sent from Flex side and the pdf template in the server side which is designed by LiveCycle Designer.
    But now my question is that my form is dynamic, like the rows of table. How could I implement such kind of functionality?
    Thanks
    Alan Ji

    And actually, the exact requirement is that user should enter values in Flex pages and click "View as PDF", data will be sent back to merge with PDF template.
    Under this situation, how could the form be dynamic?
    Thanks for any help.

  • How to implement PL/SQL expression in Report conditonal?

    Hi All,
    In my application i am want use Pl/SQl as expression in Conditional Display for Report region. Can you please suggest me how to handle using PL/SQl expression in conditonal.
    Thanks,
    Anoo..

    In general terms, your PL/SQL expression should evaluate to true or false - true will display the region, false will hide it. It's analogous to writing the conditional expression part of an if statement.
    So, if you had normal PL/SQL code that looks like this:
    if :P999_MYPAGEITEM is null or :P999_MYPAGEITEM = 0 then
    end if;The equivalent conditional pl/sql expression would simply be:
       :P999_MYPAGEITEM is null or :P999_MYPAGEITEM = 0 Note: this is NOT the same as you would do for "PL/SQL body returning boolean Expression", which looks more like:
       return :P999_MYPAGEITEM is null or :P999_MYPAGEITEM = 0;or
    declare
       bl_retval boolean;
    begin
       bl_retval := :P999_MYPAGEITEM is null or :P999_MYPAGEITEM = 0;
       return bl_retval;
    end;

  • How to use Dynamic SQL in ABAP

    If I have mara table and I have an selection screen where I have allowed user to select the fields of MARA,Now What I want is depending on his selection we should be able to execute the sql command.
    E.g.
    Tables: mara.
    selection-screen
    MATNR , ERSDA , ERNAM , MTART , MEINS.
    NOW THE OUTPUT SHOULD BE ABLE TO DISPLAY ONLY THE SELECTED FIELD VALUE.

    Hello Nandan,
    Try the following code. It works.
    tables: mara.
    data: tablename  type tabname,
          fname      type fieldname,
          fieldnames type fieldname occurs 0.
    field-symbols : <fs_tableline> type any,
                    <fs_fieldval>  type any.
    initialization.
      tablename = 'MARA'.
      assign (tablename) to <fs_tableline> .
      fname = 'MATNR'.
      append fname to fieldnames.
      fname = 'MTART'.
      append fname to fieldnames.
    select (fieldnames)
      from (tablename)
      up to 20 rows
      into corresponding fields of <fs_tableline>.
      loop at fieldnames into fname.
        assign component fname of structure <fs_tableline> to <fs_fieldval>.
        write : <fs_fieldval>.
      endloop.
      new-line.
    endselect.
    The <b>tables</b> statement is very important. You should at least have the list of the tables which you expect the user to enter.
    Please do get back if you have any doubts. If you think the question is answered, please reward the points to the useful answers and close the thread.
    Regards,
    Anand Mandalika.

  • How to implement dynamic Strings

    Hi everyone,
    i have a problem i�ve no clue how to solve.
    I have to create an array of Stringsbut i do not know the length of it. i tryes to find out if there is any method in java which allows me to do that, but i didn�t find it.
    So if anyone could help me? Thanks a lot.
    the code i�m using to get an idea is as follows:
    public String [] GetEnabled(){
    String[] cadena ;
    for (int i = 0;i < mainLogical.getNumPoints();i++){
    if ( (mainLogical.getPointEnabled(i) ){
    //this is the line which does not work, at least as i�m looking for
    cadena = cadena + mainLogical.getPointName(i);
    return cadena;
    Thanks

    If you are using earlier Java version, you would declare your List like this:List cadena = new LinkedList();The add method allows you to add an element to the list:cadena.add(mainLogical.getPointName(i));As your List contains only Strings, you can get a String array out of it:String[] array = (String[])cadena.toArray(new String[0]);

Maybe you are looking for

  • Workflow error

    Hi, I'm receiving the below error during workflow in progress.. Note: Due to heavy load, the latest workflow operation has been queued. It will attempt to resume at a later time. Anandhan.S Remember to 'mark or propose as answer' or 'vote as helpful'

  • When using multiple displays, is it possible to only have full screen zoom (universal access) only effect one display?

    I am visually impaired which makes it difficult for me to use computers. The zoom feature in Mac OS is extremly useful to me and is the first reason I choose mac over windows. Although, now that I've been using a mac for 8 years, I would pick a mac a

  • Is it possible to store preferences per psd file?

    For several projects we use different (grid etc) settings in the preferences. Is is possible to store them along with the psd file in such a way that they are or can be restored when the psd file is opened? When this it not possible, what are the bes

  • Mod_jk.conf file is NOT created

    Hi Experts, I am using Apache(2.0.40), JBOSS(3.0.3) and Tomcat(4.0.4) on IBM AIX 5.1 System. After spending 1 week on Integrating Apache and Tomcat on IBM AIX System (and getting HELP from you guys from Mailing List), I finally builded "mod_jk.so" fi

  • Can i get the new iPhone and sell my old iPhone?

    I have the 4GB original iPhone and i was wondering if it was possible for me to upgrade to the new iPhone for the $199 price. If i can, am i able to sell my old on eBay? Some people say i can get the 8GB for 199 and some say i can get it for 499. I d