oracle存储过程 语法格式
CREATE OR REPLACE PROCEDURE procedureName
IS
DECLARE
.......
BEGIN
...........
END;
开始使用
su - oracle
sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on 星期二 5月 15 13:58:04 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
请输入用户名: user1
输入口令:
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create or replace procedure testp
2 is
3 begin
4 dbms_output.put_line('aaa');
5 end;
6 /
过程已创建。
SQL> call testp();
调用完成。
SQL> set serveroutput on
SQL> call testp();
aaa
调用完成。
SQL> begin
testp();
end;
.
SQL> /
aaa
PL/SQL 过程已成功完成。
输入代码以“.”结束代码录入
输入"/" 执行代码
http://blog.csdn.net/super1900/article/details/4246854
例子2 :输出小于指定年龄人的名字
创建表
create table k1(name varchar2(20),age number);
插入数据
insert into k1(name,age) values('aaa',20);
insert into k1(name,age)values('bbb',30);
创建存储过程
create or replace procedure uAge1(a2 number)
is
vName varchar2(20);
begin
select name into vName from k1 where age<a2;
dbms_output.put_line('name='||vName);
exception when others then
dbms_output.put_line('table no data found');
end;
.
SQL> /
调用存储过程
SQL> call UAGE1(30);
name=aaa
调用完成。
call UAGE1(40);
table no data found
调用完成。