我正在使用Oracle 10g XE.我有一个数据库查询 –
SELECT PID FROM PROUCT WHERE last_modified > '${dih.last_index_time}'
我在这里要做的是比较时间戳.问题是我的表没有last_modified列,也没有我可以将它添加到表中.但是有一个问题 –
SELECT SCN_TO_TIMESTAMP( ORA_ROWSCN ) FROM PRODUCT;
这将返回一个包含所需时间戳的列.
如何使用此查询代替上次修改的列进行必要的比较?
最佳答案 您只需将其放在WHERE子句中:
SELECT PID
FROM PRODUCT
WHERE SCN_TO_TIMESTAMP( ORA_ROWSCN ) > '${dih.last_index_time}'
但是,您的两个查询不相同.从ORA_ROWSCN文档(我的重点):
For each row, ORA_ROWSCN returns the conservative upper bound system change number (SCN) of the most recent change to the row in the current session. This pseudocolumn is useful for determining approximately when a row was last updated. It is not absolutely precise, because Oracle tracks SCNs by transaction committed for the block in which the row resides.
这意味着如果修改块中的一行,则整个块(多行)将具有相同的SCN.
如果您希望查询准确无误,则需要添加LAST_MODIFIED列,或者可能启用row-level dependency tracking.这仍然不准确:
… each row in the table has a system change number (SCN) that represents a time greater than or equal to the commit time of the last transaction that modified the row