Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: [Q] Removing all characters except some

Re: [Q] Removing all characters except some

From: Martin Burbridge <pobox002_at_bebub.com>
Date: 5 Dec 2003 18:29:12 -0800
Message-ID: <45a06b65.0312051829.50e35753@posting.google.com>


son42uk_at_yahoo.co.uk (Peter Amberg) wrote in message news:<f8232d10.0312030449.38c691aa_at_posting.google.com>...
> I have a VARCHAR column in some table T. How can I zap away all
> characters from the string except digits? I need this in a SELECT
> clause, I need to order the entries by the integer values within the
> string. There may be non-digit characters anywhere in the string, I
> can't just use SUBSTR.
>

You can also use two translates in cases where you only want to specify the characters to keep.

SQL> var s varchar2(100)
SQL> exec :s := 'rubbish123in456here7_at_8*9!!'

PL/SQL procedure successfully completed.

SQL> select
  2 translate(:s,'0'||translate(:s,'*0123456789','*'),'0')   3 from dual
  4 /

TRANSLATE(:S,'0'||TRANSLATE(:S,'*0123456789','*'),'0')


123456789

SQL> exec :s := ' 1 xx 2 3 p 1'

PL/SQL procedure successfully completed.

SQL> / TRANSLATE(:S,'0'||TRANSLATE(:S,'*0123456789','*'),'0')


1231

-- 
Martin Burbridge

pobox 002 email is full of spam and never read
Received on Fri Dec 05 2003 - 20:29:12 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US