Select 查询上的 Oracle 更新查询 |错误 ORA-01733 Virtual Column Not Allowed Here

Oracle Update Query On Select Query | Error ORA-01733 Virtual Column Not Allowed Here

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":'||status, '"key":'||status1) Error at Command Line:26 Column:7 Error report: SQL Error: ORA-01733: virtual column not allowed here 01733. 00000 - "virtual column not allowed here"

我的oracle版本12c

更新子查询有几个奇怪的限制,可以通过使用 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);