问题
I am new in Oracle PL/SQL and I am creating application which will read data from .CVS and insert into database. But problem cames when I run application, it came to the end and I get success message but the data is not inserted to database.
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;
Anyone how can help me with this, I would be very thankfull. I suppose the problem is somewhere in insert statment, since when I correct delete
statment it delete data from database but it doesn't enter data into database.
来源:https://stackoverflow.com/questions/56864181/after-read-from-cvs-file-it-doesnt-insert-data-into-database