奇怪!日期类型与任意字符串比较都能成功执行. querydatetime 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 MySQL 的文档 (Type Conversion in Expression Evaluation) 中提到,在做比较时,会按这样的规则进行必要的类型转换:两个参数至少有一个是 NULL 时,比较的结果也是 NULL,例外是使用 <=> 对两个 NULL 做比较时会返回 1,这两种情况都不需要做类型转换两个参数都是字符串,会按照字符串来比较,不做类型转换两个参数都是整数,按照整数来比较,不做类型转换十六进制的值和非数字做比较时,会被当做二进制串,和数字做比较时会按下面的规则处理有一个参数是 TIMESTAMP 或 DATETIME,并且另外一个参数是常量,常量会被转换为 timestamp有一个参数是 decimal 类型,如果另外一个参数是 decimal 或者整数,会将整数转换为 decimal 后进行比较,如果另外一个参数是浮点数,则会把 decimal 转换为浮点数进行比较所有其他情况下,两个参数都会被转换为浮点数再进行比较 mysql> show warnings;+---------+------+----------------------------------------------------------------------------+| Level | Code | Message |+---------+------+----------------------------------------------------------------------------+| Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_input_datetime' at row 1 || Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_input_datetime' at row 1 || Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_expect_datetime' at row 1 || Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_expect_datetime' at row 1 |+---------+------+----------------------------------------------------------------------------+4 rows in set (0.82 sec)这种不合法的日期格式会被当做什么值去处理,这个在文档、或者代码上有没有说明 MYSQL的源代码肯定有的。除非自己下载MYSQL源代码分析外,其实可以做个实现。 当 datatime 与 varchar 比较时会转换成什么。结论是转换成 char mysql> select convert('- -',char);+----------------------+| convert('- -',char) |+----------------------+| - - |+----------------------+1 row in set (0.77 sec)mysql> select convert('- -',datetime);+--------------------------+| convert('- -',datetime) |+--------------------------+| NULL |+--------------------------+1 row in set, 1 warning (0.14 sec)mysql> show warnings;+---------+------+----------------------------------+| Level | Code | Message |+---------+------+----------------------------------+| Warning | 1292 | Incorrect datetime value: '- -' |+---------+------+----------------------------------+1 row in set (0.02 sec)可不可以这么理解:SELECTcreate_time,create_user_id,gen_method,inh_approve_datetime,inh_approve_user_id,inh_expect_datetime,inh_finish_datetime,inh_finish_user_id,inh_id,inh_input_datetime,inh_input_user_id,inh_notice_no,inh_org_id,inh_owner_id,inh_owner_no,inh_re,inh_status,inh_total_cubage,inh_total_gross_weight,inh_total_money,inh_total_net_weight,inh_total_packs,inh_tx_type_id,inh_vendor_id,update_time,update_user_id,version_numberFROMriv_inbound_notice_hWHERE inh_notice_no = 'ASN20150220000002'AND inh_input_datetime >= nullAND inh_input_datetime <= nullAND inh_expect_datetime >= nullAND inh_expect_datetime <= null ORDER BYupdate_time DESC 数据库个别字段乱码 颜色标出的部分,有什么办法可以整合到一起 mysql最大能存储多少条记录?每条能容许多少k的数据? insert MySQL数据丢失的问题。(libmysql API) 怎么能够比较两个Mysql数据库在结构上有什么差异? 数据分段显示? 哪位能提供MySQLAdmin_v1.0.6的注册代码 myql 类似bulkcopy 之类的批量插入功能 mysql 把两个查询结果放一起输入,如何写,用left join行吗 求教一个去重的SQL 求高手 ,树状结构数据怎么插入MYSQL数据库 奇怪!where 条件中日期类型字段与任意的字符串都可以比较!
两个参数都是字符串,会按照字符串来比较,不做类型转换
两个参数都是整数,按照整数来比较,不做类型转换
十六进制的值和非数字做比较时,会被当做二进制串,和数字做比较时会按下面的规则处理
有一个参数是 TIMESTAMP 或 DATETIME,并且另外一个参数是常量,常量会被转换为 timestamp
有一个参数是 decimal 类型,如果另外一个参数是 decimal 或者整数,会将整数转换为 decimal 后进行比较,如果另外一个参数是浮点数,则会把 decimal 转换为浮点数进行比较
所有其他情况下,两个参数都会被转换为浮点数再进行比较
+---------+------+----------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------------------------------+
| Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_input_datetime' at row 1 |
| Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_input_datetime' at row 1 |
| Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_expect_datetime' at row 1 |
| Warning | 1292 | Incorrect datetime value: '- -' for column 'inh_expect_datetime' at row 1 |
+---------+------+----------------------------------------------------------------------------+
4 rows in set (0.82 sec)
这种不合法的日期格式会被当做什么值去处理,这个在文档、或者代码上有没有说明
除非自己下载MYSQL源代码分析外,其实可以做个实现。 当 datatime 与 varchar 比较时会转换成什么。结论是转换成 char
+----------------------+
| convert('- -',char) |
+----------------------+
| - - |
+----------------------+
1 row in set (0.77 sec)mysql> select convert('- -',datetime);
+--------------------------+
| convert('- -',datetime) |
+--------------------------+
| NULL |
+--------------------------+
1 row in set, 1 warning (0.14 sec)mysql> show warnings;
+---------+------+----------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------+
| Warning | 1292 | Incorrect datetime value: '- -' |
+---------+------+----------------------------------+
1 row in set (0.02 sec)可不可以这么理解:SELECT
create_time,
create_user_id,
gen_method,
inh_approve_datetime,
inh_approve_user_id,
inh_expect_datetime,
inh_finish_datetime,
inh_finish_user_id,
inh_id,
inh_input_datetime,
inh_input_user_id,
inh_notice_no,
inh_org_id,
inh_owner_id,
inh_owner_no,
inh_re,
inh_status,
inh_total_cubage,
inh_total_gross_weight,
inh_total_money,
inh_total_net_weight,
inh_total_packs,
inh_tx_type_id,
inh_vendor_id,
update_time,
update_user_id,
version_number
FROM
riv_inbound_notice_h
WHERE inh_notice_no = 'ASN20150220000002'
AND inh_input_datetime >= null
AND inh_input_datetime <= null
AND inh_expect_datetime >= null
AND inh_expect_datetime <= null
ORDER BY
update_time DESC