Reputation: 19
I need to write a SQL query to get all "a" in the string aabcaadfgaaa. I am using Oracle 11g database.
The result for this should be aaaaaaa
So, in case my input is Alaska the result should be aaa.
Any help would be appreciated.
Regards, Abhishek
Upvotes: 1
Views: 56
Reputation: 11195
Use REGEXP_REPLACE:
SELECT REGEXP_REPLACE ('aabcaadfgaaa', '[^a]') FROM dual;
This is case sensitive, btw.
Upvotes: 0
Reputation: 1269873
You have an odd requirement. But you can do this using regexp_replace()
:
select regexp_replace(lower(col), '[^a]', '', 1, 0)
Upvotes: 6