当前位置: 首页 > wzjs >正文

南宁新技术产业建设开发总公司网站seo建站网络公司

南宁新技术产业建设开发总公司网站,seo建站网络公司,上海关键词排名优化怎样,做赚钱问卷调查的网站好目录 1.日期函数 1.1获得年月日 1.2获得时分秒 1.3获得年月日时分秒 1.4获得时间戳 1.5日期加天数 1.6日期减天数 1.7计算两个日期相隔多少天 1.8案例 2.字符串函数 2.1获取字符集 2.2字符串拼接 2.3字符串查询 2.4大小写转换 2.5字符串提取 2.6字符串长度 2.7…

目录

1.日期函数

1.1获得年月日

1.2获得时分秒

1.3获得年月日时分秒

1.4获得时间戳

1.5日期加天数

1.6日期减天数

1.7计算两个日期相隔多少天

1.8案例

2.字符串函数

2.1获取字符集

2.2字符串拼接

2.3字符串查询

2.4大小写转换

2.5字符串提取

2.6字符串长度

2.7字符串替换

2.8字符串截取

2.9去除空格

3.数学函数

3.1绝对值

3.2转二进制

3.3转十六进制

3.4进制转换

3.5向上向下取整

3.6保留n位小数

3.7随机数

3.8取模

4.其他函数

4.1查询当前用户

4.2显示当前数据库

4.3md5摘要

4.4passwor加密

4.5ifnull


1.日期函数

1.1获得年月日

mysql> select current_date();
+----------------+
| current_date() |
+----------------+
| 2024-03-24     |
+----------------+
1 row in set (0.00 sec)

1.2获得时分秒

mysql> select current_time();
+----------------+
| current_time() |
+----------------+
| 22:10:04       |
+----------------+
1 row in set (0.00 sec)

1.3获得年月日时分秒

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2024-03-24 22:30:14 |
+---------------------+
1 row in set (0.00 sec)

1.4获得时间戳

会以日期的方式显示。

mysql> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2024-03-24 22:10:55 |
+---------------------+
1 row in set (0.00 sec)

1.5日期加天数

mysql> select date_add('2022-01-01', interval 12 day) as res;
+------------+
| res        |
+------------+
| 2022-01-13 |
+------------+
1 row in set (0.00 sec)mysql> select date_add('2022-01-01', interval 3 month) as res;
+------------+
| res        |
+------------+
| 2022-04-01 |
+------------+
1 row in set (0.00 sec)

1.6日期减天数

mysql> select date_sub('2022-01-01', interval 12 day) as res;
+------------+
| res        |
+------------+
| 2021-12-20 |
+------------+
1 row in set (0.00 sec)mysql> select date_sub('2022-01-01', interval 3 month) as res;
+------------+
| res        |
+------------+
| 2021-10-01 |
+------------+
1 row in set (0.00 sec)

1.7计算两个日期相隔多少天

mysql> select datediff('2024-03-24', '2022-01-01') as res;
+------+
| res  |
+------+
|  813 |
+------+
1 row in set (0.00 sec)


1.8案例

  • 创建一张生日表
mysql> create table bir(-> id int primary key auto_increment,-> birthday date-> );
Query OK, 0 rows affected (0.02 sec)mysql> insert into bir(birthday) values('1998-05-28');
Query OK, 1 row affected (0.00 sec)mysql> insert into bir(birthday) values(current_date);
Query OK, 1 row affected (0.00 sec)mysql> insert into bir(birthday) values(current_timestamp());
Query OK, 1 row affected, 1 warning (0.00 sec)mysql> insert into bir(birthday) values(date(current_timestamp()));
Query OK, 1 row affected (0.00 sec)mysql> select * from bir;
+----+------------+
| id | birthday   |
+----+------------+
|  1 | 2024-03-24 |
|  2 | 1998-05-28 |
|  3 | 2024-03-24 |
|  4 | 2024-03-24 |
+----+------------+
4 rows in set (0.00 sec)

第三次插入的为时间戳,mysql会自动转化为日期。

  • 创建一个留言表
mysql> create table mes(-> id int primary key auto_increment,-> message varchar(100) not null,-> sendtime datetime-> );
Query OK, 0 rows affected (0.02 sec)mysql> insert into mes (message, sendtime) values ('窗前明月光', now());
Query OK, 1 row affected (0.00 sec)mysql> insert into mes (message, sendtime) values ('疑是地上霜', now());
Query OK, 1 row affected (0.00 sec)mysql> select * from mes;
+----+-----------------+---------------------+
| id | message         | sendtime            |
+----+-----------------+---------------------+
|  1 | 窗前明月光      | 2024-03-24 22:29:33 |
|  2 | 疑是地上霜      | 2024-03-24 22:29:43 |
+----+-----------------+---------------------+
2 rows in set (0.00 sec)
  • 查询3分钟之内发的评论
