sql 记录一次灾难 游标问题
作者:互联网
起因:游标执行存储过程 下载begin 外面了.. ,造成一直触发存储过程
收获:定义变量统一在游标外部使用, 书写内容在begin 内部书写
alter PROCEDURE USP_dgd_wzh_INPUT_SAVE @inputrowidhd VARCHAR(10), @doccode varchar(30) as DECLARE @rowid varchar(40) begin --游标更改数据 --申明一个游标 DECLARE @po_no varchar(50),@modelcode varchar(50),@size_state varchar(50),@rec_date datetime,@plan_date datetime, @exdate datetime,@lot_date datetime,@to_country varchar(50) --循环变量 DECLARE MyCursor CURSOR FOR SELECT po_no,modelcode,size_state,rec_date,plan_date,exdate,lot_date,to_country FROM po_order_input where inputrowid = @inputrowidhd and size_state !='码制' --循环一个游标 --打开一个游标 OPEN MyCursor FETCH NEXT FROM MyCursor INTO @po_no,@modelcode,@size_state,@rec_date,@plan_date,@exdate,@lot_date ,@to_country WHILE @@FETCH_STATUS =0 BEGIN exec getxxxx @rowid output INSERT INTO wzh_ddgl_item(Doccode,rowid,ordercode,modelcode,size_state,Orderdate,Originaldate,postdate,lot_date,Portmsg) values (@doccode,@rowid, @po_no,@modelcode,@size_state,@rec_date,@plan_date,@exdate,@lot_date ,@to_country) FETCH NEXT FROM MyCursor INTO @po_no,@modelcode,@size_state,@rec_date,@plan_date,@exdate,@lot_date ,@to_country END --关闭游标 CLOSE MyCursor --释放资源 DEALLOCATE MyCursor end
太久不用忘记游标的写法了
标签:varchar,灾难,游标,state,sql,date,modelcode,size 来源: https://www.cnblogs.com/baili-luoyun/p/12077112.html