date function

--Trunc ,Round return date

-- To_char returns String 
-- month length

select trunc(add_Months(trunc(sysdate, 'mm'), 1), 'mm') -
       trunc(sysdate, 'mm')
  from dual;
  
select trunc(add_Months(trunc(to_date('&V','yyyy-mm-dd'), 'mm'), 1), 'mm') -
       trunc(to_date('&V','yyyy-mm-dd'), 'mm')
  from dual;  

 

 

 ALTER   SESSION   SET   NLS_DATE_LANGUAGE   =   'AMERICAN';   


-- 2010-02-01 IS Monday
-- 2010-03-01 is Monday
select next_day(TO_date('2010-02-27','yyyy-mm-dd'),'MONDAY' )  from dual;  -- 2010-03-01  it shows next month!

select next_day( trunc( TO_date('2010-02-27','yyyy-mm-dd'),'mm'),'MONDAY' )  from dual;  -- 2010-02-08  incorrect  ;actually 2010-02-01 is first monday for month

select next_day(trunc(TO_date('2010-02-27', 'yyyy-mm-dd'), 'mm') - 1,
                'MONDAY')
  from dual; -- 2010-02-01  correct first monday of month
  
  
select next_day(trunc(TO_date('2010-02-27', 'yyyy-mm-dd'), 'mm') - 1,
                'MONDAY')+2*7
  from dual; -- 2010-02-01  correct  third monnday of month



select next_day(trunc(TO_date('&V', 'yyyy-mm-dd'), 'mm') - 1,
                'MONDAY')+(&SEQUENCE-1)*7
  from dual; -- 2010-02-01  correct  third monnday of month

 

  

  select  trunc (sysdate ,'Q') from dual;
  select to_char(sysdate,'Q') from dual;

 

你可能感兴趣的:(function)