I want to ad column by using subquery.
Insert into Table_name
values (1, 'a', 'b', sysdate, sysdate + 120, 'c',
(Select number from other_table where column_name = 'x'), 2);
Error:
ORA-01427: single-row subquery returns more than one row.
How can I solve it?
I think you want to use an INSERT INTO ... SELECT
here. Note that generally you should always specify the target columns.
INSERT INTO Table_name (c1, c2, c3, c4, c5, c6, c7, c8)
SELECT 1, 'a', 'b', sysdate, sysdate + 120, 'c', number, 2
FROM other_table
WHERE column_name = 'x';
you need to force a single row
note the extra "ROWNUM" below
something like:
Insert into Table_name values(1,'a','b',sysdate,sysdate + 120,'c',(Select number from other_table where column_name = 'x' and ROWNUM = 1),2);
see: https://blogs.oracle.com/connect/post/on-rownum-and-limiting-results
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.