在sql*plus中直接用就可以了在procedure中,需要使用游标
解决方案 »
- 请问如何得到Oracle SQLException的errorCode, 用SQLException.getErrorcode() 总是返回0
- 过程恢复(急)
- 这个语句如何写?
- 超高难度的sql查询语句,能行你就来(老难了,要有心里准备)
- Oracle 数据库和 SQL SEVER2000 数据库的概念有什么不一样呢?
- oracle启动服务程序的问题
- oracle中的number(10,2)等同于sql server数据库中什么类型???
- 我只想用oracle作为后台数据库,没想成为DBA,懂这些够了吗?
- 数据文件或控制文件损坏了,我怎么知道是哪个文件?
- 盼高手帮助解决
- Proc登陆数据库?
- 一条sql语句不会写,求助
create or replace package dinya_pkg_test
as
type myCursor is ref cursor;
function get(p_id number) return myCursor;
end dinya_pkg_test;--包体
create or replace package body dinya_pkg_test
as --*********************************************************************************
--输入ID 返回记录集的函数
function get(p_id number) return myCursor is
rc myCursor;
strsql varchar2(200);
begin
if p_id=0 then
open rc for select a.user_name from fnd_user a ;
else
strsql:='select a.user_name from fnd_user a where a.user_id=:p_id';
open rc for strsql;
end if;
return rc;
end get;
end dinya_pkg_test;--调用:
set serverout on
declare
w_rc dinya_pkg_test.myCursor;
w_name varchar2(100);
begin
w_rc:=dinya_pkg_test.get(0); --这里输入要的参数
loop
fetch w_rc into w_name;
exit when w_rc%notfound;
dbms_output.put_line(w_name);
end loop;
end;
/
eg:
conn scott/tiger@你的实例名
set serveroutput on
declare
v_emp emp%rowtype;
begin
select * into v_emp from emp where empno=7499;
dbms_output.put_line('Salary commision');
dbms_output.put_line(v_emp.sal || ' ' || v_emp.comm);
end;
/