If function behave differently in MySQL 5.5.49 I'm running MySQL 5.5.49 on my Windows 7 32-bit

I'm using a stored procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_testing`(
IN in_param VARCHAR(50)
, OUT out_1 VARCHAR(50)
)
BEGIN

    DECLARE v_no_por_cabang VARCHAR(50);
    DECLARE v_no_por_cabang1 VARCHAR(50);
    DECLARE v_no_por_cabang2 VARCHAR(50);

    SET v_no_por_cabang = in_param;

    SET v_no_por_cabang1 = IF(v_no_por_cabang = 0, NULL, v_no_por_cabang); 

    SET v_no_por_cabang2 = IF(v_no_por_cabang = '0', NULL, v_no_por_cabang); 

    SELECT v_no_por_cabang1;
    SELECT v_no_por_cabang2;

END$$


and I'm calling it like this:

CALL sp_testing('POR1',@out1);


The output for v_no_por_cabang1 is NULL. The output for v_no_por_cabang2 is POR1.

Why does the IF function behave like that? In my previous test in MySQL 5.5.xx on Ubuntu 12 the same stored procedure didn't behave like that. It returned POR1 for v_no_por_cabang1.

Anybody know why?
It's because in the comparison v_no_por_cabang = 0 you're converting v_no_por_cabang implicitly to a number. When you use single-quotes like in v_no_por_cabang = '0' you're correctly comparing two strings.

MySQL also tells you so, when you execute show warnings; afterwards. Result:

+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: 'POR1' |
+---------+------+------------------------------------------+


Fun fact: When your string starts with a number, MySQL converts the first number part of the string to a number.

root@localhost:playground &gt; CALL sp_testing('1POR1',@out1);

+------------------+
| v_no_por_cabang1 |
+------------------+
| 1POR1            |
+------------------+
1 row in set (0.01 sec)

+------------------+
| v_no_por_cabang2 |
+------------------+
| 1POR1            |
+------------------+
1 row in set (0.01 sec)

Query OK, 0 rows affected, 1 warning (0.01 sec)

root@localhost:playground &gt; CALL sp_testing('0POR1',@out1);
+------------------+
| v_no_por_cabang1 |
+------------------+
| NULL             |
+------------------+
1 row in set (0.00 sec)

+------------------+
| v_no_por_cabang2 |
+------------------+
| 0POR1            |
+------------------+
1 row in set (0.00 sec)