如何使用 sqlldr 将数据导入 varray

How to import data into a varray using sqlldr

我正在尝试使用 sqlldr 将数据导入 Oracle 数据库。

我正在使用此文档,但未成功:sqlldr and sqlldr2

描述我在做什么:

创建 varray 类型和 table:

CREATE OR REPLACE TYPE fv_integer_varray_12 AS VARRAY(12) OF INTEGER NOT NULL;

CREATE OR REPLACE TYPE VC_Array_MInteger_12 AS Object (
  fv_array fv_integer_varray_12,
  MEMBER FUNCTION   typeDimension   RETURN NUMBER ,
  MEMBER FUNCTION typeName RETURN VARCHAR2);
/  

CREATE TABLE fv_varray_12 (
id NUMBER, 
fv fv_integer_varray_12,
PRIMARY KEY (id)
);

创建控制文件:

options (errors=9999999, rows=5)
load data
 characterset WE8MSWIN1252
 infile '<path>'
 badfile '<path>'
 discardfile '<path>'
 into table fv_varray_12
 fields terminated by " "
( id, fv VARRAY COUNT(12) (fv))

要加载的数据是:

8 18 29 38 9 16 15 14 16 18 16 13 15 
9 22 31 32 8 13 18 10 15 18 16 13 13 

当我尝试通过命令加载它时:

sqlldr user/pass control=imp_fv_12dim.ctl

我收到错误:

SQL*Loader-403: Referenced column not present in table FV_VARRAY_12.

但事实并非如此,因为 id 和 fv 列都在那里。

一定是我的控制文件有问题。我该如何解决?

您只是缺少关键字 CONSTANT:

fv VARRAY COUNT(CONSTANT 12) (fv)

文档中的示例中缺少这一点(但他们的数据看起来也很奇怪);但它在加载 VARRAY 时显示为必需 in the count_spec syntax diagram, which is linked to from the 12c documentaion - 但在早期版本的文档中也可用..

使用您的示例数据以及对控制文件的修改:

options (errors=9999999, rows=5)
load data
characterset WE8MSWIN1252
infile 'imp_fv_12dim.dat'
badfile 'imp_fv_12dim.bad'
discardfile 'imp_fv_12dim.dis'
into table fv_varray_12
fields terminated by " "
( id,
  fv VARRAY COUNT(CONSTANT 12) (fv)
)

然后就可以了:

> sqlldr user/pass control=imp_fv_12dim.ctl

SQL*Loader: Release 11.2.0.4.0 - Production on Mon Dec 4 17:41:04 2017

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 2

并且查询显示数据:

column fv format a80
select * from fv_varray_12;

        ID FV                                                                              
---------- --------------------------------------------------------------------------------
         8 FV_INTEGER_VARRAY_12(18, 29, 38, 9, 16, 15, 14, 16, 18, 16, 13, 15)             
         9 FV_INTEGER_VARRAY_12(22, 31, 32, 8, 13, 18, 10, 15, 18, 16, 13, 13)