sql >> Base de Datos >  >> RDS >> Mysql

Cómo exportar la línea de ruptura '\ n' en un archivo usando MySQL INTO OUTFILE

Se trata de secuencias de escape y hay varias formas de hacerlo. Elegí simplemente poner la comilla simple inicial dentro de las comillas dobles externas cerca del final de la primera forma (con 3 fragmentos en concat ).

Y comillas simples como la segunda forma (con 2 fragmentos en concat ):

SET @filename = 'C:/icl/myfile.CSV';
-- C:/icl/myfile.CSV

SET @str = CONCAT('LOAD DATA INFILE ',@filename);
-- LOAD DATA INFILE C:/icl/myfile.CSV

-- First way is below (with the result being the line after it if you ignore the `-- ` at the beginning):
SET @str = CONCAT(@str," INTO TABLE icl_process_data.filecontent LINES TERMINATED BY '","\\n'");
-- LOAD DATA INFILE C:/icl/myfile.CSV INTO TABLE icl_process_data.filecontent LINES TERMINATED BY '\n'

-- Second way is below (with the result being the line after it if you ignore the `-- ` at the beginning):
SET @str = CONCAT('LOAD DATA INFILE ',@filename);
SET @str = CONCAT(@str,' INTO TABLE icl_process_data.filecontent LINES TERMINATED BY \'\\n\'');
-- LOAD DATA INFILE C:/icl/myfile.CSV INTO TABLE icl_process_data.filecontent LINES TERMINATED BY '\n'

Desde la página del manual de mysql en Literales de cadena :