当前位置:网站首页>How SQL intercepts specified characters from strings (three functions of LEFT, MID, RIGHT)
How SQL intercepts specified characters from strings (three functions of LEFT, MID, RIGHT)
2022-07-31 10:18:00 【xiaoweiwei99】
Table of Contents
1.LEFT function
(1) Grammar: left(text,len) is left(string text, length)
Query Statementselect [column(s),] left(text,len)[from table]Parameter description:
text: string, which can be directly quoted as a string or a field;
len: The length of the string to be intercepted, which is a positive integer. If it is 0 or a negative number, it returns a null value.
Description: The query enclosed in "[]" indicates optional.If you need to enter the from statement to specify the target table when querying with other fields, you also need to enter the from statement to specify the target table when text is a field. If you only use left to obtain a specified string to intercept, you can directly omit the from statement, but this usageGenerally only for debugging and not often used in practice.
(2)Usage: Intercept the characters of the specified length on the left.
(3) Example
Example 1: Intercept "hello" from "hello world".
select left('hello world',5)There is a student table student, student ID, name, gender, native_place, nationality, date of birth born, age.as shown in the table below.
student
ID
name
sex
native_place
nation
born
age
1001
Zhang San
Male
Guangdong Province
Chinese
2000/3/16
22
1002
Chen Yi
Female
Guangdong
strong
1998/3/15
24
1003
Wang Wu
Male
Tibet
Hidden
2002/1/6
20
1004
Chen Hong
Female
Guangdong Province
Li
2001/1/17
21
1005
Li Si
Male
Northeast Province
Chinese
1999/3/16
23
1006
-
Female
Guangdong Province
Li
5/6/1998
24
1008
Chen Xiaoxiao
Female
Guangdong
strong
1997/5/9
25
Example 2: Remove the apostrophe from the place of origin, and intercept the first two characters.Obtain student ID, name, gender and age at the same time.
select ID,name,sex,left(native_place,2),agefrom student2.MID function
(1) Grammar and usage: there are two forms
#①Two parametersmid(text,start) #Get characters from an ordinal of the specified string#②Three parametersmid(text,start,len) #Get characters of the specified length from a certain position in the specified stringParameter description:
text: string, which can be directly quoted as a string or a field;
start: The string position to start intercepting, which can be a positive or negative integer.
len: The length of the string to be intercepted, which is a positive integer. If it is 0 or a negative number, it returns a null value.
Note: The MID function is synonymous with SUBSTRING(), and the usage is the same.
(2) Instance
Example: Intercept the string "world" from "hello world".
When start is a positive number, the position of the start character "w" is 7. Note that the empty character between "hello" and "world" is counted as one character.
#start is a positive number#two two parametersselect mid('hello world',7) ?orselect mid('hello world'from 7)#Three parametersselect mid('hello world',7,5)orselect mid('hello world'from 7 for 5)3.RIGHT function
(1) Syntax: right(text,len) is right(string text, length)
Query Statementselect [column(s),] right(text,len)[from table]Parameter description:
text: string, which can be directly quoted as a string or a field;
len: The length of the string to be intercepted, which is a positive integer. If it is 0 or a negative number, it returns a null value.
Description: The query enclosed in "[]" indicates optional.If you need to enter the from statement to specify the target table when querying with other fields, you also need to enter the from statement to specify the target table when text is a field. If you only use left to obtain a specified string to intercept, you can directly omit the from statement, but this usageGenerally only for debugging and not often used in practice.
(2)Usage: Intercept the characters of the specified length on the right.
(3) Example
Example 1: Intercept "world" from "hello world".
select right('hello world',5)The usage of SQL's LEFT, MID and RIGHT functions is very similar to EXCEL's LEFT, MID and RIGHT functions. Please refer to:
边栏推荐
猜你喜欢

csdn file export to pdf

出色的移动端用户验证

Burndown chart of project management tools: Dynamic assessment of team work ability

NowCoderTOP28-34二叉树——持续更新ing

Build finished with errors/Executable Not Found

Come n times with the sword--05. Replace spaces

【LeetCode】21. 合并两个有序链表

NowCoderTOP17-22 二分查找/排序——持续更新ing

Meikle Studio--Hongmeng 14-day development training notes (8)

透过开发抽奖小程序,体会创新与迭代
随机推荐
KVM虚拟化作业
Gradle series - Groovy overview, basic use (based on Groovy document 4.0.4) day2-1
顺序表的删除
乐观锁和悲观锁
unity-shader-2
csdn file export to pdf
尚医通【预约挂号系统】总结
细讲DDD领域驱动设计
浅谈Attention与Self-Attention,一起感受注意力之美
Come n times with the sword--05. Replace spaces
小程序如何使用订阅消息(PHP代码+小程序js代码)
【LeetCode】36.有效的数独
双链表的插入和删除
Redis Sentinel原理
Redis缓冲穿透和缓冲击穿工具类的封装
GCD简单了解
开放麒麟 openKylin 自动化开发者平台正式发布
LeetCode二叉树系列——101.对称二叉树
Dart Log tool class
我们能做出来数据库吗?