当前位置:网站首页>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
边栏推荐
- 440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
- ES6 face test questions (reference documents)
- 极致体验,揭晓抖音背后的音视频技术
- 41. 缺失的第一个正数
- Tell the truth of TS
- Ring back to origin problem - byte jumping high frequency problem
- 高德地图搜索、拖拽 查询地址
- C1 notes [task training chapter I]
- 102. 二叉树的层序遍历
- cv_ Solution of mismatch between bridge and opencv
猜你喜欢

SystemVerilog(六)-变量

JS parsing and execution process

【Appium】通过设计关键字驱动文件来编写脚本

Uniapp custom search box adaptation applet alignment capsule

440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题

C1小笔记【任务训练篇一】

Chrome浏览器的跨域设置----包含新老版本两种设置

102. Sequence traversal of binary tree

2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展

JS forms the items with the same name in the array object into the same array according to the name
随机推荐
Commonly used functions -- spineros:: and spineros::)
92. 反转链表 II-字节跳动高频题
209. Minimum length subarray - sliding window
386. 字典序排数(中等)-迭代-全排列
undefined reference to `Nabo::NearestNeighbourSearch
Chrome浏览器的跨域设置----包含新老版本两种设置
Listen for click events other than an element
48. 旋转图像
122. 买卖股票的最佳时机 II-一次遍历
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Remember using Ali Font Icon Library for the first time
Halo 开源项目学习(二):实体类与数据表
极致体验,揭晓抖音背后的音视频技术
SystemVerilog(六)-变量
Encapsulate a timestamp to date method on string prototype
C1 notes [task training part 2]
470. Rand10() is implemented with rand7()
On the method of outputting the complete name of typeID from GCC
JS implementation private attribute
Operation of 2022 mobile crane driver national question bank simulation examination platform