Introduction

EXTRACT function takes a single part of a date/interval/timestamp:

v_nr:= EXTRACT (TYPE from DATE|TIMESTAMP|INTERVAL value);

EXTRACT always returns a numeric value, so if you need the text name of the month, you should use TO_CHAR.

Demo

SQL>
SQL> declare--  ww  w  . j  a  v a  2 s.  c om
  2      v_nr number;
  3  begin
  4      v_nr:=EXTRACT(MONTH from sysdate);
  5      DBMS_OUTPUT.put_line(v_nr);
  6  end;
  7  /
4

PL/SQL procedure successfully completed.
SQL>

The possible types you can pass into EXTRACT are YEAR, MONTH, DAY, HOUR,MINUTE, and SECOND.

You can also use time zone types with timestamps.

Related Topic