从整理字符串中删除非数字,只保留数字
需要语法或方法来从整理的VARCHAR列中删除任何非数字值,并替换为零填充的10位帐户号结果。该列有字母和特殊字符,但我需要删除这些字母,只保留数字。
我正在使用 lpad 函数函数code> ')
将结果剩下的零
00 |
---|
# |
000123456M |
councel_number_column |
, |
---|
' 0 |
10 |
9999999 |
Need syntax or method to remove any non-numeric values from a collated varchar column and replace with zero padded 10-digit account number result. The column has letters and special characters, but I need to remove those and only keep the numbers.
I am using LPAD function LPAD(Account_Number_Column,10,'0')
to left pad the result with zeros
Account_Number_Column |
---|
00#9999999 |
000123456M |
N/A |
Expected_Result |
---|
0009999999 |
0000123456 |
0000000000 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该做到这一点:
当然,您可能还需要将其他元素纳入数据质量(例如确保您的非填充结果是< = 10个字符等)。在您的用例中构成可接受的结果。
如果您有整理,我建议将其删除以作为RegexP函数,然后重新应用结果字符串。
这是一个示例,如果您有“ en-ci”的整理,则可以将其剥离以作为功能并重新申请结果:
This should do it:
Of course, you may want to also incorporate other elements around data quality (like ensuring your non-padded result is <= 10 characters, etc). Whatever constitutes an acceptable result in your use case.
If you have collation, I would suggest removing it for the REGEXP function, and reapply to the resulting string.
Here's an example where if you had a collation of 'en-ci' you could strip it for the function and reapply for the result:
一种方法是使用 regexp_substr_all 数字,然后将该数组与 array_to_to_string ,然后可以是LPAD至10
给出:
. - 参考/ comLation.html#satering-using-utf-8-vs-vs-locale-Collation“ rel =” nofollow noreferrer“> colation> colation off strings通常不好因此,通过
colate(Account_number_column,'utf8')
,但这应该是吉姆的答案:
One method is it use REGEXP_SUBSTR_ALL to get the array of matching digits, and then turn that array into a string with ARRAY_TO_STRING, which can then be LPAD to 10
gives:
Striping the COLLATION off strings is normally bad, BUT given you only want digit's is should ok in this instance to do so via
collate(Account_Number_Column,'utf8')
but it should be Jim's answer: