Use utl-file to operate file in Oracle

The below is about utl_file operation:

First, you should make a directory at the path that you wish:

[jeffreyxu@rat167 ~]$ mkdir test_dir

If you want anyone has the privileges read, write and execute, you can use the command to add these privileges to this directory.

[jeffreyxu@rat167 ~]$ chmod 777 test_dir 

 


Use sys account log in oracle, and the next commands are entered by sys

[jeffreyxu@rat167 ~]$ rlwrap sqlplus sys/111111@localhost:1522/xe as sysdba;

SQL*Plus: Release 12.1.0.1.0 Production on Mon Dec 7 14:35:22 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

 
  Make a alias for the directory you have found

SQL> create or replace directory BLOBDIR as '/sandbox/test_dir';

Directory created.

 

   Add read and write privileges to the directory above on your account

 SQL> grant read,write on directory BLOBDIR to GDB;

Grant succeeded.


  Check is there this directory:

SQL> select * from ALL_DIRECTORIES;

OWNER                   DIRECTORY_NAME
------------------------------ ------------------------------
DIRECTORY_PATH
--------------------------------------------------------------------------------
SYS                   TEST_DIR
/sandbox/project/modified03-cci-09abby/match_acct_report

SYS                   XMLDIR
/u01/app/oracle/product/11.2.0/xe/rdbms/xml

SYS                   DATA_PUMP_DIR
/u01/app/oracle/admin/XE/dpdump/


OWNER                   DIRECTORY_NAME
------------------------------ ------------------------------
DIRECTORY_PATH
--------------------------------------------------------------------------------
SYS                   BLOBDIR
/sandbox/test_dir

 
  Add execute privilege to utl_file on useraccount

SQL> grant execute on utl_file to GDB;

Grant succeeded.

 

你可能感兴趣的:(Use utl-file to operate file in Oracle)