IBM Db2: select numeric characters only from a col

2019-08-17 11:28发布

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条回答
何必那么认真
2楼-- · 2019-08-17 12:19

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
查看更多
登录 后发表回答