首页 > 其他分享 >2.2、字符串截取函数

2.2、字符串截取函数

时间:2023-07-13 17:12:47浏览次数:42  
标签:set 截取 sec mysql 字符串 2.2 0.00 select row

substring()

 

mysql> select substring('abc',1,1);
+----------------------+
| substring('abc',1,1) |
+----------------------+
| a |
+----------------------+
1 row in set (0.00 sec)

 

 

mid()

 

mysql> select mid((select database()),1,1);
+------------------------------+
| mid((select database()),1,1) |
+------------------------------+
| s |
+------------------------------+
1 row in set (0.00 sec)

 

 

right()

 

mysql> select right((select database()),2);
+------------------------------+
| right((select database()),2) |
+------------------------------+
| ty |
+------------------------------+
1 row in set (0.00 sec)

mysql> select right('abcd',2);
+-----------------+
| right('abcd',2) |
+-----------------+
| cd |
+-----------------+

 

 

left()

 

mysql> select left('abcd',2);
+----------------+
| left('abcd',2) |
+----------------+
| ab |
+----------------+
1 row in set (0.00 sec)

 


regexp

 

#   ^ 从最第一个字符开始匹配,右边的匹配字符 可以是 hex


mysql> select database();
+------------+
| database() |
+------------+
| security |
+------------+
1 row in set (0.00 sec)

mysql> select (select database()) regexp '^s';
+---------------------------------+
| (select database()) regexp '^s' |
+---------------------------------+
| 1 |
+---------------------------------+
1 row in set (0.00 sec)


区分大小写 binary
mysql> select (select database()) regexp binary '^S';
+----------------------------------------+
| (select database()) regexp binary '^S' |
+----------------------------------------+
| 0 |
+----------------------------------------+
1 row in set (0.00 sec)

 

 


rlike

mysql> select 'abcd' rlike '^ab';
+--------------------+
| 'abcd' rlike '^ab' |
+--------------------+
| 1 |
+--------------------+
1 row in set (0.00 sec)

mysql> select 'abcd' rlike binary '^aB';
+---------------------------+
| 'abcd' rlike binary '^aB' |
+---------------------------+
| 0 |
+---------------------------+
1 row in set (0.00 sec)

 


ord 和 ascii

返回最左边的 hex,配合字符串截取使用
mysql> select ord('ab');
+-----------+
| ord('ab') |
+-----------+
| 97 |
+-----------+
1 row in set (0.00 sec)

mysql> select ascii('ab');
+-------------+
| ascii('ab') |
+-------------+
| 97 |
+-------------+
1 row in set (0.02 sec)


mysql> select substr('abc' from 2 for 1);
+----------------------------+
| substr('abc' from 2 for 1) |
+----------------------------+
| b |
+----------------------------+
1 row in set (0.00 sec)

mysql> select ord(substr('abc' from 1 for 1));
+---------------------------------+
| ord(substr('abc' from 1 for 1)) |
+---------------------------------+
| 97 |
+---------------------------------+
1 row in set (0.00 sec)

 


trim()

 

//前导 删除,返回字符串,支持hex

mysql> select trim(leading 'd' from 'abc')=trim(leading 'e' from 'abc');
+-----------------------------------------------------------+
| trim(leading 'd' from 'abc')=trim(leading 'e' from 'abc') |
+-----------------------------------------------------------+
| 1 |
+-----------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select trim(leading 'd' from 'abc')=trim(leading 'a' from 'abc');
+-----------------------------------------------------------+
| trim(leading 'd' from 'abc')=trim(leading 'a' from 'abc') |
+-----------------------------------------------------------+
| 0 |
+-----------------------------------------------------------+
1 row in set (0.00 sec)

 

 


insert()

 

mysql> select insert((insert('abcde',1,0,'')),2,9999,'');
+--------------------------------------------+
| insert((insert('abcde',1,0,'')),2,9999,'') |
+--------------------------------------------+
| a |
+--------------------------------------------+
1 row in set (0.00 sec)

mysql> select insert((insert('abcde',1,1,'')),2,9999,'');
+--------------------------------------------+
| insert((insert('abcde',1,1,'')),2,9999,'') |
+--------------------------------------------+
| b |
+--------------------------------------------+
1 row in set (0.00 sec)

