Contents Index OPEN statement [ESQL] [SP] PARAMETERS statement [Interactive SQL]

ASA SQL Reference
  SQL Statements

OUTPUT statement [Interactive SQL]


Description 

Use this statement to output the current query results to a file.

Syntax 

OUTPUT TO filename
APPEND ]
VERBOSE ]
FORMAT output-format ]
ESCAPE CHARACTER character ]
DELIMITED BY string ]
QUOTE string [ ALL ] ]
COLUMN WIDTHS (integer, ...) ]
HEXADECIMAL { ON | OFF | ASIS } ]

output-format :
ASCII | DBASEII | DBASEIII | EXCEL
FIXED | FOXPRO | HTML | LOTUS | SQL | XML

Parameters 

APPEND clause    This optional keyword is used to append the results of the query to the end of an existing output file without overwriting the previous contents of the file. If the APPEND clause is not used, the OUTPUT statement overwrites the contents of the output file by default. The APPEND keyword is valid if the output format is ASCII, FIXED, or SQL.

VERBOSE clause    When the optional VERBOSE keyword is included, error messages about the query, the SQL statement used to select the data, and the data itself are written to the output file. If VERBOSE is omitted (the default) only the data is written to the file. The VERBOSE keyword is valid if the output format is ASCII, FIXED, or SQL.

FORMAT clause    Allowable output formats are:

ESCAPE CHARACTER clause    The default escape character for characters stored as hexadecimal codes and symbols is a backslash (\), so \x0A is the linefeed character, for example.

This can be changed using the ESCAPE CHARACTER clause. For example, to use the exclamation mark as the escape character, you would enter

... ESCAPE CHARACTER '!'

DELIMITED BY clause    The DELIMITED BY clause is for the ASCII output format only. The delimiter string is placed between columns (default comma).

QUOTE clause    The QUOTE clause is for the ASCII output format only. The quote string is placed around string values. The default is a single quote character. If ALL is specified in the QUOTE clause, the quote string is placed around all values, not just around strings.

COLUMN WIDTHS clause    The COLUMN WIDTHS clause is used to specify the column widths for the FIXED format output.

HEXADECIMAL clause    The HEXADECIMAL clause specifies how binary data is to be unloaded for the ASCII format only. When set to ON, binary data is unloaded in the format 0xabcd. When set to OFF, binary data is escaped when unloaded (\xab\xcd). When set to ASIS, values are written as is, that is, without any escaping—even if the value contains control characters. ASIS is useful for text that contains formatting characters such as tabs or carriage returns.

Usage 

The OUTPUT statement copies the information retrieved by the current query to a file.

The output format can be specified with the optional FORMAT clause. If no FORMAT clause is specified, the Interactive SQL OUTPUT_FORMAT option setting is used (see OUTPUT_FORMAT option [ISQL]).

The current query is the SELECT or INPUT statement which generated the information that appears on the Results tab in the Results pane. The OUTPUT statement will report an error if there is no current query.

When exporting Java data, you may wish to export objects as binary, or you may want to export them as strings using the toString() method. You can control which way Java data is exported using the DESCRIBE_JAVA_FORMAT Interactive SQL option.

For example, consider the following script:

CREATE VARIABLE JavaString java.lang.String;
SET JavaString = NEW java.lang.String( 'TestVar' );
SELECT JavaString FROM dummy;

If you set DESCRIBE_JAVA_FORMAT to Varchar:

If you set DESCRIBE_JAVA_FORMAT to binary:

For more information, see DESCRIBE_JAVA_FORMAT option [ISQL].

Permissions 

None.

Side effects 

In Interactive SQL, the Results tab displays only the results of the current query. All previous query results are replaced with the current query results.

See also 

SELECT statement

INPUT statement [Interactive SQL]

xp_write_file system procedure

Standards and compatibility 
Examples 

Place the contents of the employee table in a file in ASCII format:

SELECT *
FROM employee;
OUTPUT TO employee.txt
FORMAT ASCII

Place the contents of the employee table at the end of an existing file, and include any messages about the query in this file as well:

SELECT *
FROM employee;
OUTPUT TO employee.txt APPEND VERBOSE

Output the contents of the toString() method of the JProd column to file:

SELECT JProd>>toString()
FROM jdba.product;
OUTPUT TO d:\temp\temp.txt
FORMAT ASCII HEXADECIMAL OFF

Suppose you need to export a value that contains an embedded line feed character. A line feed character has the numeric value 10, which you can represent as the string '\x0a' in a SQL statement. If you execute the following statement, with HEXADECIMAL set to ON,

SELECT 'line1\x0aline2';
OUTPUT TO file.txt HEXADECIMAL ON

you get a file with one line in it containing the following text:

line10x0aline2

But if you execute the same statement with HEXADEMICAL set to OFF, you get the following:

line1\x0aline2

Finally, if you set HEXADECIMAL to ASIS, you get a file with two lines:

line1
line2

You get two lines when you use ASIS because the embedded line feed character has been exported without being converted to a two digit hex representation, and without being prefixed by anything.


Contents Index OPEN statement [ESQL] [SP] PARAMETERS statement [Interactive SQL]