0

I'm trying this PL/SQL program in Oracle 10g. To Read text file (data) from loaction 'C:\Oracle' and load it into Oracle Table using PLSQL script. But, I'm getting the following errors:

ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 488
ORA-29283: invalid file operation

Here's my Script:

Create or Replace PROCEDURE Rfile is
    line VARCHAR2(100);
    namesfile UTL_FILE.FILE_TYPE;
BEGIN
    --  Syntax : FOPEN ( directory alias, filename, open mode)

    namesfile  := UTL_FILE.FOPEN('FILESDIR1','NAMES2.TXT','R'); -- open in read mode 

    LOOP
      UTL_FILE.GET_LINE(namesfile,line,100);
      dbms_output.put_line(line);

      insert into names2 values(line);                  -- insert into NAMES table
    END LOOP;
EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('Others exceptions....');
END;
3

3 Answers 3

1

You can try a different approach:
Create an external table, which is a table mapped to a file, to read the file and then just insert-select to your table from the external
(or maybe you don't even need to insert it to a different table ?)

Sign up to request clarification or add additional context in comments.

Comments

0

You may need a lowercase 'r' on this line...

namesfile  := UTL_FILE.FOPEN('FILESDIR1','NAMES2.TXT','r'); -- open in read mode 
                                                       ^

1 Comment

It needs to be a lower case 'r'. You had it in uppercase in your original question.
0

Your loop does not check for end-of-file, so logically at some point the file read operation should raise an exception, and that is the one you got presumably.

Also you have to check that the directory (FILESDIR1) is pointing to the right OS directory AND you have been granted access to that directory, and the file is on that OS directory (not on your local file system).

Btw. in some cases you could better use SQL Loader to bulk load data in a table, esp. if the file is large because you can direct SQL loader to directly load the data in the datafiles, bypassing the SQL layers (generated by the INSERT statements) all together.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.