Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2003
    Posts
    12

    Unanswered: If statements in PLSQL

    Quick Question? Is it possible to have more than one if statement in a PLSQL procedure or trigger. I have tried but have been unsucsesful thus far.

    So basically what I want to achive is.

    Select name into ename from table where varaible= something;

    If name= this then

    If name= that then

    and so on.....


    Thanks for any help provided

  2. #2
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    The syntax is the same as VB,

    If (condition) Then
    End If
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: If statements in PLSQL

    Do you mean like this? :-

    IF name = 'this' THEN
    ...
    ELSIF name = 'that' THEN
    ...
    ELSIF name = 'other' THEN
    ...
    ELSE
    ...
    END IF;

  4. #4
    Join Date
    Sep 2003
    Posts
    12

    Talking

    Ah I see now same as VB....
    I was just continually putting in if statement followed by another if statement (not an elseif)

    andrewst quick question is the syntax 'elseif' or 'elsif'.

    Thanks for your help guys....

  5. #5
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Originally posted by burningmoney
    andrewst quick question is the syntax 'elseif' or 'elsif'.
    It is ELSIF

  6. #6
    Join Date
    Dec 2003
    Location
    italy
    Posts
    4

    Re: If statements in PLSQL

    Originally posted by burningmoney
    Quick Question? Is it possible to have more than one if statement in a PLSQL procedure or trigger. I have tried but have been unsucsesful thus far.

    So basically what I want to achive is.

    Select name into ename from table where varaible= something;

    If name= this then

    If name= that then

    and so on.....


    Thanks for any help provided
    ===============================
    Have you considered to use the CASE statement?

  7. #7
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    You can have consecutive If Statements without Elsif, If your conditions are independent of each other.

    If (condition) Then
    ..
    End If;
    If (condition) Then
    ..
    End If;
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  8. #8
    Join Date
    Oct 2003
    Posts
    706

    Smile

    Also, don't worry too much about "efficiency." Some people will ponder for hours whether the computer will execute CASE vs. IFs "faster" in this situation or that one.

    Don't worry about that. Worry instead about clarity. Soon enough someone will be looking at that code again, to debug it or to extend it in some way. Write for that person. Also be conscious about how easy your code will be to maintain. Those are the considerations that really matter... For instance, CASE might be much more tolerant of a typo, vs. a misplaced part of a nested IF...
    ChimneySweep(R): fast, automatic
    table repair at a click of the
    mouse! http://www.sundialservices.com

Posting Permissions

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