0
这与this question有关,但略有不同,我有while循环插入记录,我希望它继续,即使某些插入失败。因此,insertrecords过程插入记录,方法是一次对顶部50行的临时表执行一次操作。即使sybase中发生异常,如何继续执行while循环的其余部分?
问题是如果insertrecords中的任何插入失败,它将不会继续?如何修改sql以便继续使用接下来的50行,即使目前的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
我不认为'try'是sybase中的有效关键字。 – Vishal
你的示例代码看起来像SQL,并且我给出了一个sql示例。 不确定它会在sybase中工作与否。 – sudhAnsu63
是的,但我提到了sybase,我知道这将在SQL Server中起作用。我在寻找类似于Sybase的东西。 – Vishal