0

Data in table(Oracle database)

Date        Id      Flag
16-DEC-13   163750  1
16-DEC-13   163755  1
16-DEC-13   063801  1

whenever I'm read above data from table and writing into flat file using UTL file function,it misses zero from field in the flat file.

Flat file abc.txt

16-DEC-13|163750|1
16-DEC-13|163755|1
16-DEC-13|63801|1
4

1 回答 1

1

我认为您在脚本中的某处丢失了 0 在 UTL_FILE 将相同值保存到 2 个文件中的示例下方,在文件 tst-i.csv 我们丢失了前导零,但在文件 tst-v.csv 我们正确地拥有它

create table tst (col1 varchar2(50));
insert into tst values('1');
insert into tst values('02');
insert into tst values('3');

DECLARE
  fi UTL_FILE.FILE_TYPE;
  fv UTL_FILE.FILE_TYPE;
  i  integer;
  v  varchar2(50);
begin

  fi := utl_file.fopen('MYDIR','tst-i.csv','w');
  fv := utl_file.fopen('MYDIR','tst-v.csv','w');
  for rc in (select * from tst) loop
    i := rc.col1;
    v := rc.col1;
    utl_file.PUTF(fi, i ||' \n');
    utl_file.PUTF(fv, v ||' \n');
  end loop;

  utl_file.FCLOSE(fi);
  utl_file.FCLOSE(fv);
end;

输出是 tst-i.csv

1 
2 
3 

tst-v.csv

1 
02 
3 
于 2015-11-02T16:05:28.093 回答