ORA-21700:对象不存在或被标记为要删除的关联数组作为从ODP.NET调用的输入参数 [英] ORA-21700: object does not exist or is marked for delete for Associative Array as input parameter called from ODP.NET

查看:1260
本文介绍了ORA-21700:对象不存在或被标记为要删除的关联数组作为从ODP.NET调用的输入参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Oracle 12c上有此程序包代码

I have this package code on Oracle 12c

CREATE OR REPLACE PACKAGE Support_Data_Types AS
  TYPE ttDate            IS TABLE OF DATE  
END Support_Data_Types;

PROCEDURE GetData
(
    tabDates        IN SUPPORT_DATA_TYPES.TTDATE,
)

AS
BEGIN

    SELECT count(*) INTO n FROM table(tabDates);

END GetData;

如果我从PL/SQL代码中调用它,它将起作用

If I call it from PL/SQL code it works

declare
    dates SUPPORT_DATA_TYPES.TTDATE;
begin
    dates(1) := To_DATE('12/31/2005','MM/DD/YYYY');
    dates(2) := To_DATE('03/31/2006','MM/DD/YYYY');
    dates(3) := To_DATE('06/30/2006','MM/DD/YYYY');
    dates(4) := To_DATE('09/30/2006','MM/DD/YYYY');

    MyPackage.GETVALUE(dates);
end;

但是,如果我从ODP.NET调用它,则会在SELECT count(*) INTO n FROM table(tabDates);

But If I call it from ODP.NET then I get error message on the line SELECT count(*) INTO n FROM table(tabDates);

ORA-21700:对象不存在或被标记为删除

ORA-21700: object does not exist or is marked for delete

我的.NET代码

    Public Function GetValue(dates As IEnumerable(Of Date))

        Using connection As IDbConnection = Odp.ConnectionBuilder.CreateDatabaseConnection()
            Using cmd As OracleCommand = New OracleCommand
                cmd.Connection = DirectCast(connection, OracleConnection)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "MyPackage.GETVALUE"
                cmd.BindByName = True

                Using datesParam As OracleParameter = New OracleParameter()
                    datesParam.ParameterName = "tabDates"
                    datesParam.OracleDbType = OracleDbType.Date
                    datesParam.CollectionType = OracleCollectionType.PLSQLAssociativeArray
                    datesParam.Size = dates.Count()
                    datesParam.Direction = ParameterDirection.Input
                    datesParam.Value = dates.ToArray()
                    cmd.Parameters.Add(datesParam)
                End Using

                cmd.ExecuteNonQuery()

            End Using
        End Using
    End Function

如果我与Oracle的示例代码进行比较我不确定这是怎么了.

If I compare with Oracle's sample code I am not sure what is wrong here.

有人有见识吗?

推荐答案

经过几天的谷歌搜索,我以这种方式更改了代码:

after several days of googling, I changed the code this way:

CREATE OR REPLACE PACKAGE Support_Data_Types AS
            TYPE ttDate            IS TABLE OF DATE
END Support_Data_Types;
PROCEDURE GetData
(
    tabDates IN SUPPORT_DATA_TYPES.TTDATE,
)
AS
    v_temp SUPPORT_DATA_TYPES.TTDATE:= tabDates;  -- assigned the parameter to a temporary variable
BEGIN
    SELECT count(*) INTO n FROM table(v_temp);
END GetData;

我唯一要做的就是使用看起来很多余的v_temp.但它有效.我进行此更改是因为我在此处进行了搜索...它提到:

the only thing I did is to use a v_temp which looks quite redundant. but it works. I made this change because I searched this article here ... it mentioned:

但是请注意,从12.1开始,您不能直接在TABLE运算符内部调用table函数.您必须在PL/SQL中调用它,将结果分配给一个变量,然后在TABLE中引用该变量.

Note, however, that as of 12.1, you cannot call the table function directly inside the TABLE operator. You must invoke it in PL/SQL, assign result to a variable, and then reference the variable inside TABLE.

尽管在我的情况下情况有所不同(我使用的是12.2),但它解决了我的问题.

though the situation is different in my case (I m using 12.2), it solved my problem.

这篇关于ORA-21700:对象不存在或被标记为要删除的关联数组作为从ODP.NET调用的输入参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