xpdp system/manager@my_db_alias DUMPFILE=expdp_s.dmp
LOGFILE=expdp_s.log SCHEMAS=scott
如果SCOTT用户不是授权用户,不能使用默认的DATA_PUMP_DIR。
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39145: directory object parameter must be specified and non-null
用户SCOTT的解决方法:如上面5.3,SCOTT可以设置环境变量DATA_PUMP_DIR为MY_DIR:
-- On windows, place all expdp parameters on one single line:
C:\> set DATA_PUMP_DIR=MY_DIR
C:\> expdp scott/tiger@my_db_alias DUMPFILE=expdp_s.dmp
LOGFILE=expdp_s.log SCHEMAS=scott
或者这种特定场景下,用户SCOTT也可以有目录DATA_PUMP_DIR的读和写权限:
-- On windows, place all expdp parameters on one single line:
C:\> set DATA_PUMP_DIR=DATA_PUMP_DIR
C:\> expdp scott/tiger@my_db_alias DUMPFILE=expdp_s.dmp
LOGFILE=expdp_s.log SCHEMAS=scott
实验:
创建目录:CREATE DIRECTORY UTL_FILE_DIR AS '/oracle/backup';
向用目录对象标识的文件写内容:
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, 'test write one');
6 utl_file.put_line(fhandle, 'test write two');
7 utl_file.fclose(fhandle);
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> !
ora10g@vm-vmw4131-t$ more /oracle/backup/example.txt
test write one
test write two
读取使用目录对象DIRECTORY标识的文件内容: 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 utl_file.get_line(fhandle, fp_buffer);
7 dbms_output.put_line(fp_buffer);
8 utl_file.get_line(fhandle, fp_buffer);
9 dbms_output.put_line(fp_buffer);
10 utl_file.fclose(fhandle);
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> /
PL/SQL procedure successfully completed.
此时没有任何输出,设置serveroutput: SQL> set serveroutput on
SQL> /
test write one
test write two
PL/SQL procedure successfully completed.
打印文件内容。
DIRECTORY的目就在于可以让我们在Oracle中灵活地对文件系统中的文件进行操作。
?