sql编程的通过三种循环方式计算1-100之间能被7整数的和

**#sql编程的通过三种循环方式计算1-100之间能被7整数的和。提示(取余使用mod()函数)

**`

通过三种循环方式计算1-100之间能被7整数的和。提示(取余使用mod()函数)
  1 (for)
declare
 s int :=0;
 m constant int:=7;
 begin
     for n in reverse 1..100 loop
       if mod(n,m)=0 then s := s+n;
       else s:=s;
       end if;
     end loop;
    dbms_output.put_line('s的和:'||s);
   end;


  2(loop)
      declare
 s int :=0;
 n int :=1;
 m constant int:=7;
 begin
     loop
       if mod(n,m)=0 then s := s+n;
       else s:=s;
       end if;
       n:=n+1;
       exit when n>100;
     end loop;
    dbms_output.put_line('s的和:'||s);
   end;  

 3(while)

  declare
 s int :=0;
 n int :=1;
 m constant int:=7;
 begin
    while n<=100 loop
       
       if mod(n,m)=0 then s := s+n;
       else s:=s;
       end if;
       n:=n+1;
       
     end loop;
    dbms_output.put_line('s的和:'||s);
   end;
 

你可能感兴趣的:(数据预处理,sql,sql,数据库,database)