dbTalk Databases Forums  

trouble with insert

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss trouble with insert in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sheldonlg
 
Posts: n/a

Default trouble with insert - 07-13-2008 , 08:17 AM






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.

Reply With Quote
  #2  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:28 AM






sheldonlg schrieb:
Quote:
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/B...4.htm#i2111652
http://download.oracle.com/docs/cd/B...4.htm#i2145081
(Inserting values with a subquery example)

Best regards

Maxim


Reply With Quote
  #3  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:28 AM



sheldonlg schrieb:
Quote:
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/B...4.htm#i2111652
http://download.oracle.com/docs/cd/B...4.htm#i2145081
(Inserting values with a subquery example)

Best regards

Maxim


Reply With Quote
  #4  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:28 AM



sheldonlg schrieb:
Quote:
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/B...4.htm#i2111652
http://download.oracle.com/docs/cd/B...4.htm#i2145081
(Inserting values with a subquery example)

Best regards

Maxim


Reply With Quote
  #5  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:28 AM



sheldonlg schrieb:
Quote:
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/B...4.htm#i2111652
http://download.oracle.com/docs/cd/B...4.htm#i2145081
(Inserting values with a subquery example)

Best regards

Maxim


Reply With Quote
  #6  
Old   
sheldonlg
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:31 AM



sheldonlg wrote:
Quote:
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.
After posting this, I think I understand the error message. The select
is retrieving multiple rows. It might be that it thinks that only
enough values are going to be supplied and so not enough fields are
being specified. If this is the case, then how do accomplish putting in
N rows of data obtained from the select where each row has values for
each of the named fields?


Reply With Quote
  #7  
Old   
sheldonlg
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:31 AM



sheldonlg wrote:
Quote:
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.
After posting this, I think I understand the error message. The select
is retrieving multiple rows. It might be that it thinks that only
enough values are going to be supplied and so not enough fields are
being specified. If this is the case, then how do accomplish putting in
N rows of data obtained from the select where each row has values for
each of the named fields?


Reply With Quote
  #8  
Old   
sheldonlg
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:31 AM



sheldonlg wrote:
Quote:
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.
After posting this, I think I understand the error message. The select
is retrieving multiple rows. It might be that it thinks that only
enough values are going to be supplied and so not enough fields are
being specified. If this is the case, then how do accomplish putting in
N rows of data obtained from the select where each row has values for
each of the named fields?


Reply With Quote
  #9  
Old   
sheldonlg
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:31 AM



sheldonlg wrote:
Quote:
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.
After posting this, I think I understand the error message. The select
is retrieving multiple rows. It might be that it thinks that only
enough values are going to be supplied and so not enough fields are
being specified. If this is the case, then how do accomplish putting in
N rows of data obtained from the select where each row has values for
each of the named fields?


Reply With Quote
  #10  
Old   
sheldonlg
 
Posts: n/a

Default Re: trouble with insert - 07-13-2008 , 08:36 AM



sheldonlg wrote:
Quote:
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.
Duh! I found the answer. I cannot specify "VALUES". I should have
written:

insert into table2 (fld1, fld2, fld3)
(select fld1, fld2, fld3 from table1 where blah)

Sorry to bother everyone.


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.