简体   繁体   中英

Why am I getting ORA-00936 error while trying to save picture in Oracle?

I'll try this to insert picture to Oracle DataBase - but it doesn't work

(same code in Sql server work's excellent)

string sampleImage = PicNativ;
BinaryReader sampleBR = null;
FileStream sampleFS = null;
OracleConnection sampleConnection = null;
OracleCommand sampleCommand = null;
FileInfo sampleFI = null;
byte[] sampleArr = null;
try
{
    if (EDIT_M == 1) 
        Oracle = "update Sex set Name = '" + txtC.Text.Trim() + 
            "',pic = @p_pic  where ID like '" + txtC4.Text.Trim() + "'";
    else
        Oracle = "insert into Sex (Id,Code,Name,pic) values "+
            "(Sex_Code.nextval,'" + txtA.Text.Trim() + "','" + 
            txtC.Text.Trim() + "', @p_pic )";
    sampleFI = new FileInfo(sampleImage);
    sampleFS = new FileStream(sampleImage, FileMode.Open, FileAccess.Read);
    sampleBR = new BinaryReader(sampleFS);
    sampleArr = sampleBR.ReadBytes((int)sampleFI.Length);
    using (sampleConnection = new OracleConnection(Conect))
    {
        sampleConnection.Open();
        using (sampleCommand = new OracleCommand())
        {
            sampleCommand.Connection = sampleConnection;
            sampleCommand.CommandText = Oracle;
            sampleCommand.Parameters.
                Add("@p_pic", OracleDbType.Blob ).Value = sampleArr;
            sampleCommand.ExecuteNonQuery();
        }
    }
}
finally
{
    sampleBR.Close();
    sampleFS.Close();
}

As you know, ORA-00936 is a missing expression error. In your question code, you are using a bind variable in your SQL statement. In Oracle, placeholder variable starts with a colon . So where you have @p_pic the correct format is :@p_pic .

Using the ampersand in your named parameter is a Microsoft SQL Server.

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