sql中写程序时,如何进行错误处理呢?比如类似vb中的 on error goto err这种方式?
写一个存贮过程,如何进行错误处理呢?没有类似的 on error 语句呀?
------解决方案--------------------
@@error
------解决方案--------------------
GOTO
将执行流变更到标签处。
------解决方案--------------------
USE pubs
GO
DECLARE @tablename sysname
SET @tablename = N 'authors '
table_loop:
IF (@@FETCH_STATUS <> -2)
BEGIN
SELECT @tablename = RTRIM(UPPER(@tablename))
EXEC ( "SELECT " " " + @tablename + " " " = COUNT(*) FROM "
+ @tablename )
PRINT " "
END
FETCH NEXT FROM tnames_cursor INTO @tablename
IF (@@FETCH_STATUS <> -1) GOTO table_loop
GO
------解决方案--------------------
由SQL [email protected]
例如:
insert into table1(a,b) select 'aaa ', 'bbbb '
if @@error <> 0 goto err
return 0
err:
return 1