如何检入10位数字,4-6字节是999还是000?
我有一个使用INSTR的想法,但我不知道如何执行它
发布于 2018-08-01 19:11:00
这很奇怪。如果"number“实际上是一个字符串,那么可以使用like或substr()
where col like '___999%' or col like '___000%'或者:
where substr(col, 4, 3) in ('999', '000')甚至是正则表达式。
根据问题的性质,您可以将数字转换为字符串并使用这些方法。但是,如果您查看的是特定的数字,那么"number“应该存储为字符串。
发布于 2018-08-01 19:26:42
如果它们实际上是数字而不是字符串,那么您可以使用数字操作:
with t (n) as (
select 1234567890 from dual
union all select 1239997890 from dual
union all select 1230007890 from dual
union all select 1299967890 from dual
union all select 1234000890 from dual
)
select n,
mod(n, 10000000) as stage1,
mod(n, 10000000)/10000 as stage2,
trunc(mod(n, 10000000)/10000) as stage3,
case when trunc(mod(n, 10000000)/10000) in (0, 999) then 'Yes' else 'No' end as matches
from t;
N STAGE1 STAGE2 STAGE3 MATCHES
---------- ---------- ---------- ---------- -------
1234567890 4567890 456.789 456 No
1239997890 9997890 999.789 999 Yes
1230007890 7890 .789 0 Yes
1299967890 9967890 996.789 996 No
1234000890 4000890 400.089 400 No 阶段1有效地剥离了前三个数字。阶段2几乎去掉了最后四位数字,但保留了小数,因此阶段3添加了trunc() (您也可以使用floor())来忽略这些小数部分。
结果是4-6位数字的数值,然后你可以测试它是0,999还是其他值。
这实际上是在查看第四到第六个最高有效数字,如果数字始终是10位,这是相同的;如果它实际上可能有不同的数字,那么您需要澄清您想要看到的是什么。
发布于 2018-08-01 20:28:50
从(6)中的instr(98800054542,000,4,3)或(6)中的instr(98800054542,999,4,3)中选择1;让我知道这是否有帮助。
https://stackoverflow.com/questions/51631766
复制相似问题