Solved

Can I create a variable from a resultset?

Posted on 2011-09-16
9
379 Views
Last Modified: 2012-05-12
I would like to use a variable to hold the resultset of query lets just say the sysdate for the moment and then spool it off with my the reult from my other query.

Is this possible?

NG,
set feedback off
set verify off
set head off
set echo off
set linesize 30
set pages 0

Declare Vsysdate
Vsysdate = select sysdate into Vsysdate from dual;

spool W:\scripts\Wk1.csv

Prompt Vsysdate

SELECT * from table 1;

spool off
quit

Open in new window

0
Comment
Question by:nike_golf
  • 6
  • 3
9 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 36548677
declare is PL/SQL.  Not sqlplus.

Try this:

col sysdate new_value Vsysdate

select sysdate from dual;
prompt &Vsysdate
0
 
LVL 13

Author Comment

by:nike_golf
ID: 36548799
hmmm...

Where does the SELECT statement set the sysdate to the variable Vsysdate?

0
 
LVL 13

Author Comment

by:nike_golf
ID: 36548862
Well I tried the following without success..

col Vsysdate new_value Vsysdate
select sysdate Vsysdate from dual;

spool W:\scripts\Wk1.csv

Prompt Wkly2011
Prompt Vsysdate
Prompt 37

'------------------------------------- Results -------------------------------

wkly2011
Vsysdate
37
0
 
LVL 13

Author Comment

by:nike_golf
ID: 36549520
I ended up having to use a bind variable and was able to get it to work.

Thanks,
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 13

Author Comment

by:nike_golf
ID: 36549920
I've requested that this question be closed as follows:

Accepted answer: 0 points for nike_golf's comment http:/Q_27311816.html#36549520

for the following reason:

Self answered
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36549921
Just because you chose a different approach does not mean what I posted does not work.  I have to object.

>>Where does the SELECT statement set the sysdate to the variable Vsysdate?

in the NEW_VALUE of the column command.

>>Prompt Vsysdate

Look at what I posted.

It should be: Prompt &Vsysdate

Did you run what I posted to see it work?
0
 
LVL 13

Author Comment

by:nike_golf
ID: 36550096
No offense intended.

I revisited your solution and it does work...

I will make the change and award the points.

NG,
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36550301
I apologize if you thought I was offended.  Intent is so hard to 'type'.

I was just trying to point out the solution was what you asked.

Glad it worked for you.
0
 
LVL 13

Author Comment

by:nike_golf
ID: 36551926
No problem.

I now have 2 solutions... ;-)

NG,
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now