티스토리 뷰

💼 정보 ver1.0

커서(cursor) 사용법

James Wetzel 2016. 1. 22. 14:34

-- 커서 선언

declare cur_purchaseCount cursor

for

select rn, member_id, purchase_count from @mobileFlatPrice


-- 커서 오픈

open cur_purchaseCount


-- 변수 선언(cursor에서 사용할 변수)

declare @v_rn bigint

declare @v_member_id varchar(12)

declare @v_purchase_count int


-- 첫 로우 fetch

fetch next from cur_purchaseCount into @v_rn, @v_member_id, @v_purchase_count


while @@FETCH_STATUS = 0

begin

update @mobileFlatPrice set

purchase_count = (select count(*) from tb_flatprice_member where member_id = @v_member_id)

where rn = @v_rn


-- 다음 로우 fetch

fetch next from cur_purchaseCount into @v_rn, @v_member_id, @v_purchase_count

end


--커서 닫기

close cur_purchaseCount

deallocate cur_purchaseCount

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함