【问题标题】:Why does this query in SQL Developer cause this error?为什么 SQL Developer 中的这个查询会导致这个错误?
【发布时间】:2019-03-19 14:51:18
【问题描述】:

当我尝试在 SQL Developer 中运行此查询时,为什么会出现错误:

DECLARE
    p_latitude number;
BEGIN
    p_latitude:=TO_NUMBER(LTRIM(RTRIM(REGEXP_SUBSTR('BT1 1AA|54.60240|-5.92214|875082434', '[^|]+', 1, 2),'"'),'"'));
END;

错误:

ORA-06502:PL/SQL:数字或值错误:字符到数字的转换错误
ORA-06512: 在第 4 行

谁能帮我解决这个错误?

预期输出:

54.60240

【问题讨论】:

  • decimal separator oracle的可能重复
  • 你能发布select value from nls_session_parameters where parameter = 'NLS_NUMERIC_CHARACTERS';的输出吗?
  • 输出是,.
  • 由于您应该读取由 "." 分隔的小数,因此没有理由将其设置为 ,. ,很可能是错误的?阅读this的回答,了解错误详情及修改方法

标签: oracle plsql


【解决方案1】:

我认为你可以通过这样的转换来管理它:

DECLARE
 p_latitude number;
BEGIN
 with t(nr) as
 (
  select LTRIM(RTRIM(REGEXP_SUBSTR('BT1 1AA|54.60240|-5.92214|875082434', '[^|]+', 1, 2),'"'),'"') 
     from dual
 )
 select to_number(replace(nr,'.',','),'fm99G990D00000','NLS_NUMERIC_CHARACTERS = '',.''')
   into p_latitude
   from t;
END;

【讨论】:

  • 嗨,Barbaros,我希望输出为 54.60240
  • @SindhuChoudary 你已经有了点分格式,没有to_number 转换。我的意思是,只要确定了小数部分,格式对于数值变量并不重要。
猜你喜欢
  • 2015-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多