Print Friendly, PDF & Email

 
REQUEST

I want to remove a file through PL/SQL block

 
RELATED

 
TESTCASE

To remove a file you need FREMOVE procedure from the UTL_FILE package and sufficient privileges on a file

oracle@dbpilot.net: ls -lh /tmp/dir2/ --time-style='+'
total 4.0K
-rw-r--r-- 1 oracle oinstall 35  myfile.cloned.txt
SET SERVEROUTPUT ON
BEGIN
   UTL_FILE.FREMOVE('DIR2', 'myfile.cloned.txt');
END;
/
oracle@dbpilot.net: ls -lh /tmp/dir2/ --time-style='+'
total 0

If a file does not exist or you don’t have sufficient privileges you will get a following error

SET SERVEROUTPUT ON
BEGIN
   UTL_FILE.FREMOVE('DIR2', 'nonexistingfile.txt');
END;
/

BEGIN
*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 251
ORA-06512: at "SYS.UTL_FILE", line 1230
ORA-06512: at line 2

For more details refer to the official documentation.

 
 

Version  : 14:11 18.01.2018
Platform : Red Hat 5.11
Database : Oracle database 12.1.0.1.0