Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQl Question

Status
Not open for further replies.

ADB1

Programmer
Aug 24, 2001
235
GB
Could somebody please tell me the syntax/format for using an IF THEN ELSE statement in Oracle?

Thanks,

Adam.
 
[tt]
if VAR1 = VAR2 then
null; -- processing
elsif VAR3 = VAR4 then
null; -- processing
else null; -- processing
end if;
[/tt]


(select * from life where brain is not null)
Consultant/Custom Forms & PL/SQL - Oracle 8.1.7 - Windows 2000
 
Thanks for the information.

I was trying to enter the following sql, and i keep getting the error 'Missing Right Parenthesis'
---------------------------------------------
SELECT
IF (ZEUS.SPEC_ORD.SPEC_ORD_STAT = 'EEA' )
THEN (ZEUS.SPEC_ORD.SPEC_ORD_STAT_CRBD - ZEUS.SPEC_ORD_STAT_HIST.STAT_CHANG_DATE)
ELSE NULL END

FROM
ZEUS.SPEC_ORD,
ZEUS.SPEC_ORD_STAT_HIST
WHERE
( ZEUS.SPEC_ORD.SPEC_ORD_NUMB = ZEUS.SPEC_ORD_STAT_HIST.SPEC_ORD_NUMB )
-----------------------------------------------

Thanks,

Adam.
 
In pure SQL you need a decode:

SELECT
Decode(ZEUS.SPEC_ORD.SPEC_ORD_STAT,
'EEA',ZEUS.SPEC_ORD.SPEC_ORD_STAT_CRBD - ZEUS.SPEC_ORD_STAT_HIST.STAT_CHANG_DATE,
NULL)
FROM
ZEUS.SPEC_ORD,
ZEUS.SPEC_ORD_STAT_HIST
WHERE
( ZEUS.SPEC_ORD.SPEC_ORD_NUMB = ZEUS.SPEC_ORD_STAT_HIST.SPEC_ORD_NUMB )
 
You may use CASE statement. The syntax is:

CASE
WHEN <condition1> THEN <result1>
WHEN <condition2> THEN <result2>
...
ELSE <resultN>
END

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top