我正在为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"

代码是:
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();
            }
        }
    }
}

最佳答案

根据OracleDataAdapter,您可以使用以下代码。
SqlQuery而不是@中,替换为:
所以SqlQuery将是

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

参数中不需要@
 command.Parameters.Add("@Version", version.ToString());

关于c# - ORA-00936:将数据集填充到OracleDataAdapter时缺少表达式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56000761/

10-14 12:55