locked
Oracle Like RRS feed

  • Question

  • User1864322503 posted

    Hello all,

    I am wanting to add in a Like to my sqlquery. I cannot get any examples to work correctly with my code.

    currently my sqlquery is like this, and working fine 

                    string sqlquery = @"SELECT * " + 
                                    "FROM NICK_TEST " +
                                    "WHERE upper(LASTNAME)=upper(:LASTNAME) or upper(FIRSTNAME)=upper(:FIRSTNAME)";

    However, I have tried to reuse some examples of a Like query but they are causing general exceptions on my ODA.Fill(); line. Anyone have any pointers on how to implement a Like into my query here for both Lastname and Firstname?

    Thank you very much.

    Wednesday, August 7, 2013 10:19 AM

Answers

  • User-861818263 posted
    string sqlquery = @"SELECT * " + "FROM NICK_TEST " + "WHERE upper(LASTNAME)=upper(:LASTNAME) or upper(FIRSTNAME)=upper(:FIRSTNAME) 
    or upper(LASTNAME) like '%' || :LASTNAME || '%'";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 7, 2013 10:26 AM

All replies

  • User-861818263 posted
    string sqlquery = @"SELECT * " + "FROM NICK_TEST " + "WHERE upper(LASTNAME)=upper(:LASTNAME) or upper(FIRSTNAME)=upper(:FIRSTNAME) 
    or upper(LASTNAME) like '%' || :LASTNAME || '%'";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 7, 2013 10:26 AM
  • User1864322503 posted

    hi Sameer,

    Thank you. Is there any way to put an OR within my query? One like this is not returning proper data... 

    string sqlquery = @"select * from NICK_TEST where upper(LASTNAME) Like upper('%'||:LASTNAME||'%') or upper(FIRSTNAME) Like upper('%'||:FIRSTNAME||'%')";



    Wednesday, August 7, 2013 10:49 AM
  • User-861818263 posted
    string sqlquery = @"select * from NICK_TEST where upper(LASTNAME) Like upper('%'||:LASTNAME||'%') and upper(FIRSTNAME) Like upper('%'||:FIRSTNAME||'%')";

    You can try with "and" condition also you can remove any '%' as per your filter condition .

    Also please read 

    http://www.techonthenet.com/sql/like.php

    Wednesday, August 7, 2013 10:56 AM
  • User1508394307 posted

    WHERE upper(LASTNAME)=upper(:LASTNAME)

    Can you give an example of the data you are looking for?

    Usually, it should be similar to

    select * from nick_test
    where upper(lastname) like ('%DOE%') or upper(firstname) like ('%JOHN%')

    Wednesday, August 7, 2013 11:08 AM