- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试了解 T-SQL 中 try ... catch 构造的工作原理。
所以我在 MSDN 上读过文章:http://msdn.microsoft.com/en-us/library/ms175976.aspx
我对这个说法有点困惑:TRY…CATCH 构造不能跨越多个批处理。 TRY…CATCH 构造不能跨越多个 Transact-SQL 语句 block 。例如,TRY…CATCH 构造不能跨越 Transact-SQL 语句的两个 BEGIN…END block ,也不能跨越 IF…ELSE 构造。
这意味着 try ... catch 不能跨越 2 个 BEGIN...END block ,也不能跨越 IF...ELSE 结构。
但是,我已经尝试过并且有效! (2005年和2008年)
有人能解释一下为什么吗?看起来 MSDN 上有一些错误。
看看我的测试脚本:
print 'start'
begin transaction test_tran
begin try
-- first begin ... end
begin
-- some statements
print 'begin ... end - #1'
end
-- second begin ... end
begin
print 'begin ... end - #2'
-- statement with error
select 1/0 -- division by zero
end
print 'end of try'
end try
begin catch
print 'catch'
goto RollbackTran
end catch
-- commit
print 'commit'
commit transaction test_tran
-- rollback
RollbackTran:
BEGIN
print 'rollback'
WHILE @@TRANCOUNT > 0
begin
ROLLBACK TRANSACTION test_tran
print 'actual rollback'
end
END
结果:
start
begin ... end - #1
begin ... end - #2
(0 row(s) affected)
catch
rollback
actual rollback
它有效(2 个开始...结束 block )!但 MSDN 说不应该。IF ... ELSE 语句也是如此。
谁能解释一下吗?
最佳答案
T-SQL 批处理通常由 GO 语句表示。他们说你不能这样做:
BEGIN TRY
PRINT 'statement 1'
GO -- Cannot have a GO to end batch inside of a TRY / CATCH
PRINT 'statement 2'
END TRY
BEGIN CATCH
PRINT 'Catch Block'
END CATCH
同样你不能:
IF (1 = 1)
BEGIN
BEGIN TRY
PRINT 'test'
END -- Cannot END a block that began prior to the TRY / CATCH
END TRY
BEGIN CATCH
PRINT 'Catch block'
END CATCH
你也不能这样做:
IF (1 = 1)
BEGIN TRY
PRINT 'statement 1'
ELSE -- Cannot do ELSE for an IF that started prior to the TRY / CATCH
PRINT 'statement 2'
END TRY
BEGIN CATCH
PRINT 'Catch Block'
END CATCH
关于sql - T-SQL try ... catch 和多个批处理(2 begin...end,if...else),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9599975/
我想处理 vector 中的元素一段时间。为了优化这一点,我不想在处理项目时删除它,而是在最后删除所有已处理的项目。 vector::iterator it; for(it = items.begin
我对 perl 中的 const 声明有疑问,并且无法弄清楚差异,请指出有什么不同。 下面是代码: BEGIN { *SIZE = sub() { 2 }; } *ITEM = sub() {
在右值上调用std::vector 和std::begin() 的成员函数.begin() 会导致不同的输出, 如以下测试所示: vector a{ 1, 2, 3 }; vector::iterat
我正在尝试创建自己的 vector 类。目前,我正在为我的 vector 类 Vec 添加一个删除函数。当我将 variable.begin() 传递到 erase 函数参数时,我的代码会报错,但在我
在 c++ 中迭代 vector 时,我注意到标准库中有一个 begin() 函数,还有一个 begin() 作为成员函数vector 类。如果有的话,两者之间有什么区别,应该使用哪个而不是另一个?
为什么标准将 end() 定义为末尾,而不是实际末尾? 最佳答案 最好的论据是Dijkstra himself 提出的论据。 : 您希望范围的大小是一个简单的差异end - begin; 当序列退化为
我正在尝试遍历大量记录并处理它们中的每一个。即使在处理过程中发生错误,游标也应该继续循环遍历记录,但在批处理结束时,我希望看到所有产生错误的记录的错误消息。 我有以下代码: 选择.... OP
这个问题在这里已经有了答案: error: no matching function for call to 'begin(int*&)' c++ (3 个答案) 关闭 6 年前。 我想获取数组的长
如果我有 std::vector(它是一个 std::vector 并且永远是一个 std::vector)。 使用 std::begin() 代替 std::vector::begin()(或相反)
这个问题在这里已经有了答案: Why use non-member begin and end functions in C++11? (7 个答案) 关闭 4 年前。 在这个问题(https://
我一直在尝试在网络上查找有关这些陈述之间差异的信息,在我看来它们是相同的,但我找不到对此的确认或两者之间的任何类型的比较。 这样做有什么区别: BEGIN -- Some update, in
我正在使用 Tiled Map 学习 LibGDX。我遇到了以下两种渲染方法。第一个是我通常使用的简单的。 但是,我不明白为什么我们需要第二个。我可以使用 batch.begin();在方法 2 中也
是否可以在 SpriteBatch begin 和 end 调用之间使用 ShapeRenderer 绘制形状。 我已经尝试过但没有结果,只绘制了 SpriteBatch 纹理,场景中没有任何形状。示
嗨,我正在编写一个程序,该程序从 .pem 文件导入私钥并创建一个私钥对象以供稍后使用。我遇到的问题是一些 pem 文件头以 开头 -----BEGIN PRIVATE KEY----- 而其他人则以
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
观看 Stephan T. Lavavej:核心 C++ #1,并注意到他使用的是 begin(collection) 而不是 collection.begin()。 有什么优势? 最佳答案 我想到的
Python脚本 ''' a ''' from __future__ import print_function 运行良好(即什么都不做),但是 ''' a ''' ''' b ''' from __
如何在两种风格的公钥格式之间进行转换, 一种格式是: -----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY----- 另一种格式是: -----BEGI
我是 STL c++ 的新手。我从书中复制了这个函数: string ConverToLowerCase(string s) { transform(s.begin(), s.end(),
给定代码: #include #include #include #include using namespace std; int main() { string s("ABCDE
我是一名优秀的程序员,十分优秀!