简体   繁体   English

C#:使用存储过程和ODP.NET更新BLOB时出现错误ORA-06550

[英]C# : Getting error ORA-06550 while updating BLOB using stored procedure & ODP.NET

ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'UPDATEPHOTO' ORA-06550:第1行,第7列:PLS-00306:对“ UPDATEPHOTO”的调用中参数的数量或类型错误
ORA-06550: line 1, column 7: PL/SQL: Statement ignoredOracle.ManagedDataAccess.Client.OracleException ORA-06550:第1行,第7列:PL / SQL:语句已忽略Oracle.ManagedDataAccess.Client.OracleException

I don't know what is wrong either with procedure or my code. 我不知道过程或代码有什么问题。

Here's my stored procedure 这是我的存储过程

create or replace 
PROCEDURE UpdatePhoto
(
  v_ac_photo_fileName IN VARCHAR2 DEFAULT NULL ,
  v_ac_photo_contentType IN VARCHAR2 DEFAULT NULL ,
  v_ac_photo_Data IN BLOB DEFAULT NULL ,
  v_ac_uniqueID IN VARCHAR2 DEFAULT NULL 
)
AS

BEGIN
   UPDATE account_table
      SET ac_photo_fileName = v_ac_photo_fileName,
          ac_photo_contentType = v_ac_photo_contentType,
          ac_photo_Data = v_ac_photo_Data
      WHERE ac_uniqueID = v_ac_uniqueID;
END;

Here's my C# code: 这是我的C#代码:

public int UpdatePhoto(BO nBo)
{
    OracleConnection ocon = new OracleConnection(orastr);
    OracleCommand ocmd = new OracleCommand("UpdatePhoto", ocon);
    ocmd.CommandType = CommandType.StoredProcedure;

    ocon.Open();

    try
    {
        ocmd.Parameters.Add("ac_uniqueID", nBo.account_uniqueID);//String
        ocmd.Parameters.Add("ac_photo_fileName", nBo.account_photo_fileName);//string
        ocmd.Parameters.Add("ac_photo_contentType",   nBo.account_photo_contentType);//string
        ocmd.Parameters.Add("ac_photo_Data", nBo.account_photo_Data);// (Byte[] photo data)       

        // tried these also
        ocmd.Parameters.Add("ac_uniqueID", OracleDbType.Varchar2, ParameterDirection.Input).Value = nBo.account_uniqueID;
        ocmd.Parameters.Add("ac_photo_fileName", OracleDbType.Varchar2, ParameterDirection.Input).Value = nBo.account_photo_fileName;
        ocmd.Parameters.Add("ac_photo_contentType", OracleDbType.Varchar2, ParameterDirection.Input).Value = nBo.account_photo_contentType;
        ocmd.Parameters.Add("ac_photo_Data", OracleDbType.Blob, ParameterDirection.Input).Value = nBo.account_photo_Data;

        return ocmd.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        ocon.Dispose();
        ocon.Close();
        nBo = null;
    }
}

Check out this post: 看看这个帖子:

How to Update a BLOB column, error ORA-00932, while Insert works 在插入工作时如何更新BLOB列,错误ORA-00932

I can't say for sure this is your issue, but per this post if you have BLOBs as parameters, you need to list them first in the parameter list for this to work. 我不能肯定地说这是您的问题,但是根据这篇文章,如果您将BLOB作为参数,则需要在参数列表中首先列出它们才能起作用。 I have no idea why, but at the time I tried it both ways, and sure enough it worked when the BLOB was first, and it did not when it wasn't. 我不知道为什么,但是在那时我同时尝试了两种方法,并且确定它在BLOB首次使用时就可以正常工作,而在非BLOB上却没有。 I know, it makes no sense. 我知道,这没有任何意义。

Alternatively, if you set the BindByName property of your OracleCommand object to true, this should also work. 或者,如果将OracleCommand对象的BindByName属性设置为true,这也应该起作用。 I'd try both to be sure. 我会尽力确保。

One caveat: the post I referenced is for an insert function, not a stored procedure, so it's possible there is a difference. 一个警告:我引用的帖子是针对插入函数的,而不是针对存储过程的,因此可能会有区别。

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

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