简体   繁体   English

无法从存储过程中获取完整的字符串(输出参数)

[英]Unable to get the full string (Output parameter) from Stored Procedure

I am using Dapper and have specified the ParameterDirection and Size.我正在使用 Dapper 并指定了 ParameterDirection 和 Size。 But the string that comes back is not the whole string.但是返回的字符串不是整个字符串。

[INF] Return message: The person-ID 23 has been inse [INF] 返回信息:person-ID 23 已插入

var queryParameters = new DynamicParameters();
queryParameters.Add("id", item.Id);
queryParameters.Add("first_name", item.FirstName);
queryParameters.Add("last_name", item.LastName);
//queryParameters.Add("out_message", direction: ParameterDirection.Output, size: 250);
//queryParameters.Add("out_message", direction: ParameterDirection.Output, size: DbString.DefaultLength);
queryParameters.Add("out_message", dbType:DbType.String, direction: ParameterDirection.Output, size: 500);

var results = connection.Query("kwc_test_person_procedure2",
queryParameters,
commandType: CommandType.StoredProcedure);

var returnMessage = queryParameters.Get<string>("out_message");
Log.Information("Return message: {0}", returnMessage);

The Oracle Stored Procedure is as follow, and I am getting the full string of out_message when I test it directly in the database: Oracle存储过程如下,当我直接在数据库中测试时,我得到了out_message的完整字符串:

create or replace procedure kwc_test_person_procedure2(
id in number,
first_name in varchar2,
last_name in varchar2,
out_message out varchar2
) is

begin
  insert into kwc_test_person(id, first_name, last_name) values (id, upper(first_name), upper(last_name));
  out_message := 'The person-ID ' || id || ' has been inserted to database on ' || sysdate;
  dbms_output.put_line( 'The person-ID ' || id || ' has been inserted to database on ' || sysdate);

End kwc_test_person_procedure2;

The person-ID 84 has been inserted to database on 24-JUN-21个人 ID 84 已于 21 年 6 月 24 日插入数据库

As you can see in the commented out lines, I have tried different things.正如您在注释掉的行中看到的那样,我尝试了不同的方法。

When I tried:当我尝试:

queryParameters.Add("out_message", dbType: DbType.String, direction: ParameterDirection.Output, size: int.MaxValue);

I even got exception:我什至有例外:

[ERR] Parameter 'out_message': No size set for variable length data type: String. [ERR] 参数“out_message”:未为可变长度数据类型设置大小:字符串。

I have found the solution.我找到了解决办法。

So the following works, If I was using the correct client.所以下面的工作,如果我使用的是正确的客户端。

queryParameters.Add("out_message", direction: ParameterDirection.Output, size:DbString.DefaultLength);

I didn't realize that I was using System.Data.OracleClient in my test-project.我没有意识到我在我的测试项目中使用了 System.Data.OracleClient。 So the solution was by using the client under ManagedDataAccess.所以解决方案是使用 ManagedDataAccess 下的客户端。

//using System.Data.OracleClient;
using System.Linq;
using Dapper;
using Oracle.ManagedDataAccess.Client;

2021-06-25 13:35:41.452 +02:00 [INF] Return message: The person-ID 23 has been inserted to database on 25.06.2021 2021-06-25 13:35:41.452 +02:00 [INF] 返回消息:person-ID 23 已于 25.06.2021 插入数据库

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

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