您好,登錄后才能下訂單哦!
行語句的正常執(zhí)行
搭建bc網(wǎng)站q<277.03.4.83.6>
比如執(zhí)行多條正常執(zhí)行的語句,示例命令如下所示:
select version();
select "Hello LiuMiao" as "Greetings";
select 20+22 as Result;
使用HereDocument方式執(zhí)行如下所示:
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多行語句執(zhí)行出錯時在sqlplus中會繼續(xù)執(zhí)行,而在mysql控制臺中會怎樣呢?我們可以在上述語句中添加一行錯誤的語法或者命令來進行驗證:
mysql -uroot -proot <<EOF
select version();
errorcommand;
select "Hello LiuMiao" as "Greetings";
select 20+22 as Result;
EOF
執(zhí)行結(jié)果如下所示
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]}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。