今天同事来问我一个问题,在一个新部署的9208的环境中,开发人员用UTL_FILE.fopen(file_Location, file_name, ‘W’)总是报错:
1 |
ORA-29280: invalid directory path |
UTL_FILE.fopen后面可以跟2种类型的路径,一种是直接加绝对路径,这个路径必须在utl_file_dir中设置,另一种是用create directory
该开发环境中是用第一种方式的,而且在utl_file_dir中还设置了2个路径,通过对比开发环境和生产环境,两边的设置是一模一样的,但是为什么开发环境却报错了?
经过检查,发现是设置utl_file_dir的时候设置错误,导致了该问题。我们用下面的实验来模拟此问题:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
sys@ORADG(192.168.190.241)> show parameter utl NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ utl_file_dir string /oracle/test123, /oracle/logmnr <====-修改前的值 sys@ORADG(192.168.190.241)> alter system set utl_file_dir='/oracle/test123, /oracle/logmnr' scope=spfile;<====错误的用了'xxxxx,yyyyyy'来设置,应该是'xxxxx','yyyyyyy' System altered. Elapsed: 00:00:00.01 sys@ORADG(192.168.190.241)> sys@ORADG(192.168.190.241)> sys@ORADG(192.168.190.241)> startup force ORACLE instance started. Total System Global Area 370218244 bytes Fixed Size 451844 bytes Variable Size 167772160 bytes Database Buffers 201326592 bytes Redo Buffers 667648 bytes Database mounted. Database opened. sys@ORADG(192.168.190.241)> sys@ORADG(192.168.190.241)> show parameter utl NAME TYPE VALUE ------------------------------------ ---------------------- ------------------------------ utl_file_dir string /oracle/test123, /oracle/logmnr <====修改后的值,注意此处,看上去和修改前一模一样。 sys@ORADG(192.168.190.241)> 但是测试SQL就报错了: > DECLARE 2 file_location VARCHAR2(256) := '/oracle/test123'; 3 file_name VARCHAR2(256) := 'utlfile.txt'; 4 file_text VARCHAR2(256) := 'Hello World'; 5 file_id UTL_FILE.file_type; 6 BEGIN 7 file_id := UTL_FILE.fopen(file_Location, file_name, 'W'); 8 UTL_FILE.put_line(file_id, file_text); 9 UTL_FILE.fclose(file_id); 10 EXCEPTION 11 WHEN UTL_FILE.INVALID_PATH 12 THEN dbms_output.put_line('Invalid path ' || SQLERRM); 13 WHEN OTHERS 14 THEN dbms_output.put_line('Others '|| SQLCODE || ' ' || SQLERRM); 15 END; 16 / Invalid path ORA-29280: invalid directory path <====此处就报错了。 PL/SQL procedure successfully completed. Elapsed: 00:00:00.01 > |
正确的语句应该是:
1 |
alter system set set utl_file_dir='路径1','路径2' scope=spfile; |
而不是:
1 |
alter system set set utl_file_dir='路径1,路径2' scope=spfile; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
sys@ORADG(192.168.190.241)> alter system set utl_file_dir='/oracle/test123','/oracle/logmnr' scope=spfile; System altered. Elapsed: 00:00:00.01 sys@ORADG(192.168.190.241)>--重启生效 > DECLARE 2 file_location VARCHAR2(256) := '/oracle/test123'; 3 file_name VARCHAR2(256) := 'utlfile.txt'; 4 file_text VARCHAR2(256) := 'Hello World'; 5 file_id UTL_FILE.file_type; 6 BEGIN 7 file_id := UTL_FILE.fopen(file_Location, file_name, 'W'); 8 UTL_FILE.put_line(file_id, file_text); 9 UTL_FILE.fclose(file_id); 10 EXCEPTION 11 WHEN UTL_FILE.INVALID_PATH 12 THEN dbms_output.put_line('Invalid path ' || SQLERRM); 13 WHEN OTHERS 14 THEN dbms_output.put_line('Others '|| SQLCODE || ' ' || SQLERRM); 15 END; 16 / PL/SQL procedure successfully completed. Elapsed: 00:00:00.01 > |