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,一经查实,立即删除!

相关文章

HDU 1024Max Sum Plus Plus(最大m字段和)

/* 动态转移方程&#xff1a;dp[i][j]max(dp[i-1]a[i], max(dp[t][j-1])a[i]) (j-1<t<i) 表示的是前i个数j个字段和的最大值是多少&#xff01; */ 1 #include<iostream> 2 #include<cstdio>3 #include<cstring>4 #define N 10000 5 using nam…

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

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

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

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

(单例设计模式中)懒汉式与饿汉式在多线程中的不同

/*目的&#xff1a;分析一下单例设计模式中&#xff0c;懒汉式与饿汉式在多线程中的不同&#xff01;开发时我们一般选择饿汉式&#xff0c;因为它简单明了&#xff0c;多线程中不会出现安全问题&#xff01;而饿汉式需要我们自己处理程序中存在的安全隐患&#xff0c;但是饿汉…

shiro修改html不生效,shiro中anon配置不生效

再配置shiro的时候&#xff0c;如下代码要注意&#xff1a;1、下述代码中必须是LinkedHashMap 而不能是HashMap。2、anon定义必须在authc之前否则anon定义不生效Beanpublic ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager){ShiroFilterFactor…

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

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

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

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

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

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

poj 1905Expanding Rods

1 /*2 二分 几何3 弧长L&#xff0c; 圆半径R&#xff0c; 弧度 q&#xff0c; LR*q;4 二分&#xff1a; 弧度&#xff08;0~PI&#xff09; 或者 高度&#xff08;L/2~L&#xff09; 5 */6 #include<cstdio> 7 #include<iostream>8 #include<cmath>9…

java中同步嵌套引起的死锁事例代码

/*目的&#xff1a;自己写一个由于同步嵌套引起的死锁&#xff01;思路&#xff1a;多个线程在执行时&#xff0c;某一时刻&#xff0c;0-Thread绑定了LockA锁&#xff0c;1-Thread绑定了LockB锁&#xff01;当0-Thread要去绑定LockB锁时 和 1-Thread要去绑定LockA锁时都不能绑…

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

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

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

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

poj 2031Building a Space Station(几何判断+Kruskal最小生成树)

1 /*2 最小生成树 几何判断3 Kruskal 球心之间的距离 - 两个球的半径 < 0 则说明是覆盖的&#xff01;此时的距离按照0计算 4 */5 #include<iostream>6 #include<cstdio>7 #include<cstring>8 #include<cmath>9 #include<algorithm>…

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

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

将数据转化成字符串时:用字符串的链接 还是 StringBuilder

/*目的&#xff1a;将数据转化成字符串时&#xff1a;用字符串的链接 还是 StringBuilder呢&#xff1f; */ public class Test{public static void main(String[] args){int[] arr{1,2,4,5};System.out.println(arrayToString(arr));}/* public static String arrayToString(…

html频谱跳动效果,HTML5音频可视化频谱跳动代码

HTML5音频可视化频谱跳动代码*{margin:0;padding:0;}#canvas {display: block;background: linear-gradient(135deg, rgb(142, 13, 133) 0%, rgb(230, 132, 110) 100%);}window.οnclickfunction () {if(oAudio.paused) {oAudio.play();}else{oAudio.pause();}}//创建音频上下文…

hive转16进制unhex_Java 进制的转换

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

html中css二级联动,html二级联动学习笔记

DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">http://www.cnblogs.com/whgw/archive/2012/05/11/2496667.htmlJquery的select操作集合jQuery获取Select选择的Text和Value: 语法解释&#xff1a; 1. $("#select_id").change(function()…

poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

1 /* poj 2187 Beauty Contest2 凸包&#xff1a;寻找每两点之间距离的最大值3 这个最大值一定是在凸包的边缘上的&#xff01; 4 5 求凸包的算法&#xff1a; Andrew算法&#xff01; 6 */7 #include<iostream> 8 #include<cstdio>9 #include&l…

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

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