SQL/SELECT ... INTO

Материал из Энциклопедия о программировании
Перейти к: навигация, поиск

SELECT … INTO — SQL оператор выборки и вставки.

The SELECT … INTO form of SELECT enables a query result to be stored in variables or written to a file:

  • SELECT … INTO var_list selects column values and stores them into variables.
  • SELECT … INTO OUTFILE writes the selected rows to a file. Column and line terminators can be specified to produce a specific output format.
  • SELECT … INTO DUMPFILE writes a single row to a file without any formatting.

Примеры

SET NAMES utf8;
SELECT id, 
   client,
   project,
   task,
   description, 
   time,
   date  
  INTO OUTFILE '/path/to/file.csv'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'
  FROM ts
SELECT 
REPLACE( IFNULL(notes, ''), '\r\n' , '\n' )   AS notes
FROM sometables
INTO OUTFILE '/tmp/test.csv' 
FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '"'
LINES TERMINATED BY '\r\n';

http://dev.mysql.com/doc/refman/5.7/en/select-into.html

Эта статья относится к ЯЗ SQL.