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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help me somebody, what is th

Status
Not open for further replies.

Iby

Programmer
Jul 17, 2002
18
0
0
IT
Please help me somebody, what is the syntactic the "if" statement but I wouldn't like to use decode instead the "if" clause.

Thank you!
 
If you don't want to use decode, you can put your query in pl/sql, and use if/then/else there.

If it's the syntax you're after, it's:

If condition - (compulsory)
Then Action - (compulsory)
Else Action - (optional)

I would argue that decode would be more sensible than putting sql in pl/sql if the query is quite straightforward.

decode(if,then,...,else)

Naith
 
The syntax of if statement is
if(condition) then
else
end if;

(or)

if(condition) then
elsif (condition)
else
end if;

Hope this is what u r looking for.
 
what i forgot?

SELECT * FROM OMS_POHEADM
WHERE To_Date(DATE_ENTERED,'dd/MM/yy') =
if (To_Date('01/05/02', 'dd/MM/yy') = To_date('01/01/70','dd/MM/yy')) then
To_Date('01/05/02', 'dd/MM/yy')
elsif (To_Date('01/05/03', 'dd/MM/yy') = To_date('01/01/70','dd/MM/yy'))
To_Date('01/05/03', 'dd/MM/yy')
else To_date(sysdate,'dd/MM/yy')-30
end if

Because I always get "Missing right parenthesis" error msg.
 
And do you have suggest about it?
 
As Bimalaggarwal said, you can't use if/then/else in sql. Use decode.

But having said that, why are you checking against this condition?

if (To_Date('01/05/02', 'dd/MM/yy') = To_date('01/01/70','dd/MM/yy') ...

That criteria is never going to be satisfied, because you're pitching two completely different hardcoded dates against each other, and checking if they're ever going to be the same date - which of course, they never will be.

What are you trying to do, exactly?

Naith
 
try with case in the query

(CASE WHEN STATUS = '1' THEN '1'
WHEN STATUS = '2' THEN '2'
WHEN STATUS = '3' THEN '3'
WHEN STATUS = '4' THEN '4'
ELSE '1' END)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top