oracle 创建存储过程_Oracle存储过程编程:流程控制选择结构和循环结构总结
《大數(shù)據(jù)和人工智能交流》頭條號(hào)向廣大初學(xué)者新增C 、Java 、Python 、Scala、javascript 等目前流行的計(jì)算機(jī)、大數(shù)據(jù)編程語(yǔ)言,希望大家以后關(guān)注本頭條號(hào)更多的內(nèi)容。
一、if /then語(yǔ)句和if/else/then語(yǔ)句和if/elsif/else/then
有個(gè)t1表,表結(jié)構(gòu)和數(shù)據(jù)如下:
要求實(shí)現(xiàn)下列需求:
1、如果a的值小于20,那么加100
create or replace procedure pro1(sname varchar2) is
v_a t1.a%type;
begin
select a into v_a from t1 where b=sname;
if v_a<20 then
update t1 set a=a+100 where b=sname;
end if;
end;
調(diào)用過(guò)程:
call pro1('aaa');
2、如果a的值小于20,那么加100,否則減少100
create or replace procedure pro2(sname varchar2) is
v_a t1.a%type;
begin
select a into v_a from t1 where b=sname;
if v_a<20 then
update t1 set a=a+100 where b=sname;
else
update t1 set a=a-100 where b=sname;
end if;
end;
call pro2('ccc');
二、循環(huán)
有個(gè)t1表,表結(jié)構(gòu)和數(shù)據(jù)如下:
要求實(shí)現(xiàn)下列需求:
1、loop/end loop
這種循環(huán)先執(zhí)行一次,再判斷相當(dāng)于java的do—while循環(huán)
創(chuàng)建過(guò)程
create or replace procedure pro3(sname varchar2) is
v_i number:=1;
begin
loop
insert into t1 values(v_i,sname);
exit when v_i=5;
v_i:=v_i+1;
end loop;
end;
執(zhí)行過(guò)程
call pro3(kkk);
2、while循環(huán)
create or replace procedure pro4(sname varchar2) is
v_i number:=1;
begin
while v_i<5 loop
insert into t1 values(v_i,sname);
v_i:=v_i+1;
end loop;
end;
call pro4('qqq');
總結(jié)
以上是生活随笔為你收集整理的oracle 创建存储过程_Oracle存储过程编程:流程控制选择结构和循环结构总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 如何学习前端 转载
- 下一篇: 跟我学Shiro目录贴