如何在事务中使用try catch块? [英] How to use try catch block with transaction?
本文介绍了如何在事务中使用try catch块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我是postgresql的新手。我的任务是使用特殊处理与事务。
有谁能建议我解决我的问题。
谢谢...
Dear all,
I am new to postgresql. Here my task is to use exceptional handling with transaction.
Can anyone suggest me any solution to my problem.
Thank you...
推荐答案
取自 Postgresql异常捕获石头! [ ^ ] -
Taken from Postgresql exception-catching rocks! [^] -
begin try
begin transaction
-- alter table z drop column aaa;
alter table z add zzz int;
commit tran;
end try
begin catch
print 'hello';
SELECT
ERROR_NUMBER() as ErrorNumber,
ERROR_MESSAGE() as ErrorMessage;
IF (XACT_STATE()) = -1
BEGIN
PRINT
N'The transaction is in an uncommittable state. ' +
'Rolling back transaction.'
ROLLBACK TRANSACTION;
END;
end catch
print 'reached';
这篇关于如何在事务中使用try catch块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文