IBM Db2: select numeric characters only from a col

2019-08-17 12:17发布

问题:

I have a column 'TEST_COLUMN' that carries 3 values:

123
123ad(44)
w-eq1dfd2

I need to SELECT TEST_COLUMN but get the following result:

123
12344
12

I am running on Db2 Warehouse on Cloud.

回答1:

You can use REGEXP_REPLACE:

SELECT REGEXP_REPLACE(
   '123Red345', '[A-Za-z]','',1) 
      FROM sysibm.sysdummy1

The query would return "123345".

Because you asked below, here is the generic version:

SELECT REGEXP_REPLACE(YOUR_COLUMN, '[A-Za-z]','',1) 
          FROM SCHEMA.TABLE