Insert Procedure For LOOP question

Hi all,
I have made a Procedure which basically massages data and loads into into another table and makes a time record aswell. I am practising my good datawarehousing practise (So load table into real DW_table)
I am using an Explicit Cursor For Loop....
What i was wondering is if there is some type of SQL%rowcount I can do in order to check that the record where "INSERTED" into dw_client and dw_time; before i create a auit record in another table. I know this is normally done using triggers, but I am testing this for a Datawarehouse and not sure triggers are the best answer. But please correct me if im wrong:
I basically wanted to put another insert in there, if the inserts actually ran!

RPuttagunta wrote:
Why can you not use a merge statement in your code instead of writing a whole procedure for it?
merge into mehmet_schema.dw_client a
using
mehmet_schema.client.....
If I understand it right, you are checking if there are any records that exists in 'client' and doesn't exist in 'dw_client' table, then, you are inserting. Is that correct?Yes that is correct. Also I am inserting into the dw_time table using the sqeuence values, so i didnt think merge statement would do this!
aslo i wanted to use this procedure to clean up some of the data, as you can see in my Cursor, again why i havent used a merge
Edited by: oraCraft on 09-Nov-2010 09:53

Similar Messages

  • Cursor For loop question

    Hi,
    I have a cursor in my plsql and I am trying to get the record through a FOR loop. I know that for loop will take care of opening, fetching and closing the cursor implicitly.
    Ex.
    declare
    cursor c1 is
    select * from emp;
    begin
    for l_rec in c1 loop
    end loop;
    My question is i want to check whether the cursor in the for loop is returning any record or not using IF condition.
    where and how i will find that?
    Can anyone help how to do that.
    Rds,
    Nag

    without using boolean variables.Obvious question, WHY?
    If you are so particular..
    SQL> declare
      2   cursor c1 is
      3        select empno, ename, job
      4        from emp
      5        where empno = 7839123;
      6   ex exception;
      7   rec c1%rowtype;
      8  begin
      9   open c1;
    10   fetch c1 into rec;
    11   if c1%notfound then
    12    raise ex;
    13   end if;
    14   loop
    15    dbms_output.put_line(rec.empno||'-->'||rec.ename||'-->'||rec.job);
    16    fetch c1 into rec;
    17    exit when c1%notfound;
    18   end loop;
    19  exception
    20   when ex then
    21    dbms_output.put_line('cur not found');
    22  end;
    23  /
    cur not found
    PL/SQL procedure successfully completed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • VERY IMPORTANT FOR LOOP QUESTION

    public class ForTest2 {
         public static void main(String args[]) {
              int i=0, j = 0;
              for (j=0; j < 10; j++) {
                   i++;
                   System.out.println("i is: " + i);
                   System.out.println("j is: " + j);
              System.out.println("Final i is: " + i);
              System.out.println("Final j is: " + j);
    }j ends up being 10. Why? It should only be 9. This is as when j is 10 the for loop fails, so j++ shouldnt happen.

    First, please, please, please stop using all caps. It's extremely annoying.
    Second, don't mark your question as urgent or important. It is 100
    % guaranteed NOT to get you help any faster, and it might just delay you getting help because it's annoying.
    As for your question, you're misunderstanding how the for loop works. j HAS to become 10 for it to end. The loop body executes as long as j < 10. If j didn't become 10, the loop body couldn't terminate, because j<10 would always be true.
    The body is executed, the j++ is executed, then the j<10 is tested.
    int j;
    for (j = 0; j < 10; j++) {
        // body
    // is equivalent to
    int j;
    j = 0;
    while (j < 10) {
        // body
        j++:
    }

  • A simple for loop question

    Hi
    Lets say I have an array with boolean values in it:
    my_array = [ false , false , false ]
    My question is:
    How do you make a function to check, if the value is all
    false, than do this (not only one but all false than trigger a
    function)
    thank you

    The 350Z,
    > Lets say I have an array with boolean values in it:
    > my_array = [ false , false , false ]
    I'm with ya.
    > My question is:
    > How do you make a function to check, if the value is
    > all false, than do this (not only one but all false than
    > trigger a function)
    Your subject line already states the answer. A for loop
    would come in
    handy. :) In your case, you're looking for all three values
    to be false.
    If even a mere one of them is true, the whole result doesn't
    count. Let's
    write a function that returns true if all three are false,
    and returns false
    if any are true.
    function checkWholeArray(arr:Array):Boolean {
    for (var n:Number = 0; n < arr.length; n++) {
    if (arr[n] == true) {
    return false;
    return true;
    To use this function, you could call it and supply your
    array as the
    parameter ...
    checkWholeArray(my_array);
    ... and since that resolves to either true or false, you
    could even use that
    expression in an if statement.
    if (checkWholeArray(my_array)) {
    // do something
    } else {
    // do something else
    The for loop simply steps through each element in the
    passed-in array.
    If the current element is true, then the desired outcome --
    that all
    elements are false -- is a loss, so the function returns
    false and
    immediately stops (the return statement always exits the
    function at that
    point). Otherwise, the for loop finishes, and the function
    returns true.
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • For loop question

    Hi here is a segment of my code:
    public void vietaLoop(){
         int loopParameter;
         final int START_CONDITION=0;
         final long END_CONDITION=no_Terms;
         double initialTerm = Math.sqrt(2)/2;
         double newTerm;
         double previousTerm;
         /* calculate the next PI term */
         newTerm = Math.sqrt(2+previousTerm);
         /* assign new term to previous */
         previousTerm = newTerm;
         for (loopParameter = START_CONDITION; loopParameter < END_CONDITION;
         loopParameter++)
         /* Prints the new PI approximation */
         System.out.println(+ newTerm);
    im having loads of trouble, above is how far I have got but I'm unable to 'call' the previous calculation to be included in the next calculation to calculate the new term of PI. as a result all my output is the same..... ie = 1.645.......
    If anyone could point me in the right direct... its really getting to me. Thanks.

    Hi there,
    Is this what you want?
    import java.awt.*;
    class vietaLoop
        public static void main(String[] args)
              int loopParameter;
              int no_Terms=10;
              int START_CONDITION=0;
              int END_CONDITION=no_Terms;
              double initialTerm=Math.sqrt(2)/2;
              double newTerm;
              double previousTerm;
              previousTerm=initialTerm;
              for (loopParameter=0; loopParameter<END_CONDITION;loopParameter++)
                   newTerm = Math.sqrt(2+previousTerm);
                   previousTerm = newTerm;
                   System.out.println(newTerm);
    }If you use it as a function, set it as
    public double vietaLoop(int noTerm)
    Then you can change no of term for looping.
    Regards
    John

  • Quick for loop question

    Hi everybody,
    I have a feeling this is so obvious that I'm missing it, so if anyone would give me some advice, I'd appreciate it.
    I have a method with with three parameters that loops through them and progressively adds or subtracts them with a for loop, based on the order. The only way I can think of to do this, though, is with two for loops with almost identical code. I know there must be an easier way to do this, but I think I've been staring at it too long, can anyone give me a hand conceptually, please?
    The method is:
    private void create( int param1, int param2 ) {
            int entries = 5;
            double increment;
            if( param1 > param2 ) {
                increment = param1 - param2;
                for( int i = 0; i < entries; i++ ) {
                    System.out.println( param1 - ( i * increment ) );
            } else if( param2 > param1 ) {
                increment = param2 - param1;
                for( int i = 0; i < entries; i++ ) {
                    System.out.println( param1 + ( i * increment ) );
         }Thanks,
    Jezzica85
    Edited by: jezzica85 on Mar 30, 2009 2:38 PM

    private void create( int param1, int param2 ) {
        if( param1 > param2 ) {
            create(param2, param1);
        } else if( param2 > param1 ) {
            int entries = 5;
            double increment = param2 - param1;
            for(int i = 0; i < entries; i++ ) {
                System.out.println( param2 + (i * param1));
        } //equal do nothing?
    }or
    private void create2( int param1, int param2 ) {
        if (param1 != param2) {
            int entries = 5;
            int minParam = Math.min(param1, param2);
            int maxParam = Math.max(param1, param2);
            double increment = maxParam - minParam;
            for( int i = 0; i < entries; i++ ) {
                System.out.println( maxParam - (i * minParam));
      }

  • Enhance for loop question

    I like it, but I can't figure out how to use it for the following situation (printing contents of two arrays using one iterator):
    old way:
            System.out.println(menuTitle + "/n");
            for (int e ; e < length.menuChoices ; e++)
                System.out.print(menuChoices[e] + " - " + menuLabels[e]);
            }new?
            System.out.println(menuTitle + "/n");
            for (String e : menuChoices)
                System.out.print(e + " - " + menuLabels[????]);
            }Is there a nice way to do this or should I just use the old for loop and hope my teacher doesn't think that I just don't know about the new loop? Thanks.

    Is there a nice way to do this or should I just use
    the old for loop and hope my teacher doesn't think
    that I just don't know about the new loop?No there isn't. In the new for-loop the loop counter has been abstracted away. You'll have to either use the old for-loop, or introduce a counter in the new.
    Another way could be to change the design a little.
    class MenueItem {
       Type1 choice();
       Type2 label();
    for (String e : menuItems)  { // all MenuItems
       System.out.print(e.choise() + " - " + e.label());
    }

  • Stacked sequence inside for loop question

    Hi everyone,
    I am new to LabVIEW and I just want to make a for loop with a stack sequence inside. I want it so that when the for loop executes for the n-th time, the stacked sequence is at the n-th frame (because each frame contains different tasks to be carried out). Is this possible? or is there an alternative equivalent method? Please help me out! Thanks!!

    Thank you Norbert for the words of advice.
    Try to avoid Stacked Sequence Structures at all cost.  They are a nightmare to deal with when maintaining the code and they do not offer simple scalability, especially if you need to deal with parallelism.
    As Norbert suggested, State Machines is the way to go.  Try to avoid naming covention such as 1...2...3...4...5.......9999.  Give the name of each case based on what that case does.  Create a TypeDef Control for the state selector (you'll thank me after having changed it for the 5th time   ).
    There are probably 100's of examples in this forum.
    RayR

  • Procedure Body Loop Question

    I have a procedure that builds an Excel Spreadsheet from a parameter form, depending on the user's selected criteria. To make it easier for testing I am just selecting a range of 3 leases from this form. Each lease may have several entries according to the number of invoices. I am trying to put a total and a blank line between each lease group, but I'm having a problem with how to loop it.
    Below is the code:
    CODE
    PROCEDURE Excel_ReportData ( v_cl_no varchar2,
    v_pr_no varchar2,
    v_ls_date date,
    v_beg_no varchar2,
    v_end_no varchar2 ) is
    cursor c1 ( v_cl_no varchar2,
    v_pr_no varchar2,
    v_ls_date date,
    v_beg_no varchar2,
    v_end_no varchar2 ) is
    select tran_type, lease_no, tran_no, tran_date, dscr, amount, ar_col, ap_col,
    lease_date, cl_no, pr_no, ls_no
    from lease_transactions a, lease_master b
    where b.ls_no = a.lease_no
    and b.cl_no = decode( v_cl_no, null, b.cl_no, v_cl_no )
    and b.pr_no = decode( v_pr_no, null, b.pr_no, v_pr_no )
    and b.lease_date = decode( v_ls_date, null, b.lease_date, v_ls_date )
    and nvl(b.ls_no,0) between nvl(v_beg_no,-100) and nvl(v_end_no,9999999999)
    order by 2, 4;
    cursor c2 ( v_cl_no varchar2,
    v_pr_no varchar2,
    v_ls_date date,
    v_beg_no varchar2,
    v_end_no varchar2 ) is
    select lease_no, nvl(sum(ar_col), 0) ar_sum, nvl(sum(ap_col), 0) ap_sum
    from lease_transactions a, lease_master b
    where b.ls_no = a.lease_no
    and b.cl_no = decode( v_cl_no, null, b.cl_no, v_cl_no )
    and b.pr_no = decode( v_pr_no, null, b.pr_no, v_pr_no )
    and b.lease_date = decode( v_ls_date, null, b.lease_date, v_ls_date )
    and nvl(b.ls_no,0) between nvl(v_beg_no,-100) and nvl(v_end_no,9999999999)
    group by lease_no
    order by 1;
    cr1 c1%rowtype;
    cr2 c2%rowtype;
    v_i number;
    v_no number;
    v_name varchar2 (20) := 'Lease_Trans';
    v_tran_type varchar2 (50);
    v_lease_no varchar2 (20);
    v_tran_no varchar2 (100);
    v_tran_date date;
    v_dscr varchar2 (500);
    v_amount number;
    v_ar_col number;
    v_ap_col number;
    v_lease_date date;
    BEGIN
    Oleexcel.sheetname := 'Sheet1';
    OleExcel.OpenSheet;
    Ole2.release_obj( oleexcel.worksheet );
    OleExcel.LineWeight := 0;
    -- Insert new worksheet in front
    oleexcel.sheetname := v_name;
    Oleexcel.NewSheet;
    Excel_PageSetup( 2, 5 );
    -- Build Header
    v_i := 1;
    ac.counter := 0;
    OleExcel.Set_Cell_ValFullFmt( v_i, ac.nxt, 'T. S. DUDLEY LAND COMPANY, INC.', null, 'Arial', 14, 'Bold', null, OleExcel.cellWhite, false, OleExcel.Left );
    Blank_Cells( v_i, ac.counter+4, 52 );
    v_i := v_i + 1;
    ac.counter := 0;
    OleExcel.Set_Cell_ValFullFmt( v_i, ac.nxt, 'LEASE TRANSACTION REPORT', null, 'Arial', 10, 'Bold', null, OleExcel.cellWhite, false, OleExcel.Left );
    Blank_Cells( v_i, ac.counter+4, 52 );
    v_i := v_i + 1;
    ac.counter := 0;
    OleExcel.Set_Cell_ValFullFmt( v_i, ac.nxt, 'Date', null, 'Arial', 10, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Left );
    OleExcel.Set_Cell_ValFullFmt( v_i, ac.nxt, to_char( sysdate, 'MM/DD/YYYY'), 'MM/DD/YYYY', 'Arial', 10, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Left );
    Blank_Cells( v_i, ac.counter+1, 52 );
    v_i := v_i + 1;
    Blank_Cells( v_i, 1, 52 );
    -- Do Headings
    v_i := v_i + 1;
    OleExcel.LineWeight := 4;
    ac.counter := 0;
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Lease No.', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Transaction Type', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Transaction No.', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Transaction Date', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Transaction Description', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Transaction Amount', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Accounts Receivable', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Accounts Payable', null, 'Arial', 10, 'Bold', null, OleExcel.cellGray, true );
    v_i := 5;
    ac.counter := 0;
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '12' );
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '16' );
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '22' );
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '12' );
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '40' );
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '14' );
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '12' );
    oleexcel.Set_Cell_Property (v_i, ac.nxt, oleexcel.cellWidth, '12' );
    OleExcel.LineWeight := 2;
    OleExcel.Border_Cells( OleExcel.CellAddress( v_i, 1 ) || ':' || OleExcel.CellAddress( v_i, ac.counter ) );
    oleexcel.Set_Cell_Property (v_i, ac.counter, oleexcel.cellHeight, '38.25' );
    v_i := 5;
    open c1 ( v_cl_no, v_pr_no, v_ls_date, v_beg_no, v_end_no );
    open c2 ( v_cl_no, v_pr_no, v_ls_date, v_beg_no, v_end_no );
    loop
    fetch c1 into cr1;
    exit when c1%notfound;
    fetch c2 into cr2;
    exit when c2%notfound;
    v_i := v_i + 1;
    ac.counter := 0;
    -- Output data
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, cr1.lease_no, null, 'Arial', 10, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Left );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, cr1.tran_type, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Left );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, cr1.tran_no, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Left );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, to_char(cr1.tran_date, 'MM/DD/YYYY'), 'MM/DD/YYYY', 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Center );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, cr1.dscr, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Left );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, to_char(cr1.amount), '$###,##0.00', 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Right );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, to_char(cr1.ar_col), '$###,##0.00', 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Right );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, to_char(cr1.ap_col), '$###,##0.00', 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Right );
    oleexcel.Set_Cell_Property (v_i, ac.counter, oleexcel.cellHeight, '15' );
    OleExcel.LineWeight := 2;
    OleExcel.Border_Cells( OleExcel.CellAddress( v_i, 1 ) || ':' || OleExcel.CellAddress( v_i, ac.counter ) );
    Blank_Cells( v_i, ac.counter+1, 52 );
    v_i := v_i + 1;
    ac.counter := 0;
    -- Output data
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, 'Total', null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, true, OleExcel.Left );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, null, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, null, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, null, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, null, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, null, null, 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, to_char(cr2.ar_sum), '$###,##0.00', 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Right );
    oleexcel.Set_Cell_ValFullFmt ( v_i, ac.nxt, to_char(cr2.ap_sum), '$###,##0.00', 'Arial', 9, 'Normal', null, OleExcel.cellWhite, false, OleExcel.Right );
    oleexcel.Set_Cell_Property (v_i, ac.counter, oleexcel.cellHeight, '15' );
    OleExcel.LineWeight := 2;
    OleExcel.Border_Cells( OleExcel.CellAddress( v_i, 1 ) || ':' || OleExcel.CellAddress( v_i, ac.counter ) );
    Blank_Cells( v_i, ac.counter+1, 52 );
    end loop;
    close c1;
    close c2;
    END;
    I've tried several different things, but this is the basic code, which is putting the totals at the end and only showing one lease when it should return 3 leases with multiple lines with the total line after each group.
    I've only been doing Oracle development for a few months so I hope this is an easy question.
    Thanks JLW

    PROCEDURE (some variables passed from form) IS
    cursor c1 is (select statement to get data to populate Excel spreadsheet)
    cursor c2 is (select statement to get totals for Total line in Excel)
    cr1 c1%rowtype;
    cr2 c2%rowtype;
    v_ ...
    Begin
    --Access Last Sheet
    --Insert New WS
    --Build Header
    --Build Column Headings
    *****Here is where I'm having the problem. I am trying to put a total and a blank line between each lease group.
    *****Not sure how to loop this ... sorry I'm a newbie.
    open c1;
    open c2;
    loop
    fetch c1 into cr1;
    exit when c1%notfound;
    fetch c2 into cr2;
    exit when c2%notfound;
    --Output Data from c1 (I need this to be only 1 lease group from c1)
    --Output Data from c2 (total from c2 with a blank line)
    ... and so on until c1-c2 notfound
    end loop
    close c1
    close c2
    end
    Below is an example of the output in Excel:
    ~*Lease No.* TransType Trans No. Trans Date Trans Description Trans Amount Accounts Receivable ~~*Accounts Payable*~
    ~812320 Invoice 681050 7/23/2008 68105 $3,156.55 $3,156.55 $3,156.55~
    ~812320 Check 35058 08/18/2008 County Clerk $17.00 $0.00 -$17.00~
    ~Total $0.00 $0.00~
    ~(BLANK LINE)~
    ~812327 Paid by Other 07/15/2008 $1,260.00 $0.00 -$1,260.00~
    ~812327 Bonus 07/15/2008 $1,260.00 $0.00 $1,260.00~
    ~Total $0.00 $0.00~
    Any help would be greatly appreciated.
    Thanks

  • Is there a way to run a For Loop independen​tly within a While Loop in LabVIEW 2013?

    In my program I would like to run a For loop inside of a While loop, and have them run independently, at their own execution rates.  As a test, I wrote a simple VI with a While loop with 1 second timing, and into this I inserted a For loop with 3 second timing.  I created indicators for both iteration terminals.  Upon running the VI, I found the While loop waits for the For loop to run N times before the While loop executes again.  I also found that sometimes the first iteration of the For loop will end at 1 second rather than 3 seconds, and the STOP button to terminate execution of the While loop does not always work.
    Solved!
    Go to Solution.

    ksinks wrote:
    Thanks, how would you synchronize the loops?  I have gone through the Getting Started exercises and manual.
    Why would synchronization matter? Did you want them to run independantly at their own speed or not?
    Regardless, there's a synchronization pallette with functions for this, as Occurance.
    Other solutions include a common loop counter and a case structure executing every X'th iteration, or having the faster loop send a queue or event every X'th loop that controls the slower loop.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • How to make for loop pass only once in a next() method

    Good Day!
    Can anyone help me or suggest any idea to resolve my problem with the below code, wherein it will only pass the for loop only once. I already tried inserting the for loop in side the if (sqlset4.isFirst()) condition but the problem is it only retrieved the first row of the resultset.
    Cheers!
                   Statement sOutput = consrc.createStatement();
                            ResultSet sqlset4 = sOutput.executeQuery(xquery);
                            ResultSetMetaData rsMetaData = sqlset4.getMetaData();
                            int numberOfColumns = rsMetaData.getColumnCount();
                            String writefld = "";
                            while (sqlset4.next()) {
                                 writefld = "";
                                 for (int i = 1; i <= numberOfColumns; i++) {
                                     if (xxformatid.equals("1") || xxformatid.equals("3")) {
                                         writefld = writefld + "sqlset4.getString(" + i + ").trim()" + "|";
                                writefld = writefld.substring(0, writefld.length() - 1) + ")";
                                output.write("\r\n");
                                output.write(writefld);
                            output.close();I am using Netbean IDE 6.8
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi

    Hi everyone!
    What I actually trying to do is that I have a multiple tables and from these tables I'm going to write each of it into a flatfile that is a pipe delimeted that is why I have to make a loop to know how many fields I am going to write. The code that was attached are actually working, my only concern is that it will take a longer time of processing cause every record of a table it will pass to the for loop(checking how many column) wherein number of column/ were already known on the first loop.
    Hi kajbj,
    I think what your trying to explain is almost the same with below code which i had already tried. The problem with this is that the every loop of the outer loop data retrieve is only the data of the first record.
                   Statement sOutput = consrc.createStatement();
                            ResultSet sqlset4 = sOutput.executeQuery(xquery);
                            ResultSetMetaData rsMetaData = sqlset4.getMetaData();
                            int numberOfColumns = rsMetaData.getColumnCount();
                            String writefld = "";
                            while (sqlset4.next()) {
                                 writefld = "";
                                 if (sqlset4.isFirst()) {
                                    for (int i = 1; i <= numberOfColumns; i++) {
                                        if (xxformatid.equals("1") || xxformatid.equals("3")) {
                                            writefld = writefld + "sqlset4.getString(" + i + ").trim()" + "|";
                                writefld = writefld.substring(0, writefld.length() - 1) ;
                                output.write("\r\n");
                                output.write(writefld);
                            output.close();

  • How to create procedure for header table and  item table

    Hi,
    Can anyone help me to understand how to write SQLscript procedure for looping item table inside header table?
    I fetch records from sales header table ( order number ) and using that order number to loop sales item table,thereafter I need to perform business logic.
    Any example similar above requirement would be helpful
    thanks
    Sourav

    Hi Folks,
    This is my use case
    1) Select fact records from tables (say A,B,C,D ) with suitable Joins and certain Where conditions
        SELECT ordid FROM TABLES A,B,C,D on join condition where ....
    2) Using above header records , I have to select each and every item level data from different tables ( say X,Y,Z ) and perform calculation to derive new columns to update a new table ( Zreport )
    UPDATE TABLE ZREPORT
    SET col1 = ( Select qty  FROM TABLE X WHERE ordid = A.ordid
    UPDATE TABLE ZREPORT
    SET col2 = ( Select price FROM TABLE y WHERE ordid = B.ordid.
    and so on for other columns..
    3) Zreport table will be used for reporting.
    I would like to know the best way to achieve this to gain performance.
    Appreciate the help!
    Thanks
    Sourav

  • Procedure to insert same record for 30 times in a table using for loop

    Hi,
    I need to insert a record in a table which has to be iterated using for loop

    I think you are in the wrong forum. You can do that like this:
    CREATE TABLE my_table (my_column NUMBER);
    BEGIN
       FOR i IN 1 .. 30
       LOOP
          INSERT INTO my_table
                      (my_column
               VALUES (i
       END LOOP;
    END;
    /Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Procedure for Insert to BULK COLLECT

    hi,
    I have 2 questions-
    1) Say I have below code. I want to call an insert procedure insead of INSERT INTO. If I do would it give any performance issue?
    CREATE OR REPLACE PROCEDURE test_proc (p_array_size IN PLS_INTEGER DEFAULT 100)
    IS
    TYPE ARRAY IS TABLE OF all_objects%ROWTYPE;
    l_data ARRAY;
    CURSOR c IS SELECT * FROM all_objects;
    BEGIN
    OPEN c;
    LOOP
    FETCH c BULK COLLECT INTO l_data LIMIT p_array_size;
    FORALL i IN 1..l_data.COUNT
    INSERT INTO t1 VALUES l_data(i);
    EXIT WHEN c%NOTFOUND;
    END LOOP;
    CLOSE c;
    END test_proc;
    CREATE OR REPLACE PROCEDURE insert_proc ( col1 table.col1%Type,
    col2 table.col2%Type,
    col20 table.col20%Type)
    BEGIN
    INSERT INTO HistoryTable (col1, col2, ...col20)
    VALUES(val1, val2, ...val 20);
    END;
    END;
    2) Is there any clean method to create insert procedure which has 20 columns which I can call in other proc to do bulk insert?

    It is good that you explained your requirements, but you did not give us some data to see with and work with.
    If you could, help us with below details, it might be possible to help you:
    1. Create table statements for your Tables (eg. Checking, Savings and history)
    2. Insert Into statements for Sample data for your Tables.
    3. validations that you need to perform
    4. Expected output based on the Sample data provided in step 2.
    Please do not forget to post your version number
    select * from v$version;Also, use {noformat}{noformat} tags, before and after SQL Statements, Expected Output to preserve spaces and make the post more readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Passing an array in a for loop to a procedure

    I am trying to pass an array in a cursor for loop to a procedure which performs a table insert using the array's contents. Somehow I am missing something, or it is not possible. The compile error states: PLS-00306: wrong number or types in call to 'insert_address' I checked to be sure I am creating the arrays in both cases from similar data objects. Both address and work_address_table contain the same 4 columns with the same data types.
    create or replace package work_address as
    FUNCTION populate_address return boolean;
    procedure insert_address(in_address IN work_address_table%ROWTYPE);
    end work_address;
    create or replace package body work_address as
    function populate_address return boolean is
    cursor c1 is
    select 'H' as header,
    street1 as street
    city as city,
    NULL as state
    from address
    where city = 'HANOVER';
    TYPE addressT IS TABLE OF c1%ROWTYPE INDEX BY BINARY_INTEGER;
    rec1 addressT;
    BEGIN
    OPEN c1;
    FETCH c1 BULK COLLECT INTO rec1 LIMIT 500;
    FOR i IN 1..rec1.count LOOP
    rec1(i).state := 'US'
    insert_address(rec1(i));
    exit when c1%notfound;
    END LOOP;
    CLOSE c1;
    return TRUE;
    END populate_address;
    PROCEDURE insert_address(in_address IN work_address_table%ROWTYPE) IS
    BEGIN
    INSERT INTO work_address_table
    VALUES (in_address.header,
    in_address.street,
    in_address.city,
    in_address.state);
    COMMIT;
    END insert_address;
    END work address;
    /

    Both address and work_address_table contain the same 4 columns with the same data types.Are you 100% sure about this?
    SQL> declare
      cursor c1
      is
        select 1 deptno, dummy dname, 'Loc' location from dual;
      type addresst is table of c1%rowtype
        index by binary_integer;
      rec1   addresst;
      procedure p (d dept%rowtype)
      as
      begin
        dbms_output.put_line(d.dname);
      end p;
    begin
      rec1 (1).dname := 'z';
      p (rec1 (1));
    end;
    z
    PL/SQL procedure successfully completed.but changing just the first column of the cursor:
    SQL> declare
      cursor c1
      is
        select 'xy' deptno, dummy dname, 'Loc' location from dual;
      type addresst is table of c1%rowtype
        index by binary_integer;
      rec1   addresst;
      procedure p (d dept%rowtype)
      as
      begin
        dbms_output.put_line(d.dname);
      end p;
    begin
      rec1 (1).dname := 'z';
      p (rec1 (1));
    end;
    Error at line 3
    ORA-06550: line 20, column 3:
    PLS-00306: wrong number or types of arguments in call to 'P'
    ORA-06550: line 20, column 3:
    PL/SQL: Statement ignored

Maybe you are looking for