Output Redirection

You can use output redirection to export query results.

You can redirect the output of any command to a file or device by putting the ># redirection symbol anywhere on the command. The redirection symbol must be followed by a file name. (In a command file, the file name is then followed by the semicolon used as statement terminator.) The file is placed relative to the directory where Interactive SQL was started.

This example redirects output to a file called empfile:

SELECT *
FROM Employees
># empfile

Do not enclose the file name in quotation marks.

Output redirection is most useful on the SELECT statement.

Use two > characters in a redirection symbol instead of one (for example, >>#), to append output to the specified file instead of replacing the contents of the file. Headings are included in the output from the SELECT statement if the output starts at the beginning of the specified file and the output format supports headings.

Redirecting Output and Messages

The >& redirection symbol redirects all output including error messages and statistics for the command on which it appears. For example:

SELECT *
FROM Employees 
>& empfile

Do not enclose the file name in quotation marks.

This example sends the SELECT statement to the file empfile, followed by the output from the statement, and some statistics pertaining to the command.

You can use the >& redirection method to obtain a log of what happens during a READ command. The statistics and errors of each command are written following the command in the redirected output file.

NULL Value Output

Although the most common reason to extract data is for use in other software products, these products may sometimes have issues processing NULL values.

The dbisql option NULLS allows you to choose how NULL values are output. Alternatively, you can use the IFNULL function to output a specific value whenever there is a NULL value.