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 > store a query from a select statement into a variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-03, 10:33
let99 let99 is offline
Registered User
 
Join Date: Jun 2003
Posts: 5
store a query from a select statement into a variable

hi all

PROCEDURES:

i want to store a select statement into a variable which i want to call later.. how can this be done ???


Varoable1 = select email from person where ....;

insert into movie (email, imdbnr, moviename, duration, genre)
values (Variable1, nimdbnr, nmoviename, nduration, ngenre);

this doesnt work ... anyone has an idea ???

thx
Reply With Quote
  #2 (permalink)  
Old 06-03-03, 11:06
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: store a query from a select statement into a variable

Quote:
Originally posted by let99
hi all

PROCEDURES:

i want to store a select statement into a variable which i want to call later.. how can this be done ???


Varoable1 = select email from person where ....;

insert into movie (email, imdbnr, moviename, duration, genre)
values (Variable1, nimdbnr, nmoviename, nduration, ngenre);

this doesnt work ... anyone has an idea ???

thx
What DBMS? If it was Oracle the answer would be:

DECLARE
v_email person.email%TYPE;
BEGIN
select email INTO v_email FROM person where ...;
...
insert into movie (email, imdbnr, moviename, duration, genre)
values (v_email, nimdbnr, nmoviename, nduration, ngenre);
END;

Mind you, what are nimdbnr etc.? They look like variables too!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 06-03-03, 11:13
dbmadcap dbmadcap is offline
Registered User
 
Join Date: May 2003
Posts: 87
Re: store a query from a select statement into a variable

declare
lvar1 varchar2(50);
begin
select email into lvar1 from person where <condition>;
insert into movie (email, imdbnr, moviename, duration, genre)
values (lvar1, nimdbnr, nmoviename, nduration, ngenre);
end;
/

Do not forget to handle exceptions like no_data_found or too_many_rows.

Quote:
Originally posted by let99
hi all

PROCEDURES:

i want to store a select statement into a variable which i want to call later.. how can this be done ???


Varoable1 = select email from person where ....;

insert into movie (email, imdbnr, moviename, duration, genre)
values (Variable1, nimdbnr, nmoviename, nduration, ngenre);

this doesnt work ... anyone has an idea ???

thx
Reply With Quote
  #4 (permalink)  
Old 06-03-03, 11:50
let99 let99 is offline
Registered User
 
Join Date: Jun 2003
Posts: 5
thank you thank you !!
it was like this:

PROCEDURE add (attr1, attr2, .....);
v_email person.email%TYPE;
BEGIN
select person.email INTO v_email from person,member ....
insert into movie (email, imdbnr, moviename, duration, genre)
values (v_email, nimdbnr, nmoviename, nduration, ngenre);

P.S. it was oracle & plsql
Reply With Quote
  #5 (permalink)  
Old 06-03-03, 11:53
dbmadcap dbmadcap is offline
Registered User
 
Join Date: May 2003
Posts: 87
Again, do not forget to handle the exception just in case your select statement fails i.e. returns no rows or more than 1 row.


Quote:
Originally posted by let99
thank you thank you !!
it was like this:

PROCEDURE add (attr1, attr2, .....);
v_email person.email%TYPE;
BEGIN
select person.email INTO v_email from person,member ....
insert into movie (email, imdbnr, moviename, duration, genre)
values (v_email, nimdbnr, nmoviename, nduration, ngenre);

P.S. it was oracle & plsql
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