Example of actual Oracle time application code

Source: Internet
Author: User

The following articles mainly use the relevant Code to introduce the actual application of Oracle time. I saw the actual application of Oracle time on the relevant website two days ago, if you are interested in the actual operations, you can click to view the following articles.

 
 
  1. select to_char(sysdate,''hh:mi:ss'') TIME from all_objects  

Note: the TIME of the first record is the same as that of the last record.

You can create a function to solve this problem.

 
 
  1. create or replace function sys_date return date is   
  2. begin   
  3. return sysdate;   
  4. end;   
  5. select to_char(sys_date,''hh:mi:ss'') from all_objects;   

Hours in Oracle time applications

 
 
  1. SELECT EXTRACT(HOUR FROM TIMESTAMP ''2001-02-16 2:38:40'') from offer   
  2. SQL> select sysdate ,to_char(sysdate,''hh'') from dual;   
  3. SYSDATE TO_CHAR(SYSDATE,''HH'')   
  4. 2003-10-13 19:35:21 07   
  5. SQL> select sysdate ,to_char(sysdate,''hh24'') from dual;   
  6. SYSDATE TO_CHAR(SYSDATE,''HH24'')   
  7. 2003-10-13 19:35:21 19   

Obtain the year, month, and day.

Processing of year, month, and day in Oracle time applications

 
 
  1. select older_date,   
  2. newer_date,   
  3. years,   
  4. months,   
  5. abs(   
  6. trunc(   
  7. newer_date-   
  8. add_months( older_date,years*12+months )   
  9. )   
  10. ) days   
  11. from ( select   
  12. trunc(months_between( newer_date, older_date )/12) YEARS,   
  13. mod(trunc(months_between( newer_date, older_date )),   
  14. 12 ) MONTHS,   
  15. newer_date,   
  16. older_date   
  17. from ( select hiredate older_date,   
  18. add_months(hiredate,rownum)+rownum newer_date   
  19. from emp )   
  20. )  

The above content is an introduction to Oracle time application related projects. I hope you will have some gains.

Article by: http://www.programbbs.com/doc/class10-3.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.