码迷,mamicode.com
首页 > 数据库 > 详细

ORACLE 常用

时间:2020-03-25 01:22:27      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:lang   image   where   com   连续   second   排名   ||   rom   

 1 select sysdate from dual;--2020-03-24 23:07:53
 2 select to_char(sysdate,yyyy-mm-dd hh24:mi:ss) as nowTime from dual; --日期转化为字符串  2020-03-24 23:08:13
 3 select to_char(sysdate,yyyy) as nowYear from dual; --获取时间的年 2020
 4 select to_char(sysdate,mm) as nowMonth from dual; --获取时间的月 03
 5 select to_char(sysdate,dd) as nowDay from dual; --获取时间的日  24 
 6 select to_char(sysdate,hh24) as nowHour from dual; --获取时间的时  23 
 7 select to_char(sysdate,mi) as nowMinute from dual; --获取时间的分  07
 8 select to_char(sysdate,ss) as nowSecond from dual; --获取时间的秒 53
 9 
10 
11 select to_date(2020-03-24 23:07:53,yyyy-mm-dd hh24:mi:ss) from dual;
12 select to_char( to_date(222,J),Jsp) from dual ;--显示Two Hundred Twenty-Two 
13 
14 
15  select to_char(to_date(2020-03-24,yyyy-mm-dd),dd) from dual; --   24
16   select to_char(to_date(2020-03-24,yyyy-mm-dd),mm) from dual; --  03
17     select to_char(to_date(2020-03-24,yyyy-mm-dd),yyyy) from dual;  --2020
18 ------------------------------------
19     select sysdate from  dual ;--2020/3/24 23:20:46
20     select ‘‘||sysdate||‘‘ from dual ;--24-3月 -20
21     
22     
23  select to_char(to_date(2020-03-24,yyyy-mm-dd),dd-mm-yyyy,NLS_DATE_LANGUAGE = American) from dual;--twenty twenty  
24  
25  SELECT TO_CHAR(sysdate,MM/DD/YYYY HH:MI AM,  NLS_DATE_LANGUAGE = American)  
26  FROM DUAL;--03/24/2020 11:28 PM
27  
28  --求两个日期差
29  select floor(sysdate - to_date(20020405,yyyymmdd)) from dual;   --6563
30   select floor(sysdate - date2002-04-05) from dual;--6535
31   
32   
33    --求月份差
34    select months_between( date2010-9-1,sysdate) MONTHS FROM DUAL;  --   -114.773613724612
35    
36    --trunc
37    select trunc(sysdate) from  dual;--   2020/3/24
38    select trunc(sysdate,year) from  dual;--  2020/1/1
39    select trunc(sysdate,month) from  dual;--2020/3/1  当月第一天
40    select trunc(sysdate,day) from  dual;--2020/3/22 本周第一天 星期天
41    
42 select   trunc(sysdate,month)-1 from dual;--2020/2/29   上月最后一天

 

 

select* from emp  ;
技术图片

 


 

--row_number() 顺序排序 常见去重
select *from (
select t.* , row_number()over (partition by job , deptno order by sal desc) as row_num
from emp t  order by row_num desc )
where row_num =1 ;
技术图片

 

 技术图片

 

 --分析函数

select t.*, sum(sal)over(order by job , sal  ) as job与sal累加,
sum(sal)over() as 总和
 from emp t    ;

技术图片

 

 

 

 --跳跃排序
 select t.*, rank()over(order by job   ) as 排名
 from emp t    ;
 

技术图片

 


 

--连续排序
 select t.*, dense_rank()over(order by job   ) as 排名
 from emp t    ;

技术图片

 

 

 



 

ORACLE 常用

标签:lang   image   where   com   连续   second   排名   ||   rom   

原文地址:https://www.cnblogs.com/swanchan/p/12563294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!