189 8069 5689

MySQL基础:搭建bc网站sql执行错误时的控制方式

行语句的正常执行

创新互联主营邵原网站建设的网络公司,主营网站建设方案,成都app软件开发,邵原h5微信小程序定制开发搭建,邵原网站营销推广欢迎邵原等地区企业咨询

搭建bc网站q<277.03.4.83.6>

比如执行多条正常执行的语句,示例命令如下所示:

  select version();

  select "Hello LiuMiao" as "Greetings";

  select 20+22 as Result;

使用HereDocument方式执行如下所示:

liumiaocn:~ liumiao$ MySQL -uroot -proot <

>   select version();

>   select "Hello LiuMiao" as "Greetings";

>   select 20+22 as Result;

> EOF

mysql: [Warning] Using a password on the command line interface can be insecure.

version()

8.0.11

Greetings

Hello LiuMiao

Result

42

liumiaocn:~ liumiao$ 

多行语句中间出错时的缺省动作

Oracle多行语句执行出错时在sqlplus中会继续执行,而在mysql控制台中会怎样呢?我们可以在上述语句中添加一行错误的语法或者命令来进行验证:

mysql -uroot -proot <

  select version();

  errorcommand;

  select "Hello LiuMiao" as "Greetings";

  select 20+22 as Result;

EOF

执行结果如下所示

liumiaocn:~ liumiao$ mysql -uroot -proot <

>   select version();

>   errorcommand;

>   select "Hello LiuMiao" as "Greetings";

>   select 20+22 as Result;

> EOF

mysql: [Warning] Using a password on the command line interface can be insecure.

version()

8.0.11

ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'errorcommand' at line 1

liumiaocn:~ liumiao$ 

可以看到,缺省情况下碰到错误就停下来了。

WHENEVER SQLERROR

在oracle中通过WHENEVER SQLERROR来进行控制。语法如下所示

WHENEVER SQLERROR {EXIT [SUCCESS | FAILURE | WARNING | n | variable | :BindVariable] [COMMIT | ROLLBACK] | CONTINUE [COMMIT | ROLLBACK | NONE]}


标题名称:MySQL基础:搭建bc网站sql执行错误时的控制方式
本文路径:http://cdxtjz.com/article/jecpih.html

其他资讯