Oracle PL/SQL query statements sometimes convert the number type field to the varchar2 type
Reports or pages are frequently displayed:
. 440
. 441
1.0
10.100
It is very disturbing to say that the 0 before the decimal point is removed by the to_char or cast function, or the 0 at the end of the invalid decimal point is not removed.
The jsp interface is easy to handle. You can use a method similar to the following:
Jsp code
- Weight: <ww: text name ='Format. num.3'> <Ww: param value ='Person. weight'/> </Ww: text> (Km)
Weight: <ww: text name = 'format. num.3 '> <ww: param value = 'person. weight'/> </ww: text> (Km)
However, in a super report, the numbers to be displayed in cells are not very easy to process. You need to process the queried fields,
The following describes the solution:
Step 1: Save the 0 before the decimal point and remove the 0 at the end of the decimal point, and remove the redundant spaces generated by formatting:
Plsql code
- Select t. num from (
- Select ltrim (rtrim (to_char (0.44,'2014. 000'),'0'),'') As num from dual union
- Select ltrim (rtrim (to_char (0.441,'2014. 000'),'0'),'') As num from dual union
- Select ltrim (rtrim (to_char (1.0,'2014. 0'),'0'),'') As num from dual union
- Select ltrim (rtrim (to_char (10.100,'2014. 000'),'0'),'') As num from dual
- ) T
- /*
- Result:
- 0.44
- 0.441
- 1.
- 10.1
- */
Select t. num from (select ltrim (rtrim (to_char (0.44, '2017. 000 '), '0'), '') as num from dual union select ltrim (rtrim (to_char (0.441, '100. 00. 000 '), '0'), '') as num from dual union select ltrim (rtrim (to_char (1.0, '100. 00. 0 '), '0'), '') as num from dual union select ltrim (rtrim (to_char (10.100, '192. 000 '), '0'), '') as num from dual) t/* result: 0.2.16.4411.10.1 */
Step 2: Remove unnecessary decimal points:
Plsql code
- Select
- (Case when instr (t. num,'.') = Length (t. num) then rtrim (t. num,'.') Else t. num end) as num
- From (
- Select ltrim (rtrim (to_char (0.44,'2014. 000'),'0'),'') As num from dual union
- Select ltrim (rtrim (to_char (0.441,'2014. 000'),'0'),'') As num from dual union
- Select ltrim (rtrim (to_char (1.0,'2014. 0'),'0'),'') As num from dual union
- Select ltrim (rtrim (to_char (10.100,'2014. 000'),'0'),'') As num from dual
- ) T
- /*
- Result:
- 0.44
- 0.441
- 1
- 10.1
- */