SQLzoo刷题-%、_、concat、replace
2020-08-01 18:11
20 查看
1、通配符%
%可以代表0个、1个、多个字符
- 以a开头-----“a%”
- 以a结尾-----“%a”
- 含有a----"%a%"
/*筛选出name中含有aeiou所有元素的,但不含空格的*/ SELECT name FROM world WHERE name like '%a%' and name like'%e%' and name like '%i%' and name like '%o%' and name like '%u%' and name not like '% %'`
2、通配符_
_仅代表一个字符
- 找出名字是4个字母的:where name like “____”
3、concat函数
- concat是用来连接两个字符串的函数
/*①筛选所有国家名字,其首都是国家名字加上”City”*/ select name from world where capital = concat(name,' City') /*②筛选出首都、国家,其首都包含国家名*/ select capital,name from world where capital like concat('%',name,'%')
注意:concat将两个字符连接起来是没有空格的,如concat(“hello”,“cat”) 得到的结果是hellocat,若想得到hello cat,则需自己添加空格,concat(“hello”," cat")
4、replace函数
- replace( ‘st1’ , ‘str2’ , ‘str3’ )
st1: 被搜索的字符串。
str2: 在st1中要被 str3 替换的字符串。
str3: 该字符串用于替换 str2。如果str3是空字符串,那么直接在st1中删除str2。
如,replace(‘hellocat’,‘hello’,‘goodbye’)表示用goodbye替换hellocat中的hello
/*筛选国家名字,及其扩展词,首都是国家名字的延伸。*/ select name, replace (capital, name, '') as extend /*由于’‘为空字符串,因此在capital中删除name*/ from world where capital like concat ( name, '%_' ) ;/*扩展词至少包含一个字符,故使用 '%_' */
相关文章推荐
- javascript字符串string常用的几种方法(indexOf/lastIndexOf/search/charAt/match/slice/substr/replace/concat/split
- Oracle 常用函数:nvl/nullif/case when/wm_concat/replace
- Excel数据分析常用函数③——字符串查找/替换/拼接/截取函数(replace/find/left/right/mid/concat)
- 参数返回Oracle 常用函数:nvl/nullif/case when/wm_concat/replace
- Oracle常用函数:nvl/nullif/case when/wm_concat/replace
- MySQL数据库字符串(单行)函数#concat、length、tirm、replace、strcmp、substr等函数总结
- replace、||、concat
- Oracle中CONCAT,SUBSTR,REPLACE的实例介绍
- concat_instr_replace
- Oracle字符串操作函数(CONCAT,REPLACE,SUBSTR ....)
- WM_CONCAT和replace使用
- javascript-string类型的方法(match,replace,split,concat+join)
- Mysql使用replace代替CONCAT 速度提高十几倍
- 【mysql】mysql中常用的字符串函数,如:replace、cast、concat等函数
- js数组翻转、数组排序、查找reverse、sort、substring、indexOf、concat、splice、 replace
- [SQL语句复习] - 02 使用select like (concat, replace 关键字)
- mysql中的replace,concat,cast等等字符串函数
- Oracle replace 函数用法
- Jquery字符替换replace
- js replace 与replaceall实例用法详解