正则表达式匹配sql中的字符 [英] regex to match character in sql

查看:459
本文介绍了正则表达式匹配sql中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个包含%符号的Hike%列,我已将表中的另一列声明为数字。我正在将数据从一个表复制到其他因为数字列中的%符号而失败。


我需要在该Hike列中检查逗号,%和&,$等字符。如果它们中的任何一个存在,我应该替换为'' 


请提示一种检查所有这些字符的最佳方法并让我copy。我不确定是否正在构造正则表达式,因此卡住了。


解决方案

替换功能应该适合你。


REPLACE(string_expression,string_pattern
,string_replacement)



https://docs.microsoft.com/en-us/sql/t-sql/functions/replace-transact-sql?view=sql-server-2017


Hi,

I have a Hike% column that contains % symbol and i have declared another column in a table as numeric.I am copying the data from one table to other and it fails because of % symbol in numeric column.

I need to check for characters like comma,%,&,$ in that Hike column.If any of them are present,i should replace with '' 

Pls suggest a best way that checks for all those characters and lets me copy.I am not sure of framing the regex ,hence stuck.

解决方案

The Replace function should work for you.

REPLACE ( string_expression , string_pattern , string_replacement )

https://docs.microsoft.com/en-us/sql/t-sql/functions/replace-transact-sql?view=sql-server-2017


这篇关于正则表达式匹配sql中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