你能帮我把一个值从C#传递给refCursor类型。我试图发送dataTable,如下面链接所示,但它无法正常工作。 Pass datatable to refcursor of Oracle stored procedure
存储过程:
PROCEDURE PROC_INS( P_USERID IN VARCHAR2,
P_ATTACH_LIST IN SYS_REFCURSOR,
P_out OUT NUMBER,
P_msg OUT VARCHAR2) AS
V_BRS_USERID VARCHAR2(50);
V_ATTACHMENT_TYPE_ID BRS_USER_ATTACHMENT.ATTACHMENT_TYPE_ID%TYPE;
V_FILE_NAME BRS_USER_ATTACHMENT.FILE_NAME%TYPE;
V_FILE_SIZE BRS_USER_ATTACHMENT.FILE_SIZE%TYPE;
V_FILE_DESCR BRS_USER_ATTACHMENT.FILE_DESCR%TYPE;
BEGIN
LOOP
FETCH P_ATTACH_LIST INTO V_BRS_USERID, V_ATTACHMENT_TYPE_ID,V_FILE_NAME, V_FILE_SIZE, V_FILE_DESCR;
EXIT WHEN P_ATTACH_LIST%NOTFOUND;
INSERT INTO USER_ATTACHMENT VALUES
(SEQ_RER_EMP_REP_ID.NEXTVAL,
V_BRS_USERID,
V_ATTACHMENT_TYPE_ID,
V_FILE_NAME,
V_FILE_SIZE,
V_FILE_DESCR,
NULL,
NULL,
0,
0,
'A',
P_USERID,
SYSDATE,
NULL,
NULL
);
END LOOP;
CLOSE P_ATTACH_LIST;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK; -- Transaction mgmt
p_out := 2;
p_msg := sqlerrm;
END PROC_REG_INS_ATTACH;
答案 0 :(得分:0)
这是此用户的重复帖子。见Pass datatable to refcursor of Oracle stored procedure
您无法将DataTable绑定到Ref Cursor。你需要传入另一个引用游标,你只能将它作为存储过程/函数的输出,或者对匿名块中的表进行查询...也许你可以创建一个使用不同的包装器存储过程数据类型,例如关联数组。
http://www.oracle.com/technetwork/issue-archive/2006/06-jan/o16odpnet-087852.html
答案 1 :(得分:-1)
使用OracleCommand个OracleParameter课程。注意OracleParameter的ParameterDirection属性。
以下是我的代码中的示例,我正在调用web_shop_interface.kreiraj_mp_racun
存储过程,并为其设置参数:
var fnRac = new OracleCommand();
fnRac.Connection = conn;
fnRac.CommandText = "web_shop_interface.kreiraj_mp_racun";
fnRac.CommandType = CommandType.StoredProcedure;
var ret = new OracleParameter("ret", OracleDbType.Varchar2);
ret.Direction = ParameterDirection.ReturnValue;
ret.Size = 4096;
fnRac.Parameters.Add(ret);
var p1 = new OracleParameter("did", OracleDbType.Decimal);
p1.Value = 15m;
p1.Direction = ParameterDirection.Input;
fnRac.Parameters.Add(p1);
var p2 = new OracleParameter("prn", OracleDbType.Varchar2);
p2.Value = "Invoice 15";
p2.Direction = ParameterDirection.Input;
fnRac.Parameters.Add(p2);
fnRac.ExecuteNonQuery();