行語句的正常執行

搭建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]}
本文名稱:MySQL基礎:搭建bc網站sql執行錯誤時的控制方式-創新互聯
標題鏈接:http://www.yijiale78.com/article44/dodgee.html
成都網站建設公司_創新互聯,為您提供電子商務、品牌網站制作、小程序開發、網站維護、移動網站建設、搜索引擎優化
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