How to format a date and place decimal points in Oracle?

0

I have a query which gets Date fields and fields type number

The result of this query is placed in an excel file and what it does is that it does NOT show the date fields in DD / MM / YYYY format and it does not show the number type fields with decimals, try to convert them with to_char but when you show them in the excel the fields "null"

SELECT F.ID, F.NOMBRE, TO_CHAR(F.FECHA_INI,'DD/MM/YYYY'), TO_CHAR(F.FECHA_REGISTRO,'DD/MM/YYYY'), TO_CHAR(F.FECHA.CARGA,'DD/MM/YYYY'), TO_CHAR(F.IMPORTE_UNO,'fm9990.00'), TO_CHAR(F.IMPORTE_DOS,'fm9990.00')
FROM FACTURA F
WHERE (?1 IS NULL OR  F.ID =?1)
AND F.FECHA_INI >= TO_DATE(?2 'DD/MM/YYYY')
AND F.FECHA_INI <= TO_DATE(?3 'DD/MM/YYYY')

Why do they come out null when showing them in the document?

What makes me fata or is it wrong? I also tried TO_DATE for the date and sample null

This is the code of the method you used to download the file with the query

if(factList !=null) {
    response.addHeader("Content-Type", "application/csv");
    response.addHeader("Content-Disposition", "attachment;filename=archivo.csv");
    PrintWriter out = response.getWriter();
    out.write("columna1,columna2,columna3");
    out.write("\n");
    for(String factu: factList){
        out.write(factu.toCSVRepresentation()); 
        out.write("\n"); 
    } 
    out.flush(); 
    out.close(); 
}else{ 
    log.info("Esta vacio"); 
} 
}catch(ControlException e){ throw new ControlException("Error", e); } }
    
asked by Root93 24.07.2018 в 21:00
source

1 answer

0

Why not try to generate your CSV file from the same oracle in a stored procedure, and to see that it was generated correctly you can open your csv with a notepad ++

        --------------
        -- Cabecera
        --------------
        cursor cabecera is
        SELECT F.ID l1, F.NOMBRE l2, TO_CHAR(F.FECHA_INI,'DD/MM/YYYY') l3, TO_CHAR(F.FECHA_REGISTRO,'DD/MM/YYYY') l4, TO_CHAR(F.FECHA.CARGA,'DD/MM/YYYY') l5, TO_CHAR(F.IMPORTE_UNO,'fm9990.00') l6, TO_CHAR(F.IMPORTE_DOS,'fm9990.00') l7
        FROM FACTURA F
        WHERE (?1 IS NULL OR  F.ID =?1)
        AND F.FECHA_INI >= TO_DATE(?2 'DD/MM/YYYY')
        AND F.FECHA_INI <= TO_DATE(?3 'DD/MM/YYYY');

        --Recorres el cursor y vas generando linea por linea tu csv
        For i in cabecera loop
            nombre_archivo:='NombreArchivo||'.csv';
            v_archivo := UTL_FILE.FOPEN('RutaGuarda Archivo', nombre_archivo, 'W');  
                utl_file.putf(v_archivo,convert(i.l1||separador||'\n', 'AL32UTF8', 'WE8ISO8859P15'));
                utl_file.putf(v_archivo,convert(i.l2||separador||'\n', 'AL32UTF8', 'WE8ISO8859P15'));
                utl_file.putf(v_archivo,convert(i.l3||separador||'\n', 'AL32UTF8', 'WE8ISO8859P15'));
                utl_file.putf(v_archivo,convert(i.l4||separador||'\n', 'AL32UTF8', 'WE8ISO8859P15'));
                utl_file.putf(v_archivo,convert(i.l5||separador||'\n', 'AL32UTF8', 'WE8ISO8859P15'));
                utl_file.putf(v_archivo,convert(i.l6||separador||'\n', 'AL32UTF8', 'WE8ISO8859P15'));    
                utl_file.putf(v_archivo,convert(i.l7||separador||'\n', 'AL32UTF8', 'WE8ISO8859P15'));    
                utl_file.FCLOSE(v_archivo); --Cerrando el archivo
         end loop;
    
answered by 25.07.2018 в 14:24