简体   繁体   中英

How can i return a Varchar2 out of my stored procedure

When I run my program I get this error in my catch

ORA-06550: line 1, column 7:

PLS-00905: object DBI304134.FINDFREEBARCODE is invalid

ORA-06550: line 1, column 7:

This is the c# code I use:

string freeBarcode = null;

    try
    {
        string connection = ConfigurationManager.ConnectionStrings["P4connection"].ConnectionString;
        using (OracleConnection con = new OracleConnection(connection))
        {
            OracleCommand cmd = new OracleCommand("FindfreeBarcode", con);
            cmd.CommandType = CommandType.StoredProcedure;

            OracleParameter outpuparameter = new OracleParameter("outpuparameter", OracleDbType.Varchar2,100);
            outpuparameter.ParameterName = "FREEBARCODE";
            outpuparameter.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(outpuparameter);

            con.Open();
            cmd.ExecuteNonQuery();

            freeBarcode = Convert.ToString(outpuparameter.Value.ToString());

            if (freeBarcode == null)
            {
                freeBarcode = null;
            }

            else
            {
                freeBarcode = Convert.ToString(outpuparameter.Value.ToString());
            }
        }

    }
    catch
    {
        freeBarcode = null;
    }

    return freeBarcode;

And this is the stored procedure i use:

create or replace procedure FindfreeBarcode
   (FREEBARCODE out VARCHAR2)
is
begin
   select b.BARCODE
    INTO FREEBARCODE
    from GAST g,BARCODECHECK b 
    WHERE g.GASTID(+) = b.GASTID and b.GASTID is null and ROWNUM <= 1;
END FindfreeBarcode;

Find my answer on this page

Stored procedure output parameter returns @Value

had to change

freeBarcode = Convert.ToString(outpuparameter.Value.ToString());

to:

Convert.ToString(outpuparameter.Value);

Use the original version of your stored proc, and change

OracleCommand cmd = new OracleCommand("FindfreeBarcode", con);

to

OracleCommand cmd = new OracleCommand("FindfreeBarcode(:FREEBARCODE)", con);

Share and enjoy.

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.

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