简体   繁体   中英

Oracle update table value returned 'single-row sub-query returned more than one row '

I wanna add a column named 'Bonus_AMT' on table 'Employee'. Here's the clause I wrote. enter image description here I ran the above clause, but it didn't work. It returns that 'single-row' sub-query return more than one row. How could I solve that?

You need to join table in update clause with table in select clause used in SET. Here is the example.

update employees e1 set bonus = (select salary*commission_pct from employees e2 where e1.employee_id = e2.employee_id);

You need to make sure that both versions of tables are joined on primary key.

Your select query clause used in set is returning multiple row for the applied date range. So you need to change that select clause so that at a time it will single record and update the same record using joins.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM