Re: trouble with insert

From: <sheldonlg>
Date: Sun, 13 Jul 2008 09:43:20 -0400
Message-ID: <at-dnRopd9gUm-fVnZ2dnUVZ_rfinZ2d@giganews.com>


Maxim Demenko wrote:
> sheldonlg schrieb:

>> This should be so simple, yet it is not working.  I am trying to do an 
>> insert into a table where the values inserted are gathered from a 
>> select from another table.  This form works:
>>
>> insert into table2 (select fld1, fld2, fld3 from table1 where blah)
>>
>> However, I do not want to be dependent upon the order of the fields in 
>> table2 so, I tried this:
>>
>> insert into table2 (fld1, fld2, fld3) values(
>>   select fld1, fld2, fld3 from table1 where blah)
>> )
>>
>> This gave me a not enough values error coming from the first set of 
>> parentheses.  I don't understand that error.  It should not care how 
>> many fields are inserted, so long as the two sets match.  Also, in 
>> this case, all the fields of table2 are named.

>
> Just remove surrounding values() clause from your select.
> The syntax for insert ... select is documented here:
> http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#i2111652
>
> http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#i2145081
>
> (Inserting values with a subquery example)
>
> Best regards
>
> Maxim

Thanks. I figured it out before reading your reply, but thanks for the help. Received on Sun Jul 13 2008 - 08:43:20 CDT

Original text of this message