數(shù)字轉字符串
select cast(123 as VARCHAR);
字符串轉數(shù)字
select cast('123' as INTEGER);
以此類推,應該也可以轉換為其他數(shù)據(jù)類型。
補充:pgSql, mySql中字符串轉化為數(shù)字
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的數(shù)字,此處不一定是1,只要是數(shù)字即可*/
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')
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。
您可能感興趣的文章:- Postgresql 截取字符串的案例
- postgresql 查詢集合結果用逗號分隔返回字符串處理的操作
- postgresql 查詢字符串中是否包含某字符的操作
- PostgreSQL 使用raise函數(shù)打印字符串
- PostgreSQL 字符串拆分與合并案例
- PostgreSQL判斷字符串是否包含目標字符串的多種方法