学习oracle也有一段时间了,发现oracle中的函数好多,对于做后台的程序员来说,大把大把的时间还要学习很多其他的新东西,再把这些函数也都记住是不太现实的,所以总结了一下oracle中的一些常用函数及示例,一是为了和大家分享,二是可以在以后工作中忘记了随时查阅。
1.to_char
日期型或数值型转换字符型
select to_char(sysdate,'yyyy') from dual;--返回结果2022
2.to_date
字符串转换为日期型
select to_date('2022/09/18','yyyy-mm-dd') from dual;--返回结果2022-09-18
3.to_number
字符型转换为数值型
select to_number('2022') from dual;--返回结果2022
4.convert
字符串字符集转换
select convert('源字符串','ZHS16GBK') from dual;--返回结果源字符串
5.cast
将源值转换为指定数据类型
select cast('123.43', as int) from dual;--返回结果123
6.hextoraw
将一个十六进制构成的字符串转换raw
select hextoraw('918') from dual;
7.rawtohex
将raw类数值转换为一个相应的十六进制的字符串
select rawtohex('18') from dual;
8.rowidtochar
将rowid数据类型转换为字符类型
select rowidtochar(rowid) from table_name;
9.chartorowid
将字符类型转换为rowid
select chartorowid(column_name) from table_name;