数据库SQL编程题

来源:百度知道 编辑:UC知道 时间:2024/06/06 19:37:03
编写程序实现[1,40]的奇数平方和赋x,偶数平方和赋y,并输出x,y的值(程序的正确输出应为x=10660,y=11480)

declare @j int,@o int,@i int
set @i=1
set @j=0
set @o=0
while @i<=40
begin
if(@i%2=1)
set @j=@j+@i*@i
else
set @o=@o+@i*@i
set @i=@i+1
end
print 'x='+convert(char(5),@j)+',y='+convert(char(5),@o)

declare
x INTEGER:=0;
y INTEGER:=0;
i INTEGER:=0;
begin
loop
x:= (1+i*2)*(1+i*2)
y:=(2+i*2)*(2+i*2)
i:= i+1;
exit when i>19;
end loop;
DBMS_OUTPUT.PUT_LINE(To_char(x));
DBMS_OUTPUT.PUT_LINE(To_char(y));
end;

你试试?