替换配置单元表中的字符串和int值

mutmk8jj  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(306)

我想使用regex\u replace将配置单元表中特定列的所有值替换为随机值。
我怎么能那样做。
与shell脚本编写类似:

tr '[a-j]' '[j-s]'

tr '[1-4]' '[5-8]'

或者是否有其他方法来替换配置单元中的值。
我可以用

select cust_id, regexp_replace(cust_id, '23456', '74563') as cust_id from cust_table;

但是我想用随机数替换100行的所有值。

daupos2t

daupos2t1#

您不需要regexp,只需使用 rand 以及 round 为每一行生成一个随机数。例如,如果要生成0到10000之间的随机数:

select round(rand() * 10000) as cust_id from cust_table
``` `rand` 返回从0到1的随机双精度 `round` 以bigint形式返回舍入值

相关问题