创建过程:create or replace procedure p_1(n in out number) is r emp%rowtype; BEGIN dbms_output.put_line('姓名 薪水'); select * into r from emp where empno=n; dbms_output.put_line(r.ename||' '||r.sal); --输出结果,需要 set serverout on 才能显示. n:=r.sal; END;使用过程:declare n number; begin n:=&请输入员工号; p_1(n); dbms_output.put_line('n的值为 '||n); end;
一、无返回值存储过程实例:添加book表书,需求通过java程序调用该过程 ---建表 oracle table book(bookid number(10),bookname varchar2(20),price number(4,2)); ---创建存储过程 create or replace tt_pro(mbookid number,mbookname in varchar2,price number)is begin insert into book values(mbookid,mbookname,price); end;二、有返回值的存储过程(列表结果集)案例:输入部门号,返回部门所有的雇员的信息 ---建包 create or replace package testpackage as type test_cursor is ref cursor; end; ---创建存储过程 create or replace tt_pro( mno in number, m_cursor out testpackage test_cursor )is begin open m_cursor for select * from emp where deptno=mno; end; 最后然后编写一个java调用该存储过程
-----创建序列 create sequence book_id INCREMENT BY 1 -- 每次加几个 START WITH 001 -- 从1开始计数 NOMAXVALUE -- 不设置最大值 NOCYCLE -- 一直累加,不循环 CACHE 10; ------创建books表 create table books( books_id number, books_name varchar2(100), price number, qty number, pub varchar2(200) ); -------------往books表中插入数据 insert into books values(book_id.nextval,'中国文学1',39,12,'人民文学'); insert into books values(book_id.nextval,'中国文学2',30,32,'人民文学'); insert into books values(book_id.nextval,'中国文学3',59,22,'清华大学'); insert into books values(book_id.nextval,'中国文学4',33,52,'清华大学'); insert into books values(book_id.nextval,'中国文学5',99,62,'电子工业');根据书名,利用游标,怎么返回所查询的结果,代码怎么写
Oracle 存储过程 使用示例
http://blog.csdn.net/tianlesoftware/article/details/6147230
r emp%rowtype;
BEGIN
dbms_output.put_line('姓名 薪水');
select * into r from emp where empno=n;
dbms_output.put_line(r.ename||' '||r.sal); --输出结果,需要 set serverout on 才能显示.
n:=r.sal;
END;使用过程:declare
n number;
begin
n:=&请输入员工号;
p_1(n);
dbms_output.put_line('n的值为 '||n);
end;
http://blog.csdn.net/tianlesoftware/article/details/6147230
---建表
oracle table book(bookid number(10),bookname varchar2(20),price number(4,2));
---创建存储过程
create or replace tt_pro(mbookid number,mbookname in varchar2,price number)is
begin
insert into book values(mbookid,mbookname,price);
end;二、有返回值的存储过程(列表结果集)案例:输入部门号,返回部门所有的雇员的信息
---建包
create or replace package testpackage as type test_cursor is ref cursor;
end;
---创建存储过程
create or replace tt_pro(
mno in number,
m_cursor out testpackage test_cursor
)is
begin
open m_cursor for select * from emp where deptno=mno;
end;
最后然后编写一个java调用该存储过程
create sequence book_id
INCREMENT BY 1 -- 每次加几个
START WITH 001 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
CACHE 10;
------创建books表
create table books(
books_id number,
books_name varchar2(100),
price number,
qty number,
pub varchar2(200)
);
-------------往books表中插入数据
insert into books values(book_id.nextval,'中国文学1',39,12,'人民文学');
insert into books values(book_id.nextval,'中国文学2',30,32,'人民文学');
insert into books values(book_id.nextval,'中国文学3',59,22,'清华大学');
insert into books values(book_id.nextval,'中国文学4',33,52,'清华大学');
insert into books values(book_id.nextval,'中国文学5',99,62,'电子工业');根据书名,利用游标,怎么返回所查询的结果,代码怎么写