READ statement [Interactive SQL]

Use this statement to read Interactive SQL statements from a file.

Syntax
READ [ ENCODING encoding ] filename [ parameter ] ...
encoding : identifier or string
Remarks

The READ statement reads a sequence of Interactive SQL statements from the named file. This file can contain any valid Interactive SQL statements, including other READ statements. READ statements can be nested to any depth. If the file name does not contain an absolute path, Interactive SQL searches for the file. Interactive SQL first searches the directory of the calling file (if there is one), then the current directory, and then the directories specified in the environment variable SQLPATH, and then the directories specified in the environment variable PATH. If the named file has no file extension, Interactive SQL searches each directory for the same file name with the extension .sql.

The ENCODING clause allows you to specify the encoding that is used to read the file. The READ statement does not process escape characters when it reads a file. It assumes that the entire file is in the specified encoding.

With Interactive SQL, if the ENCODING clause is not specified, the encoding that is used to read the file is determined in the following order:

  • the encoding specified with the default_isql_encoding option (if this option is set)

  • the default encoding of the operating system character set on the computer that Interactive SQL is running on

For more information about Interactive SQL and encodings, see default_isql_encoding option [Interactive SQL].

Parameters can be listed after the name of the command file. These parameters correspond to the parameters named in the PARAMETERS statement at the beginning of the statement file. See PARAMETERS statement [Interactive SQL])

Parameter names must be enclosed in square brackets. Interactive SQL substitutes the corresponding parameter wherever the source file contains {parameter-name}, where parameter-name is the name of the appropriate parameter.

The parameters passed to a command file can be identifiers, numbers, quoted identifiers, or strings. When quotes are used around a parameter, the quotes are put into the text during the substitution. Parameters that are not identifiers, numbers, or strings (contain spaces or tabs) must be enclosed in square brackets ([ ]). This allows for arbitrary textual substitution in the command file.

If not enough parameters are passed to the command file, Interactive SQL prompts for values for the missing parameters.

When executing a reload.sql file with Interactive SQL, you must specify the encryption key as a parameter. If you do not provide the key in the READ statement, Interactive SQL prompts for the key. See Interactive SQL utility (dbisql).

The location of filename is determined based on the location of the READ statement, as follows:

  • If the READ statement is executed directly in Interactive SQL, the path to filename is resolved relative to the directory in which Interactive SQL is running.

  • If the READ statements reside in an external file (for example, a .sql file), Interactive SQL first attempts to resolve the path to filename relative to the location of the external file. If unsuccessful, Interactive SQL looks for filename in a path relative to the directory in which Interactive SQL is running.

Permissions

None.

Side effects

None.

See also
Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following are examples of the READ statement.

READ status.rpt '160';
READ birthday.sql [>= '1988-1-1'] [<= '1988-1-30'];