简体   繁体   English

Oracle SQL-查询数据库更改

[英]Oracle SQL - Query for Changes to Database

Currently experiencing an issue. 目前遇到问题。 We are trying to build a report where we can see the changes between a field from one moment in time to another. 我们正在尝试构建一个报告,以便可以查看某个字段从一个时刻到另一个时刻之间的变化。 For instance, a small example would be that we want the report to produce their last name 6 months ago and their last name as of today. 例如,一个小例子是我们希望报告生成6个月前的姓氏和今天的姓氏。

Is there a SQL expression that can do this for me? 是否有一个SQL表达式可以为我执行此操作? (eg add a SQL date parameter to the first last name column where the data is from 6 months ago). (例如,将SQL日期参数添加到数据来自6个月前的“姓氏”列中)。

Thank you 谢谢

Use a flashback query (you will have to ensure the database is set up to support this first and has enough flashback retention to handle 6 months of data): 使用闪回查询 (您必须确保数据库已设置为首先支持此功能,并且具有足够的闪回保留能力来处理6个月的数据):

SELECT COALESCE( current.id, previous.id ) AS id,
       current.name  AS current_name,
       previous.name AS name_six_months_ago
FROM   table_name current
       FULL OUTER JOIN
       (
         SELECT id, name
         FROM   table_name
         AS OF TIMESTAMP ( ADD_MONTHS( SYSTIMESTAMP, -6 ) )
       ) previous
       ON ( current.id = previous.id );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM