- 论坛徽章:
- 0
|
SQL语句请教!
又什么区别,我做了一个试验:
如下:
- create table testsubstr(OID number not null PRIMARY KEY,
- ngame varchar2(20));
- create index ngameindex on testsubstr(ngame);
- declare
- i number;
- begin
- i:=0;
- while(i<200000) loop
- if((i mod 10) = 4)
- then
- insert into testsubstr(OID,ngame) values(i,'DDwee');
- else
- insert into testsubstr(OID,ngame) values(i,'weeDD');
- end if;
- i:=i+1;
- end loop;
- end;
复制代码
上面是建表,加索引,加数据
下面我用oci进行了测试,下面的又部分代码是用对oci进行亲度封装的类,不影响效率:
- int TimeStart, TimeEnd, TimeDelta;
- TimeStart = timeGetTime();
- string query;
- query = "select OID from testsubstr where substr(ngame,0,2) = 'DD' ";
- statement &st = *conn.prepare(query.data());
- resultset &rs = *st.select ();
- rs.release();
- st.release();
- TimeEnd = timeGetTime();
- TimeDelta = TimeEnd - TimeStart;
- printf("substr= %d\n", TimeDelta );
- TimeStart = timeGetTime();
- query = "select OID from testsubstr where ngame like 'DD%'";
- statement &st2 = *conn.prepare(query.data());
- resultset &rs2 = *st2.select ();
- rs2.release();
- st2.release();
- TimeEnd = timeGetTime();
- TimeDelta = TimeEnd - TimeStart;
- printf("like= %d\n", TimeDelta );
复制代码
得到的结果是
substr = 1773
like = 47979
可能like的语句用到了索引,但是like操作太费时间,优化器也没有办法,可见还是substr好 |
|