2

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

4

1 回答 1

3

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
于 2012-12-03T12:22:36.077 回答