存储过程常用技巧4

上面的两种方式都是非常的复杂,如果仅仅是需要返回一个结果集,那就完全可以使用函数来实现了。
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);
}
有几点需要注意,这里不能使用索引表,而是嵌套表。
另外就是把嵌套表强制转换为普通表。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值