getting error while trying to extract month from date

13,674

Try to explicitly convert your bind variable to the date datatype using to_date function:

select
    case
        when extract(month from to_date(:mydate, 'dd-mm-rr')) <= 6 then '1st'
        when extract(month from to_date(:mydate, 'dd-mm-rr')) >= 7 then '2nd'
    end as half_of_the_year
from dual
Share:
13,674
Basit
Author by

Basit

A solution-oriented well balanced technical IT Professional with a rich experience of 8 years + in software development covering multiple technologies. I keep atop of new developments within the industry and can adapt quickly to new coding conventions. I am happy working independently or in a close team environment, and apply a positive attitude to every task I undertake. I possess a broad range of technical skills which I refresh on a regular basis, allowing me to respond to new issues with considerable speed.

Updated on June 15, 2022

Comments

  • Basit
    Basit almost 2 years

    I want to extract month from input date. I am trying this

    select
        case
            when extract(month from :myDate) <= 6 then '1st' 
            when extract(month from :myDate) >= 7 then '2nd'
        end as half_of_the_year
    from dual
    

    If i enter 2-12-12 then i get the error that

    ORA-30076: invalid extract field for extract source
    30076. 00000 -  "invalid extract field for extract source"
    *Cause:    The extract source does not contain the specified extract field.
    *Action:
    

    Why i am getting this error ?

    Thanks