ORACLE Directory directory--Reprint

Source: Internet
Author: User
Tags create directory

Create directory gives us the flexibility to read and write files in an Oracle database, greatly improving the ease of use and scalability of Oracle.
Its syntax is:
CREATE [OR REPLACE] Directory directory as 'pathname';

This case is specifically created as follows:

Create or replace directory Exp_dir as '/tmp ';

After the directory is created, you can grant read and write permissions to specific users, with the following syntax:
GRANT Read[,write] on the directory directory to username;

For example:

Grant read, write on directory exp_dir to Eygle;

At this point, the user eygle has read and write access to the directory.

Let's look at a simple test:

sql> Create or replace directory Utl_file_dir as '/opt/oracle/utl_file '; Directory created. Sql> declare 2 fhandle utl_file.file_type; 3 begin 4 Fhandle: = Utl_file.fopen (' Utl_file_dir ', ' example.txt ', ' W '); 5 utl_file.put_line (fhandle, ' eygle test write one '); 6 utl_file.put_line (fhandle, ' eygle test write '); 7 Utl_file.fclose (fhandle); 8 end; 9 / PL/SQL procedure successfully completed. Sql>! [[email protected] 9.2.0]$ more/opt/oracle/utl_file/example.txt eygle Test write one eygle test write Two [[email protected] 9.2.0]$

Similarly we can read the file via Utl_file:

Sql> declare 2 fhandle utl_file.file_type; 3 fp_buffer varchar2 (4000); 4 begin 5 Fhandle: = Utl_file.fopen (' Utl_file_dir ', ' example.txt ', ' R '); 6 7 utl_file.get_line (Fhandle, fp_buffer); 8 Dbms_output.put_line (fp_buffer); 9 utl_file.get_line (Fhandle, fp_buffer); Ten Dbms_output.put_line (fp_buffer); Utl_file.fclose (fhandle); The end; / eygle Test write one eygle test write, PL/ SQL procedure successfully completed.

You can query dba_directories to see all your directory.

Sql> select * from Dba_directories; OWNER directory_name directory_path -------------------------------------------------------------- ---------------------------- sys utl_file_dir /opt/oracle/utl_file sys Bdump_dir / Opt/oracle/admin/conner/bdump SYS exp_dir /opt/oracle/utl_file

You can use drop directory to delete these paths.

sql> Drop directory Exp_dir; Directory dropped sql> select * from Dba_directories; OWNER directory_name directory_path -------------------------------------------------------------- ---------------------------- sys utl_file_dir /opt/oracle/utl_file sys Bdump_dir / Opt/oracle/admin/conner/bdump

ORACLE Directory directory--Reprint

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.