Decimal to Varchar without leading zeros

select d,
		CASE WHEN d < 0    THEN '-' ELSE '' END
       || CASE INT(d) WHEN 0 THEN '0' ELSE '' END
       || STRIP(CHAR(ABS(d)),L,'0')                               strip_a
	   , SUBSTR('-0',1+SIGN(INT(SIGN(d))+1),2-ABS(SIGN(INT(d)))-SIGN(INT(SIGN(d))+1))
       || STRIP(CHAR(ABS(d)),L,'0')                               strip_b
     , RTRIM(SUBSTR('-0 ',2+SIGN(INT(d*2-1+6e-17)),2-ABS(SIGN(INT(d)))))
       || STRIP(CHAR(ABS(d)),L,'0')                               strip_c
	 , strip(strip(left(d, 1), L, '0'), L, '+')|| strip(strip(substr(d, 2)), L, '0') strip_d	 
	, rtrim (char (integer (d))) || '.'|| substr (char (d),locate ('.', char (d))+1,length (char (d)) - locate ('.', char (d)))  strip_e
	 
 FROM (VALUES -001.267, 0, 1234.5, 0.123, -0.123) dm(d);

strip_a strip_b strip_c is correct,
strip_d and strip_e is not all correct


运行结果:
引用

D                   STRIP_A               STRIP_B               STRIP_C                STRIP_E                       
------------------- --------------------- --------------------- ---------------------- -------------------------------
          -1.267000 -1.267000             -1.267000             -1.267000              -1.267000                     
           0.000000 0.000000              0.000000              0.000000               0.000000                      
        1234.500000 1234.500000           1234.500000           1234.500000            1234.500000                   
           0.123000 0.123000              0.123000              0.123000               0.123000                      
          -0.123000 -0.123000             -0.123000             -0.123000              0.123000                      

  5 record(s) selected.

你可能感兴趣的:(varchar)