oracle 创建存储过程_Oracle存储过程编程:流程控制选择结构和循环结构总结
《大數據和人工智能交流》頭條號向廣大初學者新增C 、Java 、Python 、Scala、javascript 等目前流行的計算機、大數據編程語言,希望大家以后關注本頭條號更多的內容。
一、if /then語句和if/else/then語句和if/elsif/else/then
有個t1表,表結構和數據如下:
要求實現下列需求:
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;
調用過程:
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');
二、循環
有個t1表,表結構和數據如下:
要求實現下列需求:
1、loop/end loop
這種循環先執行一次,再判斷相當于java的do—while循環
創建過程
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;
執行過程
call pro3(kkk);
2、while循環
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');
總結
以上是生活随笔為你收集整理的oracle 创建存储过程_Oracle存储过程编程:流程控制选择结构和循环结构总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何学习前端 转载
- 下一篇: 跟我学Shiro目录贴