利用游标返回结果集的的例子(Oracle 存储过程)
2011-09-22 09:30
477 查看
在sqlplus中建立如下的内容: 1、程序包 SQL> create or replace package types 2 as 3 type cursorType is ref cursor; 4 end; 5 / 程序包已创建。 2、函数 SQL> create or replace function sp_ListEmp return types.cursortype 2 as 3 l_cursor types.cursorType; 4 begin 5 open l_cursor for select id, title from cf_news order by id;--表的名字 6 return l_cursor; 7 end; 8 / 函数已创建。 3、过程 SQL> create or replace procedure getemps( p_cursor in out types.cursorType ) 2 as 3 begin 4 open p_cursor for select id, title from cf_news order by id;--表的名字 5 end; 6 / 过程已创建。
4、建立一个可执行的java控制台程序 import java.sql.*; import java.io.*; import oracle.jdbc.driver.*; class GetValues { public static void main (String args []) throws SQLException, ClassNotFoundException { String driver_class = "oracle.jdbc.driver.OracleDriver"; String connect_string = "jdbc:oracle:thin:@127.0.0.1:1521:database"; String query = "begin :1 := sp_listEmp; end;"; //此处调用前面建立的函数! Connection conn; Class.forName(driver_class); conn = DriverManager.getConnection(connect_string, "scott", "tiger"); CallableStatement cstmt = conn.prepareCall(query); cstmt.registerOutParameter(1,OracleTypes.CURSOR); cstmt.execute(); ResultSet rset = (ResultSet)cstmt.getObject(1); while (rset.next ()) System.out.println( rset.getString (1) ); cstmt.close(); } }http://www.chinaitpower.com/A200507/2005-07-27/171528.html
相关文章推荐
- 利用游标返回结果集的的例子(Oracle 存储过程)JAVA调用方法和.NET调用方法
- 利用游标返回结果集的的例子(Oracle 存储过程)
- 用游标返回结果集的的例子(Oracle 存储过程)
- Oracle利用游标返回结果集的的例子(C#)...(最爱)
- Oracle利用游标返回结果集的的例子(C#)
- oracle 游标 返回结果集 例子
- hibernate里使用jdbc方式调用oracle带游标返回参数的简单分页存储过程
- java程序调用Oracle 存储过程 获取返回值(无返回,非结果集,结果集)
- 最完整的:JAVA调用ORACLE的存储过程、函数的返回结果集例子
- Oracle用存储过程返回游标
- oracle ibatis 存储过程 返回游标 嵌套表
- Oracle 创建存储过程返回结果集
- java调用oracle过程返回结果集(包和游标)
- oracle 动态调用存储过程,返回游标类型
- Oracle 返回结果集的 存储过程
- fineRepot 读取存储过程返回游标数据源(oracle)
- ORACLE语法-包(package)、存储过程(procedure)、游标(cursor)以及java对Result结果集的处理
- oracle函数返回结果集(动态查询Sql并定义游标)
- Oracle 存储过程 返回结果集
- mybatis 调用 oracle 返回结果集 存储过程