Sunday 22 April 2018

Loading CLOB data into oracle table using SQL Loader


SQL Loader utility can be used to load data from flat files into oracle tables.
This utility also supports loading the content of files into LOB data type columns as well.

This utility comes handy whenever you want load huge amount of text data from files into LOB columns.

This post shows how to load the content of text file into CLOB column.

For demo purpose, let us consider we want to load content of three text files ( "1_SQL_Loader_details.txt", "2_External_table_details.txt" & "3_UTL_File_details.txt" ) into table.
So to capture the file name, and its content we might need two columns, to hold name and content respectively.



Here is the table creation script.

To load the data using SQL Loader utility, we need the data file and control file.
"Data file" contains the information on "what" to load, and "Control File" contains the information about "where & how" to load.

Given below the content of data file. (data_file.txt)

1,1_SQL_Loader_details.txt
2,2_External_table_details.txt
3,3_UTL_File_details.txt

Given below the content of control file. (control_file.ctl)

LOAD DATA
INFILE 'data_file.txt'
   INTO TABLE file_content_tab
   FIELDS TERMINATED BY ','
   (s_no    ,
    file_name    CHAR(100),
    file_data    LOBFILE(file_name) TERMINATED BY EOF)
Upon running sql loader utility for above control file, the data from data files would be read, and loaded into the target table specified.
On successful completion of load, all the contents of the file would be loaded into CLOB column.

Here is the vedio with real time example.


2 comments:

  1. how to create the control file

    ReplyDelete
  2. Control file is just a text file only.
    You just need to follow few syntax to create the control file.
    Refer to oracle documentation for syntax and details https://docs.oracle.com/cd/B19306_01/server.102/b14215/ldr_concepts.htm#i1004652

    ReplyDelete

About Me

I am Siva Jeevan.LK [LEARN | CODE | TRAIN | SHARE] Passionate to answer oracle SQL & PLSQL related questions. In my day to day job, I work with technologies including Oracle, Java, Python, MongoDB, talend and UNIX. I am passionate about "DATA", “SQL” , coding & training. In my spare time, I teach database technologies , ETL etc. I am very glad that you are reading my Profile, and I value your time as well as mine. Looking forward to see you in my videos at Siva Academy Passionate to answer oracle SQL & PLSQL related questions. You can contact me via My youtube channel (Siva Academy) or drop an email at siva.k.academy@gmail.com Happy to Learn & Help :-)

Total Pageviews