一天一点MySQL复习——获取数据库系统时间、变量赋值、变量比较
一、SQL获取系统时间
mysql> select now() from dual;
+---------------------+
| now() |
+---------------------+
| 2016-05-24 08:34:12 |
+---------------------+
1 row in set (0.00 sec)
mysql> select curdate() from dual;
+------------+
| curdate() |
+------------+
| 2016-05-24 |
+------------+
1 row in set (0.01 sec)
mysql> select curtime() from dual;
+-----------+
| curtime() |
+-----------+
| 08:36:23 |
+-----------+
1 row in set (0.00 sec)
二、变量赋值
赋值方式分为'select'与'set'
select 方式:
select @name:=value;
mysql> select @b:=4;
+-------+
| @b:=4 |
+-------+
| 4 |
+-------+
1 row in set (0.00 sec) mysql> select @b;
+------+
| @b |
+------+
| 4 |
+------+
1 row in set (0.00 sec)
select row_name from table INTO @name;
mysql> select now() from dual INTO @test1;
Query OK, 1 row affected (0.00 sec) mysql> select @test1;
+---------------------+
| @test1 |
+---------------------+
| 2016-05-24 08:48:21 |
+---------------------+
1 row in set (0.00 sec)
set方式:
赋值:set @name:=value;
set @name=value;
mysql> set @c=1;
Query OK, 0 rows affected (0.00 sec) mysql> select @c;
+------+
| @c |
+------+
| 1 |
+------+
1 row in set (0.00 sec) mysql> set @c:=2;
Query OK, 0 rows affected (0.00 sec) mysql> select @c;
+------+
| @c |
+------+
| 2 |
+------+
1 row in set (0.00 sec)
三、变量比较
mysql> select @time1,@time2;
+---------------------+---------------------+
| @time1 | @time2 |
+---------------------+---------------------+
| 2016-05-24 08:54:44 | 2016-05-24 08:27:57 |
+---------------------+---------------------+
1 row in set (0.00 sec) mysql> select now() from dual INTO @time1;
Query OK, 1 row affected (0.00 sec) mysql> select now() from dual INTO @time2;
Query OK, 1 row affected (0.00 sec) mysql> select @time1,@time2;
+---------------------+---------------------+
| @time1 | @time2 |
+---------------------+---------------------+
| 2016-05-24 08:58:23 | 2016-05-24 08:58:38 |
+---------------------+---------------------+
1 row in set (0.00 sec) mysql> select @time1 < @time2;
+-----------------+
| @time1 < @time2 |
+-----------------+
| 1 |
+-----------------+
1 row in set (0.00 sec) mysql> select @time1 > @time2;
+-----------------+
| @time1 > @time2 |
+-----------------+
| 0 |
+-----------------+
1 row in set (0.00 sec)
一天一点MySQL复习——获取数据库系统时间、变量赋值、变量比较的更多相关文章
- 数据库——mysql如何获取当前时间---https://www.cnblogs.com/Chenshuai7/p/5136469.html
数据库——mysql如何获取当前时间 1.1 获得当前日期+时间(date + time)函数:now() -------https://www.cnblogs.com/Chenshuai7/p/51 ...
- 数据库——mysql如何获取当前时间
1.1 获得当前日期+时间(date + time)函数:now() 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数: current_timestamp() curren ...
- mysql 数据库获取当前时间
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2016-05-27 17:34 ...
- 一天一点MySQL复习——存储过程
一.存储过程概念 使用SQL编写访问数据库的代码时,可用两种方法存储和执行这些代码,一种是在客户端存储代码,并创建向数据库服务器发送的SQL命令(或SQL语句),比如在C#.Java等客户端编程语言中 ...
- MySQL时间函数-获取当前时间-时间差
MySQL中获取当前时间为now(),不同于sqlserver getdate(). SQLServer转MySQL除变化top 1 -> limit 1之后报错: limit [Err] 15 ...
- 使用jquer获取当前时间,并赋值到input上。
今天,做一个项目,需要将自动获取的时间能够赋值到input上.我一开始试用javascript写的,写之后使用很多办法都赋值失败,最后使用了jquery写了出来,下面附上代码. <script ...
- Mysql 如何设置字段自动获取当前时间
应用场景: 1.在数据表中,要记录每条数据是什么时候创建的,不需要应用程序去特意记录,而由数据数据库获取当前时间自动记录创建时间: 2.在数据库中,要记录每条数据是什么时候修改的,不需要应用程序去特意 ...
- mysql获取当前时间,及其相关操作
获取UNIX时间戳 : UNIX_TIMESTAMP(NOW()) 1.1 获得当前日期+时间(date + time)函数:now() 除了 now() 函数能获得当前的日期时间外,MySQL 中还 ...
- mysql通过now()获取的时间不对
先用now()获取系统时间,发现时间不对(差8个小时): mysql> select now(); +---------------------+ | now() | +------------ ...
随机推荐
- MySQL5.6 Replication主从复制(读写分离) 配置完整版
MySQL5.6 Replication主从复制(读写分离) 配置完整版 MySQL5.6主从复制(读写分离)教程 1.MySQL5.6开始主从复制有两种方式: 基于日志(binlog): 基于GTI ...
- ruby libmysqlclient.18.dylib
在mac 的rails环境中,如果已经确定安装了 mysql server,但是在启动rails s (服务器)的时候出现 Library not loaded: libmysqlclient.18 ...
- Junit单元测试学习笔记三
一. 高级 Fixture 上一篇文章中我们介绍了两个 Fixture 标注,分别是 @Before 和 @After ,我们来看看他们是否适合完成如下功能:有一个类是负责对大文件(超过 50 ...
- ruby 学习 -- string --1
# define french_string = "il \xc3\xa9tait une fois" long_string = <<EOF Here is a lo ...
- How a woman's glance can tell a man if she's interested
How a woman's glance can tell a man if she's interested揭秘:女人是否喜欢你?看眼神就知道The female mind has always b ...
- AcmeAir安装AI探针--SaaS版
一.安装SaaS版AI探针准备工作: 1.准备好可用的docker版AcmeAir应用 2.在SaaS官网tpm.oneapm.com上已注册可用的账号 3.登录tpm.oneapm.com,点击选择 ...
- Java-马士兵设计模式学习笔记-观察者模式-OOD线程
一.概述 1.情景:孩子睡觉,醒后要吃东西,用java模拟此情况 2.设计:child类,Dad类,都继承Runnable,dad线程监视child线程(缺点:因为要监视,所以耗cup资源) 二.代码 ...
- schtasks确实可以绕过UAC,简直不可思议啊~~
https://msdn.microsoft.com/en-us/library/windows/desktop/bb736357(v=vs.85).aspx
- Heap和Heapify
最近复习数据结构,又回去再看塞神的课件,看到PriorityQueue的实现.自己也根据塞神的代码写一写. 下面使用Binary Heap实现了一个简单的 Max-oriented PriorityQ ...
- POJ3020——Antenna Placement(二分图的最大匹配)
Antenna Placement DescriptionThe Global Aerial Research Centre has been allotted the task of buildin ...