oracle sql中的数字检查

时间:2018-08-01 11:07:57

标签: sql oracle oracle-sqldeveloper

如何检查10位数字在第4-6个字节中是否包含999或000?

我对使用INSTR有一个想法,但我不知道如何执行

3 个答案:

答案 0 :(得分:1)

这很奇怪。如果“数字”确实是字符串,则可以使用likesubstr()

where col like '___999%' or col like '___000%'

或:

where substr(col, 4, 3) in ('999', '000')

甚至是正则表达式。

鉴于问题的性质,您可以将数字转换为字符串并使用这些方法。但是,如果要查看特定的数字,则“数字”应存储为字符串。

答案 1 :(得分:0)

如果它们实际上是数字而不是字符串,则可以使用数字操作:

<key>UIBackgroundModes</key>
  <array>
    <string>location</string>
    <string>fetch</string>
    <string>remote-notification</string>
  </array>

第1阶段有效地去除了前三位数字。第二阶段几乎去除了最后四个数字,但保留了分数,因此第三阶段添加了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 (您也可以使用trunc())来忽略那些小数部分。

结果是第4-6位数字,然后可以测试该数字是否为0、999或其他。

这实际上是第4至6位最高有效数字,如果数字始终为10位,则相同。如果它实际上可能具有不同的数字位数,则需要澄清您想看的内容。

答案 2 :(得分:0)

选择  1中的instr(98800054542,000,4,3)在(6)中的instr(98800054542,999,4,3)中的对偶中的1;让我知道是否有帮助。