Using LIKE with Variable Value not Literal Value….INSTR not optional

pts.
Tags:
Oracle
SQL
I'm trying to build a search type select statement constrained by a users input.....variable(x) which forces the use of like in the selection processing: x := (whatever user enters); I have tried with no luck: Select * from personnel where lastname like '%x%'; Select * from personnel where lastname like "'%" x "%'"; If you know of a way to pass a variable value to a like expression please let me know. Thank you for your time!

Answer Wiki

Thanks. We'll let you know when a new response is added.

BAdams2,

I suggest you use bind variables to solve this problem. If that doesn’t work, you can always use dynamic SQL. Of course, bind variables are faster.

Here is a really informative link. Be sure to check out the follow-up section to the May 21, 2003 entry, as he uses like in the Where clause:
http://asktom.oracle.com/pls/ask/f?p=4950:8:9963520253322092830::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:7832114438832

Hope this helps,
Charles

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • SheldonLinker
    SELECT * FROM personnel WHERE lastName LIKE '%' || :x || '%'; --- Sheldon Linker (sol@linker.com) Linker Systems, Inc. (www.linkersystems.com) 800-315-1174 (+1-949-552-1904)
    30 pointsBadges:
    report
  • Using LIKE with Variable Value not Literal Value….INSTR not optional (Q/A) | Seek The Sun Slowly
    [...] Address: http://itknowledgeexchange.techtarget.com/itanswers/using-like-with-variable-value-not-literal-value... (0) Comments Read [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: