Oracle写法:
FOR REC IN (SELECT STATUS_VALUE_ID
FROM TMP_SB_VWSSTATUSCURTAR
WHERE JOB_ORDER_ID = V_COMPJOBORDERID AND
STATUS_TYPE_ID = V_STATUS_TYPE_ID) LOOP
V_COMP_STATUS_VALUE_ID := REC.STATUS_VALUE_ID;
END LOOP;
上面是在Oracle里的存储过程里的,我要转换成sql里,下面的写法有错吗,或是更好的方法吗
sql里写法:
declare CUR_STATUS_VALUE_IDs cursor for
SELECT STATUS_VALUE_ID
FROM TMP_SB_VWSSTATUSCURTAR
WHERE JOB_ORDER_ID =@V_COMPJOBORDERID AND
STATUS_TYPE_ID =@V_STATUS_TYPE_ID
open CUR_STATUS_VALUE_IDs
fetch next from CUR_STATUS_VALUE_IDs into @V_SBSTATUS_VALUE_ID --将游标向下移1行,获取的数据放入之前定义的变量@V_STATUS_TYPE_ID,@V_STATUS_VALUE_ID中
while @@fetch_status=0
begin
set @V_COMP_STATUS_VALUE_ID=@V_SBSTATUS_VALUE_ID
fetch next from CUR_STATUS_VALUE_IDs into @V_SBSTATUS_VALUE_ID --将游标向下移1行
end
close CUR_STATUS_VALUE_IDs --关闭游标
deallocate CUR_STATUS_VALUE_IDs