简体   繁体   中英

How to remove trailing zeros after decimal points from number column in sqlplus?

I have a one database table field called Amount which type is number(38,8), and in sqlplus I have formatted the column like "COLUMN Amount FORMAT 999999999999999999999999.99999",but while writing into csv we are getting always trialing zeros. eg if number is 9.23 then result is will be 9.2300

eg if number is 9 then result is will be 9.0000

How to remove trailing zeros.

Please help me..

You can do it with to_char and the format-code TM (see documentation )

SELECT to_char(column, 'TM') FROM table;

examples:

SELECT to_char(9.2300, 'TM') FROM dual; -- returns 9.23
SELECT to_char(9.0000, 'TM') FROM dual; -- returns 9
SELECT to_char(100, 'TM') FROM dual;    -- returns 100
SELECT to_char(010, 'TM') FROM dual;    -- returns 10

edit:

With

SELECT round(to_char(column, 'TM'), 5) FROM table;

you can limit your result to 5 decimal places.

SELECT to_char(round(123.654321000, 5), 'TM') FROM dual; -- returns 123.65432

TO_NUMBER function also removes the zeroes after decimal point.

eg : 1.4500 to 1.45, 1.9000 to 1.9 etc.

Sample Query :

SELECT TO_NUMBER(column_name) FROM table_name;

尝试这个。

select rtrim(rtrim(to_char(column_name), 0 ), '.' ) from table_name;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM