MySQL基础:搭建bc网站sql执行错误时的控制方式-创新互联
行语句的正常执行
创新互联专注于企业网络营销推广、网站重做改版、巍山网站定制设计、自适应品牌网站建设、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执行错误时的控制方式-创新互联
URL分享:http://pwwzsj.com/article/dodgee.html