SQL相关简单游标

Posted 烟雨楼台^浮云往事

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL相关简单游标相关的知识,希望对你有一定的参考价值。

BEGIN TRY

Create Table #Temp_Table_Record_Stat
(
....
)

DECLARE table_Cursor CURSOR FOR
SELECT object_id,t.name,convert(nvarchar,isnull(tn.Value,t.name)) as caption
FROM sys.tables t
left join sys.extended_properties tn on t.object_id=tn.major_id and tn.minor_id=0
WHERE t.Type=‘U‘ and t.is_ms_shipped=0 AND t.name<>‘sysdiagrams‘;

OPEN table_Cursor
FETCH NEXT FROM table_Cursor INTO @v_Table_ID,@v_Table_Name,@v_Table_Caption;
WHILE @@FETCH_STATUS = 0
BEGIN
-- make sure the object exists before calling sp_spacedused
IF EXISTS(SELECT id FROM sysobjects WHERE id = @v_Table_ID)
BEGIN
--相关游标操作
UPDATE #Temp_Table_Record_Stat SET [email protected]_Table_Caption WHERE [email protected]_Table_Name;
END

FETCH NEXT FROM table_Cursor INTO @v_Table_ID,@v_Table_Name,@v_Table_Caption;
END
CLOSE table_Cursor
DEALLOCATE table_Cursor

RETURN 0;
END TRY
-- 结束Try
-- 开始对抛出的例外处理
BEGIN CATCH
BEGIN TRY
IF CURSOR_STATUS(‘global‘,‘table_Cursor‘)<>-3
DEALLOCATE table_Cursor;
END TRY
BEGIN CATCH
PRINT ‘关闭游标出错‘;
END CATCH;

PRINT ERROR_MESSAGE();
RETURN ERROR_NUMBER();
END CATCH;





































以上是关于SQL相关简单游标的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server存储过程和游标有关实例以及相关网址

SQL server存储过程,触发器,游标相关实例

java.sql.SQLException: - ORA-01000: 超过最大打开游标

java.sql.SQLException: - ORA-01000: 超过最大打开游标

java.sql.SQLException: - ORA-01000: 超过最大打开游标

java.sql.SQLException: - ORA-01000: 超过最大打开游标