Oracle Query - Get only strings in the select field

。_饼干妹妹 提交于 2020-01-02 19:20:12

问题


Maybe this sounds a little bit crazy, but I need to come up with a query to retrieve only letters out of an alphanumeric field.

For example:

TABLE
1234ADD
3901AC
1812OPA
82711AUU

RESULTS EXPECTED
ADD
AC
OPA
AUU

Thank you!


回答1:


Looks like you only want to remove numbers. You can use REGEXP_REPLACE for that in 10g or 11g:

SELECT REGEXP_REPLACE( your_column, '[0-9]*', '' ) FROM your_table;



回答2:


SELECT  REGEXP_REPLACE('1234ADD 3901AC 1812OPA 82711AUU', '[0-9]', '')
FROM    dual



回答3:


Try

SELECT TRANSLATE('1234ADD 3901AC 1812OPA 82711AUU', 'A1234567890', 'A') FROM dual;

and in general see: http://www.psoug.org/reference/translate_replace.html



来源:https://stackoverflow.com/questions/2375426/oracle-query-get-only-strings-in-the-select-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!