【发布时间】:2013-10-15 19:07:00
【问题描述】:
这与this question 有关,但略有不同,我有插入记录的while 循环,即使某些插入失败,我也希望它继续。因此,insertrecords 过程通过在临时表上一次执行前 50 行的 where 来插入记录。
问题是如果插入记录中的任何插入失败,它就不会继续?即使当前 50 条记录失败,如何修改 sql 以继续下一个 50 行。我想sybase中是否有类似try/catch异常处理的东西?
SELECT id INTO #temp FROM myTable
-- Loop through the rows of the temp table
WHILE EXISTS(SELECT 1 FROM #temp)
BEGIN
BEGIN TRANSACTION
exec insertrecords
IF @@error = 0
begin
print 'commited'
commit
end
else
begin
print 'rolled back'
rollback
end
DELETE TOP 50 FROM #temp order by id
END
-- Drop the temp table.
DROP TABLE #temp
【问题讨论】:
标签: tsql error-handling sybase sqlanywhere