案例:添加学生,然后返回该班级的所有学生。create or replace procedure add_stu(p_sid stu.sid%type, p_sname stu.sn
案例:添加学生,然后返回该班级的所有学生。
create or replace procedure add_stu(
p_sid stu.sid%type,
p_sname stu.sname%type,
p_cid stu.cid%type,
p_data out sys_refcursor -- 输出变量,系统引用游标
)
as
begin
insert into stu(sid,sname,cid)
values(p_sid,p_sname,p_cid);
commit;
--将查询的结果集的地址放到引用游标变量中,,再传递出去
open p_data for select * from stu where cid=p_cid;
end;
--PL/SQL 调用
declare
stu_data sys_refcursor;
stu_row stu%rowtype;
begin
add_stu(52,'b',1,stu_data);
fetch stu_data into stu_row;
while(stu_data%found)
loop
dbms_output.put_line(stu_row.sname);
fetch stu_data into stu_row;
end loop;
close stu_data;
end;
MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架。MyBatis 消除 了几乎所有的 JDBC 代码和参数的手工设置以及结果集的检索。MyBatis 使用简单的 XML 或注解用于配置和原始映射,将接口和 Java 的 POJOs(Plan Old Java Objects,普通的 Java 对象)映射成数据库中的记录。有需要的朋友可以下载看看
1
--java中调用
CallableStatement cstmt = null;
String spName = “{call add_stu(?,?,?,?)}";
cstmt = conn.prepareCall(spName);
cstmt.setInt(1, 工号);
…………
cstmt.registerOutParameter(4, Oracle.jdbc.OracleTypes.CURSOR); --设置第4个问号的值
cstmt.executeUpdate();
ResultSet rs = (ResultSet)cstmt.getObject(4);

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号