Dynamic loop with for

Hello,
i have a procedure, which has a string parameter , this string is a select
i wanna use this select in a for loop
for ref in param loop
--trt
end loop;
is this possible, and what type should i define to ref
Regards
Sallemel

A simple example of using DBMS_SQL...
SQL> ed
Wrote file afiedt.buf
  1  CREATE OR REPLACE PROCEDURE replace_text(p_txt IN VARCHAR2, p_sql IN VARCHAR2) IS
  2    v_finaltxt  VARCHAR2(4000);
  3    v_val       VARCHAR2(2000);
  4    v_ret       NUMBER;
  5    c           NUMBER;
  6    d           NUMBER;
  7    col_cnt     INTEGER;
  8    f           BOOLEAN;
  9    rec_tab     DBMS_SQL.DESC_TAB;
10    col_num     NUMBER;
11  BEGIN
12    c := DBMS_SQL.OPEN_CURSOR;
13    DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
14    d := DBMS_SQL.EXECUTE(c);
15    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
16    FOR j in 1..col_cnt
17    LOOP
18      DBMS_SQL.DEFINE_COLUMN(c,j,v_val,2000);
19    END LOOP;
20    LOOP
21      v_ret := DBMS_SQL.FETCH_ROWS(c);
22      EXIT WHEN v_ret = 0;
23      v_finaltxt := p_txt;
24      FOR j in 1..col_cnt
25      LOOP
26        DBMS_SQL.COLUMN_VALUE(c,j,v_val);
27        v_finaltxt := replace(v_finaltxt,'$'||lower(rec_tab(j).col_name),v_val);
28      END LOOP;
29      DBMS_OUTPUT.PUT_LINE(v_finaltxt);
30    END LOOP;
31    DBMS_SQL.CLOSE_CURSOR(c);
32* END;
SQL> /
Procedure created.
SQL> exec replace_text('Person $ename of the $dname department has a salary of $sal ...','select ename, dname, sal from emp join dept on (emp.deptno = dept.deptno)');
Person SMITH of the RESEARCH department has a salary of 800 ...
Person ALLEN of the SALES department has a salary of 1600 ...
Person WARD of the SALES department has a salary of 1250 ...
Person JONES of the RESEARCH department has a salary of 2975 ...
Person MARTIN of the SALES department has a salary of 1250 ...
Person BLAKE of the SALES department has a salary of 2850 ...
Person CLARK of the ACCOUNTING department has a salary of 2450 ...
Person SCOTT of the RESEARCH department has a salary of 3000 ...
Person KING of the ACCOUNTING department has a salary of 5000 ...
Person TURNER of the SALES department has a salary of 1500 ...
Person ADAMS of the RESEARCH department has a salary of 1100 ...
Person JAMES of the SALES department has a salary of 950 ...
Person FORD of the RESEARCH department has a salary of 3000 ...
Person MILLER of the ACCOUNTING department has a salary of 1300 ...
Person WILLIS of the RESEARCH department has a salary of 900 ...
PL/SQL procedure successfully completed.
SQL> exec replace_text('Person $per_name of the $dept_name department has a salary of $sal_val ...','select ename as per_name, dname as dept_name, sal as sal_val from emp join dept on (emp.deptno = dept.deptno)');
Person SMITH of the RESEARCH department has a salary of 800 ...
Person ALLEN of the SALES department has a salary of 1600 ...
Person WARD of the SALES department has a salary of 1250 ...
Person JONES of the RESEARCH department has a salary of 2975 ...
Person MARTIN of the SALES department has a salary of 1250 ...
Person BLAKE of the SALES department has a salary of 2850 ...
Person CLARK of the ACCOUNTING department has a salary of 2450 ...
Person SCOTT of the RESEARCH department has a salary of 3000 ...
Person KING of the ACCOUNTING department has a salary of 5000 ...
Person TURNER of the SALES department has a salary of 1500 ...
Person ADAMS of the RESEARCH department has a salary of 1100 ...
Person JAMES of the SALES department has a salary of 950 ...
Person FORD of the RESEARCH department has a salary of 3000 ...
Person MILLER of the ACCOUNTING department has a salary of 1300 ...
Person WILLIS of the RESEARCH department has a salary of 900 ...
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • Dynamic Select Query including Dynamic Tables with For all Entries

    Hello everyone,
    I need to create a select query which involves using of Dynamic Tables.
    Suppose I have a dynamic table <d1> which consist of let say 10 records.
    Now i need to make a select query putting data into another dynamic table <d2>
    CONCATENATE keyfield '=' '<d1>' INTO g_condition SEPARATED BY space.
    CONCATENATE g_condition '-' keyfield INTO g_condition.
    SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <d1>
            FOR ALL ENTRIES IN <d1>
    WHERE (g_condition).
    But it is giving dump.
    Please help me on this....

    Short text
        A condition specified at runtime has an unexpected format.
    What happened?
        Error in the ABAP Application Program
        The current ABAP program "ZNG_CUSTOMWRITE" had to be terminated because it has
        come across a statement that unfortunately cannot be executed.
    Error analysis
        An exception occurred that is explained in detail below.
        The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
         not caught in
        procedure "WRITE_ARCHIVE_PROD" "(FORM)", nor was it propagated by a RAISING
         clause.
        Since the caller of the procedure could not have anticipated that the
        exception would occur, the current program is terminated.
        The reason for the exception is:
        The current ABAP program has tried to execute an Open SQL statement
        which contains a WHERE, ON or HAVING condition with a dynamic part.
        The part of the WHERE, ON or HAVING condition specified at runtime in
        a field or an internal table, contains the invalid value "ZCOURIER-ZCOURIERID".
    CONCATENATE keyfield '=' g_header INTO g_condition SEPARATED BY space.
    CONCATENATE g_condition '-' keyfield INTO g_condition.
    SELECT * FROM (wa_all_tables-name) INTO CORRESPONDING FIELDS OF TABLE <dyn_table1>
    FOR ALL ENTRIES IN <dyn_table>
      WHERE (g_condition).

  • Dynamic SELECT with FOR ALL ENTRIES IN: take 2

    Hello Xperts,
    we are now having a bit of new trouble with the following SELECT ... special thanks to Raul and Suhas for their previous contributions.
    FIELD-SYMBOLS:
            <itab1>      TYPE standard table.
      ASSIGN ATTR_T_I->* TO <itab1>.
        select
          FIELD1
          FIELD2
        from DBTAB1
        into CORRESPONDING FIELDS OF table <itab1>
        FOR ALL ENTRIES IN <itab1>
        where
           (condition).
    ATTR_T_I is a static attibute of type table containing 10 records where all records have FIELD1 and FIELD2 empty.
    The select finds in DBTAB1 entries fulfilling the 'condition' for 8 of the above 10 records in ATTR_T_I.
    Hence, after the select 8 of the 10 records in ATTR_T_I have the fields FIELD1 and FIELD2 filled (ie not empty).
    So far so good!
    BUT: the 2 remaining records (i.e. those without entries in DBTAB1 fullfilling 'condition') have been deleted! Why? This is not what we want nor expected.
    Any ideas out there how to fix this?
    Thanx!

    Martin Helmstein wrote:
    > Yes, 'condition' contains all the key fields of DBTAB1.
    Hi Martin,
    It's not the Where condition fields i was talking about. I was referring to the Select fields, you have to SELECT all the keyfields when using FAE. Something like this:
    SELECT key1 key2 ... keyn "all the key fields of the table
    field1 field2 ... fieldn
    FROM table
    INTO CORRESPONDING FIELDS OF it_data
    FOR ALL ENTRIES IN <itab>
    WHERE (condition).
    You can search in the forums for further details. It has been discussed many a times.
    BR,
    Suhas

  • Dynamic SELECT with FOR ALL ENTRIES IN

    Hello Xperts,
    we are having a bit of trouble with the following SELECT
    FIELD-SYMBOLS:
            <itab1>      TYPE standard table.
      ASSIGN ATTR_T_I->* TO <itab1>.
        select
          FIELD1
          FIELD2
        from DBTAB1
        into CORRESPONDING FIELDS OF table <itab1>
        FOR ALL ENTRIES IN <itab1>
        where
          FIELD3     =   <itab1>-FIELD3    and
          FIELD4     =   <itab1>-FIELD4
    ATTR_T_I is a static attibute of type table.
    The syntax check throws the following message:
    The specified type has no structure and therefore no component  called FIELD3.
    Any ideas out there how to solve this issue?
    Thanx!

    Hi Martin,
    Change your code like this and try.
    DATA: itab2 TYPE TABLE OF string.
    FIELD-SYMBOLS:
            <itab1>      TYPE standard table.
      ASSIGN ATTR_T_I->* TO <itab1>.
    APPEND 'FIELD3     =   <itab1>-FIELD3    and' TO itab2.
    APPEND 'FIELD4     =   <itab1>-FIELD4' TO itab2.
        select
          FIELD1
          FIELD2
        from DBTAB1
        into CORRESPONDING FIELDS OF table <itab1>
        FOR ALL ENTRIES IN <itab1>
        where
          (itab2)
    Regards,
    Rahul Muraleedharan.

  • How to create a textfile dynamically(with in the loop) with given data?

    Hi all,
    Can anyone Please guide me how to create a text file in the given path dynamically? (with in the loop) with given data.
    For example:
    <%
    String data1="name";
    String data2="address";
    for(int i=0;i<10;i++)
    create the textfile at c:/test/sample.txt//name of the each file created being "sample.txt"
    //contents of text file will be
    data1+i; //to get name1,name2.....
    data2+i// to get add1,add2........
    delete(sample.txt) //to enable to create another file in the loop with same name
    %>

    The code which Ashokan mentioned is not is not creating a file.
    i used code given below to create and write into it.
    But, not is writing into it. I don't konw, where i am going worng !
    Code
    String sample2="C:/Ash/sample2.txt";     
                                                                                    FileWriter fw = new FileWriter(sample2,true);
                                            BufferedWriter bw=new BufferedWriter(fw);
                                            bw.write("EMP ID");     
                                            bw.newLine();
    Please help
    Regards
    aSh

  • Display a message in a For Loop  with field value

    Hello All,
    pls,i wanna display a message in a For Loop with field value the code is:
    FOR Q1 IN GET_SUM_EXP_QUANTITY LOOP               .
    INSERT INTO PLN_PLAN_DISTRIBUTION_WAY
    (FIN_YEAR_CODE , MONTH_CODE , MATERIAL_CODE , DISTRIBUTION_WAY , EXPECTED_QUANTITY , GROUP_CODE)
    VALUES (:PLN_PLAN.FIN_YEAR_CODE , TO_CHAR(V_FROM_DATE,'MM') , Q1.MATERIAL_CODE , 1 , V_MONTHLY_QTY , Q1.GROUP_CODE);
    MESSAGE(':PLN_PLAN.FIN_YEAR_CODE'||:PLN_PLAN.FIN_YEAR_CODE ||' '||'V_FROM_DATE = '||TO_CHAR(V_FROM_DATE,'MM'), 'Q1.MATERIAL_CODE'||' '|| Q1.MATERIAL_CODE||' '||'DISTRIBUTION_WAY'||' = 1'||'EXPECTED_QUANTITY'||' = '|| V_MONTHLY_QTY||'GROUP_CODE'|| ' '|| Q1.GROUP_CODE);
    FORMS_DDL('COMMIT');
    How 2 display a message with the value:
    Q1.MATERIAL_CODE
    Q1.GROUP_CODE
    message(Q1.MATERIAL_CODE)     
    gave me numeric or value error on run time when pressed on button
    Regards,
    Abdetu..

    Thanks 4 reply..
    again they r in a For Loop as mentioned above...
         INSERT INTO PLN_PLAN_DISTRIBUTION_WAY
                                                           (FIN_YEAR_CODE , MONTH_CODE , MATERIAL_CODE , DISTRIBUTION_WAY , EXPECTED_QUANTITY , GROUP_CODE)
                                            VALUES (:PLN_PLAN.FIN_YEAR_CODE , V_REPAIR_MONTH , Q1.MATERIAL_CODE , 1 , V_REPAIR_Qty , Q1.GROUP_CODE);
    FORMS_DDL('COMMIT');
    The fields in bold r required to be displayed for testing puposes..
    this gives me numeric or value error in runtime..
    Best regards,
    Abdetu..

  • For-each loop with colon in group name

    When making my first simple RTF report with XML Publisher, I am encountering problems with an XML tag name that contains a colon. When I set the tag name as the group for a loop - <?for-each:Blah1:Blah2?>, where Blah1:Blah2 is the tag name in my XML file, I get an error - java.lang.reflect.InvocationTargetException ... caused by oracle.xdo.parser.v2.XPathException: Namespace prefix 'Blah1' used but not declared. Any help would be appreciated.
    JW

    Hi JW
    The colon denotes that you XML is using a namespace and you need to declare in in your template. Just check out the user guide for namespaces. Its pretty straigntforward. I also touched on it in the latest blog entry here, http://blogs.oracle.com/xmlpublisher
    Regards
    Tim

  • For Loop with parameter in application process

    Hello,
    I am working on a project for school and a loop in an application process is giving me a headache. I have an application from which I make an ajax call to an "on-demand" process. Here's a short version of the process:
    declare
    valuesList varchar2(32000) := '';
    sqlWhere varchar2(32000) := '';
    begin
    begin
    //calculations, but let's hard code sqlWhere for demonstration purposes
    sqlWhere := ' where ID = 50';
    for j in (select * from myview sqlWhere) loop
    valuesList :=valuesList || '~rowsep~' || j.id || '~colsep~' || j.beds;
    end loop;
         exception
         when no_data_found then null;
         when others then HTP.p('Error: ' || SQLERRM);
    valuesList := substr(valuesList, 9, length(valuesList));
    end;
    htp.prn(valuesList);
    end;
    I thought the for loop would contain only one record but it lists all records in the view. Interestingly, when I replace the loop condition to 'select * from myview where ID = 50' it returns what it's supposed to.
    Could someone please explain what I am doing wrong?
    Thank you!

    There are a couple of different options but using a variable in the sql statement and not the where clause needs an execute immediate. The link below gives a good overview and options to accomplish what you are trying to do.
    execute immediate with for loop
    Edited by: tread on Apr 23, 2012 1:09 PM

  • Column with for dynamic Columns

    Hi,
    In my report i have dynamic columns and i am achieving this using <?split-column-header:header?> , <?split-column-data:variable?>
    I need to define with for the dynamically created columns.
    How do i achieve this.
    i have seen <?split-column-width:name?>,<?split-column-width:@width?> but didn't succeed.
    I tried <?split-column-header:header?><?split-column-width:@200pt?><?heading?><?end split-column-data?>
    Please advice.
    Regards
    Jeethi George

    If you have BIP desktop client installed, please do refer the example in C:\Program Files\Oracle\BI Publisher\BI Publisher Desktop\samples\RTF templates\Advanced\Dynamic Columns
    Also check the same described here http://download.oracle.com/docs/cd/E12844_01/doc/bip.1013/e12187/T421739T481157.htm#4535400

  • Help on changing array elements with For loop

    Hi,
    I'm wondering if anyone can help me with this problem.  I'd like to be able to modify elements of an array with For loop.  In the attached VI, my goal is to have an array of [0 1 2 3 4 5], but instead what I've got is [2 2 2 2 4 5].  I initialized the array with a value of 2 to help me identify which elements are changing.  Can anyone help me pointing where my mistake is?  Thanks.
    Peter
    Attachments:
    Array test.vi ‏19 KB

    It's a classic issue for LV newbies. In this case you HAVE to use a
    shift register otherwise the modifications of previous cicles are lost.
    It's all easier than it's seems, see attached vi.
    bye,
    manga
    Attachments:
    Array test 2.vi ‏19 KB

  • The demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.

    the demand of my application is that i can not replace for loop with a while loop.because i need fixed number of iterations and as far as i know fixed iterations could be only with possible with the for loop.
    your recommended second option that i could add true/false case.
    this true/false case must be inside the for loop or outside the for loop?if this case is inside the for
    loop, how can i send stop command from outer while
    loop?
    more over do you have any example for this please?
    thanks"

    You can execute a fixed number of iterations using a while loop by comparing the iteration count to the number of iterations you want and wiring the output of that comparison (e.g. Less Than or Equal To) to the continue (or stop) terminal of your while loop. Which comparison you use depends on personal preference, where you wire the desired count and the interation count, and whether you're using the while loop as Continue if True or Stop if True.
    Ben gave you step-by-step instructions in response to your previous question. Look here for Ben's response.
    Ben's response looks pretty good and detailed to me. It certa
    inly deserved better than a 1-star rating.

  • HT201304 How do I request a refund for "Refund for In-App Purchases made by a minor"? I received an email on this with a link that takes me into a loop with no request form to fill out as the email states. :(

    How do I request a refund for "Refund for In-App Purchases made by a minor"? I received an email on this with a link that takes me into a loop with no request form to fill out as the email states.

    Did you do this
    How to report/refund an issue with your iTunes Store, App Store, Mac App Store, or iBooks Store purchase
    or maybe
    1 - Use the Express lane and start here:
    https://expresslane.apple.com
    or the general place
    Apple - Support -form iTunes Store - Contact Us
    2 - Call Apple in your country by getting the number from here:
    http://support.apple.com/kb/HE57

  • Bug in conditional for loop with an empty array

    There appears to be a bug in the for loop with a conditional terminal.
    If an empty array is wired to an auto-indexed array input tunnel, an output array tunnel has one element instead of zero.
    The array constant on the left is empty.
    Top loop without the conditional terminal produces an empty array.
    The bottom loop with a never true conditional terminal produces an array with one element
    Using LabVIEW version 8.5
    Message Edited by TrevMrgn on 05-05-2009 02:01 PM
    Solved!
    Go to Solution.
    Attachments:
    For loop bug.png ‏3 KB

    Creating the example from scratch, I do not see the error.
    Neither do I.
    If I add one or more elements to the array (constant or control), then delete them all (using 'Delete Element') the bottom array has one element.
    Nup. Still empty.
    If I empty the array (using 'Empty Array') both are empty.
    Yep.
    Also if I create an empty array using 'initialise array' with zero elements, I get one element.
    Nup. Still empty.
    'Show constant folding' does not appear to change the behaviour, but including a random operation in the loop does.
    Agreed that constant folding doesn't cause any odd behaviour. Introducing a random operation (adding two constants) in the loop doesn't either.
    I've tried all your methods here Trevor, but I can't replicate this behaviour in 8.5.1 under WinXP SP3. Sorry!
     Maybe somebody else will be able to help, or find a useable workaround.
    Thoric (CLA, CLED, CTD and LabVIEW Champion)

  • For each loop with multidimensional arrays?

    Hi.I have a problem with for each and multidimensional combination.
    public class TestCards
    static int[][] dizi={{1,2},{3,4}};
    static int t ;
    public static void main(String[]args)
         for (int[] i : dizi)
         System.out.println(i);
    The result of the codes above is like this
    [I@9304b1
    [I@190d11
    In other words the result is now integer.It has some strange chars which i dont know
    Pls help me !

    You're printing an array. Arrays don't override toString.
    - You could iterate over both dimensions and print each value yourself.
    - You could iterate over one dimension and call java.util.Arrays.toString to print a row at a time.*
    - You could call java.util.Arrays.deepToString to print the entire thing in one shot.
    *The second option is closest to what you're doing now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to create dynamic DataTable with dynamic header/column in JSF?

    Hello everyone,
    I am having problem of programmatically create multiple DataTables which have different number of column? In my JSF page, I should implement a navigation table and a data table. The navigation table displays the links of all tables in the database so that the data table will load the data when the user click any link in navigation table. I have gone through [BalusC's post|http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable] and I found that the section "populate dynamic datatable" does show me some hints. In his code,
    // Iterate over columns.
            for (int i = 0; i < dynamicList.get(0).size(); i++) {
                // Create <h:column>.
                HtmlColumn column = new HtmlColumn();
                dynamicDataTable.getChildren().add(column);
                // Create <h:outputText value="dynamicHeaders"> for <f:facet name="header"> of column.
    HtmlOutputText header = new HtmlOutputText();
    header.setValue(dynamicHeaders[i]);
    column.setHeader(header);
    // Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.
    HtmlOutputText output = new HtmlOutputText();
    output.setValueExpression("value",
    createValueExpression("#{dynamicItem[" + i + "]}", String.class));
    column.getChildren().add(output);
    public HtmlPanelGroup getDynamicDataTableGroup() {
    // This will be called once in the first RESTORE VIEW phase.
    if (dynamicDataTableGroup == null) {
    loadDynamicList(); // Preload dynamic list.
    populateDynamicDataTable(); // Populate editable datatable.
    return dynamicDataTableGroup;
    I suppose the Getter method is only called once when the JSF page is loaded for the first time. By calling this Getter, columns are dynamically added to the table. However in my particular case, the dynamic list is not known until the user choose to view a table. That means I can not call loadDynamicList() in the Getter method. Subsequently, I can not execute the for loop in method "populateDynamicDataTable()".
    So, how can I implement a real dynamic datatable with dynamic columns, or in other words, a dynamic table that can load data from different data tables (different number of columns) in the database at run-time?
    Many thanks for any help in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    flyeminent wrote:
    However in my particular case, the dynamic list is not known until the user choose to view a table. Then move the call from the getter to the bean's action method.

Maybe you are looking for

  • Email multiple spools from background job - SM36 using Spool List recipient

    I create a background job using Spool List Recipient to email me the reports. The program that I scheduled to run creates 2 spools. When the spools are sent via email, only the last spool is sent. Please advise on how I can get the 2 spools sent via

  • Lightroom 3 crashes

    Hi, everyone! I wonder if anyone else is having this problem:  I'm using lightroom 3 on window vista home premium (with service pack 2 installed)  It seems that anytime I need to access a folder on my desktop/harddrive outside of lightroom, e.g. gett

  • Glitch with InDesign CS5s Live/Static Caption...

    I've been following some of the forums re: problems with generating live/static captions, but none have solved this problem. I'm laying out thumbnails to generate caption info from the EXIF data. All the EXIF data can be seen when in Bridge but only

  • How to switch the Isight webcam with 3 LED displays connected to my MacPro

    I have got three LED Apple displays connected to my MACPro. Now the Isight webcam is activated in the right Led display. I don't know how to activate the middle Isight webcam en de-activate the Isight webcam of my right Led display.

  • CC Ball Action stops working when I try to use a mask

    Using AE CS6 on mac os 10.7.5.  I'm trying to use CC Ball action to make a cool particle animaation.  In order to do the animation I'm trying to create I need to use a mask.  Every time I use a mask the cc ball action stops working.  It's still in th