| 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; /*open specified file*/ 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; / |
| CREATE TABLE TEST_LOADFILE ( NAME VARCHAR2 (100) NOT NULL, ADDR_JD VARCHAR2 (20), REGION VARCHAR2 (6) ) ; |
| declare v_path varchar2(200); v_filename varchar2(200); begin v_path:='F: '; v_filename:='地址信息.txt'; loadfiledata(v_path,v_filename); end; / |
4. 小结
Oracle本身提供了大量使用的包,如UTL_HTTP包,DBMS_OUTPUT包等,这些包分别封装了不同的功能,它们使得进行大量的应用程序开发的可能,从而拓展了Oracle的功能。
用户评论