Conversion of a Date Subquery to Character in Oracle

1

I have a sub-query returning dates this way:

SELECT DISTINCT DT_EMISSAO_NF FROM DANFE ORDER BY DT_EMISSAO_NF DESC

And, starting from this query, I need all the returned dates to be converted into a character in this pattern 'DD / MM / YYY'

  • If I do the conversion in a single query, sorting sorts all the number of days, after the month, and then after the year, and in case I need to return it as if it were the date itself, the most current days returning first.
asked by anonymous 02.05.2017 / 20:03

1 answer

1

Just use TO_CHAR passing the format you want.

Example:

SELECT TO_CHAR(DT_EMISSAO_NF, 'DD/MM/YYYY HH24:mi:ss') 
FROM DANFE ORDER BY DT_EMISSAO_NF DESC

To use with Distinct, do a sub select, like this:

SELECT TO_CHAR(QRY.DT_CADASTRO, 'DD/MM/YYYY HH24:mi:ss') FROM 
   (SELECT DISTINCT DT_CADASTRO FROM PROJETO ORDER BY DT_CADASTRO DESC
) QRY;

More information here .

    
02.05.2017 / 20:25