DazzaL 작업을해야하지만 귀하의 경우 입력 파일을 변경할 수없는 경우에는이 코드를 사용할 수 있습니다 제안 무엇 :
declare
v_line varchar2(2000);
v_c1 varchar2(10);
v_c2 varchar2(10);
v_c3 varchar2(1980);
nb_line_per_record integer := 3;
v_line_in_record integer;
v_seperator varchar2(1) := ',';
v_file UTL_FILE.FILE_TYPE;
begin
v_file := utl_file.FOPEN(your_directory, 'your_file','r');
v_line_in_record := 0;
--we skip the first line
UTL_FILE.GET_LINE(v_file, v_line);
loop
v_line_in_record := v_line_in_record + 1;
begin
UTL_FILE.GET_LINE(v_file, v_line);
EXCEPTION
WHEN no_data_found THEN
exit;
END;
--first line of record we cut by v_seperator
if v_line_in_record = 1 then
v_c1 := substr(v_line,1,instr(v_line,v_seperator,1,1)-1);
v_c2 := substr(v_line,instr(v_line,v_seperator,1,1)+1,
instr(v_line,v_seperator,1,2)-
instr(v_line,v_seperator,1,1)-1);
v_c3 := substr(v_line,instr(v_line,v_seperator,1,2)+1)
|| char(10);--if you want new line in adresse
else
--not first line we concatanate to adress with new line
v_c3 := v_c3 || v_line ||
case when v_line_in_record = 2 then char(10) else '' end;
end if;
if v_line_in_record = 3 then
v_line_in_record := 0;
--do something with your record
insert into yourtable values (v_c1,v_c2,v_c3);
end if;
end loop;
UTL_FILE.FCLOSE(v_file);
COMMIT;
end;
을
하지만 모든 레코드가 3 줄임을 절대적으로 확신 할 수있는 경우에만 작동합니다. 내가 당신이라면 각 레코드 뒤에 레코드 구분 기호를 추가하고이 파일을 테이블에로드하려면 SQLLOADER을 사용합니다. 여러분은 SQLLOADER.Here 레코드 구분 기호
options (skip=1)
load data
infile "yourfile" "str '&'"
truncate into table your_table
fields terminated by ","
trailing nullcols
(heading1, heading2, heading3)
로 &를 사용하는 exemple의 CTL이다와 레코드 구분 기호를 정의 할 수 있습니다 그리고 당신은 당신 구분 기호 레코드를 사용하는 경우에도 파일에 External Table을 만들 수 있습니다.
안녕 Dazzal, 캐리지 리턴 ASCII 값을 사용해 보았습니다. 나는 쉼표로 구분 된 목록으로 csv 파일에 UTL_FILE 출력을 쓰고 있습니다. 하지만이 특별한 캐리지 리턴을 각 행 사이의 상자와 같은 특수 문자로 사용하고 있습니다. 또한 같은 줄에 표시됩니다. – Avinash
캐리지 리턴에 어떤 문자 시퀀스를 사용하고 있습니까? 그것은 chr (13) || chr (10)이어야합니다. – DazzaL