//author 满晨晨
//time 2009 6 5上午
创建包(包中声明游标)和存储过程中使用游标
create or replace package mypack is
type mycursor is ref cursor;
end ;
create or replace procedure use_cursor
(v_cursor out mypack.mycursor,
v_deptno in emp.deptno%type) is
begin
open v_cursor for select * from emp where deptno=v_deptno;
end ;
用在显式多行记录
String sql="{call cursor(?)}";
try {
CallableStatement cstt=conn.prepareCall(sql);
cstt.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cstt.execute();
ResultSet s=(ResultSet) cstt.getObject(1);
ResultSetMetaData rsmd = null;
while(s.next()){
rsmd = s.getMetaData();
for(int j=1;j<rsmd.getColumnCount();j++)
{
System.out.print(s.getString(j)+ "/t");
}
System.out.println();
}