1,select count(1) from DSSF_IMPO_USER_SALE
where POWE>0 and TIME_YEAR=@time_year and TIME_MONT=@time_mont表里有几条符合条件的纪录,返回几。
"count(1)"是计数2
declare c_1 cursor for
select distinct
DIME_VALU_CODE
CODE_LEVE
from DSSD_UNIT
where IF_TOP='0'--去取表里符合条件IF_TOP='0'的纪录open c_1
fetch c_1 into @son_unit_code
while(@@sqlstatus=0) -- 把满足条件的第一条纪录赋给@son_unit
beginexec proc_dssf_tf_this @time_year,@time_mont,@son_unit_code --按照指定的值进行存储过程
fetch c_1 into @son_unit_code
end --While
close c_1
deallocate cursor c_1
--对结果集做循环。因为满足条件的纪录可能是多条。
where POWE>0 and TIME_YEAR=@time_year and TIME_MONT=@time_mont表里有几条符合条件的纪录,返回几。
"count(1)"是计数2
declare c_1 cursor for
select distinct
DIME_VALU_CODE
CODE_LEVE
from DSSD_UNIT
where IF_TOP='0'--去取表里符合条件IF_TOP='0'的纪录open c_1
fetch c_1 into @son_unit_code
while(@@sqlstatus=0) -- 把满足条件的第一条纪录赋给@son_unit
beginexec proc_dssf_tf_this @time_year,@time_mont,@son_unit_code --按照指定的值进行存储过程
fetch c_1 into @son_unit_code
end --While
close c_1
deallocate cursor c_1
--对结果集做循环。因为满足条件的纪录可能是多条。
select distinct
DIME_VALU_CODE
CODE_LEVE
from DSSD_UNIT
where IF_TOP='0' -- 定义Cursoropen c_1 -- 打开Cursor
fetch c_1 into @son_unit_code -- 相当于fetch next from c_1 into ...去第一条数据
赋值给变量@son_unit_code next 为fetch默认的
while(@@sqlstatus=0) -- 当取数成功时 @@sqlstatus = 0 否则为1或2
-- sql2000里为 @@fetch_status
begin -- 开始做循环exec proc_dssf_tf_this @time_year,@time_mont,@son_unit_code --按照指定的值进行存储过程
fetch c_1 into @son_unit_code -- 相当于fetch next from c_1 into ...取下一条数据
赋值给变量@son_unit_code next 为fetch默认的
end --结束循环
close c_1 -- 关闭cursor
deallocate cursor c_1 -- 释放cursor--cursor 主要是用于处理返回集不是一条时使用 可以依次处理返回的结果
fetch:推進游標的﹐即記錄號往下移
where POWE>0 and TIME_YEAR=@time_year and TIME_MONT=@time_mont这条语句会有怎样的显示结果呢?
"count(1)"是什么意思呀?count(1),等同于count(*),统计查询结果有多少条记录.
select distinct
DIME_VALU_CODE
CODE_LEVE
from DSSD_UNIT
where IF_TOP='0' --定义一个名为c_1的游标open c_1 --打开游标
fetch c_1 into @son_unit_code --从游标中取数据,保存到变量 @son_unit_code
while(@@sqlstatus=0) --循环,判断取数是否成功
begin --循环的开始标志
exec proc_dssf_tf_this @time_year,@time_mont,@son_unit_code --按照指定的值进行存储过程
fetch c_1 into @son_unit_code ----从游标中取下一条数据,保存到变量 @son_unit_code
end --While --循环结束标志
close c_1 --关闭游标
deallocate cursor c_1 --释放游标
就是统计查询结果有多少条记录.还有呀,就是偶在书上看到fetch是用来装取行的,在一开始已经装取了一遍了,为什么在结束的时候又装取了一遍呢?也就是问两个fetch分别代表什么意思呀?第一个fetch是读取第一条记录,后一个fetch是读取下一条记录,然后在while 判断是否到了最后一行。如果已经读到结束时,就会退出循环,关闭游标。
fetch:推進記錄號往下移
和:count(*) sum(1)一样返回记录数2
就着这个程序谁给俺仔细讲讲游标的作用?
循环读取记录还有呀,就是偶在书上看到fetch是用来装取行的,在一开始已经装取了一遍了,为什么在结束的时候又装取了一遍呢?
它是循环读取呀。也就是问两个fetch分别代表什么意思呀?
后面一个是循环里的呀。