mysqldude

Basic hash jumbler function

Version compatibility

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
CREATE FUNCTION (NOT DETERMINISTIC, NO SQL) and call it (original)
original post
✓✗ 1366✗ 1366✗ 1366✗ 1366✗ 1366✗ 1366✗ 1366✗ 1366
Same function without NO SQL / DETERMINISTIC (does binlog default trigger 1418?)
version check
✓✓✗ 1418✗ 1418✗ 1418✓✓✓✓
CREATE FUNCTION (NOT DETERMINISTIC, NO SQL) and call it (original) original post
MySQL 5.6✓5.7✗ 13668.0✗ 13668.4✗ 13669✗ 1366
MariaDB 10.6✗ 136610.11✗ 136611.4✗ 136611.8✗ 1366
Same function without NO SQL / DETERMINISTIC (does binlog default trigger 1418?) version check
MySQL 5.6✓5.7✓8.0✗ 14188.4✗ 14189✗ 1418
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-23 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (4)
  • CREATE FUNCTION (NOT DETERMINISTIC, NO SQL) and call it (original) (MySQL 5.7, MySQL 8.0, MySQL 8.4, MySQL 9): error 1366: Incorrect integer value: '' for column 'lNumber' at row 1
  • CREATE FUNCTION (NOT DETERMINISTIC, NO SQL) and call it (original) (MariaDB 10.6): error 1366: Incorrect integer value: '' for column ``.``.`lNumber` at row 1
  • CREATE FUNCTION (NOT DETERMINISTIC, NO SQL) and call it (original) (MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): error 1366: Incorrect integer value: '' for column ``.``.`lNumber` at row 0
  • Same function without NO SQL / DETERMINISTIC (does binlog default trigger 1418?) (MySQL 8.0, MySQL 8.4, MySQL 9): error 1418: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_cr

Related errors: 1418

The original article

First published 2012-10-04. The text below is the original; the table above shows how it behaves on current versions.

There are times when we need to mask some information. This can be achieved easily using some kind of hashing function which will reverse back to original if we re-run the basic hash function with the hashed out value.

This is a small white paper which shows a basic function which can achieve this. The function simply transposes each number to another number. The number transposed is fully reversible. In other words, 1 will become 2 and 2 will become 1.

DROP FUNCTION IF EXISTS jumbler;
DELIMITER $$
CREATE FUNCTION jumbler(pNumber VARCHAR(20))
RETURNS VARCHAR(20)
NOT DETERMINISTIC
SQL SECURITY INVOKER
NO SQL
BEGIN
	DECLARE lRes VARCHAR(20) DEFAULT '';
	DECLARE lMod VARCHAR(1);
	DECLARE lNew INTEGER;
	DECLARE lNumber INTEGER;

	SET lNumber := pNumber;
	WHILE lNumber > 0 DO
		SET lMod := RIGHT(lNumber,1);
		CASE lMod
		WHEN '0' THEN SET lRes := CONCAT(lRes, '4');
		WHEN '4' THEN SET lRes := CONCAT(lRes, '0');
		WHEN '1' THEN SET lRes := CONCAT(lRes, '8');
		WHEN '8' THEN SET lRes := CONCAT(lRes, '1');
		WHEN '2' THEN SET lRes := CONCAT(lRes, '3');
		WHEN '3' THEN SET lRes := CONCAT(lRes, '2');
		WHEN '6' THEN SET lRes := CONCAT(lRes, '9');
		WHEN '9' THEN SET lRes := CONCAT(lRes, '6');
		WHEN '5' THEN SET lRes := CONCAT(lRes, '7');
		WHEN '7' THEN SET lRes := CONCAT(lRes, '5');
		END CASE;
		SET lNumber := LEFT(lNumber,LENGTH(lNumber)-1);
	END WHILE;
	RETURN lRes;
END;
$$
DELIMITER ;

Here it is in action. This is simply to demonstrate how something like this is possible. One should look more closely at a more suitable function.

mysql> select jumbler(12345);
+----------------+
| jumbler(12345) |
+----------------+
| 70238          |
+----------------+
1 row in set, 1 warning (0.00 sec)

mysql> select jumbler(70238);
+----------------+
| jumbler(70238) |
+----------------+
| 12345          |
+----------------+
1 row in set, 1 warning (0.00 sec)

mysql> select jumbler(270238);
+-----------------+
| jumbler(270238) |
+-----------------+
| 123453          |
+-----------------+
1 row in set, 1 warning (0.00 sec)

mysql> select jumbler(2702382);
+------------------+
| jumbler(2702382) |
+------------------+
| 3123453          |
+------------------+
1 row in set, 1 warning (0.00 sec)

mysql> select jumbler(3123453);
+------------------+
| jumbler(3123453) |
+------------------+
| 2702382          |
+------------------+
1 row in set, 1 warning (0.00 sec)