当我尝试将数据插入到表格中varchar2(4000)
的列中时,我收到的错误为"Field in data file exceeds maximum length"
。
data =
1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,33,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,111,112,121,654,666,667,1001,1100,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,1121,1123,1124,1211,2001,2002,2003,2004,2028,2101,2102,2201,2202,2301,2302,2303,2401,2402,3001,3002,3003,3004,3010,3011,3012,3013,3020,3021,3022,3023,3024,3025,3030,3031,3032,3040,3041,3042,3043,3044,3045,3046,3047,3050,3051,3052,3053,3054,3055,3060,3061,3062,3070,3071,3072,3080,3081,3082,3083,3084,3090,3091,3092,3100,3102,3103,3110,3111,3112,3113,3120,3121,3122,3123,3130,3131,3132,5656,8040,9000`
请帮我解决此错误。
控制文件:
LOAD DATA
INFILE '$IN_DIR/$FILENAME'
BADFILE '$REJ_DIR/$FILENAME.bad'
APPEND
INTO TABLE test
FIELDS TERMINATED BY ","
TRAILING NULLCOLS
(
FILE_RECORD_DESCRIPTOR POSITION(1),
LINE_NO FILLER,
DEPT TERMINATED BY "\n",
SEQ_NO CONSTANT "1",
DEPT_NO CONSTANT "0",
STATUS CONSTANT "U",
PROCESS_ID CONSTANT "2"
)
表格结构。
CREATE TABLE TEST
(
FILE_RECORD_DESCRIPTOR VARCHAR2(5) NOT NULL,
DEPT VARCHAR2(4000) NOT NULL,
SEQ_NO NUMBER NOT NULL,
DEPT_NO NUMBER(4,0),
STATUS VARCHAR2(10),
ERROR_DETAIL VARCHAR2(3000),
PROCESS_ID NUMBER(8,0)
);
文件:
FILE_RECORD_DESCRIPTOR,LINE_NO,DEPT
EXDEP,2,1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,33,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,111,112,121,654,666,667,1001,1100,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,1121,1123,1124,1211,2001,2002,2003,2004,2028,2101,2102,2201,2202,2301,2302,2303,2401,2402,3001,3002,3003,3004,3010,3011,3012,3013,3020,3021,3022,3023,3024,3025,3030,3031,3032,3040,3041,3042,3043,3044,3045,3046,3047,3050,3051,3052,3053,3054,3055,3060,3061,3062,3070,3071,3072,3080,3081,3082,3083,3084,3090,3091,3092,3100,3102,3103,3110,3111,3112,3113,3120,3121,3122,3123,3130,3131,3132,5656,8040,9000
答案 0 :(得分:2)
错误消息是因为从数据文件读入的数据大于sqlldr的默认字符缓冲区255,如果未指定CHAR和大小,则使用该缓冲区。请注意,这与字段对应的列的大小不同。例如,如果我有一个VARCHAR2(4000)的表列,但没有在控制文件中明确给出一个大小
cola not null,
并且数据文件中的数据超过255但长度小于4000,您将收到错误。
但是,如果控制文件声明缓冲区大小如下:
cola char(4000) not null,
一切都会很好,好像创建一个更大的缓冲区(这里它匹配列大小)。所以,养成一直包括列大小的习惯。为自己省去一些麻烦并创建一个函数来为你生成一个默认的控制文件...等我发布给你的,试一试:https://stackoverflow.com/a/37947714/2543416
答案 1 :(得分:0)
在控制文件中使用CHAR(NN)
作为超过其长度255的列。
所以你的控制文件应该是这样的;
LOAD DATA
INFILE '$IN_DIR/$FILENAME'
BADFILE '$REJ_DIR/$FILENAME.bad'
APPEND
INTO TABLE test
FIELDS TERMINATED BY ","
TRAILING NULLCOLS
(
FILE_RECORD_DESCRIPTOR POSITION(1),
LINE_NO FILLER,
DEPT TERMINATED BY "\n",
SEQ_NO CONSTANT "1",
DEPT_NO CHAR(4000),
STATUS CONSTANT "U",
PROCESS_ID CONSTANT "2"
)
我不知道如何将CHAR(4000)
与CONSTANT "0"
一起使用。这应该解决问题。