oracle 返回一条记录时,java端怎么取得?
--数据库端的包体createorreplacepackagebodypkg_studentisfunctionfun_student_allreturnstu_cur_...
--数据库端的包体
create or replace package body pkg_student is
function fun_student_all return stu_cur_type
is
stu_cur stu_cur_type;
begin
open stu_cur for select * from student;
return stu_cur;
end;
procedure pro_update_student(student_id_in in student.student_id%type,student_row_out out student%rowtype)
is
begin
update student set student.student_age = student.student_age+10
where student.student_id = student_id_in returning student_age,student_id,student_name into student_row_out;
end;
end pkg_student;
--java端的调用
package com.cctv.oracle;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.OracleTypes;
public class OracleTest_3 {
public static void main(String[] args) {
Connection conn = DBUtil.getConnection();
CallableStatement call = null;
try {
call = conn.prepareCall("call pkg_student.pro_update_student(?,?)");
call.setInt(1, 10000);
// ↓ 这行语句该怎么写? 这是接收返回值为游标类型的
call.registerOutParameter(2, OracleTypes.CURSOR);
call.execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
} 展开
create or replace package body pkg_student is
function fun_student_all return stu_cur_type
is
stu_cur stu_cur_type;
begin
open stu_cur for select * from student;
return stu_cur;
end;
procedure pro_update_student(student_id_in in student.student_id%type,student_row_out out student%rowtype)
is
begin
update student set student.student_age = student.student_age+10
where student.student_id = student_id_in returning student_age,student_id,student_name into student_row_out;
end;
end pkg_student;
--java端的调用
package com.cctv.oracle;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.OracleTypes;
public class OracleTest_3 {
public static void main(String[] args) {
Connection conn = DBUtil.getConnection();
CallableStatement call = null;
try {
call = conn.prepareCall("call pkg_student.pro_update_student(?,?)");
call.setInt(1, 10000);
// ↓ 这行语句该怎么写? 这是接收返回值为游标类型的
call.registerOutParameter(2, OracleTypes.CURSOR);
call.execute();
} catch (SQLException e) {
e.printStackTrace();
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询