mysql中用来取余数的函数是_MySQL常用函数-单行处理函数-字符串处理函数(更新中...)...

本篇文章用到的数据库表

/*
SQLyog Ultimate v12.09 (64 bit)
MySQL - 5.7.23-log : Database - myemployees
*********************************************************************
*//*!40101 SET NAMES utf8 */;/*!40101 SET SQL_MODE=''*/;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`myemployees` /*!40100 DEFAULT CHARACTER SET utf8 */;USE `myemployees`;/*Table structure for table `employees` */DROP TABLE IF EXISTS `employees`;CREATE TABLE `employees` (`employee_id` int(6) NOT NULL AUTO_INCREMENT,`first_name` varchar(20) DEFAULT NULL,`last_name` varchar(25) DEFAULT NULL,`email` varchar(25) DEFAULT NULL,`phone_number` varchar(20) DEFAULT NULL,`job_id` varchar(10) DEFAULT NULL,`salary` double(10,2) DEFAULT NULL,`commission_pct` double(4,2) DEFAULT NULL,`manager_id` int(6) DEFAULT NULL,`department_id` int(4) DEFAULT NULL,`hiredate` datetime DEFAULT NULL,PRIMARY KEY (`employee_id`),KEY `dept_id_fk` (`department_id`),KEY `job_id_fk` (`job_id`),CONSTRAINT `dept_id_fk` FOREIGN KEY (`department_id`) REFERENCES `departments` (`department_id`),CONSTRAINT `job_id_fk` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`job_id`)
) ENGINE=InnoDB AUTO_INCREMENT=209 DEFAULT CHARSET=utf8;/*Data for the table `employees` */insert  into `employees`(`employee_id`,`first_name`,`last_name`,`email`,`phone_number`,`job_id`,`salary`,`commission_pct`,`manager_id`,`department_id`,`hiredate`) values (100,'Steven','K_ing','SKING','515.123.4567','AD_PRES',24000.00,NULL,NULL,90,'1992-04-03 00:00:00'),(101,'Neena','Kochhar','NKOCHHAR','515.123.4568','AD_VP',17000.00,NULL,100,90,'1992-04-03 00:00:00'),(102,'Lex','De Haan','LDEHAAN','515.123.4569','AD_VP',17000.00,NULL,100,90,'1992-04-03 00:00:00'),(103,'Alexander','Hunold','AHUNOLD','590.423.4567','IT_PROG',9000.00,NULL,102,60,'1992-04-03 00:00:00'),(104,'Bruce','Ernst','BERNST','590.423.4568','IT_PROG',6000.00,NULL,103,60,'1992-04-03 00:00:00'),(105,'David','Austin','DAUSTIN','590.423.4569','IT_PROG',4800.00,NULL,103,60,'1998-03-03 00:00:00'),(106,'Valli','Pataballa','VPATABAL','590.423.4560','IT_PROG',4800.00,NULL,103,60,'1998-03-03 00:00:00'),(107,'Diana','Lorentz','DLORENTZ','590.423.5567','IT_PROG',4200.00,NULL,103,60,'1998-03-03 00:00:00'),(108,'Nancy','Greenberg','NGREENBE','515.124.4569','FI_MGR',12000.00,NULL,101,100,'1998-03-03 00:00:00'),(109,'Daniel','Faviet','DFAVIET','515.124.4169','FI_ACCOUNT',9000.00,NULL,108,100,'1998-03-03 00:00:00'),(110,'John','Chen','JCHEN','515.124.4269','FI_ACCOUNT',8200.00,NULL,108,100,'2000-09-09 00:00:00'),(111,'Ismael','Sciarra','ISCIARRA','515.124.4369','FI_ACCOUNT',7700.00,NULL,108,100,'2000-09-09 00:00:00'),(112,'Jose Manuel','Urman','JMURMAN','515.124.4469','FI_ACCOUNT',7800.00,NULL,108,100,'2000-09-09 00:00:00'),(113,'Luis','Popp','LPOPP','515.124.4567','FI_ACCOUNT',6900.00,NULL,108,100,'2000-09-09 00:00:00'),(114,'Den','Raphaely','DRAPHEAL','515.127.4561','PU_MAN',11000.00,NULL,100,30,'2000-09-09 00:00:00'),(115,'Alexander','Khoo','AKHOO','515.127.4562','PU_CLERK',3100.00,NULL,114,30,'2000-09-09 00:00:00'),(116,'Shelli','Baida','SBAIDA','515.127.4563','PU_CLERK',2900.00,NULL,114,30,'2000-09-09 00:00:00'),(117,'Sigal','Tobias','STOBIAS','515.127.4564','PU_CLERK',2800.00,NULL,114,30,'2000-09-09 00:00:00'),(118,'Guy','Himuro','GHIMURO','515.127.4565','PU_CLERK',2600.00,NULL,114,30,'2000-09-09 00:00:00'),(119,'Karen','Colmenares','KCOLMENA','515.127.4566','PU_CLERK',2500.00,NULL,114,30,'2000-09-09 00:00:00'),(120,'Matthew','Weiss','MWEISS','650.123.1234','ST_MAN',8000.00,NULL,100,50,'2004-02-06 00:00:00'),(121,'Adam','Fripp','AFRIPP','650.123.2234','ST_MAN',8200.00,NULL,100,50,'2004-02-06 00:00:00'),(122,'Payam','Kaufling','PKAUFLIN','650.123.3234','ST_MAN',7900.00,NULL,100,50,'2004-02-06 00:00:00'),(123,'Shanta','Vollman','SVOLLMAN','650.123.4234','ST_MAN',6500.00,NULL,100,50,'2004-02-06 00:00:00'),(124,'Kevin','Mourgos','KMOURGOS','650.123.5234','ST_MAN',5800.00,NULL,100,50,'2004-02-06 00:00:00'),(125,'Julia','Nayer','JNAYER','650.124.1214','ST_CLERK',3200.00,NULL,120,50,'2004-02-06 00:00:00'),(126,'Irene','Mikkilineni','IMIKKILI','650.124.1224','ST_CLERK',2700.00,NULL,120,50,'2004-02-06 00:00:00'),(127,'James','Landry','JLANDRY','650.124.1334','ST_CLERK',2400.00,NULL,120,50,'2004-02-06 00:00:00'),(128,'Steven','Markle','SMARKLE','650.124.1434','ST_CLERK',2200.00,NULL,120,50,'2004-02-06 00:00:00'),(129,'Laura','Bissot','LBISSOT','650.124.5234','ST_CLERK',3300.00,NULL,121,50,'2004-02-06 00:00:00'),(130,'Mozhe','Atkinson','MATKINSO','650.124.6234','ST_CLERK',2800.00,NULL,121,50,'2004-02-06 00:00:00'),(131,'James','Marlow','JAMRLOW','650.124.7234','ST_CLERK',2500.00,NULL,121,50,'2004-02-06 00:00:00'),(132,'TJ','Olson','TJOLSON','650.124.8234','ST_CLERK',2100.00,NULL,121,50,'2004-02-06 00:00:00'),(133,'Jason','Mallin','JMALLIN','650.127.1934','ST_CLERK',3300.00,NULL,122,50,'2004-02-06 00:00:00'),(134,'Michael','Rogers','MROGERS','650.127.1834','ST_CLERK',2900.00,NULL,122,50,'2002-12-23 00:00:00'),(135,'Ki','Gee','KGEE','650.127.1734','ST_CLERK',2400.00,NULL,122,50,'2002-12-23 00:00:00'),(136,'Hazel','Philtanker','HPHILTAN','650.127.1634','ST_CLERK',2200.00,NULL,122,50,'2002-12-23 00:00:00'),(137,'Renske','Ladwig','RLADWIG','650.121.1234','ST_CLERK',3600.00,NULL,123,50,'2002-12-23 00:00:00'),(138,'Stephen','Stiles','SSTILES','650.121.2034','ST_CLERK',3200.00,NULL,123,50,'2002-12-23 00:00:00'),(139,'John','Seo','JSEO','650.121.2019','ST_CLERK',2700.00,NULL,123,50,'2002-12-23 00:00:00'),(140,'Joshua','Patel','JPATEL','650.121.1834','ST_CLERK',2500.00,NULL,123,50,'2002-12-23 00:00:00'),(141,'Trenna','Rajs','TRAJS','650.121.8009','ST_CLERK',3500.00,NULL,124,50,'2002-12-23 00:00:00'),(142,'Curtis','Davies','CDAVIES','650.121.2994','ST_CLERK',3100.00,NULL,124,50,'2002-12-23 00:00:00'),(143,'Randall','Matos','RMATOS','650.121.2874','ST_CLERK',2600.00,NULL,124,50,'2002-12-23 00:00:00'),(144,'Peter','Vargas','PVARGAS','650.121.2004','ST_CLERK',2500.00,NULL,124,50,'2002-12-23 00:00:00'),(145,'John','Russell','JRUSSEL','011.44.1344.429268','SA_MAN',14000.00,0.40,100,80,'2002-12-23 00:00:00'),(146,'Karen','Partners','KPARTNER','011.44.1344.467268','SA_MAN',13500.00,0.30,100,80,'2002-12-23 00:00:00'),(147,'Alberto','Errazuriz','AERRAZUR','011.44.1344.429278','SA_MAN',12000.00,0.30,100,80,'2002-12-23 00:00:00'),(148,'Gerald','Cambrault','GCAMBRAU','011.44.1344.619268','SA_MAN',11000.00,0.30,100,80,'2002-12-23 00:00:00'),(149,'Eleni','Zlotkey','EZLOTKEY','011.44.1344.429018','SA_MAN',10500.00,0.20,100,80,'2002-12-23 00:00:00'),(150,'Peter','Tucker','PTUCKER','011.44.1344.129268','SA_REP',10000.00,0.30,145,80,'2014-03-05 00:00:00'),(151,'David','Bernstein','DBERNSTE','011.44.1344.345268','SA_REP',9500.00,0.25,145,80,'2014-03-05 00:00:00'),(152,'Peter','Hall','PHALL','011.44.1344.478968','SA_REP',9000.00,0.25,145,80,'2014-03-05 00:00:00'),(153,'Christopher','Olsen','COLSEN','011.44.1344.498718','SA_REP',8000.00,0.20,145,80,'2014-03-05 00:00:00'),(154,'Nanette','Cambrault','NCAMBRAU','011.44.1344.987668','SA_REP',7500.00,0.20,145,80,'2014-03-05 00:00:00'),(155,'Oliver','Tuvault','OTUVAULT','011.44.1344.486508','SA_REP',7000.00,0.15,145,80,'2014-03-05 00:00:00'),(156,'Janette','K_ing','JKING','011.44.1345.429268','SA_REP',10000.00,0.35,146,80,'2014-03-05 00:00:00'),(157,'Patrick','Sully','PSULLY','011.44.1345.929268','SA_REP',9500.00,0.35,146,80,'2014-03-05 00:00:00'),(158,'Allan','McEwen','AMCEWEN','011.44.1345.829268','SA_REP',9000.00,0.35,146,80,'2014-03-05 00:00:00'),(159,'Lindsey','Smith','LSMITH','011.44.1345.729268','SA_REP',8000.00,0.30,146,80,'2014-03-05 00:00:00'),(160,'Louise','Doran','LDORAN','011.44.1345.629268','SA_REP',7500.00,0.30,146,80,'2014-03-05 00:00:00'),(161,'Sarath','Sewall','SSEWALL','011.44.1345.529268','SA_REP',7000.00,0.25,146,80,'2014-03-05 00:00:00'),(162,'Clara','Vishney','CVISHNEY','011.44.1346.129268','SA_REP',10500.00,0.25,147,80,'2014-03-05 00:00:00'),(163,'Danielle','Greene','DGREENE','011.44.1346.229268','SA_REP',9500.00,0.15,147,80,'2014-03-05 00:00:00'),(164,'Mattea','Marvins','MMARVINS','011.44.1346.329268','SA_REP',7200.00,0.10,147,80,'2014-03-05 00:00:00'),(165,'David','Lee','DLEE','011.44.1346.529268','SA_REP',6800.00,0.10,147,80,'2014-03-05 00:00:00'),(166,'Sundar','Ande','SANDE','011.44.1346.629268','SA_REP',6400.00,0.10,147,80,'2014-03-05 00:00:00'),(167,'Amit','Banda','ABANDA','011.44.1346.729268','SA_REP',6200.00,0.10,147,80,'2014-03-05 00:00:00'),(168,'Lisa','Ozer','LOZER','011.44.1343.929268','SA_REP',11500.00,0.25,148,80,'2014-03-05 00:00:00'),(169,'Harrison','Bloom','HBLOOM','011.44.1343.829268','SA_REP',10000.00,0.20,148,80,'2014-03-05 00:00:00'),(170,'Tayler','Fox','TFOX','011.44.1343.729268','SA_REP',9600.00,0.20,148,80,'2014-03-05 00:00:00'),(171,'William','Smith','WSMITH','011.44.1343.629268','SA_REP',7400.00,0.15,148,80,'2014-03-05 00:00:00'),(172,'Elizabeth','Bates','EBATES','011.44.1343.529268','SA_REP',7300.00,0.15,148,80,'2014-03-05 00:00:00'),(173,'Sundita','Kumar','SKUMAR','011.44.1343.329268','SA_REP',6100.00,0.10,148,80,'2014-03-05 00:00:00'),(174,'Ellen','Abel','EABEL','011.44.1644.429267','SA_REP',11000.00,0.30,149,80,'2014-03-05 00:00:00'),(175,'Alyssa','Hutton','AHUTTON','011.44.1644.429266','SA_REP',8800.00,0.25,149,80,'2014-03-05 00:00:00'),(176,'Jonathon','Taylor','JTAYLOR','011.44.1644.429265','SA_REP',8600.00,0.20,149,80,'2014-03-05 00:00:00'),(177,'Jack','Livingston','JLIVINGS','011.44.1644.429264','SA_REP',8400.00,0.20,149,80,'2014-03-05 00:00:00'),(178,'Kimberely','Grant','KGRANT','011.44.1644.429263','SA_REP',7000.00,0.15,149,NULL,'2014-03-05 00:00:00'),(179,'Charles','Johnson','CJOHNSON','011.44.1644.429262','SA_REP',6200.00,0.10,149,80,'2014-03-05 00:00:00'),(180,'Winston','Taylor','WTAYLOR','650.507.9876','SH_CLERK',3200.00,NULL,120,50,'2014-03-05 00:00:00'),(181,'Jean','Fleaur','JFLEAUR','650.507.9877','SH_CLERK',3100.00,NULL,120,50,'2014-03-05 00:00:00'),(182,'Martha','Sullivan','MSULLIVA','650.507.9878','SH_CLERK',2500.00,NULL,120,50,'2014-03-05 00:00:00'),(183,'Girard','Geoni','GGEONI','650.507.9879','SH_CLERK',2800.00,NULL,120,50,'2014-03-05 00:00:00'),(184,'Nandita','Sarchand','NSARCHAN','650.509.1876','SH_CLERK',4200.00,NULL,121,50,'2014-03-05 00:00:00'),(185,'Alexis','Bull','ABULL','650.509.2876','SH_CLERK',4100.00,NULL,121,50,'2014-03-05 00:00:00'),(186,'Julia','Dellinger','JDELLING','650.509.3876','SH_CLERK',3400.00,NULL,121,50,'2014-03-05 00:00:00'),(187,'Anthony','Cabrio','ACABRIO','650.509.4876','SH_CLERK',3000.00,NULL,121,50,'2014-03-05 00:00:00'),(188,'Kelly','Chung','KCHUNG','650.505.1876','SH_CLERK',3800.00,NULL,122,50,'2014-03-05 00:00:00'),(189,'Jennifer','Dilly','JDILLY','650.505.2876','SH_CLERK',3600.00,NULL,122,50,'2014-03-05 00:00:00'),(190,'Timothy','Gates','TGATES','650.505.3876','SH_CLERK',2900.00,NULL,122,50,'2014-03-05 00:00:00'),(191,'Randall','Perkins','RPERKINS','650.505.4876','SH_CLERK',2500.00,NULL,122,50,'2014-03-05 00:00:00'),(192,'Sarah','Bell','SBELL','650.501.1876','SH_CLERK',4000.00,NULL,123,50,'2014-03-05 00:00:00'),(193,'Britney','Everett','BEVERETT','650.501.2876','SH_CLERK',3900.00,NULL,123,50,'2014-03-05 00:00:00'),(194,'Samuel','McCain','SMCCAIN','650.501.3876','SH_CLERK',3200.00,NULL,123,50,'2014-03-05 00:00:00'),(195,'Vance','Jones','VJONES','650.501.4876','SH_CLERK',2800.00,NULL,123,50,'2014-03-05 00:00:00'),(196,'Alana','Walsh','AWALSH','650.507.9811','SH_CLERK',3100.00,NULL,124,50,'2014-03-05 00:00:00'),(197,'Kevin','Feeney','KFEENEY','650.507.9822','SH_CLERK',3000.00,NULL,124,50,'2014-03-05 00:00:00'),(198,'Donald','OConnell','DOCONNEL','650.507.9833','SH_CLERK',2600.00,NULL,124,50,'2014-03-05 00:00:00'),(199,'Douglas','Grant','DGRANT','650.507.9844','SH_CLERK',2600.00,NULL,124,50,'2014-03-05 00:00:00'),(200,'Jennifer','Whalen','JWHALEN','515.123.4444','AD_ASST',4400.00,NULL,101,10,'2016-03-03 00:00:00'),(201,'Michael','Hartstein','MHARTSTE','515.123.5555','MK_MAN',13000.00,NULL,100,20,'2016-03-03 00:00:00'),(202,'Pat','Fay','PFAY','603.123.6666','MK_REP',6000.00,NULL,201,20,'2016-03-03 00:00:00'),(203,'Susan','Mavris','SMAVRIS','515.123.7777','HR_REP',6500.00,NULL,101,40,'2016-03-03 00:00:00'),(204,'Hermann','Baer','HBAER','515.123.8888','PR_REP',10000.00,NULL,101,70,'2016-03-03 00:00:00'),(205,'Shelley','Higgins','SHIGGINS','515.123.8080','AC_MGR',12000.00,NULL,101,110,'2016-03-03 00:00:00'),(206,'William','Gietz','WGIETZ','515.123.8181','AC_ACCOUNT',8300.00,NULL,205,110,'2016-03-03 00:00:00'),(207,'xingxing','zhou','554555@qq.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL),(208,'xiaohu',NULL,'555145@126.com',NULL,NULL,NULL,NULL,NULL,NULL,NULL);/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

1 length():获取字节数

说明:我们在MySQL中创建数据库时,有一个操作就是要指定数据库的字符集,而这里的获取字节数的函数——length()就和这个字符集相关的。

339d3973d521e9734a8060b850ac5f55.png

在这里简单说一下常见的MySQL字符集一个字符所占用的字节数。(详见文章:MySQL字符集,文章地址:)

  • utf8(注意:不是utf-8):数字、字母占用一个字符,常见的中文字符占用3个字节,不能存储占用4个字节的生僻汉字、emoji等。
  • utf8mb4(真utf-8):数字、字母占用一个字符,常见的中文字符占用3个字节,但是可以存储占用4个字节的生僻汉字、emoji等。
  • gbk:数字、字母占用一个字符,常见的中文字符占用2个字节,不能存储占用4个字节的生僻汉字、emoji等。(没想到吧,gbk不能存储中文生僻字)

另外,再说一个命令:SHOW VARIABLES LIKE '%char%' ——查看系统字符集设置,包括所有的字符集设置:(关于这个字符集的说明,详见文章:MySQL字符集,文章地址:)

53d4d215b4a34bcca0bc329519360cf5.png

当前我的数据库是utf8md4字符集,其他的字符集自行测试。

(1)数字、字母、常见中文字符

#运行结果:6
SELECT LENGTH("aaa111")#运行结果:6
SELECT LENGTH("老王")

4da78f59befb4ab2d5e350af2f3f4371.png

23c1b13f654a5f5c892734c5d92cd51a.png

(2)生僻字

注意:这个生僻字需要从这里拷贝过去(" "),不能直接打出来(不是你用拼音打出来的"康熙"的“熙”,这是一个异体字。另外,本人测试过,这个异体字在知乎上可能会显示不出来,看我的截图就行。)。

#运行结果:4
SELECT LENGTH(" ");

35f03c5820592b6749e3322b6c7d3cb9.png

2 concat()

1、函数的使用

由于在MySQL中,"+"只是做加法运算的,因此拼接字符串就不能使用“+”了,需要使用concat()函数。

#错误的写法,不能使用"+"
SELECT last_name+first_name AS "姓名"  FROM employees;#正确的姿势
SELECT CONCAT(last_name,first_name) AS "姓名" FROM employees;

a82e306c51ac7398d9e36982de22e944.png

2、使用注意

该函数在进行拼接时,只要拼接的字段有null值,则拼接结果一定为null,必须使用ifnull()函数进行处理!(关于ifnull函数的用法,详见文章:ifnull(),文章地址:)

对null值不进行处理时,拼接结果为null:

#不对null值进行处理
SELECT last_name,first_name,CONCAT(last_name, first_name) AS "姓名" 
FROMemployees ;

9c434d9d3ec5ec8f0ef9701561246e0a.png

对null值进行处理后,可正常拼接

#对null值进行处理
SELECT last_name,first_name,CONCAT(IFNULL(last_name, ""), first_name) AS "姓名" 
FROMemployees ;

bea421ae834fbcc2dbf99725a57ec6d7.png

3 upper()、lower()

1、该函数的作用

upper():返回字符串str根据当前字符集映射所有字符为大写。简言之,就是将字符串中所有的字母字符转换为大写

lower():与上面的upper()相反,转换为小写。

2、使用

【案例1】将姓变为大写,名变为小写,然后进行拼接

#SQLyog使用技巧:F12键可对SQL语句进行格式化排版
SELECT UPPER(last_name) AS '姓',LOWER(first_name) AS '名' ,CONCAT(UPPER(last_name), "_", LOWER(first_name)) AS "姓名" 
FROMemployees ;

ffa9c5554db031d3b89a0885e33d38f5.png

4 substr()( 或substring() )

首先说明一下:MySQL中的下标都是从1开始的。

1、函数作用:截取字符串。该方法有四个重载方法,如下图所示:

23f3163443d1094439d464614b3b5faf.png

2、使用

(1)SUBSTR(str,pos):截取指定索引pos处后所有的字符串。

【案例1】截取字符串"李莫愁爱上了陆展元"中的"陆展元"

#注意:下标是从1开始的
SELECT SUBSTR("李莫愁爱上了陆展元",7) AS out_put;

a5d50046faf0e95f86fb418c151a60b2.png

(2)SUBSTR(str,pos,len):从指定索引pos处开始截取字符串str,截取字符长度为len。

【案例1】截取字符串""李莫愁爱上了陆展元"中的"李莫愁"

SELECT SUBSTR("李莫愁爱上了陆展元",1,3) AS out_put;

871dec06af6ae9132e37725f1f97890e.png

【案例2】姓名中首字母大写,其他字符小写,然后用_拼接

SELECT last_name,first_name,CONCAT(UPPER(SUBSTR(last_name, 1, 1)),"_",LOWER(SUBSTR(last_name, 2)),"_",LOWER(first_name)) AS out_put 
FROMemployees ;

bc883c29f8e6b43dcc05dc294aceca51.png

5 instr()

作用:返回此字符串在指定字符串中第一次出现的索引

#运行结果3
SELECT INSTR("我是张三,我的名字叫张三三","张三") AS result;

c3bf5e70779a184daf508c8470a21b50.png

6 trim()

作用1:去除前后空格

#运行结果:13
SELECT LENGTH(TRIM("   我是 张三   ")) AS result;

6ce866d8ccb821563dfdf621c720f3bc.png

作用2:去除前后指定的字符串

#运行结果:张三bb
SELECT TRIM('a' FROM 'aaaaa张三bbaaa') AS result;
​
#注意:如果写两个aa,运行结果就是 a张三bba
#两个两个进行匹配,最后还剩下一个a没有被匹配上,所以就留下了
SELECT TRIM('aa' FROM 'aaaaa张三bbaaa') AS result;

17f78d46521e002e1aecf332c219a2be.png

37d40c38c8ae1ad7d837132615448866.png

7 lpad()

作用:左填充。当字符串长度不足指定的长度时,左填充指定的字符串

注意:如果字符串长度超过指定长度,则会进行左起开始截断!

#运行结果:00100
SELECT LPAD("100",5,"0") AS result;
​
#字符串长度超长,运行结果:12345
SELECT LPAD("1234567",5,"0") AS result;

1515a73a3160d00174ba967519385d67.png

6c0b0eeb9db2872cda17048e6fa04321.png

8 rpad()

作用:右填充。当字符串长度不足指定的长度时,左填充指定的字符串

注意:如果字符串长度超过指定长度,则会进行左起开始截断!

#运行结果:10000
SELECT RPAD("100",5,"0") AS result;#字符串本身的长度已经超过了指定长度,左起开始截断
#所以运行结果是:10
SELECT RPAD("100",2,"0") AS result;

be4ba9627f27c26b2cc41360a6d57dc0.png

eed825e9fe0bd110a61a71b6ef9e7f38.png

9 replace()

作用:替换字符串

#运行结果:我是李四,我的名字叫李四三
SELECT REPLACE("我是张三,我的名字叫张三三","张三","李四") AS result;

aa1d0e870c67c08390a66f1c0a804371.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/531852.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

html盒子模型页面居中,【静态页面架构】CSS之盒子模型

CSS架构盒子模型;以内容区(显示文本和图像)内边距(内容区至边距的距离)边距(内容区的边界)外边距(元素的边框之间的距离)1.边距;border属性;简写属性用来设置边距的上(top)右(right)下(bottom)左(left)。宽度,颜色和样式div{width…

最强动画制作人书包_声优访谈丨恋与制作人动画中配声优访谈——夏磊

亲爱的制作人们:距离恋与制作人动画上线还有6天!今天的中配声优访谈嘉宾是在动画中为许墨献声的夏磊老师~固定布局 工具条上设置固定宽高背景可以设置被包含可以完美对齐背景图和文字以及制作自…

codesys com库_CoDeSys官方系统库在线下载,替换国内下载服务器教程

欢迎加入工控分享技术服务社区推荐阅读Codesys学习资料大全Codesys控制器关于CANopen总线的详细应用说明当你软件报以下错误,你可以直接下载,如果下载不成功,可以换个网络试一试,或者进行下面的操作。由于国内网络问题&#xff0c…

centos7恢复mysql数据库_MySQL数据库升级迁移填坑记

原库:*.*.101.73/74 系统环境: Suse 12.4MySQL: 5.7.29新库:*.*.110.46/47系统环境:CentOS7.7 64位MySQL版本: 5.7.30[一、数据库升级迁移场景]因业务侧在*.*.101.73/74 mysql数据库服务器上部署了java应用程序、HadoopHbase数据库等大数据…

so把asp页面生成静态的html,23、asp系列课程--server.URLEncode方法和server.HTMLEncode方法...

作者:杨凡来自:杨凡博客地址:blog.sina.com.cn/aboutshisanserver.URLEncode方法和server.HTMLEncode方法可以对字符串进行编码。我们一个一个的说。server.URLEncode可以对字符串进行URL编码转换,语法格式为:server.u…

下列关于html5表单的多样输入方式,IT兄弟连 HTML5教程 HTML5表单 多样的输入类型1...

原标题:IT兄弟连 HTML5教程 HTML5表单 多样的输入类型1HTML5拥有多个新的表单输入类型,这些新特性提供了更好的输入控制和验证。并不是所有的主浏览器都支持新的input类型,不过我们可以在所有的主浏览器中使用它们,即使不被支持&a…

v7000更换电池步骤_ups电源运行中是否可以更换电池?应如何操作呢

ups电源在日常使用中除了日常维护工作之外,对于使用达到一定年限的时候,内部使用的ups蓄电池就需要更换了,很多人以为ups不间段电源在工作的时候是可以跟换电池。其实,这个具体就需要看ups电源设计的原理,不同厂家设计…

华为怎么用手机看时间到读秒_华为手机灭屏也可以看时间?其实设置方法很简单,不会有些可惜了...

华为作为手机界名副其实的大佬,而且华为手机的口碑也是非常不错的。那么为什么会有这么多人喜欢华为手机呢?主要是华为手机的质量高,并且用很多实用的小功能,比如说神奇的灭屏显示功能等等,今天就给大家分享几个华为手…

hive转16进制unhex_Java 进制的转换

什么是进制?进制也就是进位计数制,是人为定义的带进位的计数方法(有不带进位的计数方法,比如原始的结绳计数法,唱票时常用的“正”字计数法,以及类似的tally mark计数)。 对于任何一种进制---X进制,就表示每…

引入ui组件_Vuejs, Semantic CSS前端框架fish-ui

简介基于vue2.0, github star 690, 一款小众的UI框架fish-ui,直接上截图:主要特性配备Vue.js,Moment,Vue-Router,ES6和Babel 6使用Webpack 2.0和Vue LoaderSemantic CSS 组件使用 Less支持现代浏览器快速开发安装npm i…

减去字符串_从文本字符串中提取指定值的6个超级技巧解读

在实际的工作中,从指定的字符串中提取指定文本也是常用的技巧之一,除了手动操作之外,下文的8种应用技巧也是必须要掌握的。一、Left函数法。功能:从指定文本字符串的第一个字符开始,提取指定长度的字符串。语法结构&am…

如果用计算机录制歌曲需要,网络歌手怎么用电脑录音软件录歌

现在网上有很多网络歌手主要分为两类,一类是原创,一类是翻唱。可是不管是原创还是翻唱都需要自己唱歌录歌,要有属于自己的歌曲(自己唱的)。要录歌就要有设备,毕竟网路歌手刚开始大多数都是草根没有钱找音乐工作室,只能…

中国剩余定理证明过程

原网址:http://blog.csdn.net/wtq493841534/article/details/5452720 中国剩余定理 中国剩余定理可以描述为: 若某数x分别被d1、、…、dn除得的余数为r1、r2、…、rn,则可表示为下式:xR1r1R2r2…RnrnRD其中R1是d2、d3、…、dn的公…

关闭浏览器前提示_win7系统ie总弹出查看和跟踪下载的关闭方法

今天小编给大家分享的是win7系统ie总弹出查看和跟踪下载的关闭方法,使用ie浏览器上网的时候,有些用户会遇到ie总弹出查看和跟踪下载的窗口,很多用户想关闭掉此提示,却不知如何关闭查看和跟踪下载的窗口,那么请参照以下…

html引入百度地图报错,vue引入百度地图BMapGL,或者其他个性化地图

3.jpgvue的百度地图早就有vue-baidu-map这里就不赘述了,自己去直接对着API写就好了,基本上已经满足绝大多数需求了还简单方便。vue-baidu-map 传送门 https://dafrok.github.io/vue-baidu-map/#/zh/index这里主要是在vue里面引入BMapGL,或者其…

排序千万级数据_从千万级房产成交量排名,窥探中国城市的真实家底

原标题:从千万级房产成交量排名,窥探中国城市的真实家底 文/孙不熟 来源/城市战争 如果你有1000万以上的买房预算,你的选择其实很少,总共不超过10个城市,这就是中国城市和楼市的真实家底。 昨天推送了一篇《…

html 实现列表组并排,列表组--自定义列表组

Bootstrap框加在链接列表组的基础上新增了两个样式:☑list-group-item-heading:用来定义列表项头部样式☑list-group-item-text:用来定义列表项主要内容这两个样式最大的作用就是用来帮助开发者可以自定义列表项里的内容,如下面的…

queryselectorall 怎么取name_用这个方法,我爬取了《王者荣耀》《英雄联盟》等游戏皮肤图片...

本文简介:本文使用Python制作爬虫,来爬取《英雄联盟》《王者荣耀》《神之浩劫》等游戏官方网站的英雄皮肤图片。可以作为新手爬虫的练手实战案例!!爱打游戏的各位肯定也是对游戏里面制作精美,妩媚无比或是帅气逼人的皮…

云端计算机可以玩游戏么,手机掌上云电脑是什么?为什么可以玩PC游戏?

原标题:手机掌上云电脑是什么?为什么可以玩PC游戏?经常会在一些短视频平台上看到别人用云电脑的应用在手机上玩PC游戏,那么这个掌上云电脑的应用到底是什么呢?为什么可以玩PC游戏呢?按照以往的理解&#xf…

计算机组策略怎么设置远程桌面,组策略 之   自动启用客户端远程桌面功能

在企业里进行管理的时候,有时需要利用远程桌面来管理客户端计算机,在一般情况下,往往需要客户端启用此功能,有没有好的办法,让客户端自动启用呢?当然可以,我们可以通过组策略的形式来完成。实施…