Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I am Getting invalid file operation error though file is present in my local system

Albert ChaoOct 29 2021
create or replace directory MYCSV as 'E:\sqlloader\';

grant read, write on directory MYCSV to public;

declare
   F UTL_FILE.FILE_TYPE;
   V_LINE VARCHAR2 (1000);
   V_id NUMBER(4);
   V_NAME VARCHAR2(10);
   V_risk VARCHAR2(10);
   
 BEGIN
   F := UTL_FILE.FOPEN ('MYCSV', 'testfile.csv', 'R');
  IF UTL_FILE.IS_OPEN(F) THEN
    LOOP
      BEGIN
        UTL_FILE.GET_LINE(F, V_LINE, 1000);
        IF V_LINE IS NULL THEN
          EXIT;
        END IF;
        V_id := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 1);
        V_NAME := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 2);
        V_risk := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 3);
        INSERT INTO loader_tab VALUES(V_id, V_NAME, V_risk);
        COMMIT;
      EXCEPTION
      WHEN NO_DATA_FOUND THEN
        EXIT;
      END;
    END LOOP;
  END IF;
  UTL_FILE.FCLOSE(F);
END;
/

CSV file content wherein I need to start loading from 1,a,aa and need to skip first 4 lines

portal,,
ex portal,,
,,
i_id,i_name,risk
1,a,aa
2,b,bb
3,c,cc
4,d,dd
5,e,ee
6,f,ff
7,g,gg
8,h,hh
9,i,ii
10,j,jj




Comments
Post Details
Added on Oct 29 2021
7 comments
352 views