postgreSQL 数字与字符串类型转换操作
数字转字符串
select cast(123 as VARCHAR);
字符串转数字
select cast('123' as INTEGER);
以此类推,应该也可以转换为其他数据类型。
补充:pgSql, mySql中字符串转化为数字
pgSql
语法 to_number(text, text)
例子
select to_number(trim(both 'ibs' from classname), '999999') as cn from bbs order by cn /*trim(both 'ibs' from classname)去除classname字段中的'ibs'字符*/
mySql
语法 str*1 / str+1 / -str /*str为varchar的数字,此处不一定是1,只要是数字即可*/
hql
语法 to_number(text, text)
例子
select b from BBS b where b.isDeleted=false order by to_number(trim(both 'ibs' from b.className), '999999')
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。如有错误或未考虑完全的地方,望不吝赐教。
相关文章
postgresql insert into select无法使用并行查询的解决
这篇文章主要介绍了postgresql insert into select无法使用并行查询的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-01-01Postgresql源码分析returns setof函数oracle管道pipelined
这篇文章主要为大家介绍了Postgresql源码分析returns setof函数oracle管道pipelined,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-01-01
最新评论