共計 1744 個字符,預計需要花費 5 分鐘才能閱讀完成。
oracle 中怎么設置 UTL_FILE_DIR 參數,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。
oracle 中設置 UTL_FILE_DIR 參數
第一步:以管理員用戶登陸
如:conn sys/password@sid as sysdba
第二步:設置可操作目錄
需要指定 utl_file 包可以操作的目錄。在 oracle 10g 以前,可以用以下方法:
1、alter system set utl_file_dir= e:\utl scope=spfile;
長路徑要使用,如:utl_file_dir= c:\my temp;
2、在 init.ora 文件中,配置如下:UTL_FILE=E:\utl 或者 UTL_FILE_DIR=E:\utl
在 oracle10g 中建議用以下方法配置:CREATE DIRECTORY utl AS E:\utl
第三步:授權給指定用戶,以便執行 utl_file
GRANT EXECUTE ON utl_file TO scott;
第四步:conn scott/tiger
就可以正常使用 utl_file 了。
第五步:文件 I / O 的實施
UTL_FILE 包提供了很多實用的函數來進行 I / O 操作,主要有以下幾個函數:
fopen: 打開指定的目錄路徑的文件。
get_line: 獲取指定文件的一行的文本。
put_line: 向指定的文件寫入一行文本。
fclose:關閉指定的文件。
下面利用這些函數,實現從文件取數據,然后將數據寫入到相應的數據庫中。
create or replace procedure loadfiledata(p_path varchar2,p_filename varchar2) as
v_filehandle utl_file.file_type; – 定義一個文件句柄
v_text varchar2(100); – 存放文本
v_name test_loadfile.name%type;
v_addr_jd test_loadfile.addr_jd%type;
v_region test_loadfile.region%type;
v_firstlocation number;
v_secondlocation number;
v_totalinserted number;
begin
if (p_path is null or p_filename is null) then
goto to_end;
end if;
v_totalinserted:=0;
v_filehandle:=utl_file.fopen(p_path,p_filename, r
loop
begin
utl_file.get_line(v_filehandle,v_text);
exception
when no_data_found then
exit;
end
v_firstlocation:=instr(v_text, , ,1,1);
v_secondlocation:=instr(v_text, , ,1,2);
v_name:=substr(v_text,1,v_firstlocation-1);
v_addr_jd:=substr(v_text,v_firstlocation+1,v_secondlocation-v_firstlocation-1);
v_region:=substr(v_text,v_secondlocation+1);
insert into test_loadfile
values (v_name,v_addr_jd,v_region);
commit;
end loop;
to_end
null;
end loadfiledata;
看完上述內容,你們掌握 oracle 中怎么設置 UTL_FILE_DIR 參數的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注丸趣 TV 行業資訊頻道,感謝各位的閱讀!