Lui*_*igi 12 sql postgresql pattern-matching
我name在contacts表格中的列中有几个与此类似的值:
test 3100509 DEMO NPS
我想只返回每个值的数字部分name.
我试过这个:
select substring(name FROM '^[0-9]+|.*') from contacts
但那不行.
有关如何从返回值中删除所有非数字字符的想法?
Rid*_*ANE 14
试试这个 :
select substring(name FROM '[0-9]+') from contacts
Run Code Online (Sandbox Code Playgroud)
pet*_*rov 13
select regexp_replace(name , '[^0-9]*', '', 'g') from contacts;
这应该做到这一点.即使名称中有多个数字序列,它也会起作用.
例:
create table contacts(id int, name varchar(200));
insert into contacts(id, name) values(1, 'abc 123 cde 555 mmm 999');
select regexp_replace(name , '[^0-9]*', '', 'g') from contacts;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16062 次 |
| 最近记录: |