Thursday, June 07, 2007

Reading a file using PL/SQL

Alright if the title sounds too infant to match your level I would suggest you skip going ahead because it is indeed not something fantastic. I am into converting some data and storing it as CLOB and the amateur that I am it needed me to do a lot of things before I could get it right. And to begin I had to first write a procedure to read data from a file. And that is what this blog contains.
Its got nothing fancy and a simple google would yield the needed info. Then the use of this blog? If thats what you were thinking....Folks googling , you will faind the info distributed. I have tried my best to put everything at one place.

I am assuming an oracle database on a windows machine;

The compact algorithm is -

Step1: Entry in your init.ora file -> utl_file_dir = dirPath

Step2: Create virtual directory mapping for oracle which points to the actual physical directory where the files are stored

Step3: Grant appropriate permissions on the virtual directory.

Step4: Create the file you would like to read thru PL/SQL, on the physical location

Step5: Write a procedure which would use the “utl_file” package of Oracle to read/write to a file

To get the details of this algo please click here