ORACLE中Like与Instr性能大比拼
t表中将近有1100万数据,很多时候,我们要进行字符串匹配,在SQL语句中,我们通常使用like来达到我们搜索的目标。但经过实际测试发现,like的效率与instr函数差别相当大。下面是一些测试结果:
SQL> set timing on
SQL> select count(*) from t where instr(title,’手册’)>0;
COUNT(*)
———-
65881
Elapsed: 00:00:11.04
SQL> select count(*) from t where title like ‘%手册%’;
COUNT(*)
———-
65881
Elapsed: 00:00:31.47
SQL> select count(*) from t where instr(title,’手册’)=0;
COUNT(*)
———-
11554580
Elapsed: 00:00:11.31
SQL> select count(*) from t where title not like ‘%手册%’;
COUNT(*)
———-
11554580
另外,我在另外一个2亿多的表,使用8个并行,使用like查询很久都不出来结果,但使用instr,4分钟即完成查找,性能是相当的好。这些小技巧用好,工作效率提高不少。通过上面的测试说明,ORACLE内建的一些函数,是经过相当程度的优化的。
相关文档:
字符类型:
CHAR(size):固定长度字符串,最大长度2000 bytes
VARCHAR2(size):可变长度的字符串,最大长度4000 bytes,可做索引的最大长度749
NCHAR(size):根据字符集而定的固定长度字符串,最大长度2000 bytes
NVARCHAR2(size):根据字符集而定的可变长度字符串,最大长度4000 byte
LONG:变长的字符串,最大长度限 ......
1、su – oracle 不是必需,适合于没有DBA密码时使用,可以不用密码来进入sqlplus界面。
2、sqlplus /nolog 或sqlplus system/manager 或./sqlplus system/manager@ora9i;
3、SQL>connect / as sysdba ;(as sysoper)或
connect internal/oracle AS SYSDBA ;(scott/tiger)
conn sys/change_on_install as sysd ......
为防忘记,记录于下:
oracle 11gR2 : http://www.oracle.com/pls/db112/homepage,下载网址http://www.oracle.com/technology/documentation/database.html
oracle 11gR1 : http://www.oracle.com/pls/db111/homepage
oracle 10gR2 : http://www.oracle.com/pls/db102/homepage ......
用命令行(CMD)中启动和关闭ORACLE服务
监听启动
lsnrctl start
监听停止
lsnrctl stop
启动Oracle
net start oracleservicesid
停止Oracle
net stop oracleservicesid
net命令是win系统命令!其它的服务启动和上面的类似!
......
select custid,carid,Cunote,INVNO,BUYPLAN
from ( select custid,carid,Cunote,INVNO,BUYPLAN,
row_number() over(partition by custid,carid order by Feedbackid desc) rn
from pvE3S.T_VCTM_CUSTOMER_FEEDBACK) t1 where rn=1
按Feedbackid 排序,rn是前N行 ......