SQL While 循环

语法:

WHILE condition
BEGIN
   {...statements...}
END

例子:

DECLARE @Counter INT 
SET @Counter=1
WHILE ( @Counter <= 10)
BEGIN
    PRINT 'The counter value is = ' + CONVERT(VARCHAR,@Counter)
    SET @Counter  = @Counter  + 1
END

测试结果如下:

 

 参考网址:https://www.sqlshack.com/sql-while-loop-with-simple-examples/

posted @ 2022-02-09 15:01  katesharing  阅读(97)  评论(0编辑  收藏  举报