|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Conditionals in SELECT statement
Can you put conditionals in a SELECT statement?
I'm trying to do: Code:
select ( IF (version_eol IS NOT NULL) THEN value='not null!' ELSE value='null!' END IF ) as value FROM my.table; But I get an error on it: Code:
IF (version_eol IS NOT NULL) THEN value='null!'
*
ERROR at line 3:
ORA-00907: missing right parenthesis
I'm new to PL/SQL. Any ideas? Last edited by StevenC : November 23rd, 2004 at 02:18 PM. |
|
#2
|
|||
|
|||
|
SELECT decode(version_eol, null, 'null', 'not null')
as value FROM my.table; |
|
#3
|
||||
|
||||
|
I probably shouldn't have used that example as I did.
I can't use decode, as version_eol is a date type. I need to check if SYSDATE is greater than version_eol (checking on if something has expired). From what I understand of decode, it can't handle comparisons like that. |
|
#4
|
|||
|
|||
|
This method is a little sneaky:
Code:
select decode(sign(version_eol-sysdate),-1,'less than sysdate',0,'equal to sysdate','greater than sysdate') from ?? |
|
#5
|
|||
|
|||
|
Is there some reason you cannot do this:
Code:
select fld1,fld2 from table where eol_version< sysdate; /* or */ delete from table where eol_version< sysdate; |
|
#6
|
||||
|
||||
|
Thanks hedge, that seems to be just want I wanted.
Jim: I can't use that select because I need to return a value based on each condition, hence the need for conditionals. I don't want to return only some rows. Also, why would I delete data from my table just to get to a few rows? That's not smart. Last edited by StevenC : November 24th, 2004 at 08:30 AM. |
|
#7
|
|||
|
|||
|
You would not delete. I was just using the where clause as an example.
I know that you do what you want in SQL without that much of a problem with pretty standard SQL. If you were to explain the data model, we coudl give you a good answer. |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Conditionals in SELECT statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|