mysql> select * from mes
+----+-----------------+---------------------+
| id | message         | sendtime            |
+----+-----------------+---------------------+
|  1 | 窗前明月光      | 2024-03-24 22:29:33 |
|  2 | 疑是地上霜      | 2024-03-24 22:29:43 |
|  3 | 举头望明月      | 2024-03-24 22:31:42 |
|  4 | 低头思故乡      | 2024-03-24 22:31:49 |
+----+-----------------+---------------------+
4 rows in set (0.00 sec)mysql> select * from mes where sendtime > date_sub(now(), interval 3 minute);
+----+-----------------+---------------------+
| id | message         | sendtime            |
+----+-----------------+---------------------+
|  3 | 举头望明月      | 2024-03-24 22:31:42 |
|  4 | 低头思故乡      | 2024-03-24 22:31:49 |
+----+-----------------+---------------------+
2 rows in set (0.00 sec)

2.字符串函数

2.1获取字符集

mysql> select charset('123');
+----------------+
| charset('123') |
+----------------+
| utf8           |
+----------------+
1 row in set (0.00 sec)mysql> select charset(123);
+--------------+
| charset(123) |
+--------------+
| binary       |
+--------------+
1 row in set (0.00 sec)mysql> select charset(sendtime) from mes;
+-------------------+
| charset(sendtime) |
+-------------------+
| binary            |
| binary            |
| binary            |
| binary            |
+-------------------+
4 rows in set (0.00 sec)

2.2字符串拼接

类似于c语言中的strcat

mysql> select concat('123', 'hello', 'world') as res;
+---------------+
| res           |
+---------------+
| 123helloworld |
+---------------+
1 row in set (0.00 sec)
mysql> select concat('id: ', id, ' 发送了一条消息: ', message, ' 时间:', sendtime) as res from mes;
+-------------------------------------------------------------------------+
| res                                                                     |
+-------------------------------------------------------------------------+
| id: 1 发送了一条消息: 窗前明月光 时间:2024-03-24 22:29:33               |
| id: 2 发送了一条消息: 疑是地上霜 时间:2024-03-24 22:29:43               |
| id: 3 发送了一条消息: 举头望明月 时间:2024-03-24 22:31:42               |
| id: 4 发送了一条消息: 低头思故乡 时间:2024-03-24 22:31:49               |
+-------------------------------------------------------------------------+
4 rows in set (0.00 sec)

2.3字符串查询

instr(string, substring) 返回substring在string中的下标(从1开始),不存在返回0。

mysql> select instr('helfjsadio123fjkdsfa', '123');
+--------------------------------------+
| instr('helfjsadio123fjkdsfa', '123') |
+--------------------------------------+
|                                   11 |
+--------------------------------------+
1 row in set (0.00 sec)

2.4大小写转换

ucase转大写,lcase转小写。

mysql> select ucase('fAjfkjBSD213jD1s');
+---------------------------+
| ucase('fAjfkjBSD213jD1s') |
+---------------------------+
| FAJFKJBSD213JD1S          |
+---------------------------+
1 row in set (0.00 sec)
mysql> select lcase('fAjfkjBSD213jD1s');
+---------------------------+
| lcase('fAjfkjBSD213jD1s') |
+---------------------------+
| fajfkjbsd213jd1s          |
+---------------------------+
1 row in set (0.00 sec)

2.5字符串提取

left(string, length),string中从左往右提取length个字符。

mysql> select left('hello world', 8);
+------------------------+
| left('hello world', 8) |
+------------------------+
| hello wo               |
+------------------------+
1 row in set (0.00 sec)

right(string, length)),stringg中从右向左提取length个字符。

mysql> select right('hello world', 7);
+-------------------------+
| right('hello world', 7) |
+-------------------------+
| o world                 |
+-------------------------+
1 row in set (0.00 sec)

2.6字符串长度

mysql> select length('fds28f3j28x');
+-----------------------+
| length('fds28f3j28x') |
+-----------------------+
|                    11 |
+-----------------------+
1 row in set (0.00 sec)

案例:求学生表中学生姓名占用的字节数

mysql> select name, length(name) 长度 from exam_result;
+-----------+--------+
| name      | 长度   |
+-----------+--------+
| 唐三藏    |      9 |
| 猪悟能    |      9 |
| 曹孟德    |      9 |
| 刘玄德    |      9 |
| 孙权      |      6 |
| 宋公明    |      9 |
| 张翼德    |      9 |
| 关云长    |      9 |
+-----------+--------+
8 rows in set (0.00 sec)

