Bug #12938 Stored procedures: DECIMAL arithmetic in a loop fails
Submitted: 1 Sep 2005 21:17 Modified: 14 Sep 2005 0:29
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.12-beta-debug/BK source OS:Linux (SUSE 9.2)
Assigned to: Alexey Botchkov CPU Architecture:Any

[1 Sep 2005 21:17] Peter Gulutzan
Description:
If x = 0, if I multiply x * 10 eight times, I get zero. If I multiply x * 10 nine times, I get NULL.
This happens only if x is described as a DECIMAL variable in a stored procedure.

How to repeat:
mysql> delimiter //
mysql> create procedure wg2 () begin declare v int default 1; declare tdec decimal(5) default 0; while v <= 9 do set tdec =tdec * 10; select v, tdec; set v = v + 1; end while; end//
Query OK, 0 rows affected (0.00 sec)

mysql> call wg2()//
+---+------+
| v | tdec |
+---+------+
| 1 |    0 |
+---+------+
1 row in set (0.00 sec)

+---+------+
| v | tdec |
+---+------+
| 2 |    0 |
+---+------+
1 row in set (0.00 sec)

+---+------+
| v | tdec |
+---+------+
| 3 |    0 |
+---+------+
1 row in set (0.00 sec)

+---+------+
| v | tdec |
+---+------+
| 4 |    0 |
+---+------+
1 row in set (0.00 sec)

+---+------+
| v | tdec |
+---+------+
| 5 |    0 |
+---+------+
1 row in set (0.00 sec)

+---+------+
| v | tdec |
+---+------+
| 6 |    0 |
+---+------+
1 row in set (0.00 sec)

+---+------+
| v | tdec |
+---+------+
| 7 |    0 |
+---+------+
1 row in set (0.01 sec)

+---+------+
| v | tdec |
+---+------+
| 8 |    0 |
+---+------+
1 row in set (0.01 sec)

+---+------+
| v | tdec |
+---+------+
| 9 | NULL |
+---+------+
1 row in set (0.01 sec)

Query OK, 0 rows affected, 1 warning (0.01 sec)
[4 Sep 2005 15:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/29295
[8 Sep 2005 11:24] Alexey Botchkov
5.0.13
[14 Sep 2005 0:29] Paul DuBois
Noted in 5.0.13 changelog.