Oracle 存储过程--01

1.简单的例子

/*
1.求圆的面积
*/
create or replace procedure proc_1 is
  pi constant number(9,7):=3.1415927;
  radius integer(5);
  area number(14,2);
begin
  radius:=3;
  area:= pi*power(radius,2);
  insert into areas values(radius,area);
end proc_1;

2.使用游标,loop循环

/*
2.从表中读取值,计算圆的面积
*/
create or replace procedure proc_2 is
  pi constant number(9,7) := 3.1415927;
  area number(14,2);
  cursor rad_cur is 
       select * from radius_vals ;
  rad_temp rad_cur%rowtype;
begin
  open rad_cur;
  loop
       fetch rad_cur into rad_temp;
       exit when rad_cur%notfound;
       area:=pi*power(rad_temp.radius,2);
       insert into areas values(rad_temp.radius,area);
  end loop;
  close rad_cur;
end proc_2;

3.for循环

/*
3.for循环
*/
create or replace procedure proc_3 is
pi constant number(9,7):= 3.1415625;
cursor rad_cur is 
       select * from  radius_vals;
area number(14,2);
begin
  for rad_val in rad_cur
  loop
      area:=pi*power(rad_val.radius,2);
      insert into areas values(rad_val.radius,area);
  end loop;
end proc_3;

 

 

posted @ 2019-08-15 15:04  酸奶加绿茶  阅读(207)  评论(0编辑  收藏  举报