oracle经典操作sql

分页:

SELECT * FROM (
SELECT A.*, ROWNUM RN
FROM
(SELECT * FROM TABLE_NAME) A
WHERE ROWNUM <= 40)
WHERE RN >= 21

 

去重:

delete from 表名 t1
where rowid<(select max(rowid)
from 表名 t2
where t1.user_name=t2.user_name)

 

Oracle清空回收站命令

purge recyclebin

 

oracle自动生成时间:

select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "Current Time" from dual;

select to_char(sysdate, 'MM-DD-YYYY HH24:MI:SS') "now" from dual;

 

日期时间插入:

插入oracle服务器当前时间  
insert into tb (date) values (sysdate);--sysdate为oracle服务器当前时间
插入自定义时间
INSERT  INTO  FLOOR  VALUES  ( to_date ( '2007-12-20 18:31:34' , 'YYYY-MM-DD HH24:MI:SS' ) ) ;
查询显示:2007-12-20 18:31:34.0
------------------- 
INSERT  INTO  FLOOR  VALUES  ( to_date ( '2007-12-14 14:10' , 'YYYY-MM-DD HH24:MI' ) ); 
查询显示:2007-12-14 14:10:00.0
------------------- 
INSERT  INTO  FLOOR  VALUES  ( to_date ( '2007-12-14 14' , 'YYYY-MM-DD HH24' ) ); 
查询显示:2007-12-14 14:00:00.0 
------------------- 
INSERT  INTO  FLOOR  VALUES  ( to_date ( '2007-11-15' , 'YYYY-MM-DD' ) ); 
查询显示:2007-11-15 00:00:00.0 
------------------- 
INSERT  INTO  FLOOR  VALUES  ( to_date ( '2007-09' , 'YYYY-MM' ) ); 
查询显示:2007-09-01 00:00:00.0 
------------------- 
INSERT  INTO  FLOOR  VALUES  ( to_date ( '2007' , 'YYYY' ) ); 
查询显示:2007-05-01 00:00:00.0 
------------------- 
当省略HH、MI和SS对应的输入参数时,Oracle使用0作为DEFAULT值。 
如果输入的日期数据忽略时间部分,Oracle会将时、分、秒部分都置为0,也就是说会取整到日。 
同样,忽略了DD参数,Oracle会采用1作为日的默认值,也就是说会取整到月。 
但是,不要被这种“惯性”所迷惑,如果忽略MM参数,Oracle并不会取整到年,而是取整到当前月 

查询语句过滤重复数据问题
select distinct x, y from t;

select x,y from t group by x,y



posted @ 2014-03-09 13:44  tancp  阅读(370)  评论(0编辑  收藏  举报