1.C#代码:

1)
using Oracle.DataAccess.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Oracle.DataAccess.Client; namespace YY.SmsPlatform.OracleDataSource
{
public class HotStandby_RechargeType : IOracleCustomType
{
public void FromCustomObject(OracleConnection con, IntPtr pUdt)
{
OracleUdt.SetValue(con, pUdt, "USERNAME", this.UserName);
OracleUdt.SetValue(con, pUdt, "MSGTYPE", this.MsgType);
OracleUdt.SetValue(con, pUdt, "VAL", this.Val);
} public void ToCustomObject(OracleConnection con, IntPtr pUdt)
{
this.UserName = (string)OracleUdt.GetValue(con, pUdt, "USERNAME");
this.MsgType = (int)OracleUdt.GetValue(con, pUdt, "MSGTYPE");
this.Val = (int)OracleUdt.GetValue(con, pUdt, "VAL");
}
[OracleObjectMapping("USERNAME")]
public string UserName { get; set; }
[OracleObjectMapping("MSGTYPE")]
public int MsgType { get; set; }
[OracleObjectMapping("VAL")]
public int Val { get; set; }
}
[OracleCustomTypeMappingAttribute("HOTSTANDBY_RECHARGE")]
public class HotStandby_RechargeFactory : IOracleCustomTypeFactory
{
public IOracleCustomType CreateObject()
{
return new HotStandby_RechargeType();
}
}
[OracleCustomTypeMapping("HOTSTANDBY_RECHARGE_ARRAY")]
public class HotStandby_RechargeArrayFactory : IOracleArrayTypeFactory
{
public Array CreateArray(int numElems)
{
return new HotStandby_RechargeFactory[numElems];
} public Array CreateStatusArray(int numElems)
{
return null;
}
}
}
2)
//调用存储过程
public bool UserAmountChange(Dictionary<string, long> fee, Dictionary<string, long> recharge)
{
    List<HotStandby_RechargeType> f = GetRechargeTypeArray(fee);
    List<HotStandby_RechargeType> r = GetRechargeTypeArray(recharge);
   using (OracleConnection conn = this.CreateConnection())
    using (OracleCommand cmd = conn.CreateCommand())
{
       conn.Open();
       cmd.CommandText = "Proc_HotStandbyQuotaChange";
       cmd.CommandType = CommandType.StoredProcedure;
       var op = new OracleParameter { ParameterName = "result", OracleDbType = OracleDbType.Int32, Direction = ParameterDirection.Output,Value=null };
       cmd.Parameters.AddRange(new OracleParameter[] {
       new OracleParameter {ParameterName= "FeeDeduction", OracleDbType=OracleDbType.Array,Direction=ParameterDirection.Input,UdtTypeName= "HOTSTANDBY_RECHARGE_ARRAY", Value=f.ToArray() },
       new OracleParameter {ParameterName= "Recharge", OracleDbType = OracleDbType.Array, Direction = ParameterDirection.Input, UdtTypeName = "HOTSTANDBY_RECHARGE_ARRAY", Value = r.ToArray() },
       op });//HotStandby_Recharge_Array
       cmd.ExecuteNonQuery();
       int num = Convert.ToInt32(op.Value.ToString());
       return num == 0;
  }
}

2.存储过程:

create or replace procedure Proc_HotStandbyQuotaChange
(
FeeDeduction in HotStandby_Recharge_Array,
Recharge in HotStandby_Recharge_Array,
result out integer
)as cursor f_cursor is select * from table(FeeDeduction) ;
cursor r_cursor is select * from table(Recharge);
v_userid integer:=0;
f_row f_cursor%rowtype;
r_row r_cursor%rowtype;
begin
open f_cursor;--打开游标
-- fetch f_cursor into f_row ;
loop
fetch f_cursor into f_row ;
--让游标指针往下移动
exit when f_cursor%notfound;
update user_amountinfo t set t.amount=t.amount-(f_row.Val) where t.userid=(select c.userid from base_userinfo c where c.username=f_row.UserName) and t.msgtype=f_row.MsgType;
-- fetch f_cursor into f_row ;
end loop;
close f_cursor;
open r_cursor;
loop
fetch r_cursor into r_row;
exit when r_cursor%notfound;
select nvl(max(t.userid),0) into v_userid from user_amountinfo t where t.userid = (select u.userid from base_userinfo u where u.username =r_row.UserName) and t.msgtype = r_row.MsgType;
if (v_userid>0)
then
update user_amountinfo t set t.amount=t.amount-(r_row.Val),t.addtime=SYSDATE(),t.rechargeamount=t.rechargeamount-(r_row.Val) where t.userid=v_userid and t.msgtype=r_row.MsgType;
elsif (v_userid<=0)
then
select t.userid into v_userid from base_userinfo t where t.username=r_row.UserName;
insert into user_amountinfo(userid,amount,msgtype,addtime,rechargeamount) values(v_userid,r_row.Val,r_row.MsgType,Sysdate(),r_row.Val);
end if;
end loop;
close r_cursor;
commit;
result:=sqlcode;
end Proc_HotStandbyQuotaChange;

3.自定义类型:

--创建自定义类型
CREATE OR REPLACE TYPE HotStandby_Recharge
is object(
UserName varchar2(50),
MsgType number,
Val number
);
--创建自定义表类型
CREATE OR REPLACE TYPE HOTSTANDBY_RECHARGE_ARRAY as table of HotStandby_Recharge

最新文章

  1. 实战动态PDF在线预览及带签名的PDF文件转换
  2. CSS3 笔记四(Transforms/Transition/Animations)
  3. Google开源SLAM软件cartographer中使用的UKF滤波器解析
  4. [马哥学习笔记]Linux系统裁剪之制作带网络功能的可启动linux
  5. Delphi中Interface接口的使用方法
  6. C# 键值对类相关
  7. shell脚本编程-使用结构化命令(if/else)(转)
  8. windows 创建服务提示失败 5 拒绝 访问拒绝
  9. Linux的安装 CentOS-7.1
  10. Linux Shell删除某一个目录下的所有文件夹(保留其他文件)
  11. Python 手册——Python的非正式介绍
  12. There are no accidents.
  13. 基于HTML5和WebGL的3D网络拓扑结构图
  14. 微信小程序 - 上拉加载
  15. Netbeans简要配置许可证信息
  16. 自己动手DIY macos下的绘图软件Pencil之原生菜单
  17. 线程相关代码分析-&gt;常见面试题(一、Thead类)
  18. k8s 题目
  19. mybatis如何根据mapper接口生成其实现类(springboot)
  20. jQuery与Zepto

热门文章

  1. PHP和js判断访问终端是否是微信浏览器
  2. ios学习之旅------玩转结构体
  3. 集群通信组件tribes之用法
  4. java使用默认线程池踩过的坑(二)
  5. HTML5贪吃蛇源代码
  6. js插件---layer.js使用体验是怎样
  7. Scott Hanselman的问题-1
  8. 自己增删改查Razor页面
  9. 使用Redis配置JAVA_环境
  10. GDSOI2019划水记