在 oracle 中使用 UTL 文件函数从 table 读取数据并写入平面文件时缺少零
Zero is missing while read data from table and writing in flat file using UTL file function in oracle
table(Oracle 数据库)中的数据
Date Id Flag
16-DEC-13 163750 1
16-DEC-13 163755 1
16-DEC-13 063801 1
每当我从 table 中读取上述数据并使用 UTL 文件功能写入平面文件时,它会从平面文件中的字段中丢失零。
平面文件
abc.txt
16-DEC-13|163750|1
16-DEC-13|163755|1
16-DEC-13|63801|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
table(Oracle 数据库)中的数据
Date Id Flag
16-DEC-13 163750 1
16-DEC-13 163755 1
16-DEC-13 063801 1
每当我从 table 中读取上述数据并使用 UTL 文件功能写入平面文件时,它会从平面文件中的字段中丢失零。
平面文件 abc.txt
16-DEC-13|163750|1
16-DEC-13|163755|1
16-DEC-13|63801|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