oracle利⽤游标查询数据,Oracle使⽤函数function查询数据返
回游标
create or replace function test111(itemNumber in varchar2) return SYS_REFCURSOR
is
return_cursor SYS_REFCURSOR;
begin
OPEN return_cursor FOR SELECT 'a' FROM dual WHERE 1 = itemNumber;
RETURN return_cursor;
end test111;
使⽤如下sql返回 游标,在pl sql developer可以直接点开查询结果
select test111(1) from dual;
适⽤条件: 在Sql语句过长时可以适⽤,避免在java代码中有过长的sql代码!
jdbc调⽤结果集
package com.dahuatech.job;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import oracle.jdbc.driver.OracleResultSet;
oracle游标的使用import oracle.jdbc.driver.OracleTypes;
public class Test {
public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@10.30.5.106:1521:agile9";
Connection conn = Connection(url, "agile", "***");
String sql = "{? = call test111(?)}";
CallableStatement cst = conn.prepareCall(sql);
cst.setString(2, "1");
OracleResultSet rs = (OracleResultSet) Object(1);
while (rs.next()) {
System.out.String("a"));
}
} }

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。