簡體   English   中英

嘗試在Oracle中保存圖片時為什么出現ORA-00936錯誤?

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

我將嘗試將圖片插入Oracle數據庫-但不起作用

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

如您所知, ORA-00936是缺少表達式錯誤。 在您的問題代碼中,您正在SQL語句中使用綁定變量。 在Oracle中, 占位符變量以冒號開頭 因此,在具有@p_pic的位置,正確的格式是:@p_pic

Microsoft SQL Server是您的命名參數中使用&符的工具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM