question

mallan avatar image
mallan asked

How do I search for a specific letter in a table?

Iám so new in this, and learning... I could use som help to a problem. I want to search in a table. I´m searching in for lastnames with the letter s in it. How do I do that? (Oracle SQL) I wrote: select fnamn,enamn from customers where enamn LIKE 's%'; I have tried a sevral combinatins now...
t-sqlsql-serverwildcard
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image
Grant Fritchey answered
You're close. To search for the letter 's' anywhere in the name, you need to add an additional wild card to your search like this: '%s%'. That will find it anywhere within the name. But, understand, that will also lead to a scan of the table and possibly slow performance.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
Grant is right - it won't be performant, but it is the answer... SELECT fnamn, enamn FROM Customers WHERE enamn LIKE '%s%' As you can see, it's all but identical to the code you showed. The % wildcard matches zero or more characters; there's also an _ wildcard that matches a single character. You can also build up not-quite-regular-expressions: SELECT enamn FROM Customers WHERE enamn LIKE '%[xyz]%' This will show you all names where there's a letter from what I've heard described as "the arse end of the alphabet". There are some other tricks to learn - see the documentation for [LIKE][1] for more ideas. [1]: http://msdn.microsoft.com/en-us/library/ms179859.aspx
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
I have no idea - I've spent too much time talking to pointy-haired bosses over the years, and it has warped my vocabulary...
1 Like 1 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
Excellent answer, but doesn't performant mean an actor in a play? Ha!
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.