替换柱雪花(SQL)中的值
我使用以下代码从字符串中提取数字:
regexp_substr(data, '\\d+\.\\d+') AS Age
其中值为0(在字符串中),我得到了一个空值。是否有任何方法可以在更广泛的查询中纠正此问题,因此所有空的null被0替换为0?
I'm extracting a number from a string using the following code:
regexp_substr(data, '\\d+\.\\d+') AS Age
Where the value is 0 (within the string), I'm getting a null value. Is there any way to correct this within the wider query, so all the nulls are replaced with 0s?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您共享了示例数据,我可能会有所帮助,但不确定下面是否有帮助:
与@Kurt建议的内容非常相似,但没有领先的“?:”。
I could be helpful if you have shared your sample data, but not sure if below helps:
Pretty similar to what @kurt suggested, but without the leading "?:".
注意
\ d+。\ d+
表示“一个矿石更多数字,后跟任何字符,然后是一个或多个数字。此模式至少需要3个字符才能匹配,中间甚至不必是。
数字 但是,如果您还需要捕获十进制值,则不匹配此模式,您将需要更复杂的东西来处理数字,然后是可选的小数点和更多数字:
\ d+(?:\。\。\。\ d+) ?
此模式将匹配0、0.0、42、98.6,等等。
Note
\d+.\d+
means "one ore more digits followed by any character followed by one or more digits. This pattern requires at least 3 characters to match, and the middle one doesn't even have to be a digit.0 does not match that pattern. To match 0 or 42 or 1000000, i.e. any integer that is merely a string of digits, you only need
\d+
10.5 does not match this pattern, however, so if you need to also capture decimal values, you will need something more complex that handles digits followed by an optional decimal point and more digits:
\d+(?:\.\d+)?
This pattern will match 0, 0.0, 42, 98.6, etc.