Below is what I have in table myTable
+++++++++++++++
+ id + myWord +
+++++++++++++++
+ 1 + AB123 +
+ 2 + A413D +
+ 3 + X5231 +
+ 4 + ABE
If you do this often with MySQL, you better make a Stored Function using the string functions SUBSTRING() and ASCII().
DELIMITER //;
CREATE FUNCTION find_first_int(pData CHAR(10))
RETURNS INT
BEGIN
DECLARE vPos INT DEFAULT 1;
DECLARE vRes INT DEFAULT 0;
DECLARE vChar INT;
WHILE vPos <= LENGTH(pData) DO
SET vChar = ASCII(SUBSTR(pData, vPos, 1));
IF vChar BETWEEN 48 AND 57 THEN
RETURN vPos;
END IF;
SET vPos = vPos + 1;
END WHILE;
RETURN NULL;
END//
DELIMITER ;//
The result:
mysql> SELECT id, myWord, find_first_int(myWord) AS myPos FROM t1;
+------+--------+-------+
| id | myWord | myPos |
+------+--------+-------+
| 1 | AB123 | 3 |
| 2 | A413D | 2 |
| 3 | X5231 | 2 |
| 4 | ABE921 | 4 |
| 5 | ABC | NULL |
+------+--------+-------+
The NULL result can be changed using the function IFNULL().
Note that the function only accepts CHAR(10), so you might want to change that for longer data.