oracle utl file grant,oracle中设置UTL_FILE_DIR参数
oracle中設(shè)置UTL_FILE_DIR參數(shù)
第一步:以管理員用戶(hù)登陸
如:conn??? sys/password@sid??? as??? sysdba
第二步:設(shè)置可操作目錄
需要指定utl_file包可以操作的目錄。在oracle??? 10g以前,可以用以下方法:
1、alter??? system??? set??? utl_file_dir='e:\utl'??? scope=spfile;
長(zhǎng)路徑要使用'',如: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';
第三步:授權(quán)給指定用戶(hù),以便執(zhí)行utl_file
GRANT??? EXECUTE??? ON??? utl_file??? TO??? scott;
第四步:conn??? scott/tiger
就可以正常使用utl_file了。
第五步:文件I/O的實(shí)施
UTL_FILE包提供了很多實(shí)用的函數(shù)來(lái)進(jìn)行I/O操作,主要有以下幾個(gè)函數(shù):
fopen:打開(kāi)指定的目錄路徑的文件。
get_line:獲取指定文件的一行的文本。
put_line:向指定的文件寫(xiě)入一行文本。
fclose:關(guān)閉指定的文件。
下面利用這些函數(shù),實(shí)現(xiàn)從文件取數(shù)據(jù),然后將數(shù)據(jù)寫(xiě)入到相應(yīng)的數(shù)據(jù)庫(kù)中。
create??? or??? replace??? procedure??? loadfiledata(p_path??? varchar2,p_filename??? varchar2)??? as
v_filehandle??? utl_file.file_type;??? --定義一個(gè)文件句柄
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;
<>
null;
end??? loadfiledata;
來(lái)自 “ ITPUB博客 ” ,鏈接:http://blog.itpub.net/29519108/viewspace-2142124/,如需轉(zhuǎn)載,請(qǐng)注明出處,否則將追究法律責(zé)任。
總結(jié)
以上是生活随笔為你收集整理的oracle utl file grant,oracle中设置UTL_FILE_DIR参数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python实现获取ip、网站备案信息、
- 下一篇: 面试前一些非技术注意事项--程序员面试金