How can I populate the columns with data from a text file, where each line is a different column? The text file looks like this:
Amsterdam Aalsmeerweg
Aalsmeerweg
14
Amsterdam
NL
1059NJ
0204122131
Amsterdam Bos en Lommerweg
Bos en Lommerweg
215
AMSTERDAM
NL
1055DT
0206847676
Amsterdam Ceintuurbaan
Ceintuurbaan
314
AMSTERDAM
NL
1072GL
0204705292
This post didn't help me.
My code looks like this:
set serveroutput on;
CREATE or replace DIRECTORY USER_DIR AS '/home/renejanssen/';
GRANT READ ON DIRECTORY USER_DIR TO PUBLIC;
declare
V1 VARCHAR2(200);
F1 UTL_FILE.FILE_TYPE;
f_name WINKEL.NAAM%type;
f_adres varchar2(255);
f_homenr WINKEL.HUISNR%TYPE;
f_city varchar2(100);
f_countrcode varchar(255);
f_zipcode WINKEL.POSTCODE%TYPE;
f_phonenr WINKEL.TELNR%TYPE;
v_counter number DEFAULT 1; --counter for ID
BEGIN
F1 := UTL_FILE.FOPEN('USER_DIR','test','R');
Loop
BEGIN
UTL_FILE.GET_LINE(F1,V1);
dbms_output.put_line(v_counter || ' = ' || V1);
EXCEPTION WHEN No_Data_Found THEN EXIT;
dbms_output.put_line('niets');
END;
f_name := substr(V1,1);
f_adres := substr(V1,1);
f_homenr := substr(V1,1);
f_countrcode := substr(V1,1);
f_zipcode := substr(V1,1);
insert INTO WINKEL (ID, NAAM, HUISNR, POSTCODE, TELNR )
values(v_counter, f_name, f_homenr, f_zipcode, f_phonenr);
v_counter := v_counter +1;
end loop;
IF UTL_FILE.IS_OPEN(F1) THEN
dbms_output.put_line('File is Open');
end if;
UTL_FILE.FCLOSE(F1);
END;