有很多时候我们可能定时的清理系统中的某个文件,可能是log或都是其它。在Oracle我们通上可以通过dbms_backup_restore.deleteFile或utl_file.fremove这两个package来实现,看下面的实例:(在下面的过程中我有安装windows的Linux的工具,所以才可以用Linux下的一些命令)
--在Oracle中两种删除OS文件的方法:
说明:
1.用dbms_backup_restore.deleteFile 可以直接指定绝对路径做删除。
2.用utl_file.fremove前必需先建立好存放文件的目录。
3.
C:Documents and SettingsAdministrator>cd
C:>touch 123.txt
C:>touch 456.txt
C:>ls |grep txt
123.txt
456.txt
C:>exit
SQL> conn / as sysdba
已连接。
SQL> create or replace directory dir1 as 'c:';
目录已创建。
SQL> begin
2 dbms_backup_restore.deleteFile('c:123.txt');
3 utl_file.fremove('DIR1','456.txt');
4 end;
5 /
PL/SQL 过程已成功完成。
SQL> host ls |grep txt
ls: File or directory "|grep" is not found
ls: File or directory "txt" is not found
SQL> host;
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:Documents and SettingsAdministrator>cd
C:>ls |grep txt
C:>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29987/viewspace-51934/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29987/viewspace-51934/