如何在SQL * Loader控制文件中使用XMLType?

时间:2014-06-20 11:04:08

标签: sql oracle sql-loader xmltype

我有一个csvfile,它包含一列XML数据。 csv的示例记录如下:

1,,,<capacidade><numfields>3</numfields><template>1</template><F1><name lang="pt">Apple</name></F1></capacidade>

我想使用SQL * Loader将所有数据导入Oracle;我按如下方式定义了ctl文件:

LOAD DATA
 CHARACTERSET UTF8
 INFILE '/home/db2inst1/result.csv'
 CONTINUEIF NEXT(1:1) = '#'
 INTO TABLE "TEST"."T_DATA_TEMP"
FIELDS TERMINATED BY','
(   "ID" 
  , "SOURCE" 
  , "CATEGORY" 
  , "RAWDATA"
 )

Wen运行此命令,错误日志显示RAWDATA列被视为CHARACTER数据类型。在这种情况下,如何将RAWDATA定义为XMLType,以便可以正确插入Oracle?

1 个答案:

答案 0 :(得分:0)

尝试类似这样的方法: 在xml的末尾添加一个逗号以标记定界符(不能使用空格,因为xml可能在两者之间包含空格)

然后按如下所示创建ctl文件

LOAD DATA
APPEND
INTO TABLE "TEST"."T_DATA_TEMP" fields OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
( ID terminated by "," ,
 SOURCE terminated by ",", 
 CATEGORY terminated by ",", 
 RAWDATA char(4000) terminated by ","
 )