当前位置:网站首页>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
边栏推荐
- Utilisation de la liste - Ajouter, supprimer et modifier la requête
- JS parsing and execution process
- C1小笔记【任务训练篇一】
- 402. 移掉 K 位数字-贪心
- Cross domain settings of Chrome browser -- including new and old versions
- 402. Remove K digits - greedy
- Amount input box, used for recharge and withdrawal
- 20222 return to the workplace
- 列錶的使用-增删改查
- MySQL_01_简单数据检索
猜你喜欢
92. Reverse linked list II byte skipping high frequency question
Land cover / use data product download
Kubernetes 服务发现 监控Endpoints
Remember using Ali Font Icon Library for the first time
2021 Great Wall Cup WP
【Appium】通过设计关键字驱动文件来编写脚本
Examination question bank and online simulation examination of the third batch (main person in charge) of special operation certificate of safety officer a certificate in Guangdong Province in 2022
Applet learning notes (I)
C1 notes [task training chapter I]
JS forms the items with the same name in the array object into the same array according to the name
随机推荐
JS parsing and execution process
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
2022年茶艺师(初级)考试模拟100题及模拟考试
470. Rand10() is implemented with rand7()
Halo open source project learning (II): entity classes and data tables
Gaode map search, drag and drop query address
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
198. Looting - Dynamic Planning
Kubernetes service discovery monitoring endpoints
386. 字典序排数(中等)-迭代-全排列
Flask项目的部署详解
Listen for click events other than an element
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
Construction of functions in C language programming
cartographer_ There is no problem compiling node, but running the bug that hangs directly
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
ES6 new method
209. 长度最小的子数组-滑动窗口
102. Sequence traversal of binary tree
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag