22,210
社区成员
发帖
与我相关
我的任务
分享
declare @n int,@s varchar(500)
select @n=1,@s=''
while @n<=5
begin
select @s=@s + replicate('*',@n)+ char(10)
set @n=@n+1
end
select @s
/*
*
**
***
****
*****
(1 行受影响)
*/
DECLARE @l INT
DECLARE @c VARCHAR(30)
SET @c=''
SET @l=5
WHILE(@l>0)
BEGIN
SET @c=@c+'*'
PRINT @c
SET @l=@l-1
END
/*
*
**
***
****
*****
*/
declare @N int,@M int
set @M=0
set @N=0
while @M<7
begin
if @M<=3/*输出图形的上半部分*/
begin
while @N<4
begin
print space(8-@N)+REPLICATE('*',@N*2+1)
SET @N=@N+1
end
SET @M=@M+1
end
ELSE/*输出图形的下半部分*/
BEGIN
while @n>0
begin
set @N=@N-1;
print SPACE(8-@N)+REPLICATE('*',@n*2+1);
end
set @M=@M+1
END
end
/*
*
***
*****
*******
*******
*****
***
*
*/
declare @i int
declare @s varchar(500)
set @s=''
set @i=1
while @i<6
begin
set @s = @s + REPLICATE('*',@i)+char(13)
set @i=@i+1
end
select @s
*
**
***
****
*****
(所影响的行数为 1 行)