Read text file into clob column

Dear Oracle users and Oracle support,
I have a text file that includes hundreds of data entries. The format is below. What I need to do is read each entry (
<DATALOAD ................</DATALOAD>) into the CLOB column as a table record. Then create a loop in the table to convert each record into XML data type. I have general idea on how to convert CLOB to XML. The difficult part to me is read the each entry in the text file to CLOB table. Please let me know what technique I should use. Any recommendation and sample code are welcome! I appreciate!
Thanks,
Bing
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>

RBYL wrote:
Hi,
Thank you for your response. What I want to achieve is read the text file into ClOB column. There are hundreds reocords in the text file. The format is below. Each entry is '<DATALOAD (sensitive data here, use....... instead)</DATALOAD>' that needs to be read into clob table as a record. That is basically what I need to achieve.
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>
hundreds of them here........
<DATALOAD ................</DATALOAD>
<DATALOAD ................</DATALOAD>So, is it really a text file or is it a well structured XML file?
Just reading it into a CLOB to process is not likely to be the best way.
If each line of the file is a record, then you're likely to be better using something like External Tables.
If it's a structured XML file, then it can be read using CLOB functionality into an XMLTYPE datatype and then shredded down into relational table structures.
Be more clear in what your requirements are and we can help you better.
{message:id=9360002}

