[英]Oracle SQL UPDATE not working with NVL
I have an Oracle sql table PS_Z_TREND_NOW_TBL and am trying to update the STATUS field for the 11 rows it contains. 我有一个Oracle sql表PS_Z_TREND_NOW_TBL,并且正在尝试为其包含的11行更新STATUS字段。 The subquery below should update 2 of the rows to a number.
下面的子查询应将2行更新为一个数字。 I want to set the other 9 rows to 0. But when I run the below sql I get this error: ORA-01407: cannot update ("SYSADM"."PS_Z_TREND_NOW_TBL"."STATUS") to NULL
我想将其他9行设置为0。但是当我运行以下sql时,出现此错误:ORA-01407:无法更新(“ SYSADM”。“ PS_Z_TREND_NOW_TBL”。“ STATUS”)为NULL
UPDATE PS_Z_TREND_NOW_TBL a
SET STATUS =
(
SELECT count(SEC.IS_AW_AUTH_NAME)
from PS_IS_AW_SECURITY sec, PS_Z_TREND_NOW_TBL trend
where sec.IS_AW_AUTH_NAME LIKE '%Manager%'
and sec.IS_AW_GRP_ID LIKE '%' || REPLACE(UPPER(trend.DESCR254), ' ', '%') || '%'
and a.DESCR254 LIKE '%' || REPLACE(UPPER(trend.DESCR254), ' ', '%') || '%'
GROUP BY trend.DESCR254
)
I think I need to use the NVL function, but when I added that and ran the below query it updated all the STATUS field for all 11 rows to 0. Does anyone know what I need to do to change my query? 我想我需要使用NVL函数,但是当我添加它并运行以下查询时,它将所有11行的所有STATUS字段都更新为0。有人知道我需要做什么来更改查询吗?
UPDATE PS_Z_TREND_NOW_TBL a
SET STATUS =
NVL((
SELECT count(SEC.IS_AW_AUTH_NAME)
from PS_IS_AW_SECURITY sec, PS_Z_TREND_NOW_TBL trend
where sec.IS_AW_AUTH_NAME LIKE '%Manager%'
and sec.IS_AW_GRP_ID LIKE '%' || REPLACE(UPPER(trend.DESCR254), ' ', '%') || '%'
and a.DESCR254 LIKE '%' || REPLACE(UPPER(trend.DESCR254), ' ', '%') || '%'
GROUP BY trend.DESCR254
), '0')
I think you need a correlated subquery, so remove trend
from the inner query. 我认为您需要一个相关的子查询,因此请从内部查询中删除
trend
。 This may do what you want: 这可能会做您想要的:
UPDATE PS_Z_TREND_NOW_TBL a
SET STATUS = (SELECT count(SEC.IS_AW_AUTH_NAME)
from PS_IS_AW_SECURITY sec
where sec.IS_AW_AUTH_NAME LIKE '%Manager%' and
sec.IS_AW_GRP_ID LIKE '%' || REPLACE(UPPER(a.DESCR254), ' ', '%') || '%'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.