Loading csv file into Oracle

I have to use a stored procedure, not Forms, to load a csv file into Oracle 9i. SQL Loader and text_io are not options, and it must be a stand alone procedure. Some sample code with a 3 column table with a number, date and varchar2 column would be great.
mhill0531Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sapnamCommented:
The only option I can think of is using the UTL_FILE package.  Is that OK with you ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paquicubaCommented:
OK,

Here is what I have in my file named MYCSV.csv

12345,01-JAN-2006,CSV FILE

Then do this:

CREATE TABLE tab1 (col1 CLOB);

Table created.


DECLARE
v_bfile  BFILE;
v_clob   CLOB;
BEGIN
INSERT INTO tab1 (col1)
VALUES (empty_clob())
RETURN col1 INTO v_clob;
v_bfile := BFILENAME('CDIR', 'MYCSV.CSV');
Dbms_Lob.Fileopen(v_bfile, Dbms_Lob.File_Readonly);
Dbms_Lob.Loadfromfile(v_clob, v_bfile, Dbms_Lob.Getlength(v_bfile));
Dbms_Lob.Fileclose(v_bfile);
COMMIT;
END;
/

PL/SQL procedure successfully completed.


SELECT * FROM TAB1;

COL1
--------------------------------------------------------------------------------
12345,01-JAN-2006,CSV FILE

1 row selected.


SELECT TO_NUMBER(DBMS_LOB.SUBSTR(COL1,DBMS_LOB.INSTR(COL1,',')-1,1)) "NUMBER",
TO_DATE(DBMS_LOB.SUBSTR(COL1,(DBMS_LOB.INSTR(COL1,',',DBMS_LOB.INSTR(COL1,',')+1))-(DBMS_LOB.INSTR(COL1,',')+1)
,DBMS_LOB.INSTR(COL1,',')+1),'DD-MON-RRRR') "DATE" FROM TAB1
/

    NUMBER DATE
---------- -----------
     12345 01-JAN-06

1 row selected.


I don't have time to pull the varchar2, but that one should be easier than the date...

Good night


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.