| |
|
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.
|
 |

06-03-03, 10:33
|
|
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
|
|

06-03-03, 11:06
|
|
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!
|
|

06-03-03, 11:13
|
|
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
|
|
|

06-03-03, 11:50
|
|
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
|
|

06-03-03, 11:53
|
|
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
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|