Oracle Update Query on Select Query |错误ORA-01733此处不允许使用虚拟列

问题描述 投票:2回答:1
update(
    select id, word, status
           case when sm = 1 and status = 'Renew' 
                then coalesce(lgst, 'Add') 
           else status
           end as status1, 
           timestamp,
clob_column
    from
        (select id, word, status, 
                sum(case when status = 'Renew' then 1 else 0 end) over (partition by id order by timestamp) as sm,
                lag(status) over (partition by id order by timestamp) as lgst, timestamp, clob_column
           from your_table)_
set clob_column = REPLACE( clob_column , '"key":'||status, '"key":'||status1);

在上述查询中运行时出现错误

set clob_column = REPLACE(clob_column,'“ key”:'||状态,'“ key”:'|| status1)命令行错误:26列:7错误报告:SQL错误:ORA-01733:此处不允许使用虚拟列01733. 00000-“此处不允许使用虚拟列”

我的oracle版本12c

database oracle updates oracle12c insert-update
1个回答
0
投票

更新子查询有几个奇怪的限制,可以通过使用MERGE语句来避免:

merge into your_table
using
(
    select
        id, word, status, timestamp, clob_column,
        case when sm = 1 and status = 'Renew' then coalesce(lgst, 'Add') else status end as status1
    from
    (
        select
            id, word, status, timestamp, clob_column, rowid the_rowid,
            sum(case when status = 'Renew' then 1 else 0 end) over (partition by id order by timestamp) as sm,
            lag(status) over (partition by id order by timestamp) as lgst
        from your_table
    )
) new_rows
    on (your_table.rowid = new_rows.rowid)
when matched then update set
        clob_column = replace(clob_column , '"key":'||status, '"key":'||status1);
© www.soinside.com 2019 - 2024. All rights reserved.