标签:name union 通配符 2haha dual SQL select like
通常我们只是用 % 作为通配符,用来表示任意个字符。
但sql中的通配符还有 下划线 _ ,用来标识任意一个字符
实例
SELECT * FROM WebsitesWHERE name LIKE '_oogle';
执行输出结果:
问题再延伸,如果我们数据中有包含下划线的字符,那么该怎么处理呢?--需求,找到name中包含下划线的内容,即 把前两条筛出来 with x as (select '_haha' as name from dual union all select '\_2haha' as name from dual union all select '2haha' as name from dual ) select * from x where name like '%_%';
不对,这里的下划线别理解成了通配符
-- 那么使用右斜杠+下划线的模式来转译他,可以么? with x as (select '_haha' as name from dual union all select '\_2haha' as name from dual union all select '2haha' as name from dual ) select * from x where name like '%\_%';
依然不对,这里斜杠并没有起到转译的作用。
查了下,自己以前不认识这个关键字。ESCAPE
-- 使用ESCAPE 关键字来表示【这个字符后边的东西,该被识别成普通字符。】? with x as (select '_haha' as name from dual union all select '\_2haha' as name from dual union all select '2haha' as name from dual ) select * from x where name like '%\_%' ESCAPE '\';
结果对了。那么换个别的字符呢?
with x as (select '_haha' as name from dual union all select '\_2haha' as name from dual union all select '2haha' as name from dual ) select * from x where name like '%?_%' ESCAPE '?'; --- with x as (select '_haha' as name from dual union all select '\_2haha' as name from dual union all select '2haha' as name from dual ) select * from x where name like '%!_%' ESCAPE '!';
结果都是
妥了。
标签:name,union,通配符,2haha,dual,SQL,select,like 来源: https://www.cnblogs.com/adamgq/p/14318035.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。