简体   繁体   English

删除特殊字符SQL

[英]Removing special character SQL

I have column in a table which contains special characters with an attached string. 我在一个表中的列,其中包含带有附加字符串的特殊字符。 The same column contains numbers also. 同一列中也包含数字。 I am only intresed in extracting numbers out of that column eg 我只喜欢从那一列中提取数字,例如

Name-3445 => 3445; Out-90 => 90; 786  => 786

How would i do this in SQL or PL/SQL? 如何在SQL或PL / SQL中执行此操作?

SELECT regexp_replace(some_column, '[^0-9]*', '') as clean_value
FROM your_table
REGEXP_REPLACE(<Your_String>,'[^[:alnum:]'' '']', NULL)

Example: 例:

SELECT REGEXP_REPLACE('##$$$123&&!!__!','[^[:alnum:]'' '']', NULL) FROM dual;

Output: 输出:

123

您可以使用regexp_substr函数: http ://docs.oracle.com/cd/B14117_01/server.101/b10759/functions116.htm

PL/SQL has a REGEX_REPLACE function, which you could use to replace anything that isn't a digit with an empty string. PL / SQL具有REGEX_REPLACE函数,您可以使用该函数用空字符串替换非数字的任何内容。 Details on REGEX_REPLACE can be found here: http://psoug.org/reference/regexp.html REGEX_REPLACE的详细信息可以在这里找到: http ://psoug.org/reference/regexp.html

Without knowing the integrity of your data, something like this might do what you're asking: 在不知道数据完整性的情况下,可能会执行以下操作:

select CAST(SUBSTRING(_COLUMNNAME_,CHARINDEX('-', _COLUMNNAME_),1000), Integer) as ColumnName
from tblTable where _COLUMNNAME_ like '%-%'
union all select CAST(_COLUMNNAME, Integer) as ColumnName
from tblTable where _COLUMNNAME_ not like '%-%'

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

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