How to add a 0 to the left to the value of a field in oracle with LPAD?

1

I have the following query, where the field ENTIDAD_REC is of type varchar seems to me and has values like these 012, 003, 011.

What I do is show that query in a .csv file and that field shows only the values 12, 3, 11, it does NOT show the zeros, and I do not know if it's a topic of how to interpret the information, I made the query using LPAD , to add the "0", I put the name of the field, the number of times I want the character to appear, and the character

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'), LPAD(F.ENTIDAD_REC,1,'0')
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')

but when opening the file in excel the field shows the value 0, and if I change to LPAD(F.ENTIDAD_REC,2,'0') , the file shows the value 1, then I do not know how to use it to add the zero and show the information of the BD, how can I do it?

This is my code to generate the .csv file download

if(factList !=null) { 
response.addHeader("Content-Type", "application/csv"); response.addHeader("Content-Disposition", "attachment;filename=archivo.csv"); 

PrintWriter out = response.getWriter(); out.write("ID,NOMBRE,FECHA_INI, FECHA_REGISTRO"); 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); } }

This is the.method

public String toCSV(){
    StringBuilder builder = new StringBuilder();
    builder.append(getId()).append(“,”),builder.append(getFecInicio()).append(“,”),
. . . 
return builder.toString();
    
asked by Root93 25.07.2018 в 06:05
source

0 answers