[ORA] 오라클에서 물리 디렉토리 접근방법 Create Directory
ORACLE |
2008. 2. 24. 12:05
참고 : http://www.adp-gmbh.ch/ora/sql/create_directory.html
우선 디렉토리를 마운트해야 한다.
명령은 Create Directiory
우선 디렉토리를 마운트해야 한다.
명령은 Create Directiory
【형식】예제)
CREATE [OR REPLACE] DIRECTORY 객체명 AS 경로명
• object명에 schema는 기술할 수 없다.
• directory의 길이는 30byte를 넘을 수 없다.
• path명에 file이 위치해 있는 OS의 절대경로를 기술한다.
• CREATE ANY DIRECTORY 시스템 권한이 있아야 한다.
읽어올 데이터 파일이
/temp/data
폴더라면
1. 디렉토리를 생성
SQL> conn system/manager as sysdba
SQL> create directory test_dir
2 AS '/temp/data';
2. 사용자에게 디렉도리 권한을 부여
SQL> grant read,write on directory test_dir to scott;
3. 사용자로 접속
SQL> conn scott/tiger
Connected.
create or replace directory foo_dir as '/tmp';
create directory some_dir;
grant read, write on directory some_dir to micky_mouse;
create or replace directory dir_temp as 'c:\temp';
declare
f utl_file.file_type;
begin
f := utl_file.fopen('DIR_TEMP', 'something.txt', 'w');
utl_file.put_line(f, 'line one: some text');
utl_file.put_line(f, 'line two: more text');
utl_file.fclose(f);
end;
/
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 two');
7 utl_file.fclose(fhandle);
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> !
[oracle@jumper 9.2.0]$ more /opt/oracle/utl_file/example.txt
eygle test write one
eygle test write two
[oracle@jumper 9.2.0]$
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 );
10 dbms_output.put_line(fp_buffer );
11 utl_file.fclose(fhandle);
12 end;
13 /
eygle test write one
eygle test write two
PL/SQL procedure successfully completed.
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
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