存储过程
我感觉它就是一个函数呀....大概没get到点,求告知。
【通用结构】
create or replace procedure 存储名 (输入变量名 变量的数据结构 )
as
begin
操作语句
end;
【通用语句】调用存储过程
exec 过程名()
【例题1】创建存储过程,删除score表中某学号的学生数据
create or replace procedure p_delscore
(v_sno score.sno%type)
as
begin
delete from score where sno=v_sno;
if sql%rowcount=0 then
dbms_output.put_line('nodata');
else
dbms_output.put_line('delete'||sql%rowcount||'row');
commit;
end if;
end;
【执行】exec p_delscore('0601020212')
【解析】数据操作成功,一定要写commit提交。存储过程最重要的就是安全性,如果代码运行停止了,防止数据库会处于某种不安全状态 。
【例题2】创建存储过程,给出需要修改的院名,修改sdept表中该院系的名称
create or replace procedure p_update
(v_name sdept.deptno%type,v_dname sdept.deptno%type)
as
begin
update sdept set dname=v_dname where dname=v_name;
if sql%rowcount!=0 then