在工作中用到了Oracle数据库,需要调用Oracle的Function,Function返回的游标和结果都是通过参数来获取的
比如Function定义如下:
1 FUNCTION getlinkuserinfo(inintuserid INTEGER,
2 ininttype INTEGER,
3 outcurlist OUT ref_cursor) RETURN INTEGER IS
4 BEGIN
5 OPEN outcurlist FOR
6 SELECT *
7 FROM tbuserlink
8 WHERE qidianuserid = inintuserid AND
9 intype = decode(ininttype, -1, intype, ininttype) AND
10 status = 0;
11
12 RETURN 0;
13 END;
2 ininttype INTEGER,
3 outcurlist OUT ref_cursor) RETURN INTEGER IS
4 BEGIN
5 OPEN outcurlist FOR
6 SELECT *
7 FROM tbuserlink
8 WHERE qidianuserid = inintuserid AND
9 intype = decode(ininttype, -1, intype, ininttype) AND
10 status = 0;
11
12 RETURN 0;
13 END;
那么调用这个Function的时候,就要定义4个参数,如下:
1 IDataParameter[] paramArray = new IDataParameter[]{
2 ado.GetReturnParameter(),
3 ado.GetParameter("inintuserid", DbType.Int32, userid),
4 ado.GetParameter("ininttype", DbType.Int32, typeid),
5 ado.GetParameter("outcurlist", DbType.Object, ParameterDirection.Output)
6 };
2 ado.GetReturnParameter(),
3 ado.GetParameter("inintuserid", DbType.Int32, userid),
4 ado.GetParameter("ininttype", DbType.Int32, typeid),
5 ado.GetParameter("outcurlist", DbType.Object, ParameterDirection.Output)
6 };
一点点心得,记下了!!!
最后,Function如果定义在Package 里面的话,调用的时候要加上package
this.AdoHelper.ExecuteNonQuery(this.ConnectionString, CommandType.StoredProcedure, "pkg_voteticket.uservotecount_month", paramArray);
pkg_voteticket包名,包可以理解为一个类,里面放了很多一类的方法或存储过程,调用包中的方法:包名.方法名