为什么我会收到此 SQL/DB 错误? [英] Why am I getting this SQL/DB error?
问题描述
我正在尝试使用 DB2 运行一个简单的 SQL 语句,但遇到了一些问题.我想在 txt/db2 文件中有一个脚本,并让引擎处理所有命令
I am trying to run a simple SQL statement with DB2 and am having a few problems. I would like to have a single script in a txt/db2 file and have the engine process all of the commands
这是脚本:
CONNECT TO MYDB
CREATE TABLE PERSONS(
PID SMALLINT NOT NULL,
NAME VARCHAR(20) NOT NULL
)
TERMINATE
当我运行 db2 -f/pathtofile 时,我得到:
When I run a db2 -f /pathtofile I get:
SQL0104N An unexpected token "(" was found following "CREATE TABLE PERSONS".
Expected tokens may include: "END-OF-STATEMENT". SQLSTATE=42601
我做错了什么?我的脚本有问题吗?另外,为什么没有;"我的陈述结束时的终止符?
What am I doing wrong? Is there something wrong with my script? Also, why is it working without ";" terminators at the end of my statements?
谢谢,
推荐答案
也许这会有所帮助,
http://www.uc.edu/R/r25/文档/Version3.2/install_instructions.pdf:
脚本使用分号 (;) 来终止每个 SQL命令.如果您使用 DB2 命令行处理器,您应该记住使用-t"标志.
...
如果你不使用 -t 标志,你会得到诸如
在运行 db2ct32.sql 脚本后执行以下操作:
创建表帐户"(
DB21034E 该命令被作为 SQL 语句处理,因为它不是一个
有效的命令行处理器命令.在 SQL 处理期间它返回:
SQL0104N 在吃了表帐户"之后发现了一个意外的标记(".
预期的令牌可能包括:END-OF-STATEMENT".SQLSTATE=42601
The scripts use a semi-colon (;) to terminate each SQL command. If you use the DB2 Command Line Processor, you should remember to use the "-t" flag.
...
If you do not use the -t flag, you will get errors such as the
following upon running the db2ct32.sql script:
create table "ACCOUNTS" (
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "(" was found following "ate table "ACCOUNTS"".
Expected tokens may include: "END-OF-STATEMENT". SQLSTATE=42601
所以,我会添加分号并使用 -t 开关调用它所代表的任何废话.
我查看了样本,他们使用类似的东西
So, I would add semicolons and invoke with -t switch whatever nonsense it stands for.
I looked into samples, they use something like
db2 -tf "pathtofile"
还有
db2 -tvf "pathtofile"
您可能会获得更多诊断信息.
不要将专有软件推到极限,它们并没有那么宽.
you might get more diagnostics.
Don't push proprietary soft to the limits, they are not that wide.
这篇关于为什么我会收到此 SQL/DB 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!