oracle

推荐列表 站点导航

当前位置:首页 > 数据库 > oracle >

oracle中utl_file包读写文件操作实例学习

来源:网络整理  作者:  发布时间:2020-12-14 15:15
在oracle中utl_file包提供了一些操作文本文件的函数和过程,接下来和大家一起学习他的基本操作,感兴趣的你可以参考...
END IF;
--创建directory
ex BOOLEAN;--文件是否存在



dbms_output.put_line('file is close!');
dbms_output.put_line('file is open!');
DECLARE
filehandle := utl_file.fopen('TESTFILE','hello.txt','w'); --打开文件
1.创建directory,并给用户授权
IF utl_file.is_open(filehandle) THEN
IF utl_file.is_open(filehandle) THEN
exit ;


utl_file.fremove('TESTFILE', 'hello2.dat');--删除文件


else
dbms_output.put_line(filebuffer);
create or replace directory TESTFILE as '/home/oracle/zxx/test';
END IF;
在oracle中utl_file包提供了一些操作文本文件的函数和过程,学习了一下他的基本操作
filebuffer varchar2(500);
begin
begin

Maximum number of characters for each line, including the newline character, for this file (minimum value 1, maximum value 32767). If unspecified, Oracle supplies a default value of 1024.
IF ex THEN
--测试读取
utl_file.fclose(filehandle);

utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello.xls');
utl_file.put_line(filehandle,'Hello World!');
END IF;
WHEN OTHERS THEN
utl_file.put_line(filehandle,'Hello Oracle!');--写入一行记录
dbms_output.put_line('File Exists');
utl_file.frename('TESTFILE','hello.xls','TESTFILE','frenamehello.xls',TRUE);--重命名
4.判断文件是否存在(读,重命名,复制,删除都要判断文件是否存在)
END fgetattr;
dbms_output.put_line('EXCEPTION2:'||SUBSTR(SQLERRM, 1, 100)) ;
备注:
dbms_output.put_line('File Length: ' || TO_CHAR(flen));
DECLARE
详细介绍
2.写入操作
loop
utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello.dat');--复制
fopen有一个参数max_linesize,下面是原文解释
WHEN OTHERS THEN
WHEN no_data_found THEN

复制代码 代码如下:

end loop;
bsize NUMBER;--文件大小
utl_file.fclose(filehandle);--关闭句柄
utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello2.dat');
begin
EXCEPTION

grant read, write on directory TESTFILE to zxx;
BEGIN

复制代码 代码如下:

dbms_output.put_line('File Does Not Exist');
EXCEPTION
utl_file.put_line(filehandle,'你好,胖子!');
dbms_output.put_line('EXCEPTION1:'||SUBSTR(SQLERRM, 1, 100)) ;
--判断文件是否存在

复制代码 代码如下:

set serveroutput on;
filehandle := utl_file.fopen('TESTFILE','hello.txt','R');
3.读取操作
utl_file.fgetattr('TESTFILE', 'hello.txt', ex, flen, bsize);
filehandle utl_file.file_type; --句柄
ELSE
dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
filehandle utl_file.file_type;


utl_file.get_line(filehandle,filebuffer);


end;
end;
--给用户授权
end;
flen NUMBER;--文件长度? 这个地方不知道怎么理 (原文 file_length The length of the file in bytes. NULL if file does not exist.)
dbms_output.put_line('file is open!');
DECLARE
---测试写入

复制代码 代码如下:

相关热词: oracle 实例

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://www.juheyunku.com/sql/oracle/3814.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

oracle中utl_file包读写文件操作实例学习

2020-12-14 编辑:

END IF;
--创建directory
ex BOOLEAN;--文件是否存在



dbms_output.put_line('file is close!');
dbms_output.put_line('file is open!');
DECLARE
filehandle := utl_file.fopen('TESTFILE','hello.txt','w'); --打开文件
1.创建directory,并给用户授权
IF utl_file.is_open(filehandle) THEN
IF utl_file.is_open(filehandle) THEN
exit ;


utl_file.fremove('TESTFILE', 'hello2.dat');--删除文件


else
dbms_output.put_line(filebuffer);
create or replace directory TESTFILE as '/home/oracle/zxx/test';
END IF;
在oracle中utl_file包提供了一些操作文本文件的函数和过程,学习了一下他的基本操作
filebuffer varchar2(500);
begin
begin

Maximum number of characters for each line, including the newline character, for this file (minimum value 1, maximum value 32767). If unspecified, Oracle supplies a default value of 1024.
IF ex THEN
--测试读取
utl_file.fclose(filehandle);

utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello.xls');
utl_file.put_line(filehandle,'Hello World!');
END IF;
WHEN OTHERS THEN
utl_file.put_line(filehandle,'Hello Oracle!');--写入一行记录
dbms_output.put_line('File Exists');
utl_file.frename('TESTFILE','hello.xls','TESTFILE','frenamehello.xls',TRUE);--重命名
4.判断文件是否存在(读,重命名,复制,删除都要判断文件是否存在)
END fgetattr;
dbms_output.put_line('EXCEPTION2:'||SUBSTR(SQLERRM, 1, 100)) ;
备注:
dbms_output.put_line('File Length: ' || TO_CHAR(flen));
DECLARE
详细介绍
2.写入操作
loop
utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello.dat');--复制
fopen有一个参数max_linesize,下面是原文解释
WHEN OTHERS THEN
WHEN no_data_found THEN

复制代码 代码如下:

end loop;
bsize NUMBER;--文件大小
utl_file.fclose(filehandle);--关闭句柄
utl_file.fcopy('TESTFILE', 'hello.txt', 'TESTFILE', 'hello2.dat');
begin
EXCEPTION

grant read, write on directory TESTFILE to zxx;
BEGIN

复制代码 代码如下:

dbms_output.put_line('File Does Not Exist');
EXCEPTION
utl_file.put_line(filehandle,'你好,胖子!');
dbms_output.put_line('EXCEPTION1:'||SUBSTR(SQLERRM, 1, 100)) ;
--判断文件是否存在

复制代码 代码如下:

set serveroutput on;
filehandle := utl_file.fopen('TESTFILE','hello.txt','R');
3.读取操作
utl_file.fgetattr('TESTFILE', 'hello.txt', ex, flen, bsize);
filehandle utl_file.file_type; --句柄
ELSE
dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
filehandle utl_file.file_type;


utl_file.get_line(filehandle,filebuffer);


end;
end;
--给用户授权
end;
flen NUMBER;--文件长度? 这个地方不知道怎么理 (原文 file_length The length of the file in bytes. NULL if file does not exist.)
dbms_output.put_line('file is open!');
DECLARE
---测试写入

复制代码 代码如下:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://www.juheyunku.com/sql/oracle/3814.shtml

相关文章

风云图片

推荐阅读

返回oracle频道首页