DBAsupport.com Forums - Powered by vBulletin
Results 1 to 10 of 11

Thread: exists

Threaded View

  1. #7
    Join Date
    Dec 2002
    Location
    Bangalore ( India )
    Posts
    2,434
    Originally posted by DaPi
    Hi slimdave, I think I'd spend half a minute each time I saw that wondering what on earth it does! . . . and how do you deal with the ELSE ?
    Else can be delt...but offcourse its not a good idea...

    Code:
    TEST:ABHAY> select * from TEST_EXISTS order by 1,2;
    
                      ID NAME
    -------------------- --------------------
                       1 Abhay
                       1 Bhat
                       1 Raghu
                       2 Prasad
                       2 Vimal
    
    TEST:ABHAY> Begin
      2  For X in ( Select 1 from TEST_EXISTS where ID=1 ) Loop
      3  DBMS_OUTPUT.PUT_LINE('1');
      4  End Loop;
      5  For X in ( Select 2 from TEST_EXISTS where ID not in (1) ) Loop
      6  DBMS_OUTPUT.PUT_LINE('2');
      7  End Loop;
      8  End;
      9  /
    1
    1
    1
    2
    2
    
    PL/SQL procedure successfully completed.
    
    TEST:ABHAY>
    Slimdave code can be formulated something like this

    Code:
    Begin
    ....
    
    -- If Success Part of Your logic
    
       For X In (
                 Select
                    1
                 From
                    my_table
                 Where
                    my_field='my_value'
                )
       Loop
          ...
       End Loop;
    
    -- Else part of your logic.
    
       For X In (
                 Select
                    1
                 From
                    my_table
                 Where
                    my_field NOT IN ('my_value')
                )
       Loop
          ...
       End Loop;
    
    End;
    /

    Abhay.
    Last edited by abhaysk; 06-28-2003 at 02:45 AM.
    funky...

    "I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."

    "Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width