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 > how to put the result of a query into a variable??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-11-02, 17:58
lnong lnong is offline
Registered User
 
Join Date: Jun 2002
Posts: 13
how to put the result of a query into a variable??

DEFINE invoice_count = SELECT COUNT(Invoice#) from INVOICE NUMBER;

This doesnt work. What's the correct syntax or method for doing this in SQL*Plus?
Reply With Quote
  #2 (permalink)  
Old 01-21-03, 10:03
jf_dba jf_dba is offline
Registered User
 
Join Date: Jan 2003
Posts: 10
Hi,

you have to use a sql*plus variable.

Example:
<SQL>
-- Declare the variable INVOICE_COUNT as number
variable invoice_count number

-- fill the variable in a anonym-plsql-block
begin
SELECT COUNT(Invoice#)
into :invoice_count
from INVOICE NUMBER;
end;
/

-- now you can output the Value
print invoice_count

-- or us it in a subsequence select
select * from test_table where column1=:invoice_count;

</SQL>
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