新聞中心
在SQL數(shù)據(jù)庫中,不使用游標(biāo),也能遍歷記錄?答案是肯定的,下面就為您介紹不用游標(biāo)也能遍歷記錄的sql語句實(shí)例,供您參考。

為西疇等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及西疇網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司、西疇網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
--聲明變量表@tb
declare @tb table(id int,name varchar(50))
--添加測試數(shù)據(jù)
insert into @tb
select 6,'aa' union all
select 7,'bb' union all
select 8,'cc' union all
select 9,'dd' union all
select 10,'abc' union all
select 11,'ddef' union all
select 12,'fda' union all
select 13,'rewr' union all
select 14,'eyt' union all
select 15,'jjy' union all
select 16,'bbbxd' union all
select 17,'xxx' union all
select 18,'ffff' union all
select 19,'wwwwwwww' union all
select 20,'aaaaaaaaaa'
/*
查看表中數(shù)據(jù)
select * from @tb
*/
--聲明循環(huán)用的“指針”
declare @min varchar(5)
--賦初值
select @min=min(id) from @tb
--開始循環(huán)
while @min is not null
begin
print @min --打印當(dāng)前“指針”的值
select @min=min(id) from @tb where id>@min --更新“指針”內(nèi)容,使之移到下一記錄
end
【編輯推薦】
教您使用參數(shù)化SQL語句
SQL中的分頁查詢語句介紹
批處理SQL語句的執(zhí)行效率提高的方法
SQL語句中特殊字符的處理方法
教您用SQL語句進(jìn)行模糊查詢
網(wǎng)頁名稱:不用游標(biāo)也能遍歷記錄的sql語句實(shí)例
文章網(wǎng)址:http://m.jiaoqi3.com/article/dppjidd.html


咨詢
建站咨詢
