Exit Statement

 
 FOR I IN C LOOP        --LOOP1
       Statements
          FOR J IN C LOOP   --LOOP2
                        Statements   
            EXIT;
                Statements
          END LOOP
            Statements
    END LOOP;
My doubt was RELEASED this statement out of the inner loop LOOP2 or any outer loop LOOP1?
Pls confirm.

TKS in advance

He left the inner loop, unless you use labels and explicitly to exit a loop marked by its name.

Tags: Database

Similar Questions

  • using an Exit statement for a deletion without affecting an oracle error msg

    Hello all;

    I have one similar to this delete statement below
      delete from tbl_one t
      where t.tbl_one_location = location 
      and location not in (select distinct p.issuearea  from tbl_two p);
    the delete statement is in a package, however I would like to make out a simple message to indicate if the deletion was successful which means that a real element has been deleted and if this was not successful another statement for this.

    I have an idea in my mind which is to track the number of items in tbl_one before deleting and then check the count after removal and if the number is lower, the deletion was successful... therefore the output message. Is the best way to go or there at - it an easier way to do it.

    Thank you, any help is appreciated.

    You could put something like this directly after the DELETE statement:

    IF SQL%ROWCOUNT > 0 THEN
            DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT || ' items deleted.');
    ELSE
            DBMS_OUTPUT.PUT_LINE('Nothing deleted!');
    END IF;
    

    SQL % ROWCOUNT attribute: how many lines were affected?

  • % NOTFOUND - Question on which the EXIT condition is placed right after a RECOVERY

    I so a procedure that uses a cursor, but also a loop to output values as follows

    LOOP

    / * Retrieve each row of the result of the request above for PL/SQL variables: * /.

    EXTRACT AREA_CUR IN P_ID, P_LAST_NAME, P_DEPTH;

    / * If there are no rows to extract, exit the loop: * /.

    WHEN THE OUTPUT AREA_CUR % NOTFOUND;
    DBMS_OUTPUT. Put_line (' student: ' |) P_ID);
    DBMS_OUTPUT. Put_line (' family name student: ' |) P_LAST_NAME);
    DBMS_OUTPUT. Put_line ("depth: ' |") P_DEPTH);
    END LOOP;

    Currently, if I had to start my procedure I would like to get the output of

    Schmidt
    Burha

    Who should

    But I noticed that if I pass the EXIT statement at the end just before the end of the loop I get slightly different results

    LOOP

    / * Retrieve each row of the result of the request above for PL/SQL variables: * /.

    EXTRACT AREA_CUR IN P_ID, P_LAST_NAME, P_DEPTH;
    DBMS_OUTPUT. Put_line (' student: ' |) P_ID);
    DBMS_OUTPUT. Put_line (' family name student: ' |) P_LAST_NAME);
    DBMS_OUTPUT. Put_line ("depth: ' |") P_DEPTH);

    / * If there are no rows to extract, exit the loop: * /.

    WHEN THE OUTPUT AREA_CUR % NOTFOUND;

    END LOOP;

    I then get the results of

    Schmidt
    Buhra
    Burha

    What I understand after a FETCH statement is issued, it will take the current value of the line her in and then also the movement to the next line.

    Why would he captures Burha twice?

    Since the FETCH statement moves to the next line I would expect the output to look more to

    Schmidt
    Buhra
    < White > (because that would be the new line)

    Am I misunderstand this?

    You say that since there is no value should be extracted in variables, then the variables in the FETCH stmt hold nulls, right? But he has no line (NOT EVEN NULL) must be extracted, so variables retain their values.
    And % notfound is a Boolean attribute that returns false if the previous extraction returns a line * and this argument is set to true if she didn't, that's why we use exit after fetch statement, and not the end of loop; Or we can get different results, as in your case!

    Mahanam

  • How to publish the source code

    How best to publish the source code?

    I need an alternative to fall back on.  How I would go to this topic if I had to use HTML.

    My chance to validation code has deteriorated over time. I did it via:

    I take the plain.

    Yesterday, when I tried to insert the Bash source code.  I had a lot of white lines.  I think that leading # confused CSA.

    
    #!/bin/bash 
    
       # so anyway, output from the echo statement is sent to the terminal.  The operands < and >
       # allows you to change where it is going.
      
    
    # default redirection  
    
    # 0 stdin  -- standard input
    
    # 1 stdout -- standard output, non-error output
    
    # 2 stderr  -- standard output for error messages.
    
    # had not used the exec statement before, the concept of the exec was
    
    # readily apparent to me.
    
       
    
    # of course, I ripped this off.  Turns out you want to preserve where input stream 0 is
    
    # coming from. The hack moves input stream 0 to input stream 6.  Pick any number
    
    # that is allowed.
    
       
    
    # save standard input in file descriptor 6 
    
    exec 6<&0 
    
       
    
    # now we say where we want input stream 0 to come from. 
    
    # bash has an unknown to me number of commands that read from input stream 0
    
    # via redirection we can change were stream 0 is coming from.
    
    # redirect standard input to be from the passed file 
    
    exec 0<${1} 
    
    count=0 
    
    while read lineIn  
    
    do { 
    
    # bash syntax is bizarre.   
    
    # The (( )) says it's a math expression 
    
    (( count++ )) 
    
    echo "${count}: ${lineIn}" 
    
    } 
    
    done 
    
    # put the input streams back to where they were before. 
    
    # Nice, but when the script quits they will all be put back to where they were.
    
    # Of course, I copied this stuff.  Syntax isn't the obvious.
    
    # close input.  May not need.  My innovation.  Seems nice.
    
    exec 0<&- 
    
    # restore file descriptor 0 should be standard in 
    
    exec 0<&6 
    
    # close file descriptor 6 for reuse. 
    
    exec 6<&- 
    
    echo 
    
    echo "Total lines were ${count}" 
    

    Do you get the extra lines before applying syntax highlighting? You can simply change the Courier New font.

    #! / bin/bash

    # Anyway, Exit statement echo is sent to the Terminal.  The operands< and="">

    # allows you to change its future.

    default redirection #.

    # 0, stdin - standard input

    # 1, stdout - output standard output without error

    # 2, stderr - standard output for error messages.

    # did not use the exec statement before, the concept of the exec has been

    # obvious to me.

    # good course, I snatched it.  Turns out you want to keep where the input stream 0 is

    # coming. The cut moving the input stream to the stream input 6 0.  Choose any number

    # who is allowed.

    # Save the standard entry in the file descriptor 6

    exec 6<>

    # now say us where we want to enter flow 0 to come from.

    bash # a a stranger to me the number of commands that read from the input stream 0

    # via redirection, we can change were stream 0 comes.

    # redirect the standard input from the file passed

    exec 0<>

    Count = 0

    while reading lineIn

    {}

    bash # is weird syntax.

    # (()) Is a mathematical expression

    ((count ++))

    echo "${number}: ${lineIn}.

    }

    fact

    # put the input stream to where they were before.

    # Nice, but when the script closes they will all put back to where they were.

    # Of course, I copied this kind of things.  The syntax is not obvious.

    # entry closes.  May not need.  My innovation.  Seems nice.

    exec 0<>

    Restore file descriptor # 0 should be standard in

    exec 0<>

    # close the file descriptor 6 for reuse.

    exec 6<>

    ECHO

    ECHO "the Total of the lines were ${number}.

    TT2

  • What is a good code of vi for control of pulse

    Hi, I just write a simple code to generate two pulse; the first pulse is output 5V to 200ms then stop and wait for 4 seconds. After that, another 5V pulse is on for 200ms then turned off. That's essentially what I must control relay. Relay toggle and disable type. The code seems inadequate, is there a better approach? I use USB-6008, thank you

    just a few minor changes:

    • Keep create and destroy outside loops. DAQmx tasks must be created once - preferably during development and registered to the MAX or your project.

    • Keep a handy customized with vi waiting to avoid these structures seq who botch to the top of the BD of error handling

    • 500mS pending is in parallel with the structure of the seq and does nothing but deal with 1 thread for 1/2 sec so that the structure is running.

    See revised code:

    This isn't very scalable.  For adaptabiity, it must be converted into State or QMH machine with "Init (Task), waiting (waiting time), write (Bool), and Exit" States.

  • Def sequence (table grapes) with loops, clocked by the relatively long software.

    Hello and apologies in advance I am an infrequent user of LabVIEW.

    Running on a VI to control a peristaltic pump and valve used to control some for a biosensor nanogap Microfluidic devices. I have the pump and the valve works manually (i.e., I adjust the values on the fly) but I am now trying to allow the user to define a sequence of steps that are then executed one after the other.

    User input: number, flow, duration of valve, pump direction (boolean).  Ideally the user can then run several different steps by adding more steps, so I thought of an indexed cluster array where each element represents a step?

    I would like the user to enter the time in minutes and seconds. The minimum will usually be 30 seconds and could be as long as an hour. I'm not sure of the best strategy for the timed loop, if I understand the use of the block 'waiting (ms)' can cause problems. I thought about getting a timestamp, a value added to it and the comparison? Are there any other suggestions?

    Any advice would be appreciated.

    I use an acquisition of data USB-6009.

    PS the VI LabVIEW is probably an education version, so may cause problems when opening?

    Just ask yourself how you should architect your code? Using a table of parameters of the step is an eay easy to do. And the wait is not necessarily a bad thing, it depends on your application and if you need the calendar to be exact in a certain way. You can use wait it until Mrs several place for synchronization.

    You can lookin to a State Machine architecture to make the best UI feature.

    The Computer of State Simple model that comes with LabVIEW is really the best way for new developers to become familiar with LabVIEW using a semi scalable architecture.

    Here is a large example of the works of a state machine:

    • States: Init, slowed down, exit, DoThing1, DoThing2, DoThing3
    • Each State contains code that could take some time. Ideally, not too long because this is how long your code might not meet.
    • The idle state contains a structure of event for all of the user interactions.
    • The front panel has a button that says "do the 1 thing.
    1. Loop iteration 0: Application starts, the first State is Init. Init State made the initialization stuff and tells the application to go to the idle state when finished.
    2. Iteration of the loop 1: request goes to the idle state. He's sitting there, waiting for the structure of the event.
    3. Time passes, and then the user presses the button 'do 1 thing ". There is no code or minimal code, within the occurrence of the event. The output of this state of the event tells the application to go to the State of DoThing1.
    4. Iteration of the loop 3: Application passes to the State of DoThing1. Here, there is code that does a few things. The output of DoThing1 State tells the application to return to the idle state.
    5. Iteration of the loop 4: Application goes to a State of rest where he waits again to the structure of the event.
    • Each State can tell the application to go to any State they want. You want to reset? Return to the Init State. You want to put an end to the program? Go to the exit State. You want each State to start another (such as a sequence)? Have DoThing1 out of DoThing2, which DoThing3, which outputs Idle.

    You can create a report that runs the cluster setting input and operates it. The risk with a long wait, is that the code will not be able to receive entries to user during this waiting period. So if you make a long wait, you can use a VI of elapsed time to check several times if the wait is over.

  • Control 2 while loop and a queue

    Hello Mr President

    I need handel while loopps as they run in order. I can use the structure of sequence, but the question is in my program, I also have one already queued. Please help me how I can handel this question

    Thank you

    You certainly want a State Machine. You can't do what you want using a sequence structure, as you said. If you need an architecture that can operate several different cases in a certain order, but also to repeat the States if necessary.

    The Computer of State Simple model that comes with LabVIEW is really the best way for new developers to become familiar with LabVIEW using a semi scalable architecture.

    Here is a large example of the works of a state machine:

    • States: Init, slowed down, exit, DoThing1, DoThing2, DoThing3
    • Each State contains code that could take some time. Ideally, not too long because this is how long your code might not meet.
    • The idle state contains a structure of event for all of the user interactions.
    • The front panel has a button that says "do the 1 thing.
    1. Loop iteration 0: Application starts, the first State is Init. Init State made the initialization stuff and tells the application to go to the idle state when finished.
    2. Iteration of the loop 1: request goes to the idle state. He's sitting there, waiting for the structure of the event.
    3. Time passes, and then the user presses the button 'do 1 thing ". There is no code or minimal code, within the occurrence of the event. The output of this state of the event tells the application to go to the State of DoThing1.
    4. Iteration of the loop 3: Application passes to the State of DoThing1. Here, there is code that does a few things. The output of DoThing1 State tells the application to return to the idle state.
    5. Iteration of the loop 4: Application goes to a State of rest where he waits again to the structure of the event.
    • Each State can tell the application to go to any State they want. You want to reset? Return to the Init State. You want to put an end to the program? Go to the exit State. You want each State to start another (such as a sequence)? Have DoThing1 out of DoThing2, which DoThing3, which outputs Idle.
  • saving files between multiple tabs in the same race

    Initially I thought that it was a simple question, I had, but I spent some time trying to fix it and I'm out of ideas.

    The goal is to be able to record different tabs for a VI that controls an instrument, each tab is another mode of measurement. So, first I created a VI that I could press a power button and register a separate file for each press. I was able to do it without problem. Then I tried to add features to this VI to a tab structure. The goal is that I can press a power button and record a separate file for each press on one of the tabs (and in the course of execution, use each tab). However, regardless of what I have tried I can't seem to be able to save more than one tab at a time. The first tab of the race is functional, but then any subsequent tab is not.  I tried chaning the loop structure and how to write files, but nothing worked. I have attached a VI that displays the problem without the [extreme] amount of irrelevant information that has the original.

    Any ideas? Thanks in advance.

    You can't wait to operate through different tabs in a single pass without a loop around the code. Programming LabVIEW is based entirely on the data flow and parallelism. It is incredibly powerful and has led to its success over the years (coupled with graphical programming), but is usually one of the first things the new developers stumble on. This is a simple resource to familiarize themselves with its functioning. The function to highlight execution is a great way to watch how your application uses data streams.

    You must move your Boolean control within the structure of the event in the registry value correctly, and your code will lock up since you have several structures of events separated in the case of the tab.

    You won't like hearing this, but the tab control is incredibly dangerous because you can easily lock your code. What that means, ideally, you don't use control tab for appearances or subsections of your code you want to operate differently depending on whether the tab is selected.

    One of the first applications I made, which I was so proud of, had a tab control serving of main container for code inside. It worked fine for a while, but I found I duplicate a lot of code and then sometimes it would not close, so I have to throw the code to extinguish a fire after another.

    Notice how your tab case all look the same with minor differences depending on the boolean type and the measurement? This means that if you make a change because of a tab, you'll probably end up wanting to make this same change to all the other tabs and now your workload is tripled for a change.

    Look in the Computer of State Simple model that comes with LabVIEW. It really is the best way for new developers to get familiar with LabVIEW using a semi scalable architecture.

    Here is a large example of the works of a state machine:

    • States: Init, slowed down, exit, DoThing1, DoThing2, DoThing3
    • Each State contains code that could take some time. Ideally, not too long because this is how long your code might not meet.
    • The idle state contains a structure of event for all of the user interactions.
    • The front panel has a button that says "do the 1 thing.
    1. Loop iteration 0: Application starts, the first State is Init. Init State made the initialization stuff and tells the application to go to the idle state when finished.
    2. Iteration of the loop 1: request goes to the idle state. He's sitting there, waiting for the structure of the event.
    3. Time passes, and then the user presses the button 'do 1 thing ". There is no code or minimal code, within the occurrence of the event. The output of this state of the event tells the application to go to the State of DoThing1.
    4. Iteration of the loop 3: Application passes to the State of DoThing1. Here, there is code that does a few things. The output of DoThing1 State tells the application to return to the idle state.
    5. Iteration of the loop 4: Application goes to a State of rest where he waits again to the structure of the event.
    • Each State can tell the application to go to any State they want. You want to reset? Return to the Init State. You want to put an end to the program? Go to the exit State. You want each State to start another (such as a sequence)? Have DoThing1 out of DoThing2, which DoThing3, which outputs Idle.

    You can have a different status according to the types of measure do you use and the selection of the State may still be governed by the tab control.

  • Disqualification external tasks

    Hello

    I have a stored procedure, and I am the appellant through a Windows File batch (.bat) in the location "edq\oedq.local.home\commandarea".

    The procedure is completed successfully, but the external task is not getting out even after that stored procedure runs correctly. We have to manually cancel.

    Because the command line is not automatically get closed. Is there any solution to get out of the external Disqualification task task?

    Appreciate your input on this.

    Untitled.jpg

    Thank you

    Anand R

    As we've said before, you must add an EXIT statement at the end of your script. It works for me if you do this:

    ...

    end loop;

    END;

    /

    EXIT;

    /

  • Problem with cursor

    I couldn't find the soluction to an error message, have you seen the error before, could you please help me?

    create or replace procedure update_location

    is

    cur_rec varchar2 (30);

    cursor up_loc_cur is

    Select location_code in the hr_locations_v where address_style = 'generic ';

    Start

    Open up_loc_cur; -PLS-00103: encountered the symbol "up_loc_cur" when expects it one of the following values: =. (@ %; not null default range character)

    extract the up_loc_cur in cur_rec;

    When the output up_loc_cur % notfound;

    close up_loc_cur;

    end;

    Exit statement must always be inside a loop... Try this

    create or replace procedure update_location

    is

    cur_rec varchar2 (30);

    cursor up_loc_cur is

    Select location_code in the hr_locations_v where address_style = 'generic ';

    Start

    Open up_loc_cur; -PLS-00103: encountered the symbol "up_loc_cur" when expects it one of the following values: =. (@ %; not null default range character)

    loop

    extract the up_loc_cur in cur_rec;

    When the output up_loc_cur % notfound;

    end loop;

    close up_loc_cur;

    end;

    Kind regards

  • Run the script in a loop inside sqlplus

    Hi all

    Is it possible to run a script that we can run windows inside sqlplus command prompt to run in a loop?

    for example, in unix I can do something like

    I'm in 1.10
    do
    LS - ltr
    ps - ef | grep pmon
    sleep 5
    fact

    so can I do something similar inside sqlplus?

    lets say have a script called @active_session

    and now I'm inside sqlplus, but can't, that I run in a loop? as sleep 5 sec and run @active_session and then sleep 5 sec and run @active_session?

    I hope that I asked the question clearly...

    Hello

    user8363520 wrote:
    Hi all

    Is it possible to run a script that we can run windows inside sqlplus command prompt to run in a loop?

    for example, in unix I can do something like

    I'm in 1.10
    do
    LS - ltr
    ps - ef | grep pmon
    sleep 5
    fact

    so can I do something similar inside sqlplus?

    Your best bet would be to do at the level of the BONE, in the way you know.
    For example:

    for i in 1..10
    do
    sqlplus  username/password@database @active_session
    sleep 5
    done
    

    I'm not sure of the unix syntax.
    Make sure that active_session.sql ends with a QUIT or EXIT statement.

    lets say have a script called @active_session

    and now I'm inside sqlplus, but can't, that I run in a loop? as sleep 5 sec and run @active_session and then sleep 5 sec and run @active_session?

    SQL * wan't more designed for this sort of thing. In particular, there is no reall loop mechanism built into SQL * more. You can make loops in SQL * Plus, but it's not enough. See {message identifier: = 4367027}

    According to what is in your script, you can do all the work in PL/SQL, which has loops.

  • bulk collect into with limit

    Hi all
    I was reading [http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:5918938803188] of Tom Kyte site on bulk collect within limits. The code uses the % notfound cursor to exit the recovery loop. What I do in this situation is using exists, method of table rather than cursor attribute.
    create or replace procedure p1 is
    type num_list_type is table of number index by pls_integer;
    num_list num_list_type;
    
    cursor c1 is select temp from test;
    
    begin
    open c1;
    loop
      fetch c1 bulk collect into num_list limit 2;
      if num_list.exists(1)=false then
        exit;
      end if;
      for i in num_list.first..num_list.last 
      loop
        dbms_output.put_line(num_list(i));
      END LOOP;
    end loop;
    
    end;
    Since when I do this:
    exit wen c1%notfound  
    It will close when the cursor retrieves only less than the limit, leaving a few rows. If the code works properly.
    Question:
    1. is the Exit statement properly, is there another way (I'm a little skeptical because I'm not using the cursor)?
    2 How to decide on the size limit based on what we have in the hardware settings and oracle? All of the guidelines?
    3 - is the best practice when it comes with the cursor and several lines that still use bulk collect into?

    Best regards
    Val

    Valerie Debonair wrote:
    Hi all
    I was reading [http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:5918938803188] of Tom Kyte site on bulk collect within limits. The code uses the % notfound cursor to exit the recovery loop. What I do in this situation is using exists, method of table rather than cursor attribute.

    create or replace procedure p1 is
    type num_list_type is table of number index by pls_integer;
    num_list num_list_type;
    
    cursor c1 is select temp from test;
    
    begin
    open c1;
    loop
    fetch c1 bulk collect into num_list limit 2;
    if num_list.exists(1)=false then
    exit;
    end if;
    for i in num_list.first..num_list.last
    loop
    dbms_output.put_line(num_list(i));
    END LOOP;
    end loop;
    
    end;
    

    Since when I do this:

    exit wen c1%notfound  
    

    It will close when the cursor retrieves only less than the limit, leaving a few rows. If the code works properly.
    Question:
    1. is the Exit statement properly, is there another way (I'm a little skeptical because I'm not using the cursor)?
    2 How to decide on the size limit based on what we have in the hardware settings and oracle? All of the guidelines?
    3 - is the best practice when it comes with the cursor and several lines that still use bulk collect into?

    Best regards
    Val

    Hello

    1. Yes, in above code statement EXIT will work correctly. The other way is % NOTFOUND CURSOR attribute usage.
    2. There is no precise way to decide the size limit.
    3 depends on number of records. If you have a lot of records always use LIMIT that improves performance.

    After reading the link that was posted by Blu, I am to edit this post.

    1. do not use CURSOR attribute when you use collections within a cursor. Use methods of collection such as COUNT or EXIST etc.

    @Blu,

    Thanks much for the link.

    Thank you
    Suri

    Published by: Suri on January 26, 2012 20:38

  • PL/SQL execution error Question

    Hi Experts,
    It's the SQL procedure I remove a set number of order that are closed

    CREATE OR REPLACE PROCEDURE closed_test1 (varchar tabname, v_rowcount_int certain NUMBER)
    is
    v_sql varchar2 (4000);
    Start
    v_sql: =' delete ' | tabname |' College where exists (select order_nbr from the cl closed_order where fac.internal_order_id = cl.order_nbr)';
    immediately run v_sql;
    v_rowcount_int: = number of lines sql %;
    dbms_output.put_line (v_rowcount_int |) ("' deleted rows");
    commit;
    end;
    /

    I use an ETL tool to display the number of deleted rows, so I had to create an output parameter and awarded for the number of rows sql %

    When I run

    Declare
    number of v_rowndel;
    exec closed_test1 ('COST_TRANS_TABLE', v_rowndel);

    I get this error message
    ERROR at line 3:
    ORA-06550: line 3, column 57:
    PLS-00103: encountered the symbol "end-of-file" when awaits an of the
    Next:
    := ; not null default characters

    I don't understand what the problem is! Is it because I don't have an exit statement, but the sql statement is interlooped

    Any help is apprct in advance

    Thank you
    AJ

    It's the way you need to call the procedure.

    DECLARE
      v_rowndel   NUMBER;
    BEGIN
      closed_test1 ( 'COST_TRANS_TABLE', v_rowndel);
      DBMS_OUTPUT.PUT_LINE ('v_rowndel = ' || v_rowndel);
    END;
    

    If you use a tool, then turn on dbms_output.
    If execution of sqlplus and then SET SERVEROUPUT on.

    G.

  • How to CONTINUE works in 11g?

    I ran after the simple code on the Oracle 11.1.0.7 database.
    SQL> l
      1  BEGIN
      2    FOR x IN (    SELECT ROWNUM r
      3                    FROM DUAL
      4              CONNECT BY LEVEL < 6)
      5    LOOP
      6      IF (x.r = 3)
      7      THEN
      8        CONTINUE;
      9      END IF;
     10
     11      DBMS_OUTPUT.put_line (x.r);
     12    END LOOP;
     13* END;
    SQL> /
    1
    2
    
    PL/SQL procedure successfully completed.
    I expected to see something like this where to CONTINUE would jump 3 and it appear as follows:
    1
    2
    4
    5
    But as soon as x.r becomes 3, control leaves the loop.

    I used CONTINUED in several other languages. But I am very surprised how it works in Oracle 11 g. I expected to ignore the iteration when x.r becomes 3 and continue with the next iteration of the loop.

    Please can someone explain why it does this? This is the expected behavior? If so, then what happens if you replace CONTINUE by the EXIT statement?

    Thank you.

    Bug 7306422 are looking for for workaround.

    SY.

  • How to merge two date ranges

    Hello
    I have the rest of the table. I want to merge the date ranges if dates are continuous and the value is the same. I use Oracle 10 g. Help, please.

    START_DATE END_DATE VALUE
    ----------------------------------------------------------------

    1/1/2008 12/31/2008 1234
    1/1/2009 12/31/2009 1234


    Exit statement SQL must be as follows:


    START_DATE END_DATE VALUE
    ----------------------------------------------------------------

    1/1/2008 12/31/2009 1234



    Thanks in advance.

    Published by: user3898545 on January 27, 2010 19:44

    Hello

    user3898545 wrote:
    Hello
    Dates will not overlap but sometimes start_date can be equal to end_date in a row.

    Sorry, I'm not sure of that figure.
    If the query I posted is not giving correct results, post some samples (CREATE TABLE and INSERT statements are best, but a clause WITH as Tubby displayed is correct) and the correct results, you need these data.

    Please suggest if something needs to be done through pl/sql performance is also the key.

    I don't see how the PL/SQL will help in this problem.

    When two lines need to be combined, the end_date ranked sooner than always exactly 24 hours before the start_date on the line later?
    If so:

    WITH     got_grp         AS
    (
         SELECT     data.*
         ,     end_date - SUM (end_date + 1 - start_date) OVER ( PARTITION BY  val
                                                                     ORDER BY       start_date
                                                ) AS grp
         FROM     data
    )
    SELECT       MIN (start_date)     AS start_date
    ,       MAX (end_date)     AS end_date
    ,       val
    FROM       got_grp
    GROUP BY  val
    ,            grp
    ORDER BY  val
    ,            start_date
    ;
    

    Published by: Frank Kulash, 28 January 2010 14:03
    For example, a subquery added.

Maybe you are looking for