oracle的utl_file应用讨论实例
2012-05-17 10:34
295 查看
1.在本地目录中建立文件夹,F:\oracle\oracle_dir,注意在WINDOWSXP中进行实验:
2。进行创建ORACLE对应的目录,并赋于权限
SQL> create directory my_dir2 as 'F:\oracle\oracle_dir';
目录已创建。
SQL> grant read,write on directory my_dir2 to hr;
授权成功。
SQL> show parameter utl
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string f:\oracle\oracle_dr
3。编写测试UTL_File存储过程,注意与上面授权成功的用户相同HR;
Create Or Replace Procedure sal_status(
dir In Varchar2,filename In Varchar2
)Is
file utl_file.file_type;
Cursor empc Is
Select last_name,salary,department_id From employees Order By department_id;
newdeptno employees.department_id%Type;
olddeptno employees.department_id%Type:=0;
Begin
file:=utl_file.fopen(dir,filename,'w');--如果该W变为A:表示追加,可以不断改变文件名测试是不是生成不同文件,W为覆盖
utl_file.put_line(file,'report:generated on'||Sysdate);
utl_file.new_line(file);
For emp_rec In empc Loop
If emp_rec.department_id<>olddeptno Then
utl_file.put_line(file,'department:'||emp_rec.department_id);
End If;
utl_file.put_line(file,'employee:'||emp_rec.last_name||'earns:'||emp_rec.salary);
olddeptno :=emp_rec.department_id;
End Loop;
utl_file.put_line(file,'*********end of report**');
utl_file.fclose(file);
Exception
When utl_file.invalid_filehandle Then
raise_application_error(-20001,'invalid file');
When utl_file.write_error Then
raise_application_error(-200002,'unable to be write');
End;
4。调用存储过程,注意是原来定义的ORACLE中的目录名MY_DIR2;文件名随意,就命名白云飞TXT
exec sal_status('my_dir2','baiyunfei.txt');
2。进行创建ORACLE对应的目录,并赋于权限
SQL> create directory my_dir2 as 'F:\oracle\oracle_dir';
目录已创建。
SQL> grant read,write on directory my_dir2 to hr;
授权成功。
SQL> show parameter utl
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir string f:\oracle\oracle_dr
3。编写测试UTL_File存储过程,注意与上面授权成功的用户相同HR;
Create Or Replace Procedure sal_status(
dir In Varchar2,filename In Varchar2
)Is
file utl_file.file_type;
Cursor empc Is
Select last_name,salary,department_id From employees Order By department_id;
newdeptno employees.department_id%Type;
olddeptno employees.department_id%Type:=0;
Begin
file:=utl_file.fopen(dir,filename,'w');--如果该W变为A:表示追加,可以不断改变文件名测试是不是生成不同文件,W为覆盖
utl_file.put_line(file,'report:generated on'||Sysdate);
utl_file.new_line(file);
For emp_rec In empc Loop
If emp_rec.department_id<>olddeptno Then
utl_file.put_line(file,'department:'||emp_rec.department_id);
End If;
utl_file.put_line(file,'employee:'||emp_rec.last_name||'earns:'||emp_rec.salary);
olddeptno :=emp_rec.department_id;
End Loop;
utl_file.put_line(file,'*********end of report**');
utl_file.fclose(file);
Exception
When utl_file.invalid_filehandle Then
raise_application_error(-20001,'invalid file');
When utl_file.write_error Then
raise_application_error(-200002,'unable to be write');
End;
4。调用存储过程,注意是原来定义的ORACLE中的目录名MY_DIR2;文件名随意,就命名白云飞TXT
exec sal_status('my_dir2','baiyunfei.txt');
相关文章推荐
- ORACLE UTL_FILE文件包的应用,文件I/O操作
- oracle中utl_file包读写文件操作实例学习
- ORACLE UTL_FILE文件包的应用,文件I/O操作--转帖
- oracle中utl_file包读写文件操作实例学习
- ORACLE UTL_FILE文件包的应用,文件I/O操作
- ORACLE UTL_FILE文件包的应用,文件I/O操作
- ORACLE UTL_FILE文件包的应用,文件I/O操作
- 应用开发框架讨论-应用配置-wxFileConfig
- java下OracleHelper包的应用实例
- Oracle内建包UTL_FILE使用说明
- oracle分析函数row_number的实例应用
- lsof 应用实例分享以及Oracle 数据文件删除恢复测试
- Makfile 应用进阶实例
- Unix/Linux下删除Oracle控制文件Controlfile为什么实例Instance没有立即奔溃?
- oracle中utl_file包读写文件操作学习
- Oracle UTL_FILE的使用
- oracle用PLSQL把表数据写到excel的例子(UTL_FILE)
- 用oracle utl_file包读取数据写入文件
- 使用pfile 启动oracle 实例时,启动失败---db_recovery_file_dest參数值在os上不存在。