Similar Messages

  • Fetching a text file into CLOB column in Oracle!

    Can anyone please help me to find out how to fetch a text file present on the network on to the CLOB column in Oracle 8i?
    I dont want to use BFILE for this.
    Please help its urgent.
    Love
    Prathab
    null

    Prathab,
    This is an example from the SQL package doc for DBMS_LOB, that reads from a bfile, and store in a lob.
    CREATE OR REPLACE PROCEDURE Example_l2f IS
    lobd BLOB;
    fils BFILE := BFILENAME('SOME_DIR_OBJ','some_file');
    amt INTEGER := 4000;
    BEGIN
    SELECT b_lob INTO lobd FROM lob_table WHERE key_value = 42 FOR UPDATE;
    dbms_lob.fileopen(fils, dbms_lob.file_readonly);
    dbms_lob.loadfromfile(lobd, fils, amt);
    COMMIT;
    dbms_lob.fileclose(fils);
    END;
    Hope it helps.
    Eric
    null

  • How to read/write .CSV file into CLOB column in a table of Oracle 10g

    I have a requirement which is nothing but a table has two column
    create table emp_data (empid number, report clob)
    Here REPORT column is CLOB data type which used to load the data from the .csv file.
    The requirement here is
    1) How to load data from .CSV file into CLOB column along with empid using DBMS_lob utility
    2) How to read report columns which should return all the columns present in the .CSV file (dynamically because every csv file may have different number of columns) along with the primariy key empid).
    eg: empid report_field1 report_field2
    1 x y
    Any help would be appreciated.

    If I understand you right, you want each row in your table to contain an emp_id and the complete text of a multi-record .csv file.
    It's not clear how you relate emp_id to the appropriate file to be read. Is the emp_id stored in the csv file?
    To read the file, you can use functions from [UTL_FILE|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#BABGGEDF] (as long as the file is in a directory accessible to the Oracle server):
    declare
        lt_report_clob CLOB;
        l_max_line_length integer := 1024;   -- set as high as the longest line in your file
        l_infile UTL_FILE.file_type;
        l_buffer varchar2(1024);
        l_emp_id report_table.emp_id%type := 123; -- not clear where emp_id comes from
        l_filename varchar2(200) := 'my_file_name.csv';   -- get this from somewhere
    begin
       -- open the file; we assume an Oracle directory has already been created
        l_infile := utl_file.fopen('CSV_DIRECTORY', l_filename, 'r', l_max_line_length);
        -- initialise the empty clob
        dbms_lob.createtemporary(lt_report_clob, TRUE, DBMS_LOB.session);
        loop
          begin
             utl_file.get_line(l_infile, l_buffer);
             dbms_lob.append(lt_report_clob, l_buffer);
          exception
             when no_data_found then
                 exit;
          end;
        end loop;
        insert into report_table (emp_id, report)
        values (l_emp_id, lt_report_clob);
        -- free the temporary lob
        dbms_lob.freetemporary(lt_report_clob);
       -- close the file
       UTL_FILE.fclose(l_infile);
    end;This simple line-by-line approach is easy to understand, and gives you an opportunity (if you want) to take each line in the file and transform it (for example, you could transform it into a nested table, or into XML). However it can be rather slow if there are many records in the csv file - the lob_append operation is not particularly efficient. I was able to improve the efficiency by caching the lines in a VARCHAR2 up to a maximum cache size, and only then appending to the LOB - see [three posts on my blog|http://preferisco.blogspot.com/search/label/lob].
    There is at least one other possibility:
    - you could use [DBMS_LOB.loadclobfromfile|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998978]. I've not tried this before myself, but I think the procedure is described [here in the 9i docs|http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl12bfl.htm#879711]. This is likely to be faster than UTL_FILE (because it is all happening in the underlying DBMS_LOB package, possibly in a native way).
    That's all for now. I haven't yet answered your question on how to report data back out of the CLOB. I would like to know how you associate employees with files; what happens if there is > 1 file per employee, etc.
    HTH
    Regards Nigel
    Edited by: nthomas on Mar 2, 2009 11:22 AM - don't forget to fclose the file...

  • USING WEBUTIL TO READ TEXT FILE INTO TABLE HANGS AFTER CERTAIN NUMBER OF RE

    Dear
    when we use webutil to retrieve data from text file into database table
    (using text_io) it hangs after certain number of records ( approx. 1300
    records) while the total number of records to be inserted in the table exceeds
    12000 records while it works properly on forms6i with the normal text_io any
    help please...?
    thanks and regards

    WebUtil uploads the files as Binary - so yes you could have some issues if you have a Unix host - however, that would only mean that there is an extra character to trim off of the end of the line read by Text_io.

  • Reading text file into array

    Hi, I'm reading a text file that is as follows:
    7
    5.5
    15
    5.35
    30
    6.5
    I have the file reading in fine, but am extremely confused on how to read each line to read into a different variable.
    the whole numbers are the term of a loan and the doubles are the interest rate.
    I have read through several of the existing posts on reading the file, but am still have problems.
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    public class ReadFile extends JFrame
         public static void main (String[] arguments) throws IOException
                   String line;            
                    BufferedReader input;
                   input = new BufferedReader (new FileReader ("MortgageValues.txt"));
                   String Term;
                   String Rate;
                        while ((line = input.readLine()) != null)
                      Term = input.readLine ();
                           System.out.println(line);
              input.close ();
    }     

    the whole numbers are the term of a loan and the
    doubles are the interest rate.Oh! Your problem seems to be reading alternate values. Here's a piece of code for that :)
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    public class Test7 {
        public static void main(String[] args) throws Exception {
            String line        = null;
            int count          = 0;
            StringBuffer Term  = new StringBuffer();
            StringBuffer Rate  = new StringBuffer();
            BufferedReader input = new BufferedReader (new FileReader ("MortgageValues.txt"));
            while ((line = input.readLine()) != null) {
                if(count%2 == 0) Term.append(line).append(",");
                else        Rate.append(line).append(",");
                count++;
            Term.deleteCharAt(Term.length() -1);
            Rate.deleteCharAt(Rate.length() -1);
            System.out.println("Term>>>" +Term);
            System.out.println("Rate>>>" +Rate);
            input.close ();
    }

  • Reading Text file into JEditorPane

    Hi i want to read a text file in to JEditorPane. one way is to read the whole file and make it a string and then display it. but i want to read directly form file into JEditor pane. Please help me to do that
    -Ashish

    Plz don't Reply
    i am able to do it on my own here is the sample code for that
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import javax.swing.text.*;
    // this is a function u can use it in a class
    private void addEditScroll(){
    try{
    BufferedReader infile = new BufferedReader(new FileReader("c:\\WS_FTP.log"));
    editor =new JEditorPane();
    editor.setEditable(false);
    editor.read(infile,new PlainDocument());
    editor.setSize(new Dimension(450,510));
    editorscroll = new JScrollPane(editor);
    editorscroll.setSize(new Dimension(450,510));
    }catch(Exception ex){
    ex.printStackTrace();
    -ashish

  • Reading Xml file from clob column in the staging table

    Hi,
    I am trying to poll the staging table with the database adapter which has CLOB column type containing XML file. How do I extract the XML file from CLOB and map the fields to the another variable with definite schema.
    Thanks,
    Edited by: chaitu123 on Sep 20, 2009 8:16 AM

    1) when you create DBAdapter on a table which having the clob column watch closely the created xsd for the DBAdapter the clob cloumn element should be a String data type
    2) create xsd for Xml File and create variable for the xsd element
    3) use ora:parseEscapedXML("yourDBAdapterclobElement") to XmlFileVarilable
    Krishna

  • Still having trouble with reading text file into array

    Hi, This is from another post, I have tried one of the solutions that were provided, but got the following error at runtime:
    C:\j24work>java Test7
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException
    at java.lang.StringBuffer.deleteCharAt(StringBuffer.java:681)
    at Test7.main(Test7.java:26)
    My code is attached. My text file reads as follows:
    7 5.5 15 5.35 30 6.5
    The first , third and fifth numbers should ultimately be int values representing the term of a mortgage. The second, fourth and sixth numbers ultimately need to be doubles representing the rate on a mortgage. Do I need a 2d array??
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    public class Test7 {
        public static void main(String[] args) throws Exception {
            String line        = null;
            int count   = 0;
            StringBuffer Term  = new StringBuffer();
            StringBuffer Rate  = new StringBuffer();
            BufferedReader input = new BufferedReader (new FileReader ("MortgageValues.txt"));
            while ((line = input.readLine()) != null) {
                if(count%2 == 0) Term.append(line).append(",");
                else        Rate.append(line).append(",");
                count++;
            Term.deleteCharAt(Term.length() -1);
            Rate.deleteCharAt(Rate.length() -1);
            System.out.println("Term>>>" +Term);
            System.out.println("Rate>>>" +Rate);
           // input.close ();
        }

    Okay, modify the code as below:
    import java.io.*;
    import java.util.*;
    public class Test7 {
        public static void main(String[] args) throws Exception {
            String line             = null;
            StringTokenizer strTok  = null;
            int count          = 0;
            StringBuffer term  = new StringBuffer();
            StringBuffer rate  = new StringBuffer();
            BufferedReader input = new BufferedReader (new FileReader ("MortgageValues.txt"));
            while ((line = input.readLine()) != null) {
                strTok = new StringTokenizer(line);
                while(strTok.hasMoreTokens()) {
                    if(count%2 == 0)    term.append(strTok.nextToken()).append(",");
                    else                rate.append(strTok.nextToken()).append(",");
                    count++;
            term.deleteCharAt(term.length() -1);
            rate.deleteCharAt(rate.length() -1);
            System.out.println("term>>>" +term);
            System.out.println("rate>>>" +rate);
           input.close ();
    }Cheers!
    ***Annie***

  • How to read some records from a text file into java(not all records)

    hello,
    how to read text files into java. i need only few records from the text file not all records at a time.
    If any one knows plz reply me
    my id is [email protected]

    this snipet reads a text file line by line from line 1 to 3
    try {
                  FileReader fr = new FileReader(directory);
                  BufferedReader br = new BufferedReader(fr);
                  int counter = 0;
                  while ((dbconn = br.readLine()) != null) {
                      switch(counter){
                          case 0:
                            status = dbconn;
                          break;
                          case 1:
                            userName = dbconn;
                          break;
                          case 2:
                            apword = dbconn;
                          break;
                      counter++;
                  br.close();
        }catch(IOException e){
        }

  • Error while inserting .doc file into CLOB object in oracle

    hello everybody ,
    i am trying to insert .doc file into clob column in oracle database.i am using oracle 8i. But i am getting error saying
    ORA-01461: can bind a LONG value only for insert into a LONG column
    i have no clue.
    i am pasting code here
    please help me out.
    regards
    darshan
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileReader;
    import java.io.Reader;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    public class InsertingClob {
    public static void main(String[] args) {
    File f = new File("E:\\dar
    sowres.doc");
    int len = (int) f.length();
    System.out.println(len);
    Connection conn = null;
    PreparedStatement ps = null;
    try {
    FileReader fr = new FileReader(f);
    String FILE_INSERT_QUERY = "INSERT INTO RESUMED VALUES(?,?)";
    conn = JDBCUtility.getConnection();
    ps = conn.prepareStatement(FILE_INSERT_QUERY);
    ps.setString(1,"1");
    ps.setCharacterStream(2,fr,len);
    int result = ps.executeUpdate();
    if(result ==1) {
    System.out.println("file has been successfully inserted into the db");;
    }else {
    System.out.println("not inserted");
    }catch (Exception e) {
    e.printStackTrace();
    and the error is
    java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1144)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2152)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2035)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2876)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
    at InsertBlob.main(InsertBlob.java:21)
    java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column

    You may have one of a few errors going for you there:
    The error says your column in Oracle is a Long not a CLOB, if it is, then make your column a CLOB.
    CLOB's are not suppored in all environments and/or all interfaces (specifically Windoz ODBC has a problem).
    I believe a DOC (Windoz MS-Word) file is a BLOB, due to formatting characters in the file.
    I had a very similar error using Access and trying to do this, but changing to SAS fixed the problem. It could very well be that your version of ODBC/JDBC drivers does not support it properly.

  • Load & retrieve text files from lob column

    Dear All,
    I have created a table with CLOB column in it.
    Now I have to inset text files into that column and retrieve the file/ file contents from that column through stored proc.
    Can u please tell me how can i do that??
    Thank you,
    Gautam

    Examine two packages, Dbms_Lob and Utl_File. You are building your file from clob 'piece-by-piece' until you reach the end of clob.
    Pseudo
    - open file for writing (utl_file)
    - get the length of clob
    - get first part of clob (dbms_lob.substr)
    - apend part of clob (from previous) to the file
    - while not end of clob repeat previous two steps

  • Read text file and insert into MySQL

    Dears,
    I need to read text file and then insert the data in the correct column in the MySQL database
    example
    I have the following text file:
    field1=1234 field2=56789 field3=444555
    field1=1333 field2=2222 field3=333555
    and so on and so forth ,,note that all rows are identical and just the filed value is changed(there is a dilemeter between fields)
    how can I read field1,field2 and field3 from text file and insert them in the correct table and column in the database.....
    any help?????
    thanks for your cooperation
    Best Regars

    Sure.
    Which part don't you understand?
    1. Reading a text file
    2. Parsing the text file contents.
    3. Relational databases and SQL.
    4. How to create a database.
    5. How to connect to a database in Java.
    6. How to insert records into the database in Java.
    7. How to map Java objects to records in a database.
    This is a pretty nice list. Solve complex problems by breaking them into smaller ones.
    %

  • Open and read from text file into a text box for Windows Store

    I wish to open and read from a text file into a text box in C# for the Windows Store using VS Express 2012 for Windows 8.
    Can anyone point me to sample code and tutorials specifically for Windows Store using C#.
    Is it possible to add a Text file in Windows Store. This option only seems to be available in Visual C#.
    Thanks
    Wendel

    This is a simple sample for Read/Load Text file from IsolateStorage and Read file from InstalledLocation (this folder only can be read)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Windows.Storage;
    using System.IO;
    namespace TextFileDemo
    public class TextFileHelper
    async public static Task<bool> SaveTextFileToIsolateStorageAsync(string filename, string data)
    byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(data);
    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
    var file = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
    try
    using (var s = await file.OpenStreamForWriteAsync())
    s.Write(fileBytes, 0, fileBytes.Length);
    return true;
    catch
    return false;
    async public static Task<string> LoadTextFileFormIsolateStorageAsync(string filename)
    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
    string returnvalue = string.Empty;
    try
    var file = await local.OpenStreamForReadAsync(filename);
    using (StreamReader streamReader = new StreamReader(file))
    returnvalue = streamReader.ReadToEnd();
    catch (Exception ex)
    // do somthing when exception
    return returnvalue;
    async public static Task<string> LoadTextFileFormInstalledLocationAsync(string filename)
    StorageFolder local = Windows.ApplicationModel.Package.Current.InstalledLocation;
    string returnvalue = string.Empty;
    try
    var file = await local.OpenStreamForReadAsync(filename);
    using (StreamReader streamReader = new StreamReader(file))
    returnvalue = streamReader.ReadToEnd();
    catch (Exception ex)
    // do somthing when exception
    return returnvalue;
    show how to use it as below
    async private void Button_Click(object sender, RoutedEventArgs e)
    string txt =await TextFileHelper.LoadTextFileFormInstalledLocationAsync("TextFile1.txt");
    Debug.WriteLine(txt);
    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

  • Reading String (Name-Value) from text file into XML

    Hi,
    I have a requirement for reading a text file and converting each entry of that text file into XML format. I have not came across such thing yet so looking for some ideas. I am using SQL Server 2005 and here is a sample entry from my source text file,
    Jun 4 14:31:00 zzzz64x02 fff:
    INPUT(ty=XYZ,Prefix=15063,dn=78787878787878,sgk=100.139.201.48,xxn=87878,ani=656565656565,ogrp=F7ZX05,ogtxt=NNNNN,ogx=NNNNN,oci=0xe00ac,ogi={NOA=INT,BC=1,SIG-TYPE=ZIP});
    PROCESS(ty=0x100000,cu=32880,Name=XOXOXOX,pc=88017,pd=24,dd=880175,pk=880175,rd=115472,ca=BGD,reg=RW,cdp=1,ai=245359,grp=2648,sl=9);
    OUTPUT(ty=XXXX,ret=0,rl=
    {i=1,su=99999,rizID=61084,skid=06,truckgp=1084,dd=8801,dn=78787878787878}
    I will get multiple entries like this in my source text file which I have to convert into XML (using TSQL).
    Any help will be useful.
    Regards.
    'In Persuit of Happiness' and ..... learning SQL.

    And I'm telling you that this is a bad option. You would use the vaccum cleaner to wash the dishes, would you?
    If you for some reason would do this task in SQL Server, you would implement it as a CLR stored procedure, but from what you have said I don't understand why you would do this server-side at all.
    What's wrong with the current C# solution?
    Erland Sommarskog, SQL Server MVP, [email protected]
    Got it.  I was just looking for the available options, nothing wrong with my C# solution. And yes, I don't use vacuum cleaner to wash dishes.
    'In Persuit of Happiness' and ..... learning SQL.

  • How to read a whole text file into a pl/sql variable?

    Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?

    how to read a whole text file into a pl/sql variable?
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....

Maybe you are looking for

  • HT201272 How do I get my music to play after iMatch?

    I just purchased new computer and transfered all info from one iMac to new iMac. Now I'm unable to play music because iTunes can't locate music. I'm not able to download previously purchased music/movies because a "downloaded" button is showing on ea

  • Parallel Processing in OATS

    Hi all, I'd like to know whether it's possible to kick off (start) multiple processes from within an OATS script, so that they run in parallel to the process that started them.  I'm trying to simulate the real life scenario of a number of process str

  • Delete on the basis of date

    Hi All, I need to delete data from a table based on a date column. If the date in DATE column is 180 days old than current sysdate then it should delete otherwise not. So i found out below two ways 1. Use sysdate-tab_date >180 in where clause 2. Use

  • Sending a text mail for different user in

    Hi Abapers, I am trying to use function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send a Text mail like "Purchase order is pending" .But how i can send a text mail . Here we are not attach any document only the text message we need to different mail id

  • Backup assistant My Verizon freezes does not load

    When I click on the MY VERIZON - BACKUP link, the page changes to the Backup Assistant Plus, a menu appears but quickly disappears, leaving only the 2 tabs at the top (CONTACTS & TRASH).  Then the REFRESH /RELOAD icon (2 circling arrows) comes up & n