Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday, 20 August 2014

Extract Function

We can extract Year, Month, Day  from a Date. We can also extract Hour, Minute and Second from Timestamp with the help of EXTRACT function.

Below are some examples:-

SELECT EXTRACT(YEAR FROM SYSDATE) EXT_YEAR FROM DUAL;

SELECT EXTRACT(MONTH FROM SYSDATE) EXT_MNTH FROM DUAL;

SELECT EXTRACT(DAY FROM SYSDATE) EXT_DAY FROM DUAL;


Remember, the data format should be DD-MON-YYYY or DD/MM/YYYY.

We can Extract Hour, Minute, Seconds from timestamp only :-


SELECT EXTRACT (HOUR FROM SYSTIMESTAMP) EXT_HR FROM DUAL;

SELECT EXTRACT (MINUTE FROM SYSTIMESTAMP) EXT_MIN FROM DUAL;

SELECT EXTRACT (SECOND FROM SYSTIMESTAMP) EXT_SEC FROM DUAL;





Read Also:-  

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.