为什么在尝试在Oracle中保存图片时出现ORA-00936错误?

时间:2009-04-21 08:54:45

标签: c# oracle

我会尝试将图片插入Oracle DataBase - 但它不起作用

(Sql server中的相同代码非常出色)

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();
}

1 个答案:

答案 0 :(得分:0)

如您所知,ORA-00936是一个缺失的表达式错误。在您的问题代码中,您在SQL语句中使用了绑定变量。在Oracle中,placeholder variable starts with a colon。因此,@p_pic的正确格式为:@p_pic

在命名参数中使用&符号是Microsoft SQL Server。