Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 23rd, 2004, 02:08 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 32 m 40 sec
Reputation Power: 15
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?
__________________


Webinfractions.com
Think I'm wrong? You're probably right!

Last edited by StevenC : November 23rd, 2004 at 02:18 PM.

Reply With Quote
  #2  
Old November 23rd, 2004, 02:21 PM
shammat shammat is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 989 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 2 h 3 m 55 sec
Reputation Power: 57
SELECT decode(version_eol, null, 'null', 'not null')
as value
FROM my.table;

Reply With Quote
  #3  
Old November 23rd, 2004, 02:25 PM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 32 m 40 sec
Reputation Power: 15
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.

Reply With Quote
  #4  
Old November 23rd, 2004, 03:16 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 22 h 25 m 53 sec
Reputation Power: 19
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 ??

Reply With Quote
  #5  
Old November 23rd, 2004, 04:31 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 21 sec
Reputation Power: 48
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;

Reply With Quote
  #6  
Old November 24th, 2004, 08:26 AM
StevenC's Avatar
StevenC StevenC is offline
PHP & Java Error Master
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: My Computer
Posts: 1,218 StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level)StevenC User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 1 h 32 m 40 sec
Reputation Power: 15
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.

Reply With Quote
  #7  
Old November 24th, 2004, 09:35 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 21 sec
Reputation Power: 48
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Conditionals in SELECT statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway