[英]UTL_FILE appends LF to end of file
With my following PLSQL block, I experience a Line Feed character at the end of the file. 在下面的PLSQL块中,我在文件末尾遇到换行符。 My expectation is that there will be no line feed. 我的期望是不会有换行符。
DECLARE
v_MyFileHandle UTL_FILE.FILE_TYPE;
BEGIN
v_MyFileHandle := UTL_FILE.FOPEN('MY_DIREC','HELLO.TXT','a');
UTL_FILE.PUT(v_MyFileHandle, '1');
UTL_FILE.FCLOSE(v_MyFileHandle);
END;
The above block outputs a file that looks like: 上面的块输出一个类似于以下内容的文件:
1[LF] 1 [LF]
DECLARE
v_MyFileHandle UTL_FILE.FILE_TYPE;
BEGIN
v_MyFileHandle := UTL_FILE.FOPEN('MY_DIREC','HELLO.TXT','a');
UTL_FILE.PUT(v_MyFileHandle, '1');
UTL_FILE.PUT(v_MyFileHandle, '2');
UTL_FILE.FCLOSE(v_MyFileHandle);
END;
The above block will produce a file that looks like: 上面的代码块将生成一个类似于以下内容的文件:
12[LF] 12 [LF]
How do I prevent the line feed at the end of the file? 如何防止文件末尾换行?
Try DBMS_XSLPROCESSOR.CLOB2FILE
as a workaround. 尝试使用DBMS_XSLPROCESSOR.CLOB2FILE
作为解决方法。 It does not create [LF] on Unix and [CR][LF] on Windows at the end of file. 在文件末尾,它不会在Unix上创建[LF],而在Windows上不会创建[CR] [LF]。
DECLARE
v_myClob CLOB := '1';
BEGIN
DBMS_XSLPROCESSOR.CLOB2FILE( v_myClob, 'MY_DIREC', 'HELLO.TXT');
END;
After extensive googling, I found that this worked using "wb" for byte mode and put_raw. 经过广泛的谷歌搜索,我发现这对于字节模式和put_raw使用“ wb”可以工作。
sBufToWrite := 'line1' || chr(13) || chr(10) || line2' || chr(13) || chr(10) || 'line3';
sFileName := 'testfile.txt';
out_file := utl_file.fopen('DATA_DIRECTORY', sFileName, 'wb');
utl_file.put_raw(out_file, utl_raw.cast_to_raw(sBufToWrite));
utl_file.fclose(out_file);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.