Я создаю файл CSV с использованием пакета UTL_FILE.Когда я открываю файл в Excel, все данные отображаются в одной строке.Но значения есть в каждом столбце.Я не уверен, как получить данные в отдельных строках.
Вот мой блок PL / SQL:
declare
v_file utl_file.file_type;
v_line_num number(7);
begin
for orec in ( select distinct --) loop
dbms_output.put_line('route '||orec.r_no);
v_file := utl_file.fopen('EXPORT_CSV','DAILY_REPORT_OF_'||OREC.r_no||'.csv','W',32767);
utl_file.put_line(v_file,'"SERVICEDAY","OP","PAC","RNO","DESC","DIRECTION","BLK","T_ID","T_NO","DUTY","S_STOP_SEQ","E_STOP_SEQ","LOC_FROM","SCH_TIME_FROM","OBS_TIME_FROM","LOC_TO","SCH_TIME_TO","OBS_TIME_TO","IS_SPLIT","CAUSE","M_AGE","OP_REASON","OP_COMMENT","L_COMMENT","L_AMENDED_CODE","STATUS"');
v_line_num:=0;
for irec in (select --) loop
utl_file.put(v_file, '"'||nvl(irec.SER,''));
utl_file.put(v_file,'","' || nvl(irec.OP,''));
utl_file.put(v_file,'","' || nvl(irec.PAC,''));
utl_file.put(v_file,'","' || nvl(irec.RNO,''));
utl_file.put(v_file,'","' || nvl(irec.DESC,''));
utl_file.put(v_file,'","' || nvl(irec.DIRECTION,''));
utl_file.put(v_file,'","' || nvl(irec.BLK,''));
utl_file.put(v_file,'","' || nvl(irec.T_ID,''));
utl_file.put(v_file,'","' || nvl(irec.T_NO,''));
utl_file.put(v_file,'","' || nvl(irec.DUTY,''));
utl_file.put(v_file,'","' || nvl(irec.S_STOP_SEQ,''));
utl_file.put(v_file,'","' || nvl(irec.E_STOP_SEQ,''));
utl_file.put(v_file,'","' || nvl(irec.LOC_FROM,''));
utl_file.put(v_file,'","' || nvl(irec.SCH_TIME_FROM,''));
utl_file.put(v_file,'","' || nvl(irec.OBS_TIME_FROM,''));
utl_file.put(v_file,'","' || nvl(irec.LOC_TO,''));
utl_file.put(v_file,'","' || nvl(irec.SCH_TIME_TO,''));
utl_file.put(v_file,'","' || nvl(irec.OBS_TIME_TO,''));
utl_file.put(v_file,'","' || nvl(irec.IS_SPLIT,''));
utl_file.put(v_file,'","' || nvl(irec.CAUSE,''));
utl_file.put(v_file,'","' || nvl(irec.M_AGE,''));
utl_file.put(v_file,'","' || nvl(irec.OP_REASON,''));
utl_file.put(v_file,'","' || nvl(irec.OP_COMMENT,''));
utl_file.put(v_file,'","' || nvl(irec.L_COMMENT,''));
utl_file.put(v_file,'","' || nvl(irec.L_AMENDED_CODE,''));
utl_file.put(v_file,'","' || nvl(irec.STATUS,''));
utl_file.put_line(v_file,chr(13) || chr(10));
v_line_num:=v_line_num+1;
end loop;
dbms_output.put_line('lines: '||v_line_num);
utl_file.fclose(v_file);
end loop;
--utl_file.fclose(v_file);
--utl_file.fclose_all;
/*
exception
when others then
utl_file.fclose_all;
dbms_output.put_line(sqlerrm);
*/
end;