Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, rakesh.

Asked: November 02, 2017 - 10:47 am UTC

Last updated: November 03, 2017 - 1:36 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Tom,

There is a string 'ascjhsdndfdaja' i want to print only 'a' alphabet from this string there are 3-occurrence of 'a' so i want to print 'aaa' can you please help me this.
Your help will be much appriciated.

Thanks

and Chris said...

So you want to remove all the characters that aren't 'a' from a string?

A little regular expression can do the trick:

select regexp_replace('ascjhsdndfdaja', '[^a]', '') from dual;

REGEXP_REPLACE('ASCJHSDNDFDAJA','[^A]','')   
aaa 

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Rakesh Singh, November 03, 2017 - 7:27 am UTC

Thanks, i got the answer what i was looking for.

Translate function

Rajeshwaran Jeyabal, November 03, 2017 - 12:35 pm UTC

Translate would be other option.
demo@ORA11G> select translate('ascjhsdndfdaja','abcdefghijklmnopqrstuvwxyz','a') from dual
  2  /

TRA
---
aaa

demo@ORA11G>

Chris Saxon
November 03, 2017 - 1:36 pm UTC

Provided you only have (lowercase) letters in the input ;)

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.