如何在BQ列中删除前缀
我需要从BQ中特定列中的数据中删除前缀0。应该如何完成?使用substr函数?
示例:
ID |
---|
012345 |
0012345 |
00012345 |
,输出应没有零,因此应该像:
ID |
---|
12345 |
12345 |
12345 |
在上述所有列出的情况下。
我知道如何添加一个前缀:
UPDATE
table.name
SET
id = CAST(CONCAT('99999', CAST(id AS STRING)) AS INTEGER)
WHERE
code = 'US' and cast(id as string)
I need to remove a prefix 0 from the data in specific column in BQ. How it should be done? Using substr function?
Example:
id |
---|
012345 |
0012345 |
00012345 |
and the output should be without zeros, so should be like:
id |
---|
12345 |
12345 |
12345 |
in all listed cases above.
I know how to add a prefix:
UPDATE
table.name
SET
id = CAST(CONCAT('99999', CAST(id AS STRING)) AS INTEGER)
WHERE
code = 'US' and cast(id as string)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 ltrim ,
输出将为:
Using LTRIM,
Output will be:
如果将字符串投放到整数,则将删除零。然后,为了恢复字符串,足以抛弃到字符串。
它对您有用吗?
If you cast your string to integer, you'll remove the zeroes. Then in order to get back your string, it's sufficient to cast back to string.
Does it work for you?
以下查询应起作用
The below query should work
我已经使用过正则:
I've used regex: