Oracle SQL UPDATE无法与NVL一起使用

时间:2014-09-30 14:13:36

标签: sql oracle

我有一个Oracle sql表PS_Z_TREND_NOW_TBL,我正在尝试更新它包含的11行的STATUS字段。下面的子查询应该将2行更新为数字。我想将其他9行设置为0.但是当我运行下面的sql时,我收到此错误: ORA-01407:无法更新(" SYSADM"。" PS_Z_TREND_NOW_TBL"。"状态")为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
)

我想我需要使用NVL功能,但是当我添加并运行以下查询时,它将所有11行的所有STATUS字段更新为0.有人知道我需要做什么来更改我的查询吗? / p>

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')

1 个答案:

答案 0 :(得分:1)

我认为你需要一个相关的子查询,所以从内部查询中删除trend。这可能会做你想要的:

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), ' ', '%') || '%' 
                )