简体   繁体   English

Oracle - REGEXP_SUBSTR前导零被忽略的问题

[英]Oracle - REGEXP_SUBSTR leading zeroes ignored issue

执行低于查询时我得到“235”而不是预期结果“0”

select  REGEXP_SUBSTR(000.235||'', '[^.]+', 1, 1)  from dual;

Do this instead, and you'll see where the problem comes: 这样做,你会看到问题的来源:

select  000.235||'' from dual

Result: 结果:

.235

The regexp picks up the first longest occurrence of non-period, which in this string is "235", so it's working correctly; regexp获取非周期的第一个最长的出现,在此字符串中为“235”,因此它正常工作; it's the input value that is broken 这是输入值被打破

Now, if you'd written it like this, it would be fine: 现在,如果你这样写,那就没关系了:

select  REGEXP_SUBSTR('000.235', '[^.]+', 1, 1)  from dual

So why the odd presentation of the numeric? 那么为什么奇怪的数字表示呢? What does your data in your table look like? 你桌子上的数据是什么样的? This is unlikely to be the actual query you're running - if you need help with the true query, post it up 这不太可能是您正在运行的实际查询 - 如果您需要有关真实查询的帮助,请将其发布

Oracle trim numeric values, you can fix it by adding ltrim to number: Oracle修剪数值,您可以通过将ltrim添加到数字来修复它:

select REGEXP_SUBSTR(ltrim(' 000.235')||'', '[^.]+', 1, 1) from dual;

result: 000 as expected 结果:如预期的000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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