oracel在sql中的循环

---关于Oracle里面的循环
-- while循环
CREATE OR REPLACE 
function while_test(x in number,y in number)
return number is 
z number;
totalCount number;
begin
	z:=x;
	totalCount:=0;
	while z<y+1
	loop
			delete USERTEMP where id=z;
			z:=z+1;
			totalCount:=totalCount+1;
	end loop;
return totalCount; --结果为6   
end;
--for 循环
CREATE OR REPLACE 
function for_test(x in number)
return number is
z number;
begin
	z:=0;
	for v_sum in 1..50  
	loop
				z:=z+2;
	end loop;
	return z;
end;
--单循环
CREATE OR REPLACE 
function perfunctory_test(x in number)
return number
 is z number;
begin
     loop
         z:=x*x; --实现函数(x)的平方   
         exit;
     end loop;
return z;
end;
--- 注意事项 :mysql 里面的循环和Oracle里面的不同,声明,赋值都不同。这里吃了大亏,本身一直在写MySQL的语句,因此运行不成功。
-- 【Mysql】的while循环语句
declare @i int
       set @i=1
      while @i<10
           begin
              insert into USERTEMP(id,name,CARDTYPE,CARDNO,status) VALUES(@i,'李','学生','01',2);
              set @i=@i+1
          end
相关文章
相关标签/搜索