Sqlserver 커서 복습
2741 단어 sqlserver
코드는 간단하지만 명심하세요.
Create PROCEDURE [dbo].[temphxb]
AS
BEGIN
declare @uid int
declare mycursortemp Cursor
for select uid from temptable1 where Indate>'2015-05-21' and type='1' group by uid having COUNT(*)>1
open mycursortemp
fetch next from mycursortemp into @uid
while @@FETCH_STATUS=0
begin
delete from temptable1 where id
in (select top 1 id from temptable1 where uid=@uid and Indate>'2015-05-21' and fdtype='1')
update temptable2 set num=num+1 where uid=@uid
fetch next from mycursortemp into @uid
end
close mycursortemp
DEALLOCATE mycursortemp
end
커서의 사용 과정에서 일반적으로 다음과 같은 다섯 가지 절차로 나뉜다. 1. 커서를 성명한다.
2. 커서 열기
3. 커서 사용
4. 커서 닫기
5. 커서 삭제
오늘 저는 세 번째 커서가 데이터를 훑어보는 동안fetch next from mycursortemp into @uid를 실행하는 것을 잊어버려서 사순환이 발생하고 적지 않은 손실을 초래했습니다.또 많은 사람들이 커서를 닫는 것을 잊어버려서 다음 실행에 오류가 발생할 수도 있다.
데이터베이스 조작은 신중하고 신중해야 하며 명심해야 한다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
우분투에 SQL 서버 설치Microsoft SQL Server는 오늘날 업계에서 가장 눈에 띄는 데이터베이스 중 하나입니다. 이번 포스팅에서는 우분투에 설치하는 방법을 알려드리겠습니다. sudo 권한이 있는 계정 1단계: 터미널 열기 단축키...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.