Read text file to insert data into Oracle SQL table

前端 未结 6 2038
慢半拍i
慢半拍i 2020-12-30 16:35

I am studying Oracle SQL developer.

What I am doing is reading text file line by line from the folder. Then Inserting data to the SQL table.

I am able to com

6条回答
  •  一整个雨季
    2020-12-30 17:25

    Not sure what causing problems. For me its working fine here is my example code


    --Reference Site --https://community.oracle.com/thread/3633577?start=0&tstart=0

         set serveroutput on;
         CREATE or replace DIRECTORY USER_DIR AS '/home/oracle'; 
         GRANT READ ON DIRECTORY USER_DIR TO PUBLIC;
    
         DECLARE 
            V1 VARCHAR2(200); --32767
            F1 UTL_FILE.FILE_TYPE; 
         BEGIN 
            F1 := UTL_FILE.FOPEN('USER_DIR','temp.txt','R'); 
            Loop
            BEGIN
        UTL_FILE.GET_LINE(F1,V1); 
        dbms_output.put_line(V1);
        EXCEPTION WHEN No_Data_Found THEN EXIT; END;
            end loop;
    
            IF UTL_FILE.IS_OPEN(F1) THEN
         dbms_output.put_line('File is Open');
            end if;
    
            UTL_FILE.FCLOSE(F1); 
         END; 
         /
        set serveroutput off;
    

提交回复
热议问题