length函数返回字符串长度,以字节为单位。如果是多字节字符则计算多个字节数;如果是单字节字符则算作一个字节。比如:字母,数字算作一个字节,中文表示多个字节数(与字符集编码有关),这里是3个字节。

2.7字符串替换

replace(str, s1, s2),在str中,用s2替换s1。

mysql> select replace('hello world', 'world', 'mysql');
+------------------------------------------+
| replace('hello world', 'world', 'mysql') |
+------------------------------------------+
| hello mysql                              |
+------------------------------------------+
1 row in set (0.00 sec)

案例:将表中所有姓孙的同学改成姓周。

mysql> select name from exam_result;
+-----------+
| name      |
+-----------+
| 唐三藏    |
| 猪悟能    |
| 曹孟德    |
| 刘玄德    |
| 孙权      |
| 宋公明    |
| 张翼德    |
| 关云长    |
+-----------+
8 rows in set (0.00 sec)mysql> select replace(name, '孙', '周') from exam_result;
+-----------------------------+
| replace(name, '孙', '周')   |
+-----------------------------+
| 唐三藏                      |
| 猪悟能                      |
| 曹孟德                      |
| 刘玄德                      |
| 周权                        |
| 宋公明                      |
| 张翼德                      |
| 关云长                      |
+-----------------------------+
8 rows in set (0.00 sec)

注意:select和replace配合使用并不会修改数据库中的数据。

2.8字符串截取

substring(str, pos, length),str中的pos位置开始截取length个字符。length不写表示截取完。

mysql> select substring('fja382nqf8q8n2nc', 4);
+----------------------------------+
| substring('fja382nqf8q8n2nc', 4) |
+----------------------------------+
| 382nqf8q8n2nc                    |
+----------------------------------+
1 row in set (0.00 sec)mysql> select substring('fja382nqf8q8n2nc', 4, 5);
+-------------------------------------+
| substring('fja382nqf8q8n2nc', 4, 5) |
+-------------------------------------+
| 382nq                               |
+-------------------------------------+
1 row in set (0.00 sec)

案例:截取name中第二个到第三个字段。

mysql> select name, substring(name, 2, 2) from exam_result;
+-----------+-----------------------+
| name      | substring(name, 2, 2) |
+-----------+-----------------------+
| 唐三藏    | 三藏                  |
| 猪悟能    | 悟能                  |
| 曹孟德    | 孟德                  |
| 刘玄德    | 玄德                  |
| 孙权      | 权                    |
| 宋公明    | 公明                  |
| 张翼德    | 翼德                  |
| 关云长    | 云长                  |
+-----------+-----------------------+
8 rows in set (0.00 sec)

2.9去除空格

ltrim去除左边空格,rtrim去除右边的空格。

mysql> select ltrim('  nihao  ') as res;
+---------+
| res     |
+---------+
| nihao   |
+---------+
1 row in set (0.00 sec)mysql> select rtrim('  nihao  ') as res;
+---------+
| res     |
+---------+
|   nihao |
+---------+
1 row in set (0.00 sec)

3.数学函数

3.1绝对值

mysql> select abs(-21);
+----------+
| abs(-21) |
+----------+
|       21 |
+----------+
1 row in set (0.00 sec)

3.2转二进制

mysql> select bin(7);
+--------+
| bin(7) |
+--------+
| 111    |
+--------+
1 row in set (0.00 sec)

3.3转十六进制

mysql> select hex(41);
+---------+
| hex(41) |
+---------+
| 29      |
+---------+
1 row in set (0.00 sec)

3.4进制转换

任意两种进制之间的转换

mysql> select conv(21, 10, 4);
+-----------------+
| conv(21, 10, 4) |
+-----------------+
| 111             |
+-----------------+
1 row in set (0.00 sec)

十进制转四进制

3.5向上向下取整

ceiling向上取整,floor向下取整

mysql> select ceiling(2.11);
+---------------+
| ceiling(2.11) |
+---------------+
|             3 |
+---------------+
1 row in set (0.00 sec)mysql> select floor(2.11);
+-------------+
| floor(2.11) |
+-------------+
|           2 |
+-------------+
1 row in set (0.00 sec)

3.6保留n位小数

mysql> select format(1.234578, 5);
+---------------------+
| format(1.234578, 5) |
+---------------------+
| 1.23458             |
+---------------------+
1 row in set (0.00 sec)

3.7随机数

mysql> select rand();
+---------------------+
| rand()              |
+---------------------+
| 0.21503182520627215 |
+---------------------+
1 row in set (0.00 sec)mysql> select rand();
+--------------------+
| rand()             |
+--------------------+
| 0.8824897100054563 |
+--------------------+
1 row in set (0.00 sec)

