I am using oracle 11g . My stored procedure is returning varchar2
but its value is being truncated by 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. Is there any solution to this. On server I have Oracle 12c . I need to get solution without updating oracle client version in my project as that is not allowed due to some reasons.
Below is the 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. 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 for some reason it's not possible, please provide following info:
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 :
12.1.0.2.2
Output parameter truncation
bug is mentioned in Oracle
docs as Bug21616079
Oracle
has given fix in version 12.2.0.1.0
as mentioned in Oracle
documentation here . 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.我在 64 位 Windows 操作系统上的客户端 10g 和服务器 11g 都遇到了同样的问题,我通过在 IIS 上托管我的 .net 应用程序并将 app_pool 的高级设置“启用 32 位应用程序”更改为 False 来规避它。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.