首页 > 解决方案 > Oracle 存储过程 - 跟踪验证错误

问题描述

我正在将 MsSQL 存储过程转换为 Oracle,但我遇到了一个问题,这让我对这两种实现都产生了疑问。

Sql Server 版本在存储过程中创建了一个临时表,以跟踪可能是相当大的数据集(数十万条记录)的验证错误。每个验证查询都会将无效 ID 选择到临时表中,并带有适当的错误消息(特定于查询)。完成所有验证后,会将错误插入到真实表中(该表没有用于存储 ID 的列)。然后,我可以通过从临时错误表中过滤掉 ID 来轻松插入有效行。

我希望这是有道理的。重申一下,我不简单地使用“真实”错误表的原因是它不包含用于存储无效行 ID 的列(我无法更改)。

我知道我可以在 Oracle 中使用普通/全局临时表,但是我读的越多,听起来越是不好的做法。在 Oracle 中执行此操作有什么好的选择?收藏?

谢谢。

标签: databaseoraclestored-procedurestemp-tables

解决方案


Why not just insert the errors into the real target table when the error occurs instead of into a #TEMP table then moving them later? You did not list your Oracle version but you can create a global temporary table on the system then in your stored procedure a private to your session temporary table would be created on insert. However, temp tables are normally not needed in Oracle. The entire process design sounds suspect. It is possible in Oracle to bulk insert the data capturing individual row errors from the bulk operation. If you or some members of you team have a decent understanding how Oracle works then this process seems like a candidate for refactoring (redesign).


推荐阅读