vvekselva
vvekselva

Reputation: 823

Oracle Data Backup

I'm using Oracle 11g. I wanted to move certain records from a table to a flat file. Is there are any utility to do the same like sqlldr. I created unix scripts to do the same but it was not doing the purpose. Please Help

Upvotes: 0

Views: 59

Answers (1)

Dileep
Dileep

Reputation: 664

You Can use UTL_FILE package for loading all the table data to flat file. Here is the sample code for that

DECLARE
    p_file      util_file.file_type;
    l_table     your_table_name.ROWTYPE;
    l_delimited VARCHAR2(1) := '|';
BEGIN
    p_file := utl_file.Fopen('<file_path>', '<file_name>', 'W');

    FOR l_table IN (SELECT *
                    FROM  your_table_name) LOOP
        utl_file.Putline(p_file, l_table.col1
                                 ||l_delimited
                                 ||l_table.col2
                                 ||l_delimited
                                 ||l_table.col3
                                 ||l_delimited
                                 ||l_table.col4
                                 ||Chr(10));
    END LOOP;

    utl_file.Fclose_all();
END; 

Check Oracle documentation on the package

Upvotes: 1

Related Questions