Writes the information retrieved by the current query to a file.
OUTPUT TO <filename> [ APPEND ] [ VERBOSE ] [ FORMAT output-format ] [ ESCAPE CHARACTER <character> ] [ DELIMITED BY <string> ] [ QUOTE <string> [ ALL ] ] [ COLUMN WIDTHS ( <integer>, … ) ] [ HEXADECIMAL { ON | OFF | ASIS } ] [ ENCODING <encoding> ] [ WITH COLUMN NAMES ] output-format TEXT | FIXED | HTML | SQL | XML
Three other special sequences are also used. The two characters \n represent a newline character, \\ represents a single \, and the sequence \xDD represents the character with hexadecimal code DD.
If you are exporting Java methods that have string return values, you must use the HEXADECIMAL OFF clause.
If you omit the COLUMN WIDTHS clause, the width for each column is computed from the data type for the column, and is large enough to hold any value of that data type. The exception is that LONG VARCHAR and LONG BINARY data defaults to 32KB.
The APPEND clause is valid if the output format is TEXT, FIXED, or SQL.
To change this default, use the ESCAPE CHARACTER clause. For example, to use the exclamation mark as the escape character, enter:
... ESCAPE CHARACTER '!'
SELECT * FROM Employees; OUTPUT TO employees.txt FORMAT TEXT
SELECT * FROM Employees; OUTPUT TO employees.txt APPEND VERBOSE
Execute this statement with HEXADECIMAL ON:
SELECT 'line1\x0aline2'; OUTPUT TO file.txt HEXADECIMAL ON
The result is a file with one line in it, containing this text:
line10x0aline2
Execute the same statement with HEXADECIMAL OFF:
line1\x0aline2
If you set HEXADECIMAL to ASIS, the result is a file with two lines:
'line1 line2'
Using ASIS generates two lines, because the embedded line feed character has been exported without being converted to a two-digit hex representation, and without a prefix.
The current query is the SELECT or LOAD TABLE statement that generated the information that appears on the Results tab in the Results pane. The OUTPUT statement reports an error if there is no current query.
OUTPUT is especially useful in making the results of a query or report available to another application, but is not recommended for bulk operations. For high-volume data movement, use the ASCII and BINARY data extraction functionality with the SELECT statement. The extraction functionality provides much better performance for large-scale data movement, and creates an output file you can use for loads.