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 > Storing function value in variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-24-03, 09:27
hey_david hey_david is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Storing function value in variable

I want to use the value of a complex function several times within a query. I had thought I could do something like:

SELECT (...complex function...) as x,
log(x) as log_x
FROM somewhere
WHERE x > 3
AND x <= 10
OR ....(more uses of x)

But this doesn't work.

What do you suggest?

Thanks in advance!
-David
Reply With Quote
  #2 (permalink)  
Old 10-24-03, 10:16
dbmadcap dbmadcap is offline
Registered User
 
Join Date: May 2003
Posts: 87
You can use the function in the from clause to return the value and access it in the query multiple times.

SELECT x, log(x) as log_x
FROM somewhere, (select f_cmplx as x from dual) b
WHERE x > 3
AND x <= 10
OR ....(more uses of x)
/
Reply With Quote
  #3 (permalink)  
Old 10-24-03, 15:15
hey_david hey_david is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
That worked! Thanks!
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