上面的两种方式都是非常的复杂,如果仅仅是需要返回一个结果集,那就完全可以使用函数来实现了。
Java代码
create or replace package procpkg is
type refcursor is ref cursor;
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor);
function procpostype(p varchar2) return PosTypeTable;
end procpkg;
create or replace package body procpkg is
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor)
is
v_posTypeList PosTypeTable;
begin
v_posTypeList :=PosTypeTable();--初始化嵌套表
v_posTypeList.extend;
v_posTypeList(1) := PosType('A001','客户资料变更');
v_posTypeList.extend;
v_posTypeList(2) := PosType('A002','团体资料变更');
v_posTypeList.extend;
v_posTypeList(3) := PosType('A003','受益人变更');
v_posTypeList.extend;
v_posTypeList(4) := PosType('A004','续期交费方式变更');
open p_ref_postypeList for select * from table(cast (v_posTypeList as PosTypeTable));
end;
function procpostype(p varchar2) return PosTypeTable
as
v_posTypeList PosTypeTable;
begin
v_posTypeList :=PosTypeTable();--初始化嵌套表
v_posTypeList.extend;
v_posTypeList(1) := PosType('A001','客户资料变更');
v_posTypeList.extend;
v_posTypeList(2) := PosType('A002','团体资料变更');
v_posTypeList.extend;
v_posTypeList(3) := PosType('A003','受益人变更');
v_posTypeList.extend;
v_posTypeList(4) := PosType('A004','续期交费方式变更');
return v_posTypeList;
end;
end procpkg;
create or replace package procpkg is
type refcursor is ref cursor;
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor);
function procpostype(p varchar2) return PosTypeTable;
end procpkg;
create or replace package body procpkg is
procedure procrefcursor(p varchar2, p_ref_postypeList out refcursor)
is
v_posTypeList PosTypeTable;
begin
v_posTypeList :=PosTypeTable();--初始化嵌套表
v_posTypeList.extend;
v_posTypeList(1) := PosType('A001','客户资料变更');
v_posTypeList.extend;
v_posTypeList(2) := PosType('A002','团体资料变更');
v_posTypeList.extend;
v_posTypeList(3) := PosType('A003','受益人变更');
v_posTypeList.extend;
v_posTypeList(4) := PosType('A004','续期交费方式变更');
open p_ref_postypeList for select * from table(cast (v_posTypeList as PosTypeTable));
end;
function procpostype(p varchar2) return PosTypeTable
as
v_posTypeList PosTypeTable;
begin
v_posTypeList :=PosTypeTable();--初始化嵌套表
v_posTypeList.extend;
v_posTypeList(1) := PosType('A001','客户资料变更');
v_posTypeList.extend;
v_posTypeList(2) := PosType('A002','团体资料变更');
v_posTypeList.extend;
v_posTypeList(3) := PosType('A003','受益人变更');
v_posTypeList.extend;
v_posTypeList(4) := PosType('A004','续期交费方式变更');
return v_posTypeList;
end;
end procpkg;
ibatis配置
Java代码
<resultMap id="posTypeResultMap" class="com.palic.elis.pos.common.dto.CodeTableItemDTO">
<result property="code" column="posType"/>
<result property="description" column="description"/>
</resultMap>
<select id="procPostype" resultMap="posTypeResultMap">
select * from table(cast (procpkg.procpostype(#value#) as PosTypeTable))
</select>
<resultMap id="posTypeResultMap" class="com.palic.elis.pos.common.dto.CodeTableItemDTO">
<result property="code" column="posType"/>
<result property="description" column="description"/>
</resultMap>
<select id="procPostype" resultMap="posTypeResultMap">
select * from table(cast (procpkg.procpostype(#value#) as PosTypeTable))
</select>Dao的写法跟普通查询一样
Java代码
public List queryPostype() {
return this.getSqlMapClientTemplate().queryForList("pos_dayprocset.procPostype", null);
}
public List queryPostype() {
return this.getSqlMapClientTemplate().queryForList("pos_dayprocset.procPostype", null);
}
有几点需要注意,这里不能使用索引表,而是嵌套表。
另外就是把嵌套表强制转换为普通表。