游标执行后的数字格式不正确(.0115,而不是0.115)

jpfvwuh4  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(316)

我试图执行此代码,但输出中的数字类型不正确。我尝试更改源表的(精度、小数位数)更改nls\U数字\U字符,但没有结果。

SET SERVEROUTPUT ON;
DECLARE
--Declare variables
  v_pr number ;
  v_fin number ;
--Declare cursor 
CURSOR cur_price IS
  SELECT price FROM prices;
BEGIN
OPEN cur_price; 
LOOP      --Simple Loop Start
  FETCH cur_price INTO v_pr; 
  v_fin := v_pr * 1.15; --Calculation
  DBMS_OUTPUT.PUT_LINE (to_char(v_pr) ||' --> '|| to_char(v_fin));  --Show the result
  EXIT WHEN cur_price%NOTFOUND; 
END LOOP; --Simple Loop End
CLOSE cur_price;
END;
-----------------
.01 --> .0115
.02 --> .023
.03 --> .0345
.03 --> .0345

表参数:

select * from prices
----------------
0.01
0.02
0.03

desc prices
Name  Null? Type        
----- ----- ----------- 
PRICE       NUMBER(6,3)

nls参数:

select value
from nls_session_parameters
where parameter = 'NLS_NUMERIC_CHARACTERS';

VALUE
-------------------------------
.,
gpnt7bae

gpnt7bae1#

oracle数据库以可变长度格式存储数字数据。每个值以科学记数法存储,1个字节用于存储指数。数据库最多使用20个字节来存储尾数,尾数是包含有效数字的浮点数的一部分。oracle数据库不存储前导零和尾随零。

SQL> create table prices ( price number(6,3) );

Table created.

SQL> insert into prices values ( 0.293 );

1 row created.

SQL> commit;

Commit complete.

SQL> select * from prices;

     PRICE
----------
      .293

SQL> alter session set nls_numeric_characters=',.' ;

Session altered.

SQL> select * from prices;

     PRICE
----------
      ,293

SQL> SET SERVEROUTPUT ON;
DECLARE
--Declare variables
  v_pr number ;
  v_fin number ;
--Declare cursor
CURSOR cur_price IS
  SELECT price FROM prices;
BEGIN
OPEN cur_price;
LOOP      --Simple Loop Start
  FETCH cur_price INTO v_pr;
  v_fin := v_pr * 1.15; --Calculation
  DBMS_OUTPUT.PUT_LINE (to_char(v_pr) ||' --> '|| to_char(v_fin));  --Show the result
  EXIT WHEN cur_price%NOTFOUND;
END LOOP; --Simple Loop End
CLOSE cur_price;
END;
/

,293 --> ,33695
,293 --> ,33695

相关问题