postgresSql中replace使用

uuid中横杠替换掉

uuid函数,参考链接:https://blog.csdn.net/weixin_42585386/article/details/108224690

select uuid_generate_v4() 查询是一串数字加横杠

把横杠替换掉,用replace函数,

参考链接:https://blog.csdn.net/lanxingbudui/article/details/83854735

例子:

select replace(CAST(uuid_generate_v4() as text), '-', '')

replace第一个参数是替换表中哪个字段

第二个参数是将什么替换掉

第三个参数是将替换成什么数据

 

为什么用cast呢?

是因为replace中第一个参数必须是字符类型,所以先用cast转成字符类型,再替换。

 

posted @ 2021-08-27 13:55  小小菜鸟04  阅读(1591)  评论(0)    收藏  举报