output

Description

Imports data into a database table from an external file or from the keyboard.

Syntax

output to filename
	[ append ]
	[ verbose ]
	[ format {ascii | dbase | dbasell| dbaselll 
		| excel | fixed | foxpro | lotus | sql | xml}]
	[ escape character character ]
	[ escapes { on | off}
	[ delimited by string ]
	[ quote string [ all ] ]
	[ column widths (integer , . . . ) ]
	[ hexidecimal { on | off | asis } ]
	[ encoding {string | identifier}]

Parameters

append

appends 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

Writes error messages about the query, the SQL statement used to select the data, and the data itself to the output file. Lines that do not contain data are prefixed by two hyphens. If you omit verbose (the default) only the data is written to the file. verbose is valid if the output format is ASCII, fixed, or SQL. Allowable output formats are:

  • ascii – the output is an ASCII format file with one row per line in the file. All values are separated by commas, and strings are enclosed in apostrophes (single quotes). You can change the delimiter and quote strings using the delimited by and quote clauses. If all is specified in the quote clause, all values (not just strings) are quoted.

    Three other special sequences are also used. The two characters represent a new line character, “\”, represents a single \, and the sequence \xDD represents the character with hexadecimal code DD. This is the default output format.

  • dbasell – the output is in DBASEll which includes column definitions. A maximum of 32 columns can be output. Column names are truncated to 11 characters, and each row of data in each. If the table does not exist, it is created.

  • dbaselll – the output is a dBASE III format file which includes column definitions. A maximum of 128 columns can be output. Column names are truncated to 11 characters, and each row of data in each column is truncated to 255 characters.

  • excel – the output is an Excel 2.1 worksheet. The first row of the worksheet contains column labels (or names if there are no labels defined). Subsequent worksheet rows contain the actual table data.

  • fixed – the output is fixed format with each column having a fixed width. You can specify the width for each column with column widths. No column headings are output in this format.

    If the column widths clause is omitted, the width for each column is computed from the datatype for the column, and is large enough to hold any value of that datatype. The exception is that long varchar and long binary data default to 32K.

  • foxpro – the output is a FoxPro format file which includes column definitions. A maximum of 128 columns can be output. Column names are truncated to 11 characters. Column names are truncated to 11 characters, and each row of data in each column is truncated to 255 characters.

  • html – the output is in the HyperText Markup Language format.

  • lotus – the output is a Lotus WKS format worksheet. Column names are placed as the first row in the worksheet. There are certain restrictions on the maximum size of Lotus WKS format worksheets that other software (such as Lotus 1-2-3) can load. There is no limit to the size of file Interactive SQL can produce.

  • SQL – the output is an Interactive SQL input statement required to recreate the information in the table.

  • XML – the output is an XML file encoded in UTF-8 and containing an embedded DTD. Binary values are encoded in CDATA blocks with the binary data rendered as 2-hex-digit strings. The input statement does not accept XML as a file format.

escape character

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

You can change the default escape character using escape character. For example, to use the exclamation mark as the escape character, enter:

... escape character '!'
escapes

if enabled (the default), characters following the backslash character are recognized and interpreted as special characters by the database server. New line characters can be included as the combination \n, and other characters can be included in data as hexadecimal ASCII codes, such as \x09 for the tab character. A sequence of two backslash characters ( \) is interpreted as a single backslash. A backslash followed by any character other than n, x, X or \ is interpreted as two separate characters. For example, \q inserts a backslash and the letter q.

delimited by

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

quote

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 width

specifies the column widths for the fixed format output

hexidecimal

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.

encoding

allows you to specify the encoding that is used to write the file. encoding can be used only with the ASCII format.

If encoding is not specified, Interactive SQL determines the code page that is used to write the file as follows, where code page values occurring earlier in the list take precedence over those occurring later in the list:

  • The code page specified with default_isql_encoding (if this option is set)

  • The code page specified with the -codepage option when Interactive SQL was started

  • The default code page for the computer Interactive SQL is running

Examples

Example 1

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

select *
    from employee
go
output to employee.txt
    format ASCII

Example 2

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

select *
    from employee
go
output to employee.txt append verbose

Example 3

In this example, 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 hexidecimal set to on:

select 'line1 n x0aline2'
go
output to file.txt hexidecimal on

You see a file with one line in it containing the following text:

line10x0aline2

However, if you execute the same statement with hexidecimal set to off, you see the following:

line1 n x0aline2

Finally, if you set hexidecimal to asis, you see 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 hexidecimal representation, and without being prefixed by anything.

Usage

Permissions

Any user can execute this command.