| |
Welcome to the dBforums forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact support.
If you prefer not to see double-underlined words and corresponding ads, place your cursor here for ContentLink opt out.
|
 |

06-03-03, 11: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, 12:06
|
|
Moderator.
|
|
Join Date: Sep 2002
Location: UK
Posts: 4,874
|
|
|
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, 12: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, 12: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, 12: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
|
|
|
|
|