UTL_FILE 加载文件处理

create or replace procedureloadfiledata(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;

begin

  if (p_path is null or p_filename is null) then

    goto to_end;

  end if;

  /*open   specified  file*/

  v_filehandle := utl_file.fopen(p_path, p_filename, 'r'); --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_loadfilevalues (v_name, v_addr_jd,v_region);

          commit;

  end loop;

  <<to_end>>

  null;

end loadfiledata;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值