0

I have small problem on Oracle PL-SQL,

I created a function

that at the end looks like this :

 wynik := concat(miesiac,concat(dzien,rok));
 w_date := TO_DATE(wynik);
 return w_date;

It works fine but it returns date in format MM/DD/YYYY, and i would want to return in format of DD MONTH YYYY, how can i reach that without alter sesion on global settings?

I tried messing with:

w_date := TO_DATE(wynik,'DD MONTH YYYY');

But it gives me errors....

Thanks for your help.

4

3 回答 3

2

TO_DATE converts string to date and it is rendered to output using default date format definied for session. If you want to display it differently use TO_CHAR function or change default format.

Example TO_CHAR usage:

TO_CHAR(sysdate, 'DD MONTH YYYY')

To change default format:

ALTER SESSION SET NLS_DATE_FORMAT = 'DD MONTH YYYY';
于 2013-11-14T14:25:49.190 回答
1

Internally, the DATE is stored as a number, not as a string, so neither the string converted to the DATE, nor the format date model used (explicitly or implicitly, from session parameter) during the creation of the variable, has anything to do with the way a DATE variable is presented to the user.

To show a DATE variable as a string, the TO_CHAR function should be used, and the format mask used:

SELECT TO_CHAR(SYSDATE, 'DD MONTH YYYY') AS val FROM dual;
VAL                                                
----------------------------------------------------
14 LISTOPAD    2013      

To suppress the extra blank spaces, use the fm modifier:

SELECT TO_CHAR(SYSDATE, 'DD fmMONTH YYYY') AS val FROM dual;
VAL                                                
----------------------------------------------------
14 LISTOPAD 2013  
于 2013-11-14T14:28:00.653 回答
0
w_date := TO_CHAR(wynik,'DD MONTH YYYY');
于 2013-11-14T15:26:44.750 回答