Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
sql developer中的更新表错误_Sql_Oracle11g - Fatal编程技术网

sql developer中的更新表错误

sql developer中的更新表错误,sql,oracle11g,Sql,Oracle11g,尝试运行以下脚本时,出现错误: update my_employees_above_avg set (employee_id, first_name, last_name, salary) = (select employee_id, first_name, last_name, (salary + 100) NewSalary from my_employees_above_avg where last_name like '%b%'); 出现以下错误: 从命令中的第40行开始出错: upd

尝试运行以下脚本时,出现错误:

update my_employees_above_avg set (employee_id, first_name, last_name, salary) =
(select employee_id, first_name, last_name, (salary + 100) NewSalary
from my_employees_above_avg
where last_name like '%b%');
出现以下错误:

从命令中的第40行开始出错:

update my_employees_above_avg set (employee_id, first_name, last_name, salary) =
(select employee_id, first_name, last_name, (salary + 100) NewSalary
from my_employees_above_avg
where last_name like '%b%')
错误报告:

SQL Error: ORA-01427: single-row subquery returns more than one row
01427. 00000 -  "single-row subquery returns more than one row"
*Cause:    
*Action:
请说明它给我的错误是什么或为什么,或者我如何解决这个错误


谢谢,

假设您正在尝试更新
my_employees\u Abovg
表中
last_name
类似“%b%”的每个记录的
salary
字段,那么这应该是您要查找的:

update my_employees_above_avg 
set salary = salary + 100
where last_name like '%b%'

查询的问题是,您试图更新表中所有行中的列
员工id、姓氏、薪资,并且子查询返回多行。因此oracle无法决定在列中更新哪个结果行。这很合乎逻辑

例如,我想更新表中所有员工的部门,我的子查询返回3个部门。现在无法决定要在表中更新子查询的哪个值。因此将抛出一个错误

解决方案是确保子查询返回单行

另外,如果你只是想更新工资,那么其他答案会解释正确的方法。

你试过((工资+100)新工资)吗?