INSERT INTO with subquery select from same table = ORA-00947 not enough values [message #43067] |
Fri, 06 June 2003 06:11  |
Ed Randall
Messages: 3 Registered: June 2003
|
Junior Member |
|
|
Using 9i I am trying to copy a set of rows from a table whilst making minor alterations as follows:
INSERT INTO SEC_USERFUNCTION (USER_ID, FUNCTION_ID)
VALUES ((SELECT 3 AS USER_ID, FUNCTION_ID from SEC_USERFUNCTION where USER_ID=2));
The table has only 2 columns USER_ID and FUNCTION_ID, both NUMBER; Running the subquery on its own returns 2 columns, yet when I try to do the insert I get ORA-00947 not enough values, please help! Why is this?
Thanks
Ed
|
|
|
Re: INSERT INTO with subquery select from same table = ORA-00947 not enough values [message #43068 is a reply to message #43067] |
Fri, 06 June 2003 06:36   |
Martin Chadderton
Messages: 35 Registered: May 2003
|
Member |
|
|
It's simply because you have a select in the values clause. Oracle interprets/expects a select like this to return a single value. I suspect what you need is to lose the VALUES clause, i.e.
SQL> CREATE TABLE t ( a VARCHAR2(10), b VARCHAR2(10) );
Table created.
SQL> INSERT INTO t
2 VALUES
3 (
4 ( SELECT 'x', 'y' FROM dual )
5 );
INSERT INTO t
*
ERROR at line 1:
ORA-00947: not enough values
SQL> INSERT INTO t
2 SELECT 'x', 'y' FROM dual;
1 row created.
Regards
|
|
|
|
|
|
|