Return only one word– SQL

5 pts.
Tags:
Oracle
Oracle SQL
SQL
SQL Server
Hello, I have a column called Profile in a table and I am searching for a specific word in that column. I use the keyword LIKE with the wildcard (%) and that is working fine, but how do I have the query only return that word and not all the text in the Profile column. For example, if an entry in Profile was 'Have you seen my dog', how do I just have the query return dog (the word I'm looking for) and not the whole statement. Thank you

Software/Hardware used:
Oracle SQL

Answer Wiki

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

If you know that there is a match why not just return the value that you are looking for? If you wanted to pull the value from the column you would need to use the SUBSTRING and PATINDEX (in SQL Server at least) to get that value from the column.

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    Maybe I'm missing something, but... If you code you query to look for a specific word, and it will return only rows containing that word, and you want the query to return that word only, then you should put that word as a literal (constant) in your SELECT list. i.e. SELECT 'dog' FROM your_Table WHERE field_x like '%dog%'; It doesn't make much sense for me, but that is what I understand you are trying to do. Could you please clarify your requirement ? Thanks. P.s. Words containing 'dog' will match the search criteria ("dogma" for example) . If that is not what you want, the WHERE clause would need some modifications.
    69,510 pointsBadges:
    report
  • TomLiotta
    I suspect that the WHERE clause may have multiple potential matches, perhaps using "OR", so that different matches would return different values in the result set. Or that a search for '%DOG%' might need to return the whole word 'DOGMA' when a match is found. But clarification with a couple examples seems needed. Tom
    125,585 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following