error-handling - 在Oracle实例化 View 中记录导致错误的数据的方法?

标签 error-handling oracle10g etl materialized-views

我们创建了一些物化 View ,可以与实际应用程序数据的副本很好地兼容。该应用程序不会管理自己的数据。从那时起,一些用户可能在输入数据时很粗心或很不习惯。 Mview现在窒息而死。错误消息表明我们正在从一个或多个函数返回多个行。

我们一直在尝试使用EXCEPTIONS -在DBMS_Output的第一行object_id上取得了一些成功,这导致函数(其中之一)失败。最好能够完成MView的运行,并记录导致每个函数出现问题的object_id。我们没有成功将异常数据插入表中。

平台是Oracle 10g2。我一直在尝试将DML错误登录到我的脑海。我知道这应该适用于BULK数据,并且我假设创建实例化 View 将符合条件。这项工作适用于MViews吗?这是最好的方法吗?

最佳答案

如果您只是尝试刷新实例化 View ,我不知道一种使用DML错误日志记录来捕获所有问题行的方法。另一方面,您可以创建表并在填充表时使用DML错误日志记录,以捕获刷新物化 View 时将遇到的所有错误。

可能您可以手动填充此表,然后填充create a materialized view on this prebuilt table。这可能会产生问题,具体取决于确切化的 View 的使用方式以及启用的查询重写类型,因为您构建的表将丢失基础表(写入错误日志的行)中的某些数据。

创建表和错误日志

SQL> create table t (
  2    col1 number,
  3    col2 number
  4  );

Table created.

Elapsed: 00:00:00.00

SQL> ed
Wrote file afiedt.buf

  1  begin
  2    dbms_errlog.create_error_log( 'T', 'T_ERR' );
  3* end;
SQL> /

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> create function f1
  2    return varchar2
  3  is
  4  begin
  5    return 'A';
  6  end;
  7  /

Function created.

尝试插入10行。 3将失败,因为LEVEL将是3的倍数,并且函数返回的字符串不能转换为数字
Elapsed: 00:00:00.01
SQL> insert into t( col1, col2 )
  2    select level,
  3           (case when mod(level,3) = 0
  4                 then to_number( f1 )
  5                 else mod(level,3)
  6             end)
  7      from dual
  8   connect by level <= 10
  9       log errors into t_err
 10           reject limit unlimited;

7 rows created.

Elapsed: 00:00:00.01

SQL> ed
Wrote file afiedt.buf

  1  select ora_err_mesg$, col1, col2
  2*   from t_err
SQL> /

ORA_ERR_MESG$                  COL1       COL2
------------------------------ ---------- ----------
ORA-01722: invalid number      3          0
ORA-01722: invalid number      6          0
ORA-01722: invalid number      9          0

Elapsed: 00:00:00.00

现在,使用此预建表创建实例化 View
SQL> ed
Wrote file afiedt.buf

  1  create materialized view t
  2      on prebuilt table
  3  as
  4  select 1 col1, 1 col2
  5*   from dual
SQL> /

Materialized view created.

Elapsed: 00:00:00.11

关于error-handling - 在Oracle实例化 View 中记录导致错误的数据的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7406520/

相关文章:

python - IndexError : string index out of range on equation cleaning function

sql - PL/SQL 过程字符参数

java - 使用 for 循环将数组元素传递到 Oracle 数据库表

Oracle Data Integrator 标量函数用法

java - 如何读取一个巨大的 excel 文件的前 n 行

php - 使用位运算符解释此方法的操作

html - 在 Oracle 查询中处理 HTML 数据

sql - 从事件流中 self 加入日期的有效方法是什么?

sql-server - 将批量 JSON 数据加载到 SQL Server 表中

swift - Swift 中的动态/运行时调度,或 "the strange way structs behave in one man' 的意见”