存储过程
Posted 陆伟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了存储过程相关的知识,希望对你有一定的参考价值。
CREATE [OR REPLACE] PROCEDURE procedure_name
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];
先初始化数据。
create table students ( ID int, userName varchar(100), userPass varchar(100), userAge int ) begin insert into students values(1,‘jack‘,‘jjjaa‘,23); insert into students values(2,‘rose‘,‘jjjaa‘,21); insert into students values(3,‘lucy‘,‘jjjaa‘,22); insert into students values(4,‘Tony‘,‘jjjaa‘,24);
end; commit;
新建一个存储过程,对于某个用户添加年龄
create or replace procedure SP_Update_Age ( uName in varchar,--note,here don‘t have length ,sql have lenth ,not in oracle. Age in int ) as begin update students set UserAge = UserAge + Age where userName = uName; commit; end SP_Update_Age;
执行存储过程
call SP_UPDATE_AGE(‘jack‘,1);
call和exec的区别:
1. 但是exec是sqlplus命令,只能在sqlplus中使用;call为SQL命令,没有限制.
2. 存储过程没有参数时,exec可以直接跟过程名(可以省略()),但call则必须带上().
以上是关于存储过程的主要内容,如果未能解决你的问题,请参考以下文章