Stored procedure OUTPUT VARCHAR2 value truncated using 12c client
I couldn't reproduce your problem for client version 11.2.0.1.0 connecting to server 12.1.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.
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:
- If it's possible create above test table and stored procedure, and check how string data is fetched with the above code.
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
- 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. Below is how issue was resolved :
- Oracle client version installed on machine
12.1.0.2.2
Output parameter truncation
bug is mentioned inOracle
docs asBug21616079
Oracle
has given fix in version12.2.0.1.0
as mentioned inOracle
documentation here.- So upgrading to version
12.2.0.1.0
from12.1.0.2.2
fixed this issue for me asOracle
has given fix in this version only which is mentioned in officialOracle
documentation for which I provided link above in point 3.