ITPub博客

首页 > 数据库 > Oracle > 对列进行连接操作会影响索引的使用

对列进行连接操作会影响索引的使用

原创 Oracle 作者:luisedalian 时间:2014-01-13 11:38:58 0 删除 编辑

解决办法:不对列进行连接操作,而是对要比较的字面量应用函数,从而满足列的特定要求。

点击(此处)折叠或打开

  1. --创建表
  2. hr@TESTDB11>create table employees1 as select * from employees;

  3. Table created.

  4. --在first_name和last_name列上分别创建索引
  5. hr@TESTDB11>create index idx_employees1_fn on employees1(first_name);

  6. Index created.

  7. hr@TESTDB11>create index idx_employees1_ln on employees1(last_name);

  8. Index created.

  9. --对列进行字符串的连接,没有走索引
  10. hr@TESTDB11>select e.first_name, e.last_name from employees1 e where first_name || \' \' || last_name = \'Douglas Grant\';

点击(此处)折叠或打开

  1. --调整之后走索引的可取的做法
  2. hr@TESTDB11>select e.first_name, e.last_name from employees1 e where first_name = \'Douglas\' and last_name = \'Grant\';


点击(此处)折叠或打开

  1. --姓名一起存储在一个变量中的解决办法
  2. hr@TESTDB11>select first_name, last_name from employees1
  3.   2 where first_name = substr(\'&&name\', 1, instr(\'&name\', \' \') - 1)
  4.   3 AND last_name = SUBSTR(\'&name\', INSTR(\'&name\', \' \') + 1);
  5.   
  6. old 2: where first_name = substr(\'&&name\', 1, instr(\'&name\', \' \') - 1)
  7. new 2: where first_name = substr(\'Douglas Grant\', 1, instr(\'Douglas Grant\', \' \') - 1)
  8. old 3: AND last_name = SUBSTR(\'&name\', INSTR(\'&name\', \' \') + 1)
  9. new 3: AND last_name = SUBSTR(\'Douglas Grant\', INSTR(\'Douglas Grant\', \' \') + 1)



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/17013648/viewspace-1069944/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: IS NULL和IS NOT NULL
请登录后发表评论 登录
全部评论

注册时间:2012-02-06

  • 博文量
    1986
  • 访问量
    6040856