PL_SQL基础--续五
来源:互联网 发布:淘宝秒杀回答问题技巧 编辑:程序博客网 时间:2024/05/17 06:49
存储过程
存储过程--起了名字的PL_SQL程序:
create or replace procedure p
is
cursor c is
selcet * from emp2 for update;
begin
for v_emp in c loop
if(v_emp.deptno = 10) then
update emp2 set sal = sal + 10 where current of c;
elsif(v_emp.deptno = 20) then
update emp2 set sal = sal + 20 where current of c;
else
update emp2 set sal =sal +50 where current of c;
end if;
end loop;
commit;
end;
执行存储过程:
1.exec p;
2.begin
p;
end;
--带参数的存储过程
--in 传入参数,out 传出参数,不写默认为传入参数。一个参数可既为传入参数,又可为传出参数。
create or replace procedure p
(v_a in number, v_b number,v_ret out number,v_temp in out number)
is
begin
if(v_a > v_b) then
v_ret := v_a;
else
v_ret := v_b;
end if;
v_temp := v_temp + 1;
end;
--调用程序
declare
v_a number := 3;
v_b number := 4;
v_ret number;
v_temp number := 5;
begin
p(v_a,v_b,v_ret,v_temp);
dbms_output.put_line(v_ret);
dbms_output.put_line(v_temp);
end;
需注意的是produre创建的过程中如出现语法错误,不会报错,只是出警告。
需要show error命令把错误show出来。
用存储过程实现蚂蚁大战大象的树状结构的展现:
create or replace procedure p(v_pid article.pid%type,v_level binary_integer)
is
cursor c is select * from article where pid = v_pid;
v_preStr varchar2(1024) := '';
begin
for i in 1..v_level loop
v_preStr := v_preStr || '***';
end loop;
for v_article in c loop
dbms_output.put_line(v_preStr || v_article.cont);
if(v_article.isleaf = 0) then
p(v_article.id,v_level + 1);
end if;
end loop;
end;
- PL_SQL基础--续五
- PL_SQL基础--续
- PL_SQL基础--续二
- PL_SQL基础--续三
- PL_SQL基础--续四
- PL_SQL基础--续六
- PL_SQL基础
- PL_SQL基础编程
- pl_sql
- pl_sql
- 尚学堂马士兵Oracle学习笔记之五:PL_SQL(过程化SQL语言)
- pl_sql 游标
- PL_SQL注册码
- 基础五
- PL_SQL 复习笔记
- PL_SQL笔记(1)(转载)
- Oracle PL_SQL语句总结
- PL_SQL 权限不足
- PL_SQL基础--续
- PL_SQL基础--续二
- PL_SQL基础--续三
- 数组Marshalling
- PL_SQL基础--续四
- PL_SQL基础--续五
- PL_SQL基础--续六
- 微软搜索引擎突围:斥资1亿为Kumo做广告
- 可以让你少奋斗10年的工作经验
- 强烈推荐优秀英文网站
- 这样的日子应该开心。。
- 书行鼓山道中
- 谁有穿越火线加速WG
- 怀念奶奶