表结构:
create table ZHB
(
A CHAR(10),
B CHAR(10)
)
数据:
a b
111 222
333 444
建立一个函数索引:
create index ZHB01 on ZHB (SUBSTR(A,1,1));
执行查询:
select * from zhb where a = '111'
no rows selected
select * from zhb where a like '1%',可以得到正确的查询结果。
如果再增加一个索引:
create index ZHB02 on ZHB (A);
执行查询:select * from zhb where a = '111',就可以得到正确结果。
为什么会这样?单独使用函数索引,用“=”来查询就查不出记录?各位帮忙看一下,谢谢了

最新回复
lyz0622_1022 (2008-8-14 09:40:25)
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> conn testuser/testuser
已连接。
SQL> create table zhb
2 (a char(20),
3 b char(20)
4 );
表已创建。
SQL> insert into zhb values('111','222');
已创建 1 行。
SQL> insert into zhb values('333','444');
已创建 1 行。
SQL> commit;
提交完成。
SQL> create index zhb1 on zhb(substr(a,1,1));
索引已创建。
SQL> select * from zhb where a='111';
A B
-------------------- --------------------
111 222
SQL>
楼主一定是搞错了,我刚刚试验了一把,没有问题的。
nomad (2008-8-15 00:56:34)
nomad (2008-8-15 00:57:08)
bobfang (2008-9-03 15:23:55)
SQL> create table ZHB
2 (
3 A CHAR(10),
4 B CHAR(10)
5 );
表已创建。
SQL> insert into zhb values('111','222');
已创建 1 行。
SQL> insert into zhb values('333','444');
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from zhb where a='111';
A B
---------- ----------
111 222
SQL> create index ZHB01 on ZHB (SUBSTR(A,1,1));
索引已创建。
SQL> select * from zhb where a='111';
未选定行
SQL> select * from zhb where trim(a)='111';
A B
---------- ----------
111 222
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> create table ZHB1
2 (
3 A varCHAR2(10),
4 B CHAR(10)
5 );
表已创建。
SQL> insert into zhb1 values('111','222');
已创建 1 行。
SQL> insert into zhb1 values('333','444');
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from zhb1 where a='111';
A B
---------- ----------
111 222
SQL> create index ZHB101 on ZHB1 (SUBSTR(A,1,1));
索引已创建。
SQL> select * from zhb1 where a='111';
A B
---------- ----------
111 222
cgx2111 (2008-9-04 08:37:57)
x-jeep (2008-9-06 15:56:35)
tylgl (2008-9-09 23:53:57)
Table dropped
SQL> create table test (
2 a char(10),
3 b char(10)
4 );
Table created
SQL> insert into test values ('111','111');
1 row inserted
SQL> insert into test values ('222','222');
1 row inserted
SQL> commit;
Commit complete
SQL> select * from test;
A B
---------- ----------
111 111
222 222
SQL> select * from test where a = '111';
A B
---------- ----------
111 111
SQL> create index test_index on test (substr(a,1,1));
Index created
SQL> select * from test;
A B
---------- ----------
111 111
222 222
SQL> select * from test where a= '111';
A B
---------- ----------
111 111
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE 9.2.0.1.0 Production
TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production
winxp sp3
可以 每问题