Customize SQL query output

0

How do I customize an output of a SQL query example result of a sum of the columns OUTPUT: 23000 wanted to customize only that output to $ 23,000

    
asked by anonymous 08.02.2018 / 18:42

1 answer

1

You can use TO_CHAR(number) by passing the correct values for the parameter: fmt .

Syntax:

TO_CHAR(n [, fmt [, 'nlsparam' ] ])

Example, with decimal:

SELECT TO_CHAR(23000,'L99G999D99') FROM DUAL;

Output: R$23.000,00

Example, without decimal:

SELECT TO_CHAR(23000,'L99G999') FROM DUAL;

Output: R$23.000

Explaining:

fmt : Must be the desired format for the conversion, you can see all options here , where:

Note that the number 9 in the format refers to the number of digits that your mask will share, in which case the maximum value will be: R$99.999,99 with decimal and R$99.999 without decimal. >

Update:

If your database is set to a different pattern than you want, you can change the value of the properties NLS_CURRENCY and NLS_NUMERIC_CHARACTER directly to TO_CHAR , using the nlsparam parameter, example:

SELECT TO_CHAR(23000,'L99G999', 'NLS_NUMERIC_CHARACTERS = '',.'' NLS_CURRENCY = ''R$'' ') FROM DUAL;

As you can see in this example the default SQL Fiddle is American and in this another example , changing the parameters to the pattern you want.

    
08.02.2018 / 19:37