优化查询以适用于小写和大写

时间:2019-09-27 11:57:15

标签: c# asp.net oracle soap

我想优化查询以返回结果,无论是用户插入New York还是NEW YORKnew york 我在db中有大约10000条记录,并且某些记录以较高的位置开始,而有些则以较低的位置开始,并且如果我像New York那样插入,查询不会返回结果。

 [WebMethod]
        public string GetAkontasByMjesto(string Mjesto)
        {
            OracleConnection conn = new OracleConnection("DATA SOURCE=test-1:1521/fba;USER ID=test;PASSWORD=test");
            OracleDataAdapter dr = new OracleDataAdapter("Select * from AKONTAS where MJESTO='" + Mjesto + "'", conn);
            DataSet ds = new DataSet();
            ds.Tables.Add("AKONTAS");
            dr.Fill(ds, "AKONTAS");
            DataTable tt = ds.Tables[0];
            return ds.GetXml();
        }

这个问题有解决方案吗?

2 个答案:

答案 0 :(得分:1)

  

您可以同时降低Mjesto(参数名称)和MJESTO(列名称)

[WebMethod]
public string GetAkontasByMjesto(string Mjesto)
{
    OracleConnection conn = new OracleConnection("DATA SOURCE=test-1:1521/fba;USER ID=test;PASSWORD=test");
    OracleDataAdapter dr = new OracleDataAdapter("Select * from AKONTAS where lower(MJESTO) ='" + Mjesto.ToLower() + "'", conn);
    DataSet ds = new DataSet();
    ds.Tables.Add("AKONTAS");
    dr.Fill(ds, "AKONTAS");
    DataTable tt = ds.Tables[0];
    return ds.GetXml();
}

答案 1 :(得分:1)

您将需要使用UPPER

例如:

select * 
from yourtable 
where upper(column) = upper('nEw York');