3.8取模

mysql> select mod(10, 3);
+------------+
| mod(10, 3) |
+------------+
|          1 |
+------------+
1 row in set (0.00 sec)

4.其他函数

4.1查询当前用户

mysql> select user();
+--------+
| user() |
+--------+
| root@  |
+--------+
1 row in set (0.00 sec)

4.2显示当前数据库

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

4.3md5摘要

如果当前数据库存储的是密码,并且是以明文的形式保存的,如果被黑客攻击了,拿到了数据库中所有人的密码,那就麻烦了,针对这种情况,保存密码可以使用md5形成一个32位的数据摘要。

mysql> create table user(-> id int primary key auto_increment,-> name varchar(20) not null,-> password char(32) not null-> );
Query OK, 0 rows affected (0.02 sec)mysql> insert into user(name, password) values('张三', 1234);
Query OK, 1 row affected (0.00 sec)mysql> insert into user(name, password) values('李四', md5('1234'));
Query OK, 1 row affected (0.00 sec)mysql> select * from user;
+----+--------+----------------------------------+
| id | name   | password                         |
+----+--------+----------------------------------+
|  1 | 张三   | 1234                             |
|  2 | 李四   | 81dc9bdb52d04dc20036dbd8313ed055 |
+----+--------+----------------------------------+
2 rows in set (0.00 sec)

当用户登录的时候,只需要使用用户名和md5后的摘要在表中查找,如果找到了说明密码正确

mysql> select * from user where name='李四' and password=md5('1234');
+----+--------+----------------------------------+
| id | name   | password                         |
+----+--------+----------------------------------+
|  2 | 李四   | 81dc9bdb52d04dc20036dbd8313ed055 |
+----+--------+----------------------------------+
1 row in set (0.00 sec)

4.4passwor加密

在上述例子当中,我们也可以使用passw进行加密

mysql> select password('1234');
+-------------------------------------------+
| password('1234')                          |
+-------------------------------------------+
| *A4B6157319038724E3560894F7F932C8886EBFCF |
+-------------------------------------------+
1 row in set, 1 warning (0.00 sec)mysql> select md5('1234');
+----------------------------------+
| md5('1234')                      |
+----------------------------------+
| 81dc9bdb52d04dc20036dbd8313ed055 |
+----------------------------------+
1 row in set (0.00 sec)

可以看到两种方式得到的摘要是不同的。

4.5ifnull

ifnull(val1, val2) 如果val1为null,返回val2,否则返回val1的值

mysql> select ifnull(123, 456);
+------------------+
| ifnull(123, 456) |
+------------------+
|              123 |
+------------------+
1 row in set (0.00 sec)mysql> select ifnull(null, 456);
+-------------------+
| ifnull(null, 456) |
+-------------------+
|               456 |
+-------------------+
1 row in set (0.00 sec)

http://www.dtcms.com/wzjs/484428.html

相关文章:

  • 网站规划问题福州百度开户多少钱
  • 单位门户网站建设方案十大搜索引擎
  • 如何降低网站跳出率b站推广网站入口2023是什么
  • 廉政网站管理制度建设怎么优化网络
  • 合肥有哪些做网站的公司河南百度推广公司
  • 企业建设网站公司有哪些怎样建立一个网络销售平台
  • 陕西广告公司网站建设电商网站建设公司哪家好
  • wordpress api下载文件贵州萝岗seo整站优化
  • 网站内容被攻击该怎么做宁波正规seo推广
  • 代运营网站专业网站优化推广
  • 云信网站建设黄页网络的推广网站有哪些软件
  • wordpress全站转移免费b2b网站推广
  • 监控摄像头做直播网站免费seo快速收录工具
  • 青岛企业建设网站公司济南网站seo优化
  • 网站title怎么修改百度信息流推广技巧
  • 兰州关键词排名公司旺道智能seo系统
  • 网页设计图片轮播效果郑州seo优化外包顾问
  • 稷山做网站张家港seo建站
  • wordpress短代码参数值带百度关键词优化多少钱一年
  • 没有照片怎么做网站站长工具搜索
  • 传业做微采商城网站百度官网认证免费
  • wordpress收藏中心代码seo还有未来吗
  • 企业中英文网站开发太原网络推广价格
  • 代购网站制作苏州网站外包
  • 北京网站开发公司电话凤凰网台湾资讯
  • wordpress 幻灯片 插件青岛seo整站优化招商电话
  • 网站链接到邮箱怎么做seo平台优化
  • 如何自己做网站的优化推广成都计算机培训机构排名前十
  • 深圳有几个区地图seo专员简历
  • 建一个单页网站青岛网站建设方案优化