2

I want to write a query which returns the month only in 3 characters but the first character should be Capital and the rest non-capital. For example DEC should be (Dec) or JAN (Jan).

select substr(sysdate,4,3) from dual;

SQL code above returns the month but in capital "DEC", so I want the output as "Dec".

Does anyone know how to achieve it?

Thanks

1
  • 2
    Don't use substr on a DATE column. That relies on the evil implicit data type conversion. On my computer your query would return 8-1 Commented Dec 3, 2018 at 8:37

3 Answers 3

3

There is no need for manipulation, as stated in previous answers.

You can simply write this:

SELECT TO_CHAR (SYSDATE, 'Mon', 'nls_date_language=American') FROM DUAL;

If you'd pass 'Month' as the second parameter you'd get 'December', if you'd pass 'month' you'd get 'december' and if you pass 'Mon' you will get 'Dec', as you have asked.

I hope I helped!

Sign up to request clarification or add additional context in comments.

Comments

2

You can try to use substr with to_char function.

select substr(to_char(sysdate, 'Month', 'nls_date_language=American') ,0,3)  from dual

c# online

Note

use nls_date_language=American to set culture in to_char function.

Comments

0

this will work indeed jus to use an extra function that is initials with caps on :

select initcap(substr(sysdate,4,3)) from dual;

1 Comment

Don't use substr on a DATE column. That relies on the evil implicit data type conversion. On my computer this would return 8-1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.