从.CVS文件读取后,它不会将数据插入数据库

时间:2019-07-03 06:31:45

标签: oracle plsql oracleforms

我是Oracle PL / SQL的新手,我正在创建将从.CVS读取数据并插入数据库的应用程序。 但是,当我运行应用程序时,问题就来了,它结束了,我收到了成功消息,但是数据没有插入数据库。

       declare  
    import_file text_io.file_type; 
  import_file_name varchar2(1000);

  import_log_file text_io.file_type;
  import_log_file_name varchar2(1000);

  vec_importovano number;
  brojac number;
  brojac_redova number;
  linebuf varchar2(10000);

  p_rbr varchar2(4);
  p_polica varchar2(20);
  p_banka varchar2 (20);
  p_kontakt varchar2(20);

  kraj_fajla number;

begin
        brojac_redova:=0;
        vec_importovano:=0;

    import_file_name := :Global.Lokacija_prenosa||:import.naziv_fajla||:Global.Ekstenzija_prenosa;
    import_file := text_io.fopen(import_file_name,'r');

    delete from zivot_trajni_nalog_ponude where banka is not null;
    commit;

    dbms_output.put_line(brojac_redova);

    kraj_fajla := 0;  
    while kraj_fajla = 0 loop
    begin   
    brojac_redova:=brojac_redova+1;
    text_io.get_line(import_file, linebuf);

     if brojac_redova>=2 then
         if length(linebuf)>100 then 

            p_rbr:=substr(linebuf, 1, instr(linebuf,';',1,1)-1);
            p_polica:=substr(linebuf, instr(linebuf,';',1,1)+1, instr(linebuf,';',1,2) - instr(linebuf,';',1,1)-1);
            p_banka:=substr(linebuf, instr(linebuf,';',1,2)+1, instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1);
            p_kontakt:=substr(linebuf, instr(linebuf,';',1,3)+1, instr(linebuf,';',1,4) - instr(linebuf,';',1,3)-1);

        select count(*) 
       into vec_importovano 
       from ZIVOT_TRAJNI_NALOG_PONUDE
       where broj_police=p_polica and p_rbr=redni_broj;


         if vec_importovano = 0 then
         -- dbms_output.put_line('Insert called');
        insert into ZIVOT_TRAJNI_NALOG_PONUDE(BROJ_POLICE,REDNI_BROJ,BROJ_PONUDE,BANKA) values(p_polica, p_rbr, p_kontakt, p_banka);            
            commit;
        end if;
         end if;
     end if;

     EXCEPTION WHEN NO_DATA_FOUND THEN kraj_fajla := 1;
     end;

        end loop;  
          IF p_rbr IS NOT NULL
   THEN
    update zivot_trajni_nalog_ponude set redni_broj=p_rbr;     
   END IF;

    text_io.fclose(import_file);
        message('Zavrseno prepisivanje fajla');

end;

任何人都可以为我提供帮助,我将非常感激。我认为问题出在插入语句中,因为当我更正delete语句时,它会从数据库中删除数据,但不会将数据输入数据库中。

0 个答案:

没有答案