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 the COLUMN WIDTHS clause is omitted, 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.
This default can be changed using 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, you get 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.