Home > Database > Mysql Tutorial > body text

oracle常用函数汇总

WBOY
Release: 2016-06-07 16:22:52
Original
745 people have browsed it

以下是对oracle中的常用函数进行了汇总介绍,需要的朋友可以过来参考下 一、运算符 算术运算符:+ - * / 可以在select 语句中使用 连接运算符:|| select deptno|| dname from dept; 比较运算符: = = != = like between is null in 逻辑运算符:not and or

以下是对oracle中的常用函数进行了汇总介绍,需要的朋友可以过来参考下

 

一、运算符
算术运算符:+ - * / 可以在select 语句中使用
连接运算符:|| select deptno|| dname from dept;
比较运算符:> >= = != 逻辑运算符:not and or
集合运算符: intersect ,union, union all, minus
要求:对应集合的列数和数据类型相同
     查询中不能包含long 列
     列的标签是第一个集合的标签
     使用order by时,必须使用位置序号,不能使用列名

例:集合运算符的使用:

复制代码 代码如下:


intersect ,union, union all, minus
select * from emp intersect select * from emp where deptno=10 ;
select * from emp minus select * from emp where deptno=10;
select * from emp where deptno=10 union select * from emp where deptno in (10,20); --不包括重复行
select * from emp where deptno=10 union all select * from emp where deptno in (10,20); --包括重复行


二.ORACLE日期时间函数大全
   TO_DATE格式(以时间:2007-11-02   13:45:25为例)

        Year:     
        yy two digits 两位年                显示值:07
        yyy three digits 三位年                显示值:007
        yyyy four digits 四位年                显示值:2007

        Month:     
        mm    number     两位月              显示值:11
        mon    abbreviated 字符集表示          显示值:11月,若是英文版,显示nov    
        month spelled out 字符集表示          显示值:11月,若是英文版,显示november

        Day:     
        dd    number         当月第几天        显示值:02
        ddd    number         当年第几天        显示值:02
        dy    abbreviated 当周第几天简写    显示值:星期五,若是英文版,显示fri
        day    spelled out   当周第几天全写    显示值:星期五,若是英文版,显示friday       
        ddspth spelled out, ordinal twelfth

              Hour:
              hh    two digits 12小时进制            显示值:01
              hh24 two digits 24小时进制            显示值:13

              Minute:
              mi    two digits 60进制                显示值:45

              Second:
              ss    two digits 60进制                显示值:25

              其它
              Q     digit         季度                  显示值:4
              WW    digit         当年第几周            显示值:44
              W    digit          当月第几周            显示值:1

        24小时格式下时间范围为: 0:00:00 - 23:59:59....     
        12小时格式下时间范围为: 1:00:00 - 12:59:59 ....

1. 日期和字符转换函数用法(to_date,to_char)
        
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual;   //日期转化为字符串  
select to_char(sysdate,'yyyy') as nowYear   from dual;   //获取时间的年  
select to_char(sysdate,'mm')    as nowMonth from dual;   //获取时间的月  
select to_char(sysdate,'dd')    as nowDay    from dual;   //获取时间的日  
select to_char(sysdate,'hh24') as nowHour   from dual;   //获取时间的时  
select to_char(sysdate,'mi')    as nowMinute from dual;   //获取时间的分  
select to_char(sysdate,'ss')    as nowSecond from dual;   //获取时间的秒

select to_date('2004-05-07 13:23:44','yyyy-mm-dd hh24:mi:ss')    from dual//

2. select to_char( to_date(222,'J'),'Jsp') from dual     

    显示Two Hundred Twenty-Two  

3.求某天是星期几     
   select to_char(to_date('2002-08-26','yyyy-mm-dd'),'day') from dual;     
   星期一     
   select to_char(to_date('2002-08-26','yyyy-mm-dd'),'day','NLS_DATE_LANGUAGE = American') from dual;     
   monday     
   设置日期语言     
   ALTER SESSION SET NLS_DATE_LANGUAGE='AMERICAN';     
   也可以这样     
   TO_DATE ('2002-08-26', 'YYYY-mm-dd', 'NLS_DATE_LANGUAGE = American')     

4. 两个日期间的天数     
    select floor(sysdate - to_date('20020405','yyyymmdd')) from dual;  

5. 时间为null的用法     
   select id, active_date from table1     
   UNION     
   select 1, TO_DATE(null) from dual;      
   注意要用TO_DATE(null)     

6.月份差  
   a_date between to_date('20011201','yyyymmdd') and to_date('20011231','yyyymmdd')     
   那么12月31号中午12点之后和12月1号的12点之前是不包含在这个范围之内的。     
   所以,当时间需要精确的时候,觉得to_char还是必要的

7. 日期格式冲突问题     
    输入的格式要看你安装的ORACLE字符集的类型, 比如: US7ASCII, date格式的类型就是: '01-Jan-01'     
    alter system set NLS_DATE_LANGUAGE = American     
    alter session set NLS_DATE_LANGUAGE = American     
    或者在to_date中写     
    select to_char(to_date('2002-08-26','yyyy-mm-dd'),'day','NLS_DATE_LANGUAGE = American') from dual;     
    注意我这只是举了NLS_DATE_LANGUAGE,当然还有很多,     
    可查看     
    select * from nls_session_parameters     
    select * from V$NLS_PARAMETERS     
8.     

复制代码 代码如下:

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!