代码改变世界

Procedure 存储过程

2017-06-27 00:44  cnblogs_qm  阅读(183)  评论(0编辑  收藏  举报

 

创建

create [or replace] procedure pro_name [(
  v_p1 [in] v_p_type1[ default 'val1']
  [, ...]
  [, v_o1 out v_o_type1]
  [, ...]
  )]
is|as
begin
  plsql_sentences;
[exception]
  [dowith_sentences;]
end [pro_name];
/

 

执行

EXEC[UTE] pro_name(v_p1, ..., :v_o1, ...);
EXEC[UTE] pro_name(v_p2=>'val2',..., :v_o1, ...)

 

示例

--
create procedure pro_demo(v_param varchar2, v_out out varchar2)
is
begin
  insert into t_demo values (v_param);
  commit;
  select name into v_out from t_demo where rownum = 1;
  dbms_output.put_line('Create ' || v_param || ' successfully.');
  exception
    when no_data_found then
      dbms_output.put_line('Found no data.');
end pro_demo;
/

 

-- 
variable v_out varchar2(50);
execute pro_demo('demo', :v_out);
print v_out;