dbms常用包之utl_file包小结

1、文件只能放在db server端,客户端的不能读写

2、directory 名称在程序中必须大写。

3、UTL_FILE.FILE_TYPE是包内定义好的file handle

4、使用directory;而非直接的路径名。同时要对directory有读写权限

grant read,write on directory utl to scott;

create or replace directory utl as 'c:';

declare
num number;
j number :=0;
sname varchar2(200);
numfile UTL_FILE.FILE_TYPE;
temp varchar2(1000);
cursor curemp is select empno,ename from oracleemp;
begin
numfile := utl_file.fopen('UTL','121.txt','w',2000);
for i in curemp loop
j :=j+1;
temp := j || ' : '||i.empno || ' '||i.ename;
utl_file.put_line(numfile,temp);
--utl_file.new_line(numfile);
end loop;
utl_file.fclose(numfile);
end;

5、exception。

Table 167-1 UTL_FILE Package Exceptions

Exception NameDescription
INVALID_PATHFile location is invalid.
INVALID_MODEThe open_mode parameter in FOPEN is invalid.
INVALID_FILEHANDLEFile handle is invalid.
INVALID_OPERATIONFile could not be opened or operated on as requested.
READ_ERROROperating system error occurred during the read operation.
WRITE_ERROROperating system error occurred during the write operation.
INTERNAL_ERRORUnspecified PL/SQL error
CHARSETMISMATCHA file is opened using FOPEN_NCHAR, but later I/O operations use nonchar functions such as PUTF or GET_LINE.
FILE_OPENThe requested operation failed because the file is open.
INVALID_MAXLINESIZEThe MAX_LINESIZE value for FOPEN() is invalid; it should be within the range 1 to 32767.
INVALID_FILENAMEThe filename parameter is invalid.
ACCESS_DENIEDPermission to access to the file location is denied.
INVALID_OFFSETCauses of the INVALID_OFFSET exception:
  • ABSOLUTE_OFFSET = NULL and RELATIVE_OFFSET = NULL, or

  • ABSOLUTE_OFFSET < 0, or

  • Either offset caused a seek past the end of the file

DELETE_FAILEDThe requested file delete operation failed.
RENAME_FAILEDThe requested file rename operation failed.
[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/70612/viewspace-1019378/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/70612/viewspace-1019378/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值