SQL中的Continue和Break


x

在Sql Server中,sql語句包含While循環的時候,肯定都或多或少的用到Continue和Break...

下面擼了一個小Demo

Declare @Index Int = 0,@EndIndex Int = 0

While  @Index < 100
    Begin
        Set @EndIndex = @EndIndex + 1
        Print 'Continue 之后Index增加...' + Convert(Varchar(1000),@Index)
        If @EndIndex > 100
            Begin
                Print '防止死循環...*************************************************'
                Break
            End
            
        Continue
        Set @Index =@Index + 1
    End

Set @Index = 0

While  @Index < 100
    Begin
        Print 'Continue 之前Index增加...' + Convert(Varchar(1000),@Index)
        Set @Index =@Index + 1
        Continue
    End

Set @Index = 0
While  @Index < 100
    Begin
        Print 'Break Index...' + Convert(Varchar(1000),@Index)
        Break
    End

 

 

x

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM