Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: [Q] Removing all characters except some
Martin Burbridge wrote:
> 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. >>
Here's another solution:
CREATE TABLE test (
address VARCHAR2(40));
INSERT INTO test VALUES ('123 Main Street'); INSERT INTO test VALUES ('100 State Street'); INSERT INTO test VALUES ('1100 Broadway Street'); INSERT INTO test VALUES ('One Stromlof Blvd');COMMIT; COL sortcol FORMAT 99999
SELECT address, TO_NUMBER(TRIM(TRANSLATE(address,
'0ABCDEFGHIJKLMNOPOQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,','0'))) SORTCOL
FROM test
ORDER BY SORTCOL;
-- Daniel Morgan http://www.outreach.washington.edu/ext/certificates/oad/oad_crs.asp http://www.outreach.washington.edu/ext/certificates/aoa/aoa_crs.asp damorgan_at_x.washington.edu (replace 'x' with a 'u' to reply)Received on Sat Dec 06 2003 - 01:31:40 CST