How to Export The Table with a CLOB Column Into a CSV File using UTL_FILE ? (Doc ID 1967617.1)

0    1092    1

Tags:

👉 本文共约4745个字,系统预计阅读时间或需18分钟。

How to Export The Table with a CLOB Column Into a CSV File using UTL_FILE ? (Doc ID 1967617.1)

GOAL

How to Export The Table with a CLOB Column Into a CSV File using UTL_FILE ?

Below is the sample PL/SQL function to export the table data into a CSV File.
This solution takes data from a table with CLOB column and writes it to a csv file using the UTL_FILE built-in package.
Note that UTL_FILE has a limit of 32K, so that combined length of all the columns in a row should be less than or equal to 32k.

SOLUTION

1)Login to the DB user

2)Create a sample table

3)Insert the sample data into to the above table TESTCLOB

4)Check the sample data.

5)Create a PL/SQL directory object pointing to a Valid physical directory in the database server where csv file is created and make sure that this directory has proper write permission to Oracle user.

6)Create the below function to export the table data into a CSV File.

7)Execute the PL/SQL function export_table_to_csv_file as below :

8)Now got to the physical directory and check the file csvsample.csv

How to migrate BLOB/CLOB data from Oracle to MySQL (Doc ID 2479980.1)

GOAL

To provide how to migrate BLOB/CLOB data from Oracle to MySQL

SOLUTION

For BLOB type, it is possible to migrate by converting it to a hexadecimal character string and then loading it.

When dumping BLOB data from Oracle, please write to CSV with the converted value in hexadecimal.

(In general, you can use rawtohex() in a stored procedure to change BLOB to HEX. However, this document is managed by the MySQL support team and we are not covered Oracle DB. If you have any questions in the dump process of the Oracle DB side, please contact Oracle DB support.)

When loading on the MySQL side, use UNHEX function to return from binary to hexadecimal.

The following is an example in the LOAD DATA statement. We set UNHEXed value using SET in longblog type column.

mysql> CREATE TABLE (id int, data longblob);

mysql> LOAD DATA LOCAL INFILE '/path/to/test.mycsv'
INTO TABLE test
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\'
LINES TERMINATED BY '\ n'
(id, @ col2) SET data = UNHEX (@ col2);

How to export data from Oracle:

The following link will be useful.

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信dbaup66,谢谢!
AiDBA后续精彩内容已被站长无情隐藏,请输入验证码解锁本文!
验证码:
获取验证码: 请先关注本站微信公众号,然后回复“验证码”,获取验证码。在微信里搜索“AiDBA”或者“dbaup6”或者微信扫描右侧二维码都可以关注本站微信公众号。

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复