我需要根据另一个表更新一个表,所以我有以下语句:
update FAULTS
set FAULTS.FAULT_STATE = (
select INCIDENTS.TICKET_STATE from INCIDENTS
where INCIDENTS.CF_ID = FAULTS.CF_ID
)
它给了我错误说:
ORA-01427: single-row subquery returns more than one row
我尝试了 DISTINCT,但状态值也不同,所以 DISTINCT 不起作用。所以我也改了:
update FAULTS
set FAULTS.FAULT_STATE = (
select INCIDENTS.TICKET_STATE from INCIDENTS
where INCIDENTS.CF_ID = FAULTS.CF_ID and rownum = 1
)
现在它不会给出错误。
问题是,如果子查询返回null,它也会更新行并清除内容。有什么解决办法吗?