当前位置:网站首页>MySQL 中的字符串函数
MySQL 中的字符串函数
2022-04-23 17:54:00 【剑小麟】
1.关于字符串的长度
代码示例:
select ascii('abc') ,char_length('数据库'),length ('数据库')
from dual;
ascii(s):取字符串首位所对应的ascii码
char_length(s):字符串长度
length(s):字符串字节数
运行结果:

2. 字符串的连接
代码示例:
select concat(e.lie1,'worked for',m.lie1)
from table e join table m
where e.lie3 =m.lie1 ;
concat :列和字符串的连接,中间可以连接指定的字符串,如上述示例中的worked for。
3.字符串的插入和替换
代码示例:
select insert ('hello',2,3,'ddd'),replace ('hello','ll','oo')
from dual;
insert(a,b,c,d) 在字符串a的b处出发,将b处到b+c处换成d。
replace(a,b,c) 将字符串中的b全部换成c。
select left ('mysql',3)
from dual ;
left(a,b) 取字符串a从左数前b个数字,right同理。
运行结果:


4.清理和加倍
代码示例:
select trim(' my sql ') ,trim('my' from 'mysql')
from dual;
select repeat ('mysql',2)
from dual ;
trim(a) 清除字符串a两端的空格。
trim(a from b) 清除b字符串中所包含的a字符串。
repeat(a,b) 将字符串a增至b倍。
运行结果:


5.字符串的位置寻找
代码示例:
select elt(3,'a','b','c') ,field('my','sq','mysql','my'),find_in_set('my','m,my,mysql')
from dual ;
select reverse('abc')
from dual ;
elt(n,a,b,c...) 从a开始寻找第n个字符,输出该字符。
field(n,a,b,c...) 从a开始寻找n,输出其所在位置的数字。
reverse(s) 反向输出。
运行结果:


版权声明
本文为[剑小麟]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_54185237/article/details/124330534
边栏推荐
- 2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
- Error in created hook: "referenceerror:" promise "undefined“
- 92. 反转链表 II-字节跳动高频题
- JS get link? The following parameter name or value, according to the URL? Judge the parameters after
- 31. Next arrangement
- Arithmetic expression
- MySQL advanced index [classification, performance analysis, use, design principles]
- 一些问题一些问题一些问题一些问题
- The ultimate experience, the audio and video technology behind the tiktok
- 41. 缺失的第一个正数
猜你喜欢

cv_ Solution of mismatch between bridge and opencv

Double pointer advanced -- leetcode title -- container with the most water
![MySQL advanced index [classification, performance analysis, use, design principles]](/img/96/b031868602a7b8ba4edd0d74c843b3.png)
MySQL advanced index [classification, performance analysis, use, design principles]

土地覆盖/利用数据产品下载

2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition

JS high frequency interview questions

394. String decoding - auxiliary stack

关于gcc输出typeid完整名的方法

Dry goods | how to extract thumbnails quickly?

2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
随机推荐
C1小笔记【任务训练篇一】
.105Location
土地覆盖/利用数据产品下载
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
JS forms the items with the same name in the array object into the same array according to the name
ES6 new method
102. 二叉树的层序遍历
Go's gin framework learning
Go file operation
Gaode map search, drag and drop query address
极致体验,揭晓抖音背后的音视频技术
587. Install fence / Sword finger offer II 014 Anagrams in strings
.104History
1217_ Generating target files using scons
Add animation to the picture under V-for timing
JS parsing and execution process
Kubernetes 服务发现 监控Endpoints
SystemVerilog(六)-变量
Cloud native Virtualization: building edge computing instances based on kubevirt
Go language JSON package usage