oracle中的常用函数
1.日期函数
(1)字符转日期to_date()
举例:
select to_date('2002-08-26','yyyy-mm-dd') from dual;
(2)日期转字符to_char()
举例:
(3)add_months()
(4)months_between()
(5)last_day()
举例:select last_day(sysdate) from dual;
(6)对值进行截断trunc()
○截断数字,格式:TRUNC(n1,n2),n1表示被截断的数字,n2表示要截断到那一位。n2可以是负数,表示截断小数点前。注意,TRUNC截断不是四舍五入。
举例:select TRUNC(15.79) from dual;
select TRUNC(15.79,1) from dual;
select trunc(15.79,-1) from dual;
○截断日期:先执行命令:alter session set nls_date_format='yyyy-mm-dd hh24:mi:hh';
举例:
截取今天: select sysdate,trunc(sysdate,'dd') from dual;
截取本周第一天:select sysdate,trunc(sysdate,'d') from dual;
截取本月第一天:select sysdate,trunc(sysdate,'mm') from dual;
截取本年第一天:select sysdate,trunc(sysdate,'y') from dual;
截取到小时:select sysdate,trunc(sysdate,'hh') from dual;
截取到分钟:select sysdate,trunc(sysdate,'mi') from dual;
(7)next_day()
举例:
(8)纵表转横表函数
在ORACLE10中可使用以下方法:
SELECT n_sec_code, wmsys.wm_concat (c_researcher_code) as result
FROM m_researcher_stock_rel
GROUP BY n_sec_code
posted on 2011-04-27 23:13 LeeXiaoLiang 阅读(111) 评论(0) 收藏 举报
浙公网安备 33010602011771号