如何排除闪回查询结果集中未更改的字段?

How do I exclude unchanged fields in Flashback query resultset?

是否可以排除闪回查询结果集中未更改的字段?

考虑到我有关注 table

create table first_table
(
    id int generated as identity,
    name NVARCHAR2(1024),
    age smallint,
    notebook nclob,
    userpic clob,
    salary float
)

如果 table 在版本化查询后更新非常频繁(例如在 notebook 字段上)

select ROWID, VERSIONS_OPERATION, VERSIONS_STARTSCN, VERSIONS_STARTTIME, VERSIONS_XID, id, name, age, notebook, userpic, salary
from FIRST_TABLE versions between scn 1469193 and 1482882;

将为每一行提取大量用户图片值,即使它是相同的。

我能以某种方式避免这种情况,而是为未更改的值获取 NULL 吗?

您可以使用 LAG() 分析函数来比较当前行与前一行的列值。因此,选择任何列的值与其 LAG 值不匹配以仅显示更改,同时将其他列保持为 NULL as

SELECT versions_starttime, f.ID, f.name, f.age,
       CASE WHEN NVL(TO_CHAR(f.notebook),' ') != 
                 NVL(LAG(TO_CHAR(f.notebook)) OVER 
                     (PARTITION BY TO_CHAR(f.notebook) 
                          ORDER BY VERSIONS_STARTTIME NULLS FIRST),' ')
            THEN
                 f.notebook
             END AS notebook, 
       CASE WHEN NVL(TO_CHAR(f.userpic),' ') != 
                 NVL(LAG(TO_CHAR(f.userpic)) OVER 
                     (PARTITION BY TO_CHAR(f.userpic) 
                          ORDER BY VERSIONS_STARTTIME NULLS FIRST),' ')
            THEN
                 f.userpic
             END AS userpic,
       f.salary                       
  FROM first_table 
  VERSIONS BETWEEN SCN 1469193 AND 1482882 f