- --字符函数
- select upper('itmyhome') from dual; --将小写转换成大写
- select lower('HELLO') from dual; --将大写转换成小写
- select initcap('beijing') from dual; --首字母大写
- select concat('Hello', ' world') from dual; --连接字符串 或者'Hello'||'world'
- select substr('iloveyou', 2, 4) from dual; --截取字符串
- select length('itmyhome') from dual; --字符串长度
- select replace('beijing', 'jing', 'piao') from dual; --替换字符串
- --数值函数
- select round(123.456) from dual; --四舍五入 舍去小数
- select round(345.678, 2) from dual; --保留两位小数
- select round(789.123, -1) from dual; --对整数进行四舍五入
- select trunc(123.678) from dual; --舍去小数,但不进位
- select trunc(123.678, 2) from dual; --保留两位小数 不进位
- select trunc(567.678, -2) from dual; --对整数进行四舍五入
- select mod(8, 3) from dual; --返回8%3的结果
- --日期函数
- select sysdate from dual; --返回当前日期
- select months_between(sysdate, '12-4月 -13') from dual; --返回之间的月数
- select add_months(sysdate, 6) from dual; --在日期上加上月数
- select next_day(sysdate, '星期一') from dual; --求下一个星期一
- select last_day(sysdate) from dual; --求本月的最后一天
- --转换函数
- select to_char(sysdate, 'yyyy-mm-dd') from dual;
- select to_char(sysdate, 'fmyyyy-mm-dd') from dual; --去掉月 日 前面的0
- select to_char('12345', '99,999') from dual; --分割钱 9表示格式
- select to_char('12345', 'L99,999') from dual; --加上¥符号
- select to_number('123') from dual;
- select to_date('1990-06-06', 'yyyy-mm-dd') from dual;
- --其他
- select nvl(null, 0) from dual; --如果为null,则用0代替
- select decode(state, 1, '提交', 2, '通过', 3, '未通过') from test;
- --类似于如下 case when
- select case state
- when '1' then
- '提交'
- when '2' then
- '通过'
- when '3' then
- '不通过'
- end
- from test;
Oracle常用函数
最新推荐文章于 2022-03-28 15:33:43 发布