insert 不使用 引号
database() = 'security'
?id=1' and strcmp(insert(database(),3,99,0x00),0x736500) --+

 

标签:set,截取,sec,mysql,字符串,2.2,0.00,select,row
From: https://www.cnblogs.com/baiye1/p/17551477.html

相关文章

  • ChatGPT 问答00003 mysql中删除原来的自增ID,并重新根据字符串字段data字段排序重新生
    在MySQL中,自增ID是由MySQL引擎自动生成和维护的,通常与数据表的主键关联。删除自增ID并重新生成的需求比较特殊,因为自增ID的生成是基于数据表中已有的记录顺序的,直接删除和重新生成可能会破坏数据完整性和索引等方面的约束。不建议直接删除和重新生成自增ID,但你可以通过以下步骤实......
  • 【Redis】字符串sds
    sds,即SimpleDynamicStrings,是Redis中存储绝大部分字符串所采用的数据结构。typedefchar*sds;一、类型sds的类型包括SDS_TYPE_5,SDS_TYPE_8,SDS_TYPE_16,SDS_TYPE_32,SDS_TYPE_64五种:#defineSDS_TYPE_50#defineSDS_TYPE_81#defineSDS_TYPE_162#defineSD......
  • CentOs7 静默安装Oracle12.2
    createtablespaceJWAQdatafile'/opt/oracle/oradata/orcl/JWAQ.dbf'size1024Mautoextendonnext2048Mmaxsize10gEXTENTMANAGEMENTlocalautoallocatesegmentspacemanagementauto;createuseryangxiaodongidentifiedbyyangxiaodongdefaul......
  • python 数据类型 字符串
    目录python数据类型字符串Python字符串定义Python字符串连接Python转义字符Python字符串运算符Python字符串格式化Unicode字符串python的字符串内置函数python数据类型字符串Python字符串定义#字符串是Python中最常用的数据类型。我们可以使用引号('或")来创建字......
  • H7-TOOL发布固件V2.22, 增加FreeRTOS/uCOS2 Trace,加强RTT和CAN助手,脱机烧录增加比亚迪
    H7-TOOL发布固件V2.22,增加FreeRTOS/uCOS2Trace,加强RTT和CAN助手,脱机烧录增加比亚迪,上海芯圣51,TI,S32K3,钜泉光电等 H7-TOOL所有资源汇总(含操作手册):http://www.armbbs.cn/forum.php?mod=viewthread&tid=89934 PC机软件:升级PC软件到V2.2.2h7toolPC_release(V2.2.2)......
  • c# 读取json字符串节点内容
    c#读取json字符串节点内容stringjsonstr="{\"voiceprompt_callback\":{\"result\":\"1\",\"accept_time\":\"0\"}}";varty=JsonConvert.DeserializeObject(jsonstr);Newtonsoft.Json.Linq.JOb......
  • 直接“printf”到char数组字符串——C语言snprintf函数
    注:我写这个只是为了备注并介绍一下这个神器。有关它的更详细用法,互联网的各个角落都不缺少资料。如果您和曾经的我一样是C语言的初学者,您有可能时常遇到那些“奇异”的字符串处理问题,例如,int里的数转成char数组字符串类型,在char数组中间插入或者删除什么东西,等等。要是采用传统方......
  • 字符串转list以及list调remove方法报错
    Stringstr=scanner.nextLine();String[]arr=str.split("");List<String>list=newArrayList<>(Arrays.asList(arr));注意:使用Array.aslList时转出来的list是没有add和remove方法的,所以我们调用就会报错,把它放到newArrayList里面就能解决这个......
  • Python-字符串.py
     1#!/usr/bin/python 2#coding=UTF-8 3 4str="helloworld!" 5 6printstr                      #输出整个字符串 7         8printstr[0]           #输出字符串的第一个字符 9         10......
  • Java字符串逆序的四种方法及比较
    Java中实现字符串逆序有以下几种常见的方法:方法一:使用StringBuffer或StringBuilder的reverse()方法。这是最简单和最直接的方法,只需要将String对象转换为StringBuffer或StringBuilder对象,然后调用它们的reverse()方法,就可以得到逆序的字符串。例如:publicclassStringReverse......