Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ORA-06502: PL/SQL: numeric or value error: character string buffer too small whenever I have an OUT Parameter

I know there’s already a few posts on this error (
"ORA-06502: PL/SQL: numeric or value error: character string buffer too small" is bug?), but I’ve been through them and I still can’t seem to figure out what’s wrong with my code.

I can’t seem to call stored procedures with an OUT parameter in C#.

I have this stored procedure.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

CREATE OR REPLACE PROCEDURE test_sp(v_payload OUT VARCHAR2) AS
BEGIN
    v_payload := 'he2';
END;

It really is as simple as I can make it. It works in Oracle SQL Developer.

But in my c# code.

        OracleCommand command = new OracleCommand("test_sp", con);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add(new OracleParameter("v_payload", OracleDbType.Varchar2, 32767, ParameterDirection.Output));
        await command.ExecuteNonQueryAsync();

It’ll return this error

ORA-06502: PL/SQL: numeric or value error: character string buffer too
small

>Solution :

You’re using the incorrect constructor. The constructor you’re using is:

public OracleParameter(string name, System.Data.OracleClient.OracleType oracleType, 
                       int size, string srcColumn);

And it appears string srcColumn is implicitly converting ParameterDirection.Output to string.

Try this instead:

var param = new OracleParameter("v_payload", OracleDbType.Varchar2, 32767);
param.Direction = ParameterDirection.Output;
command.Parameters.Add(param);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading