为什么会出现此SQL / DB错误? [英] Why am I getting this SQL/DB error?

查看:475
本文介绍了为什么会出现此SQL / DB错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用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/docum entation / Version3.2 / install_instructions.pdf


这些脚本使用分号(;)来终止每个SQL
命令。如果使用DB2命令行处理器
,则应记住使用 -t标志。

...

如果不使用-t标记,运行db2ct32.sql脚本时将出现诸如

之类的错误:

创建表 ACCOUNTS(

DB21034E已处理命令作为SQL语句,因为它不是有效的
命令行处理程序命令。在SQL处理期间,它返回:

SQL0104N在 ate table ACCOUNTS之后发现意外的标记(

预期的令牌可能包括: 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"

您可能会获得更多诊断信息。 r>
不要将专有软件推到极限,它们没有那么宽。

you might get more diagnostics.
Don't push proprietary soft to the limits, they are not that wide.

这篇关于为什么会出现此SQL / DB错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