Reputation: 806
I am trying to import a .csv file with 2 columns (...and just 3 rows...just for testing) using the query:
IMPORT FROM "C:\db2\dtest.csv" OF DEL INSERT INTO TEST_DATA.DTEST (CAR, NICKNAME)
I am getting this error:
SQL0104N: SQL0104N An unexpected token "IMPORT FROM "C:\db2\dtest.csv" OF DEL" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "". SQLSTATE=42601
If I'm just being stupid here please do tell me :)
Upvotes: 0
Views: 5106
Reputation: 12267
The IMPORT is not SQL, it is a command. That means you must submit the IMPORT from the Db2 command window (CLP), or from a script, or from a stored procedure . You cannot submit it directly via SQL, unless you use the ADMIN_CMD stored procedure. See the documentation for details and examples. You would use the ADMIN_CMD if you normally interact with databases via a GUI tool.
Using the command line is best ONLY if you will regularly use batch commands, or write scripts in any scripting language - and you are competent at scripting and using command-lines. But this method has pre-requisites especially if the database is on a different hostname or a different Db2-instance than the one you are working with (i.e. the db is remote). For remote databases the database needs to be catalogued via db2 catalog tcpip node ....
and db2 catalog database ...
commands.
Additionally you must first connect to the database via db2 connect to ...
. You have to do this regardless of whether the database is local or remote. See docs for details. For local databases you just use db2 connect to dbname
where dbname must be your database name.
Using the ADMIN_CMD stored procedure if often easier for new users who are not familiar with using command line tools.
To use the Db2 command window (CLP), you can either use it interactively, or you can use your operating-system shell. On Windows use db2cwadmin.bat to open such a window (for batch or command usage), or run the db2.exe to enter interactive mode. You can then in interactive mode run your import command.
Upvotes: 1
Reputation: 164
This happened to me when i was importing data from CSV to Sql DB --In my case this happened because of incorrectly formatted CSV File. When extracting data from CSV file have a look at the preview of data which will give an idea of where the data is wrong. It may be because of different characters like , ' ' etc.. --t
Upvotes: 0