MySQL Forums
Forum List  »  Newbie

Re: How to solve mysql data type convert exception
Posted by: karl ye
Date: July 19, 2015 11:35PM

mysql> select cast('7abc' as signed);
+------------------------+
| cast('7abc' as signed) |
+------------------------+
| 7 |
+------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+-------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '7abc' |
+---------+------+-------------------------------------------+
1 row in set (0.00 sec)

=============================================================================
Explication: cast('7abc' as signed) will convert '7abc' to int, but only '7' of '7abc' will convert to int, 'abc' will be truncated, so the result is 7

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.