Home » SQL & PL/SQL » SQL & PL/SQL » Insert into a table
Insert into a table [message #201339] Fri, 03 November 2006 10:29 Go to next message
yerics
Messages: 89
Registered: August 2006
Member
Within a stored procedure, If I want to insert data into a 2 column table. The data to the 1st column will the value passed to the procedure and data to the 2nd column would be a query from a different table. Is this syntax OK?

For eg.
function foo( accept_value in VARCHAR2)
..
begin
..

insert into test_table (name, address) values
(accept_value, (select address from table y where name=accept_value));

end;
Re: Insert into a table [message #201344 is a reply to message #201339] Fri, 03 November 2006 11:13 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
Well, what happens when you try it?
Re: Insert into a table [message #201345 is a reply to message #201339] Fri, 03 November 2006 11:13 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Yes, that will work. You can also use the standard insert into/select from syntax (which I would recommend):

insert into test_table (name, address)
  select name, address
    from other_table
   where name = accept_value;
Re: Insert into a table [message #201346 is a reply to message #201344] Fri, 03 November 2006 11:16 Go to previous message
yerics
Messages: 89
Registered: August 2006
Member
It works, but I wanted to know whether there is a better way to code it.

Regards,
Previous Topic: Help required in DYNAMIC SQL coding (Merged)
Next Topic: Retrieving java permissions
Goto Forum:
  


Current Time: Fri Dec 02 12:02:03 CST 2016

Total time taken to generate the page: 0.11681 seconds