Create leading zero in Oracle

后端 未结 2 1218
一生所求
一生所求 2021-01-22 03:22

I am using Adempiere which has database Oracle

I have window called Stock Code from table called M_StockCode

2条回答
  •  星月不相逢
    2021-01-22 03:39

    A NUMBER cannot have leading zero, a STRING can.

    1. If you want to store the codes with leading zero in the database table, then you must use VARCHAR2 and not NUMBER.

    2. If you want to just display the number with leading zero, then use TO_CHAR to convert the number into string.

    For example,

    SQL> SELECT TO_CHAR(1, '00') FROM DUAL;
    
    TO_
    ---
     01
    

    You could also use LPAD, but remember, the data type of the result would be a string and not a number.

    For example,

    SQL> SELECT LPAD(1, 2, '0') FROM DUAL;
    
    LP
    --
    01
    

提交回复
热议问题