ORA-00936:将数据集填充到OracleDataAdapter时缺少表达式

时间:2019-05-06 07:39:08

标签: c# database oracle

我正在将这种代码用于MySQL,SQL Server和Oracle。对于MySQL和SQL Server,它可以正常工作。对于Oracle,执行adapter.Fill(dataset);时会引发“ ORA-00936”异常。有人知道为什么会这样吗?

错误消息是

  

ORA-00936:将数据集填充到OracleDataAdapter时缺少表达式

我的SQL查询是:

sqlQuery: "SELECT * FROM \"DWSYS\" WHERE NOT FCVERSION=@Version"

C#代码为:

public class OutputOracleQuery : IWriteSQLQuery
{
    private static readonly ILogger logger = LoggerFactory.Create(typeof(OutputOracleQuery));
    HelperEnvironmentVariable GetEnvironmentVariable = new HelperEnvironmentVariable();

    public DataSet GetData(string DBUser, string DBUserPassword, string sqlQuery, string databaseName, Version version)
    {
        using (OracleConnection connection = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + GetEnvironmentVariable.MachineName + ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)))); User Id=" + DBUser + ";Password=" + DBUserPassword + ";"))
        {
            try
            {
                using (var command = new OracleCommand(sqlQuery, connection))
                {
                    connection.Open();
                    command.Parameters.Add("@Version", version.ToString());

                    OracleDataAdapter adapter = new OracleDataAdapter(command);                     
                    DataSet dataset = new DataSet();
                    adapter.Fill(dataset);

                    return dataset;
                }
            }
            catch (OracleException ex)
            {
                logger.Debug("Demanded Database action for the database " + "\"" + databaseName + "\"" + " could not be executed", ex);
                throw;
            }
            finally
            {
                connection.Close();
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

根据OracleDataAdapter,您可以使用以下代码。

在您的SqlQuery中代替@,而不是:

所以SqlQuery将是

SELECT * FROM \"DWSYS\" WHERE NOT FCVERSION= :Version

并且参数中不需要@

 command.Parameters.Add("@Version", version.ToString());