It's pretty straightforward to strip out non-alphanumeric characters out from the search term, but how do you compare it to only the non-alphanumeric characters of values in the database?
For example, if I search for stack's
, how can I get it to match both stacks
and stack's
?
What do I need to do to the what-do-i-do
variable below to make the above happen?
SELECT * FROM table WHERE <what-do-i-do> ilike 'stacks'
Using LIKE clause Val LIKE '%[A-Z]%', it ensures that string should contain alphanumeric characters. Val LIKE '%[0-9]%', it ensures that string should contain numeric characters. Lets see the output of T-SQL, you can see it returns only alphanumeric string only.
SELECT * FROM spatial_ref_sys WHERE srtext LIKE '%\ /%'; Sometimes these ticks are very useful for searching special characters in a database.
Answer: To test a string for alphanumeric characters, you could use a combination of the LENGTH function, TRIM function, and TRANSLATE function built into Oracle. The string value that you are testing. This function will return a null value if string1 is alphanumeric.
One way to do this is with translate:
select *
from table
where translate(lower(WhatIDo), translate(lower(WhatIDo), 'abcdefghijklmnopqrstuvwxyz', ''), '') = 'stacks'
The inner translate finds all non-alpha characters. The outer then removes these from the string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With