Lorik Berisha
Lorik Berisha

Reputation: 273

Manipulating with SQL query output

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

Upvotes: 2

Views: 188

Answers (3)

Nikhil
Nikhil

Reputation: 3950

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

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

Upvotes: 0

Goran Kutlaca
Goran Kutlaca

Reputation: 2024

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!

Upvotes: 3

D-Shih
D-Shih

Reputation: 46249

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.

Upvotes: 2

Related Questions