使用参数 TABLE OF INTEGER 参数调用存储过程
Calling stored procedure with parameter TABLE OF INTEGER parameter
我很难使用有史以来兼容性最不友好的数据库引擎 a.k.a Oracle。
我有这个自定义类型:
CREATE OR REPLACE TYPE INTEGERS_ARRAY AS TABLE OF INTEGER;
还有这个简单的存储过程:
CREATE OR REPLACE PROCEDURE TEST_PROCEDURE_MAHMOUD(
holy_array IN INTEGERS_ARRAY,
some_kind_of_number1 IN NUMBER,
some_kind_of_number2 IN NUMBER,
query_result OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN query_result FOR
SELECT CODE,AIRWAYBILL_DATE,REFERENCE1,REFERENCE2 FROM SHIPMENTS
ORDER BY AIRWAYBILL_DATE DESC
FETCH NEXT 10 ROWS ONLY;
end;
此存储过程是另一个非常复杂的存储过程的简化版本,该存储过程也无法正常工作。我在两者上都有相同的异常:
Oracle.ManagedDataAccess.Client.OracleException
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST_PROCEDURE_MAHMOUD'
ORA-06550: line 1, column 7: PL/SQL: Statement ignored
这是我在 C# 中尝试做的事情:
var result = new List<string>();
using(var con = new OracleConnection(connectionString))
{
using(var command = con.CreateCommand())
{
con.Open();
command.CommandText = "TEST_PROCEDURE_MAHMOUD";
command.CommandType = System.Data.CommandType.StoredProcedure;
// Parameters
var array = new OracleParameter("holy_array", OracleDbType.Int64, ParameterDirection.Input);
array.UdtTypeName = "MY_SCHEMA.INTEGERS_ARRAY";
array.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
array.Size = 100;
array.Value = new int[] { 100, 101 };
var number1 = new OracleParameter("some_kind_of_number1", OracleDbType.Int64, 1, ParameterDirection.Input);
var number2 = new OracleParameter("some_kind_of_number2", OracleDbType.Int64, 1, ParameterDirection.Input);
var cursor = new OracleParameter("query_result", OracleDbType.RefCursor, ParameterDirection.Output);
command.Parameters.AddRange(new[] { array, number1, number2, cursor });
var reader = command.ExecuteReader();
while (reader.Read())
{
var awb = reader.GetString(0);
result.Add(awb);
}
}
}
return result;
Oracle 难道不应该理解非常简单的(table 整数)类型并接受该类型的整数数组吗?我怎么解决这个问题?我已经浏览了官方网站上的文档,我阅读了 GitHub 上的代码示例,我搜索了很多但找不到任何工作示例,只有变通解决方案,比如创建一个 temp-table我不想做。
提前致谢。
编辑:Entity Framework Core 标签是因为我首先尝试使用 EF Core 执行此操作但没有成功,我切换到 ADO.NET,认为这可能是 EF Core 的问题。但事实证明,EF Core 太优秀了,不会让我这么失望。
不幸的是,Entity framework核心仍然不完全支持 Oracle 数据库,限制之一是自定义类型:
Limitations The dedicated team has successfully implemented most
features support the Entity Framework functionality as much as
possible for the Oracle Server, but there are some limitations which
cannot be overcome.
Oracle doesn't have its equivalents for the SQL Server OUTER APPLY and
CROSS APPLY constructions. User-defined types, including Oracle
objects, array types and nested tables are not supported.
我很难使用有史以来兼容性最不友好的数据库引擎 a.k.a Oracle。
我有这个自定义类型:
CREATE OR REPLACE TYPE INTEGERS_ARRAY AS TABLE OF INTEGER;
还有这个简单的存储过程:
CREATE OR REPLACE PROCEDURE TEST_PROCEDURE_MAHMOUD(
holy_array IN INTEGERS_ARRAY,
some_kind_of_number1 IN NUMBER,
some_kind_of_number2 IN NUMBER,
query_result OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN query_result FOR
SELECT CODE,AIRWAYBILL_DATE,REFERENCE1,REFERENCE2 FROM SHIPMENTS
ORDER BY AIRWAYBILL_DATE DESC
FETCH NEXT 10 ROWS ONLY;
end;
此存储过程是另一个非常复杂的存储过程的简化版本,该存储过程也无法正常工作。我在两者上都有相同的异常:
Oracle.ManagedDataAccess.Client.OracleException
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'TEST_PROCEDURE_MAHMOUD'
ORA-06550: line 1, column 7: PL/SQL: Statement ignored
这是我在 C# 中尝试做的事情:
var result = new List<string>();
using(var con = new OracleConnection(connectionString))
{
using(var command = con.CreateCommand())
{
con.Open();
command.CommandText = "TEST_PROCEDURE_MAHMOUD";
command.CommandType = System.Data.CommandType.StoredProcedure;
// Parameters
var array = new OracleParameter("holy_array", OracleDbType.Int64, ParameterDirection.Input);
array.UdtTypeName = "MY_SCHEMA.INTEGERS_ARRAY";
array.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
array.Size = 100;
array.Value = new int[] { 100, 101 };
var number1 = new OracleParameter("some_kind_of_number1", OracleDbType.Int64, 1, ParameterDirection.Input);
var number2 = new OracleParameter("some_kind_of_number2", OracleDbType.Int64, 1, ParameterDirection.Input);
var cursor = new OracleParameter("query_result", OracleDbType.RefCursor, ParameterDirection.Output);
command.Parameters.AddRange(new[] { array, number1, number2, cursor });
var reader = command.ExecuteReader();
while (reader.Read())
{
var awb = reader.GetString(0);
result.Add(awb);
}
}
}
return result;
Oracle 难道不应该理解非常简单的(table 整数)类型并接受该类型的整数数组吗?我怎么解决这个问题?我已经浏览了官方网站上的文档,我阅读了 GitHub 上的代码示例,我搜索了很多但找不到任何工作示例,只有变通解决方案,比如创建一个 temp-table我不想做。
提前致谢。
编辑:Entity Framework Core 标签是因为我首先尝试使用 EF Core 执行此操作但没有成功,我切换到 ADO.NET,认为这可能是 EF Core 的问题。但事实证明,EF Core 太优秀了,不会让我这么失望。
不幸的是,Entity framework核心仍然不完全支持 Oracle 数据库,限制之一是自定义类型:
Limitations The dedicated team has successfully implemented most features support the Entity Framework functionality as much as possible for the Oracle Server, but there are some limitations which cannot be overcome.
Oracle doesn't have its equivalents for the SQL Server OUTER APPLY and CROSS APPLY constructions. User-defined types, including Oracle objects, array types and nested tables are not supported.