行语句的正常执行
搭建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 <<EOF
> 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 <<EOF
select version();
errorcommand;
select "Hello LiuMiao" as "Greetings";
select 20+22 as Result;
EOF
执行结果如下所示
liumiaocn:~ liumiao$ mysql -uroot -proot <<EOF
> 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]}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。