封装游标存储过程(Pr_execsql2)

来源:互联网 发布:剑灵读图慢怎么优化 编辑:程序博客网 时间:2024/06/15 15:06
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

使用脚本自己可以执行自己的特性,封装游标操作存储过程如下:
CREATEPrOCEDUREPr_execsql2
      @AsqlstringVARCHAR(8000)--输入的SQL语句
AS
EXEC('
--启动事务
BEGINTRAN

DECLARE@ASqlVARCHAR(8000)
DECLAREtnames_cursorCURSORLOCALFAST_FORWARDFOR'+ @asqlstring+'
OPENtnames_cursor
FETCHNEXTFROMtnames_cursorINTO@ASql
WHILE(@@FETCH_STATUS=0)
BEGIN
Print@ASql
EXEC(@ASql)
IF@@ERROR<>0GOTOFINALEXIT
FETCHNEXTFROMtnames_cursorINTO@ASql
END
CLOSEtnames_cursor
DEALLOCATEtnames_cursor

COMMITTRAN
RETURN

FINALEXIT:
ROLLBACKTRAN
CLOSEtnames_cursor
DEALLOCATEtnames_cursor

')
使用方法:
declare@sqlvarchar(8000)
set@sql='select''updateaseta.a='' +b.afromb '
execPr_execsql2@sql

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击