无法插入数据的第三列

时间:2019-07-04 11:37:43

标签: oracle plsql

我是PL / SQL的新手,我刚刚开始学习,我想创建一个小的软件,该软件可以将.CVS文件中的数据插入Oracle数据库。 而且我停留在从.CVS文件中获取数据的位置。 我的CVS有三列:Number_Policy,Contact,Agency Number_Policy,Contact可以成功,但是代理商无法被捕获,我也不知道为什么

.container{
   z-index:900;
   overflow:hidden;
   width: 500px; 
   height: 250px;
 }

 .container img{
   z-index:920;
   position:static;
 }

从代码中可以看到,这里有错误

declare 

   import_file text_io.file_type; 
   export_file text_io.file_type; 
   import_file_name varchar2(1000);
   export_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(20);
   p_polica varchar2(20);
   p_banka VARCHAR2(50);
   p_kontakt varchar2(20);

  kraj_fajla number;

begin
    brojac_redova:=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;

    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

    p_polica:=substr(linebuf, 1, instr(linebuf,';',1,1)-1);
  --    message(p_polica); 
    p_kontakt:=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);
  --    message(p_banka);   
    --p_kontakt:=substr(linebuf, instr(linebuf,';',1,1)+1, instr(linebuf,';',1,2) - instr(linebuf,';',1,1)-1);
    --  message(p_kontakt);  


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

         if vec_importovano = 0 then
        insert into ZIVOT_TRAJNI_NALOG_PONUDE 
        (BROJ_POLICE,BROJ_PONUDE)       
         values(
         p_polica, 
         --p_rbr, 
         p_kontakt); 
        -- p_banka);            
            commit;
        end if;     
 end if;

     EXCEPTION WHEN NO_DATA_FOUND THEN kraj_fajla := 1;         
     end;

        end loop;  
          IF p_polica IS NOT NULL
   THEN
    update zivot_trajni_nalog_ponude set BROJ_POLICE=rownum;
            commit;          

     END IF;

    text_io.fclose(import_file);
      message ('Uspjesno zavrseno');

end;

在禁用此列之后,问题是无法将列p_banka:=substr(linebuf, instr(linebuf,';',1,2)+1, instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1); -- message(p_banka); p_polica插入数据库。 如果有人知道我在哪里弄错了,我将非常感谢您的帮助。 enter image description here

1 个答案:

答案 0 :(得分:1)

看起来像linebuf只有两个分号。这段代码在我的简短测试中起作用:

if instr(linebuf,';',1,3) > 0 then 
  p_banka := substr(linebuf, 
                    instr(linebuf,';',1, 2) + 1, 
                    instr(linebuf,';',1,3) - instr(linebuf,';',1,2)-1);
else
  p_banka := substr(linebuf, 
                    instr(linebuf,';',1, 2) + 1);
end if;