MySql中的数据类型转换注意事项
来源:互联网 发布:软件测试学费多少 编辑:程序博客网 时间:2024/06/08 06:28
注意可转换成的数据类型只能是:binary,char,date,datetime,decimal,signed,unsigned,time
并没有常用的 int, varchar
MySQL的类型转换函数如下:
CAST(expr AS type), CONVERT(expr,type), CONVERT(expr USING transcoding_name)
The CAST() and CONVERT() functions take a value of one type and produce a value of another type.
The type can be one of the following values:
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
mysql> select cast(now() as char);
+---------------------+
| cast(now() as char) |
+---------------------+
| 2006-06-15 09:31:20 |
+---------------------+
mysql> select convert( '中文 ' using gb2312);
+------------------------------+
| convert( '中文 ' using gb2312) |
+------------------------------+
| 中文 |
+------------------------------+
1 row in set (0.06 sec)
使用日期函数date_add,date_sub就可以了,见下例:
mysql> select date_add(now(),interval 1 day);
+--------------------------------+
| date_add(now(),interval 1 day) |
+--------------------------------+
| 2006-06-16 09:36:06 |
+--------------------------------+
1 row in set (0.02 sec)
mysql> select date_add(now(), interval 1 month);
+-----------------------------------+
| date_add(now(), interval 1 month) |
+-----------------------------------+
| 2006-07-15 09:36:38 |
+-----------------------------------+
1 row in set (0.00 sec)
mysql> select date_add(now(), interval 1 minute);
+------------------------------------+
| date_add(now(), interval 1 minute) |
+------------------------------------+
| 2006-06-15 09:38:03 |
+------------------------------------+
1 row in set (0.00 sec)
1 row in set (0.05 sec)
并没有常用的 int, varchar
MySQL的类型转换函数如下:
CAST(expr AS type), CONVERT(expr,type), CONVERT(expr USING transcoding_name)
The CAST() and CONVERT() functions take a value of one type and produce a value of another type.
The type can be one of the following values:
BINARY[(N)]
CHAR[(N)]
DATE
DATETIME
DECIMAL
SIGNED [INTEGER]
TIME
UNSIGNED [INTEGER]
mysql> select cast(now() as char);
+---------------------+
| cast(now() as char) |
+---------------------+
| 2006-06-15 09:31:20 |
+---------------------+
mysql> select convert( '中文 ' using gb2312);
+------------------------------+
| convert( '中文 ' using gb2312) |
+------------------------------+
| 中文 |
+------------------------------+
1 row in set (0.06 sec)
使用日期函数date_add,date_sub就可以了,见下例:
mysql> select date_add(now(),interval 1 day);
+--------------------------------+
| date_add(now(),interval 1 day) |
+--------------------------------+
| 2006-06-16 09:36:06 |
+--------------------------------+
1 row in set (0.02 sec)
mysql> select date_add(now(), interval 1 month);
+-----------------------------------+
| date_add(now(), interval 1 month) |
+-----------------------------------+
| 2006-07-15 09:36:38 |
+-----------------------------------+
1 row in set (0.00 sec)
mysql> select date_add(now(), interval 1 minute);
+------------------------------------+
| date_add(now(), interval 1 minute) |
+------------------------------------+
| 2006-06-15 09:38:03 |
+------------------------------------+
1 row in set (0.00 sec)
1 row in set (0.05 sec)
0 0
- MySql中的数据类型转换注意事项
- 数据类型转换及注意事项
- mysql 索引注意事项:数据类型
- MySQL数据类型注意事项
- Mysql 关于数据类型注意事项
- MySQL数据类型:UNSIGNED注意事项
- mysql 配置注意事项、 mysql 数据类型
- Java中数据类型转换注意事项
- MySQL类型转换注意事项
- 显示转换中的注意事项
- Mysql 数据类型转换
- MySql 数据类型转换
- mysql 数据类型转换
- MySql数据类型隐形转换
- java中的数据类型转换
- VC中的数据类型转换
- EVC中的数据类型转换
- c++中的数据类型转换
- 动态链接库搜索路径
- usaco training 4.1.1 麦香牛块 题解
- 响应式设计百分比
- 肉汁小土豆
- 使用AXD调试u-boot
- MySql中的数据类型转换注意事项
- for 与while 的比较
- Java堆内存的10个要点
- Jmeter 监控器Plugins
- 《高效学习OpenGL》 之 读取和绘制像素矩形
- Oracle Transportable Tablespaces (TTS)
- 【九度】题目1547:出入栈
- Power Strings poj 2406 kmp的运用
- ios各种动画效果