问题遇到的现象和发生背景
我在使用asp.net core3.1查询Oracle数据库始终出错,找不到原因。
查询语句单独复制在Oracle运行正确。查询语句如下:
string sql = "select NAME,nvl2(VALUE,VALUE,'fyp') VALUE,nvl2(ATTRIBUTE6,ATTRIBUTE6,'fyp') ATTRIBUTE6 from propertymodel where NAME in ('"+ _parameter+"','" + _parameter + "-1','" + _parameter + "-2') and PARTREF='"+ _item+"';";
问题相关代码,请勿粘贴截图
using Microsoft.Extensions.Configuration;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
/// <summary>
/// 执行查询操作,返回SqlDataReader
/// </summary>
/// <param name="sql"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public static OracleDataReader ExecuteReader(string sql, IDataParameter[] parameters)//params OracleParameter[] parameters)
{
OracleConnection connection = new OracleConnection(dbConnectionString);
connection.Open();
OracleCommand command = new OracleCommand(sql, connection);
if (parameters != null && parameters.Length > 0)
{
command.Parameters.AddRange(parameters);
}
try
{
//这句始终出错
OracleDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
command.Parameters.Clear();
return reader;
}
catch(Exception ex)
{
command.Parameters.Clear();
connection.Close();
return null;
}
}
运行结果及报错内容
报的错误是:Message = "ORA-00911: 无效字符"