TRY…CATCH语句
shark实现了一种与异常处理的类似的错误处理机制,当TRY控制块内的SQL语句出现错误时,会继续执行CATCH控制块内的语句。
注意事项
- 本章节只包含shark新增的语法。
语法格式
- BEGIN TRY { sql_statement | statement_block } END TRY BEGIN CATCH [ { sql_statement | statement_block } ] END CATCH [ ; ]
参数说明
- sql_statement
除事务管理语句外的任意SQL语句。 - statement_block
除事务管理语句外的任意SQL语句块。
示例
1. opengauss=# create table test_3(a int);
2. opengauss=# begin try;
3. opengauss=# insert into test_3 values(2);
4. opengauss=# select 1/0;
5. ERROR: division by zero
6. opengauss=# end try begin catch;
7. opengauss=# insert into test_3 values(3);
8. opengauss=# select 1/0;
9. ERROR: division by zero
10. opengauss=# select * from test_3;
11. ERROR: current catch block is failed, commands ignored until end of catch block
12. opengauss=# end catch;
13. opengauss=# select * from test_3;
14. a
15. ---
16. (0 rows)
