Chinaunix

标题: mysql concat 比程序的字符串连接好在哪里? [打印本页]

作者: tgnian    时间: 2011-05-11 19:51
标题: mysql concat 比程序的字符串连接好在哪里?
http://blog.csdn.net/tt6668282/archive/2011/04/09/6312688.aspx 中有

select id,title,name from achech_com.news where binary ucase(title) like concat(‘%’,ucase(‘a’),‘%’)

检索的步骤是先将属性指定为 BINARY ,以精确检索结果,而被 like 的 titleNeiRong存在大小写字母的可能,故先使用 ucase 函数将字段内容全部转换成大写字母,然后再进行 like 操作,而 like 的操作使用模糊方法,使用 concat的好处是传进来的可以是直接De关键字,不需要带“%”万用符,将“‘a’”直接换成你的变量,在任何语言下都万事无忧了。 当然你也可以这么写:

select id,title,name from achech_com.news where binary ucase(title) like ucase(‘%a%’)

检索的结果还算满意吧,不过速度可能会因此而慢N毫秒喔。
-----------------------------------------------
本人不理解上面那一段话说的使用contact的好处,没看出比使用程序的字符串连接好在哪里?
还有为什么说第二个语句要慢些?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2