简体   繁体   中英

oracle c# how to bind a variable with like

I have this query

 string query = "SELECT * from IMALSO3.V_BN_IVR_ACCT_BAL_MNO WHERE PHONENO Like '%':mobileNumber";

                    using (OracleCommand cmd = new OracleCommand(query, conn))
                    {
                        cmd.Parameters.Add("mobileNumber", phone8Digits);

but it seems that i am binding wrong,

what is the correct way plase?

thanks

You need to remove the single quote, and put the wildcard marker % into the value itself, not into the query string:

string query = "SELECT * from IMALSO3.V_BN_IVR_ACCT_BAL_MNO WHERE PHONENO Like :mobileNumber";

using (OracleCommand cmd = new OracleCommand(query, conn)) {
    cmd.Parameters.Add("mobileNumber", "%"+phone8Digits);
    ....
}

Remove '%' from command text and pass it while adding parameter like:

string query = "SELECT * from IMALSO3.V_BN_IVR_ACCT_BAL_MNO WHERE PHONENO Like :mobileNumber";
using (OracleCommand cmd = new OracleCommand(query, conn))
{
   cmd.Parameters.Add("mobileNumber", "%" + phone8Digits);

If you want to compare phone8Digits like contains then use:

 cmd.Parameters.Add("mobileNumber", "%" + phone8Digits + "%");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM