简体   繁体   English

从字符串中删除特殊字符和字母,db2 中 sql 查询中的数字除外

[英]Remove special characters and alphabets from a string except number in sql query in db2

Hi I tried using Regex_replace and it is still not working.嗨,我尝试使用 Regex_replace,但仍然无法正常工作。

select CASE WHEN sbbb <> ' ' THEN regexp_replace(sbbb,'[a-zA-Z _-#]',''] ELSE sbbb AS ABCDF from Table where sccc=1; select CASE WHEN sbbb <> ' ' THEN regexp_replace(sbbb,'[a-zA-Z _-#]',''] ELSE sbbb AS ABCDF from Table where sccc=1;

This is the query which I am using to remove alphabets and specials characters from string and have only numbers.这是我用来从字符串中删除字母和特殊字符并且只有数字的查询。 but it doesnot work.但它不起作用。 Query returns me the complete string with numbers,characters and special characters .What is wrong in the above query查询返回包含数字、字符和特殊字符的完整字符串。上述查询有什么问题

I am working on a sql query.我正在处理一个 sql 查询。 There is a column in database which contains characters,special characters and numbers.数据库中有一个包含字符、特殊字符和数字的列。 I want to only keep the numbers and remove all the special characters and alphabets.我只想保留数字并删除所有特殊字符和字母。 How can I do it in query of DB2.我如何在 DB2 的查询中做到这一点。 If a use PATINDEX it is not working.如果使用 PATINDEX 它不起作用。 please help here.请在这里帮忙。

The allowed regular expression patterns are listed on this page此页面上列出了允许的正则表达式模式

Regular expression control characters 正则表达式控制字符

Outside of a set, the following must be preceded with a backslash to be treated as a literal在集合之外,以下必须以反斜杠开头才能被视为文字

* ? + [ ( ) { } ^ $ | \\ . /

Inside a set, the follow must be preceded with a backslash to be treated as a literal在集合中,follow 前面必须有一个反斜杠才能被视为文字

Characters that must be quoted to be treated as literals are [ ] \\ Characters that might need to be quoted, depending on the context are - &必须引用才能被视为文字的字符是[ ] \\可能需要引用的字符,具体取决于上下文是- &

So for you, this should work所以对你来说,这应该有效

regexp_replace(sbbb,'[a-zA-Z _\-#]','')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM