c# - Oracle存储过程返回RefCursor没有行
本文关键字:RefCursor 返回 Oracle 存储过程 | 更新日期: 2023-09-27 18:05:26
我的存储过程调用返回7行,但不是当我通过Oracle管理数据访问调用它。
代码:
string _connectionString =
String.Format("Data Source={0};User Id={1};Password={2};",
tbDataSource.Text, tbUser.Text, tbPassword.Text);
using (OracleConnection conn = new OracleConnection(_connectionString)){
using (OracleCommand cmd = new OracleCommand()){
cmd.CommandText = "XXCOOT_QUERIES.getWarehouses";
cmd.CommandType = CommandType.StoredProcedure;
// Parameters
OracleParameter p1 = new OracleParameter();
p1.ParameterName = "inumActivityId";
p1.OracleDbType = OracleDbType.Varchar2;
p1.Direction = ParameterDirection.Input;
p1.Size = 10;
p1.Value = 108;
cmd.Parameters.Add(p1);
OracleParameter cursor = new OracleParameter();
cursor.ParameterName = "ocursWarehouses";
cursor.OracleDbType = OracleDbType.RefCursor;
cursor.Direction = ParameterDirection.Output;
cmd.Parameters.Add(cursor);
OracleParameter p2 = new OracleParameter();
p2.ParameterName = "ostrErrCode";
p2.OracleDbType = OracleDbType.Varchar2;
p2.Direction = ParameterDirection.Output;
p2.Size = 2000;
cmd.Parameters.Add(p2);
DataTable dt = new DataTable();
OracleDataReader reader = null;
conn.Open();
cmd.Connection = conn;
using (reader = cmd.ExecuteReader()){
dt.Load(reader);
this.tbResult.Text = "Rows Count : " +
dt.Rows.Count.ToString(); // Returns: "Rows Count : 0"
this.dataGridView1.DataSource = dt.DefaultView;
// Returns : " | Column1 | Column2 | "
// |-------- | --------|
}
}
}
存储过程
PROCEDURE getWarehouses
( inumActivityId in varchar2
, ocursWarehouses out grefCursorType
, ostrErrCode out varchar2
)
IS
lextorg varchar2(150);
BEGIN
FND_CLIENT_INFO.Set_Org_Context(inumActivityId);
lextorg := null;
SELECT b.GENERIC_EXTERNAL_ORGANIZATION
INTO lextorg
FROM HR_ORGANIZATION_INFORMATION a
, HR_ORGANIZATION_INFORMATIO_DFV b
WHERE a.organization_id = to_number(inumActivityId)
AND a.ORG_INFORMATION_CONTEXT = 'Operating Unit Information'
AND a.rowid = b.rowid;
IF lextorg is null THEN
OPEN ocursWarehouses FOR
SELECT ood.organization_code organization_code
, ood.organization_name name
FROM org_organization_definitions ood
, mtl_parameters mp
, mtl_parameters_dfv mp_dfv
WHERE ood.operating_unit = to_number(inumActivityId)
AND sysdate <= nvl(disable_date,sysdate)
AND ood.organization_id = mp.organization_id
AND mp.rowid = mp_dfv.row_id
AND upper(mp_dfv.warehouse_type) in ('INTERNAL','EXTERNAL')
ORDER by organization_name;
ELSE
OPEN ocursWarehouses FOR
SELECT ood.organization_code organization_code
, ood.organization_name name
FROM org_organization_definitions ood
, mtl_parameters mp
, mtl_parameters_dfv mp_dfv
WHERE -ood.operating_unit = to_number(inumActivityId)
AND sysdate <= nvl(disable_date,sysdate)
AND ood.organization_id = mp.organization_id
AND mp.rowid = mp_dfv.row_id
AND upper(mp_dfv.warehouse_type) in ('INTERNAL','EXTERNAL')
ORDER by organization_name;
END/
执行时:无警告,无错误(所有参数都有效)
我的问题:返回任何行(而不是预期的7行),但我检索模式(列名正确)。
环境:
- Windows x64
- 。. NET Framework: 4.0
- Oracle客户端已安装(v11.2),但不是必需的 Oracle数据提供程序。net: Oracle。ManagedDataAccess (v121.1.2)
好了,经过几个月又一个月,我找到了问题的原因:
我的存储过程在它的FROM子句中使用视图。这个(这些)视图使用LOB数据类型(我发现这个问题由于Oracle返回错误)。
同样的事情发生在我身上,我的问题是我的连接字符串,我没有打开连接…