Export SQLPlus to CSV (output format problem)

I ran into a problem with the script interface, which should export the contents of some ORACLE database table to a CSV file, followed by import of these CSVs into the MYSQL database.

STEP1: Export SQLPlus to CSV

set headsep off  
set heading off
set term off
set echo off
SET  RECSEPCHAR \n
set pagesize 0
set linesize 0
trimspool on
SET FEEDBACK OFF
spool as_ex_feature.csv
select '"AS'||'"|"'||feature_group||'"|"'||feature_desc||'"|"
    ||feature_order||'"|"'||prod_code||'"'
from MYVIEW WHERE MYCONDITIONS;
spool off;

-> this step generates a CSV file, but the format seems to be wrong, since I can find the carriage return in the output. You will also see in STEP2 that we define the value "ENCLOSED BY", how can I get the one that is included in the export format (it seems that this is not the case now).

STEP 2: loading MYSQL

LOAD DATA INFILE 'mycsvfile' REPLACE INTO TABLE `mt_feature` 
FIELDS TERMINATED BY '|'
ENCLOSED BY '"' 
ESCAPED BY '\\'
LINES TERMINATED BY '\n';

This script had to be rebuilt for some technical reasons, and the Mysql part was not changed and works fine with the corresponding CSV file for import.

, , SQLPlus, , . , ?

, , , ...


Script oracle 10g, Linux, Mysql 4.x

!

+3
2

SET LINESIZE 0 , 1 32767. , , 80, glogin script.

+2

- ( ) SO, , .

select "AS'||'"|"'||
    feature_group||'"|"'||
    feature_desc||'"|"'||
    feature_order||'"|"'||
    prod_code||'"' 
from MYVIEW 
WHERE MYCONDITIONS;

, ....

SELECT "AS'||'"|"'||
    TRANSLATE(feature_group, CHR(10), '\\n') ||'"|"'||
(etc).

lineize 0.

+1

Source: https://habr.com/ru/post/1788435/


All Articles