Usage of Oracle binding variables with LIKE in C# Usage of Oracle binding variables with LIKE in C# oracle oracle

Usage of Oracle binding variables with LIKE in C#


Try:

sql = "SELECT somedata FROM sometable WHERE machine LIKE :machineName || '%' ";

Because of the BIND variable, there wouldn't need to be single quotes around it. But the % is not, so I would expect it needing to be encapsulated.


Here is a full query example:

string commandText = "SELECT LastName, FirstName FROM PEOPLE WHERE UPPER(LastName) LIKE '%' || :lastName || '%' AND UPPER(FirstName) LIKE '%' || :firstName || '%'";string oradb = "yourDatabaseConnectionStringHere"; // Might want to add Using statement for this code and try catchOracleConnection conn = new OracleConnection(oradb); // C#conn.Open();OracleCommand cmd = new OracleCommand{     Connection = conn,     CommandText = commandText,     CommandType = CommandType.Text};/*IMPORTANT: adding parameters must be in order how they are in order in the SQL statement*/cmd.Parameters.Add(new OracleParameter("lastName", model.LastName.Trim().ToUpper()));cmd.Parameters.Add(new OracleParameter("firstName", model.FirstName.Trim().ToUpper()));OracleDataReader dr = cmd.ExecuteReader();