我的加载器脚本由于字段PATHID的ORA-01722而失败,该字段在控制文件中被定义为整数外部。现在我想检查file的列pathid是否包含Numer值,如果不是number,则作为null插入。我的数据库是oracle。
发布于 2019-05-07 00:42:06
这里有一个例子;看看它是否有帮助。
首先测试表格,以及检查参数值是否为数字的函数。它将在控制文件中使用。
SQL> create table test (pathid number, name varchar2(20));
Table created.
SQL> create or replace function f_isnum (par_value in varchar2)
2 return varchar2
3 is
4 -- if PAR_VALUE is a number, return Y. Otherwise, return N
5 begin
6 return case when regexp_like(par_value, '^\d+$') then 'Y' else 'N' end;
7 end;
8 /
Function created.
SQL>控制文件,其中还包含一些示例数据。检查PATHID字段,该字段使用先前创建的函数。
load data
infile *
replace
into table test
fields terminated by "|" TRAILING NULLCOLS
(
pathid integer external "case when f_isnum(:pathid) = 'Y' then :pathid else null end",
name)
begindata
123|Littlefoot
xxx|Invalid one
125|This is OK测试:
SQL> $sqlldr scott/tiger control=test07.ctl log=test07.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pon Svi 6 18:41:12 2019
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 2
Commit point reached - logical record count 3
SQL> select * From test;
PATHID NAME
---------- --------------------
123 Littlefoot
Invalid one
125 This is OK
SQL>https://stackoverflow.com/questions/56007243
复制相似问题