If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > If statements in PLSQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-15-03, 06:07
burningmoney burningmoney is offline
Registered User
 
Join Date: Sep 2003
Posts: 12
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
Reply With Quote
  #2 (permalink)  
Old 12-15-03, 06:54
r123456 r123456 is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 12-15-03, 08:02
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
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;
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #4 (permalink)  
Old 12-15-03, 14:18
burningmoney burningmoney is offline
Registered User
 
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....
Reply With Quote
  #5 (permalink)  
Old 12-15-03, 15:19
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally posted by burningmoney
andrewst quick question is the syntax 'elseif' or 'elsif'.
It is ELSIF
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #6 (permalink)  
Old 12-15-03, 16:00
robertolaforgia robertolaforgia is offline
Registered User
 
Join Date: Dec 2003
Location: italy
Posts: 4
Re: If statements in PLSQL

Quote:
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?
Reply With Quote
  #7 (permalink)  
Old 12-15-03, 21:18
r123456 r123456 is offline
Registered User
 
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.
Reply With Quote
  #8 (permalink)  
Old 12-15-03, 21:50
sundialsvcs sundialsvcs is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On