简体   繁体   English

使用 12c 客户端截断的存储过程 OUTPUT VARCHAR2 值

[英]Stored procedure OUTPUT VARCHAR2 value truncated using 12c client

I am using oracle 11g .我正在使用oracle 11g My stored procedure is returning varchar2 but its value is being truncated by oracle client .我的存储过程返回varchar2但它的值被oracle client截断。 Below is my code :下面是我的代码:

            if ((ds != null) && (ds.Tables.Count > 0))
                {

                    foreach (DataRow rw in ds.Tables[0].Rows)
                    {

                        OracleParameter param = new OracleParameter((rw["argument_name"]).ToString(), GetOracleType(rw["data_type"].ToString().ToUpper()));
                        param.Direction = GetParameterDirection((rw["in_out"]).ToString().ToUpper());
                        discoveryCommand.Parameters.Add(param);
                        if (param.Direction == ParameterDirection.Output && param.OracleType == OracleType.VarChar)
                        {
                            param.Size = 4000;
                        }
                    }
                }

I increased the param.size to 4000 but still values are being truncated.我将param.size增加到4000但值仍然被截断。 Is there any solution to this.有没有办法解决这个问题。 On server I have Oracle 12c .在服务器上我有Oracle 12c I need to get solution without updating oracle client version in my project as that is not allowed due to some reasons.我需要在不更新项目中的 oracle 客户端版本的情况下获得解决方案,因为由于某些原因这是不允许的。

Below is the SP .下面是SP。 I modified it to return hard-coded values.我修改了它以返回硬编码值。 Still same issue.还是一样的问题。

PROCEDURE access_level (
          p_emp_id IN  employees.emp_id%TYPE,
        p_id IN  NUMBER,
        p_type VARCHAR2,
          p_access_level OUT VARCHAR2
 ) IS
  BEGIN


 p_access_level := 'X' || 'RO' || 'RW';






 END IF;

I couldn't reproduce your problem for client version 11.2.0.1.0 connecting to server 12.1.0.1.0.对于连接到服务器 12.1.0.1.0 的客户端版本 11.2.0.1.0,我无法重现您的问题。 It's a known case when Oracle 12c client truncates output variables, however if you're using client of 11g version, it shouldn't be your case. Oracle 12c 客户端截断输出变量是一种已知情况,但是如果您使用的是 11g 版本的客户端,则不应该是这种情况。

I've used following test table and stored procedure:我使用了以下测试表和存储过程:

CREATE TABLE TEST_TABLE
(
    ID NUMBER(11) NOT NULL,
    NAME VARCHAR2(256),
    CONSTRAINT TEST_TABLE_PK PRIMARY KEY (ID)
)
/

INSERT INTO TEST_TABLE(ID, NAME) VALUES(1, 'Some test data')
/

CREATE PROCEDURE TEST_PROCEDURE
(
   P_ID OUT NUMBER,
   P_NAME OUT VARCHAR2
)
AS
BEGIN
   SELECT ID, NAME INTO P_ID, P_NAME FROM TEST_TABLE;
END;

Here is the client code that correctly fetches data:这是正确获取数据的客户端代码:

using (OracleConnection connection = new OracleConnection())
{
    connection.ConnectionString = ConfigurationManager.ConnectionStrings["TestDatabase"].ConnectionString;
    connection.Open();

    using (OracleCommand command = connection.CreateCommand())
    {
        command.CommandText = "TEST_PROCEDURE";
        command.CommandType = CommandType.StoredProcedure;

        OracleParameter param1 = new OracleParameter("P_ID", OracleType.Number);
        param1.Direction = ParameterDirection.Output;
        command.Parameters.Add(param1);

        OracleParameter param2 = new OracleParameter("P_NAME", OracleType.VarChar);
        param2.Size = 4000;
        param2.Direction = ParameterDirection.Output;
        command.Parameters.Add(param2);

        using (command.ExecuteReader())
        {
            Console.WriteLine($"Output: [{param2.Value}]");
        }
    }
}

To proceed with your question could you please do the following:要继续您的问题,请执行以下操作:

  1. If it's possible create above test table and stored procedure, and check how string data is fetched with the above code.如果可能的话,创建上面的测试表和存储过程,并检查如何使用上面的代码获取字符串数据。
  2. If for some reason it's not possible, please provide following info:如果由于某种原因无法实现,请提供以下信息:

    • Full code of called stored procedure被调用存储过程的完整代码
    • DDL for all tables engaged in the stored procedure参与存储过程的所有表的 DDL
    • Full client code that fetches data获取数据的完整客户端代码

The devil is always in the details.魔鬼总是在细节中。 We should just understand what in your case differs from working exemplary code above.我们应该只了解您的情况与上面的示例代码有何不同。

I tried to resolve issue by migrating to ODP.NET as System.Data.OracleClient is being deprecated by Microsoft as mentioned here , but issue was not resolved.我试图解决问题,通过迁移到ODP.NETSystem.Data.OracleClient正在被弃用Microsoft提到这里,但问题没有得到解决。 Below is how issue was resolved :以下是问题的解决方法:

  1. Oracle client version installed on machine 12.1.0.2.2机器12.1.0.2.2上安装的Oracle客户端版本
  2. Output parameter truncation bug is mentioned in Oracle docs as Bug21616079 Output parameter truncation错误在Oracle文档中被提及为Bug21616079
  3. Oracle has given fix in version 12.2.0.1.0 as mentioned in Oracle documentation here . Oracle已经给出了版本的修订12.2.0.1.0中提到Oracle文档在这里
  4. So upgrading to version 12.2.0.1.0 from 12.1.0.2.2 fixed this issue for me as Oracle has given fix in this version only which is mentioned in official Oracle documentation for which I provided link above in point 3.因此,从12.1.0.2.2升级到版本12.2.0.1.0为我解决了这个问题,因为Oracle仅在此版本中提供了修复,这在官方Oracle文档中提到,我在上面的第 3 点中提供了链接。

我在 64 位 Windows 操作系统上的客户端 10g 和服务器 11g 都遇到了同样的问题,我通过在 IIS 上托管我的 .net 应用程序并将 app_pool 的高级设置“启用 32 位应用程序”更改为 False 来规避它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM