温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

oracel在sql中的循环

发布时间:2020-07-18 02:37:30 来源:网络 阅读:514 作者:建波李 栏目:关系型数据库
---关于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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI