Sie sind auf Seite 1von 1

58 Chapter 2: Inserting

CREATE TABLE t1 (
key_1 INTEGER NOT NULL,
col_2 INTEGER NOT NULL,
col_3 TIMESTAMP NULL,
col_4 DECIMAL ( 11, 2 ) NULL,
col_5 VARCHAR ( 100 ) NULL,
PRIMARY KEY ( key_1 ) );

LOAD TABLE t1 ( key_1, filler(), col_4, col_3, col_2 ) FROM 'c:\\temp\\t1_b.txt';


If the input file contains this record:
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 NULL
The LOAD TABLE input file specification is relative to the server, not the cli-
ent. More specifically, the drive and path is relative to the current folder when
the SQL Anywhere database engine was started. This becomes a challenge
when youre running LOAD TABLE from ISQL on a desktop but the database
server is located somewhere else on the network. Even though you might enter
the LOAD TABLE statement on the same computer that holds the input file, it
is executed on the server, and it is the database server that goes looking for the
file, not ISQL.
The Universal Naming Convention (UNC) for network files can be used
with LOAD TABLE. Here is the layout of a UNC file specification:
\\<server-name>\<share-name>\<directory/filename>
For example, if the file C:\temp\t1_c.txt is sitting on a machine called TECRA,
and the C: drive is shared as TecraC, then the following LOAD TABLE can
be used to reach out across the network and read the file as
\\TECRA\TecraC\temp\t1_c.txt. Once again, each single backslash (\) is repre-
sented as two backslashes in the file specification:
LOAD TABLE t1 FROM '\\\\TECRA\\TecraC\\temp\\t1_c.txt';
If thats where the file resides, relative to the computer running the database
engine, thats how you have to code the file specification; it doesnt matter on
which machine ISQL is running.

Tip: Watch out for operating system permissions when specifying a file specifi-
cation in LOAD TABLE. For example, if the database engine is run as a Windows
service it may or may not have sufficient privileges to read the file.

The LOAD TABLE input file specification must be a string literal, not a vari-
able. If you want to use a variable, run LOAD TABLE via EXECUTE
IMMEDIATE. The following example puts the file specification in a variable
called @filespec and then builds the LOAD TABLE command in another vari-
able called @sql before running it via EXECUTE IMMEDIATE. This time,
sadly, each single backslash in \\TECRA\TecraC\temp\t1_c.txt must be repre-
sented as four backslashes.
BEGIN
DECLARE @filespec VARCHAR ( 1000 );

Das könnte Ihnen auch gefallen