【问题标题】:Oracle numeric string column and indexingOracle 数字字符串列和索引
【发布时间】:2015-12-08 04:42:32
【问题描述】:

我在 oracle 中有一个数字字符串列,有或没有前导零样本:

00000000056
5755
0123938784579343
00000000333  
984454  

问题是使用l​​ike的部分搜索操作非常慢

select account_number from accounts where account_number like %57%

一种解决方案是将搜索限制为仅精确匹配,并添加一个额外的整数列来表示精确匹配的数值。
在这一点上,我不确定我们是否可以添加一个额外的列,
大家还有什么想法吗?

是否可以告诉 Oracle 将数字字符串列索引为整数值,以便我们可以对其进行精确的数字匹配?

例如查询值:00000000333
将是:

select account_number from accounts where account_number = '333'

忽略前导零。
我可以使用regex_like 并忽略它们,但我担心它会很慢。

【问题讨论】:

    标签: sql oracle performance indexing oracle11g


    【解决方案1】:

    Oracle 支持基于函数的索引。所以如果你索引to_number的结果:

    CREATE INDEX acocunt_number_idx 
    ON accounts(TO_NUMBER(account_number))
    

    这样,如果您使用带有to_number 的查询来获取确切的数值,则将使用索引:

    SELECT account_number 
    FROM   accounts
    WHERE  TO_NUMBER(account_number) = 333
    

    【讨论】:

      【解决方案2】:

      您可以使用to_number

      select account_number from accounts 
      where to_number(account_number) = 333
      

      【讨论】:

        猜你喜欢
        • 2018-08-23
        • 1970-01-01
        • 1970-01-01
        • 2015-11-11
        • 2021-11-10
        • 2017-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多