一个简单的存储过程
create or replace procedure my_proc as //如果存在就replace掉(覆盖)
begin
dbms_output.put_line('Hello World!');
end my_proc; //结束
/
执行存储过程可用exec或者execute,如exec procedure_name
重要的参数:
IN 参数
• 要通过调用者传入
• 只能由过程读取. 即它们只是读取值, 不能由过程改变.
OUT 参数
• 能够由过程写入
• 这些参数适用于过程需要向调用者返回多条信息的时候.
IN OUT 参数
• 同时具有IN参数和OUT参数的特性
• 能够用于传入数值, 并且从存储过程返回值.
• 它们适用于用户需要向过程可以由过程本身修改的INPUT变量的情况.
• 过程能够读取和写入它们的值.
IN参数1
create or replace
procedure insert_into_student(
p_sno in student.sno%type,
p_sname in student.sname%type,
p_age in student.sage%type) is
begin
insert into student(
sno,sname,sage)
values(p_sno,p_sname,p_age);
end insert_into_student;
/
调用该过程来插入数据
exec insert_into_student('24151','longfei','25');
附加小知识:查看表结构:desc table_name
IN参数2 (参数传递,名称表示法)
----------待续...