Você está na página 1de 1

Chapter 2: Inserting 67

1, 'Hello, World', 67.89, 2003-09-30 02:15PM, 999


then the row inserted into t1 will look like this:
key_1 col_2 col_3 col_4 col_5
===== ===== ========================= ===== ==============
1 999 '2003-09-30 14:15:00.000' 67.89 'Hello, World'
The INPUT FROM file specification is relative to the client computer running
ISQL, not the computer running the database server. This makes it more conve-
nient for ad hoc usage than LOAD TABLE because you dont have to mess
around with UNC file specifications.
The bad news is, you are stuck using a string literal for the file specifica-
tion. You cannot use EXECUTE IMMEDIATE to run an INPUT statement, nor
can you embed an INPUT statement inside a stored procedure or even a simple
BEGIN block. Thats because the INPUT statement is parsed and executed by
ISQL, not the server, whereas other statements like EXECUTE IMMEDIATE
and BEGIN blocks are passed on to the database engine to be parsed and exe-
cuted. If you try to get the database engine to process an INPUT statement, it
will give you a syntax error.
The way INPUT works is controlled by several options:
n BY NAME specifies that the field names defined inside the file are to be
matched with the column names in the table to determine which fields are
to be used for which columns. This option can only be used with the
self-describing file formats DBASE, DBASEII, DBASEIII, EXCEL,
FOXPRO, and LOTUS.
n BY ORDER (the default) specifies that the layout of the input file matches
the layout of the table. Note that BY NAME and BY ORDER are the only
choices you have for the self-describing file formats; the column name list
is ignored. For FORMAT ASCII and FORMAT BCP, you can choose
between the default BY ORDER or an explicit column name list.
n COLUMN WIDTHS is used with FORMAT FIXED input to list the input
file field widths from left to right. In theory, COLUMN WIDTHS is
optional, but for all practical purposes it is a requirement for FORMAT
FIXED input; no attempt will be made here to describe how the INPUT
statement calculates column widths if this option is omitted.
n DELIMITED BY can be used with FORMAT ASCII to change the field
delimiter; for example, DELIMITED BY '\x09' specifies that the input file
is tab-delimited. The default is DELIMITED BY ','.
n ESCAPE CHARACTER can be used with FORMAT ASCII to specify
which single character will be interpreted as the escape character in string
literals in the input file; e.g., ESCAPE CHARACTER '!'. The default is the
ESCAPE CHARACTER '\'. Note that input fields in FORMAT FIXED files
are processed as is; there is no notion of delimiters or escape characters.
n NOSTRIP can be used with FORMAT ASCII to specify that trailing
blanks will be preserved when processing unquoted strings. The default is
to remove trailing spaces from unquoted strings. Note that leading spaces
are always removed from unquoted strings, but leading and trailing spaces
are never removed from quoted strings, regardless of whether or not
NOSTRIP is specified.

Você também pode gostar