Exforsys

H I D E

Home arrow Technical Training arrow Oracle 11g Tutorial

UTL_FILE Page - 5

Page 5 of 5
Author: Saurabh Gupta     Published on: 10th Aug 2011

UTL_FILE

FCOPY and FREMOVE

The screen dump below shows the file structure information of the directory UTLDIR.

Now, as per the requirement, I need to make a copy of Demo_file.txt in the same directory. The PL/SQL block below achieves the purpose.

Sample Code
  1. DECLARE
  2. LH UTL_FILE.FILE_TYPE
  3. L_TXT VARCHAR2(1000)
  4. BEGIN
  5. UTL_FILE.FCOPY('UTLDIR','Demo_file.txt','UTLDIR','Demo_file_moved.txt')
  6. EXCEPTION
  7. WHEN NO_DATA_FOUND THEN
  8. UTL_FILE.FCLOSE(LH)
  9. END
  10. PL/SQL procedure successfully completed.
Copyright exforsys.com


Check the UTLDIR new file structure as below.

Similarly, FREMOVE is used to delete a file from a directory.

Sample Code
  1. DECLARE
  2. LH UTL_FILE.FILE_TYPE
  3. L_TXT VARCHAR2(1000)
  4. BEGIN
  5. UTL_FILE.FREMOVE('UTLDIR','Demo_file_moved.txt')
  6. EXCEPTION
  7. WHEN NO_DATA_FOUND THEN
  8. UTL_FILE.FCLOSE(LH)
  9. END
Copyright exforsys.com


Ads

Conclusion

In the tutorial, we saw the strength of the UTL_FILE operations. For static OS file management systems, UTL_FILE is one of the most frequent used utility in Oracle, where tasks like data loading and file operations can be easily carried out.

Read Next: Manage Oracle dependencies


 
This tutorial is part of a Oracle 11g Tutorial tutorial series. Read it from the beginning and learn yourself.

Oracle 11g Tutorial

 

Comments