Thursday, 14 November 2013

Format Masking

nls_parameters:
Optional national language support parameters (nls_parameters) are useful for specifying the language and format in which the names of date and numeric elements are returned. These parameters are usually absent, and the default values for elements such as day or month names and abbreviations are used.

There is a publicly available view called NLS_SESSION_PARAMETERS that contains the NLS parameters for your current session.

 SELECT * FROM NLS_SESSION_PARAMETERS;

 SHOW PARAMETER NLS_CURR

 SELECT * FROM NLS_SESSION_PARAMETERS;

By default, NLS_CURRENCY would be '$'. We can change this to Session level.

ALTER SESSION set NLS_CURRENCY='Rs';

ALTER SESSION set NLS_CURRENCY='$'  ;

Numeric format Masks:
SELECT TO_CHAR(000201,'$000000.099')||' represents the price in Dollars' from DUAL;

SELECT TO_CHAR(000201,'L000000.099')||' represents the price in local Currency' from DUAL;




Date format Masks: 

SELECT  to_char(sysdate)||' is today''s date' from DUAL;

SELECT  TO_CHAR(sysdate,'Month')||'is a special time' from DUAL;

By prefixing the format model with the letters fm, Oracle is instructed to trim all spaces from the names of days and months. There are many formatting options for dates being converted into characters, some of which are listed in below diagram.

SELECT TO_CHAR(sysdate,'fmMonth')||'is a special time' from DUAL;






No comments:

Post a Comment