ehxz 发表于 2007-1-24 12:23:27

sybase 中正确操作游标的顺序

<p>sybase 中正确操作游标的顺序是: <br />1、DECLARE CUR_ACCTINFO CURSOR FOR SELECT &#46;&#46;&#46;&#46;&#46; (定义) <br />2、OPEN CUR_ACCTINFO (打开) <br /><br />3、WHILE @@SQLSTATUS = 0 (判断是否成功) <br />BEGIN <br /><br />4、 FETCH CUR_ACCTINFO INTO &#46;&#46;&#46;&#46;&#46;&#46;&#46; (取数据) <br />IF @@SQLSTATUS <> 0 <br />begin <br />&#46;&#46;&#46;&#46;&#46;&#46; <br />end <br />&#46;&#46;&#46;&#46;&#46;&#46;&#46;&#46;&#46;&#46;&#46; <br />5、 CLOSE CUR_ACCTINFO (关闭) <br />6、 DEALLOCATE CURSOR CUR_ACCTINFO (释放) <br /><br />别人的一个DEMO:</p><br /><p>CREATE PROCEDURE up_pos_zyinout<br />(@arg_year datetime,<br />@arg_prd int <br />)<br />AS <br />declare @temp_shop varchar(40)<br />declare cur_shop cursor for<br />select ORGAN_ID<br />from F_SALE_DEPT<br />where ORGAN_ID LIKE "281%"<br />OPEN cur_shop<br />fetch cur_shop into @temp_shop<br />while @@sqlstatus = 0 <br />begin<br />exec up_accrpt_zyposinout @arg_year,@arg_prd,"",@temp_shop,"n","y"<br /> fetch cur_shop into @temp_shop <br />end<br />close cur_shop<br />DEALLOCATE cursor cur_shop<br /></p>
页: [1]
查看完整版本: sybase 中正确操作游标的顺序