Strange behaviour on stored procedure

I have the following mysql stored procedure:

DELIMITER // CREATE PROCEDURE INSERT_INTO_WORKDAY(IN deviceName VARCHAR(16), IN cardUID VARCHAR(14))  BEGIN     SET @projectId = (SELECT MIN(ID) FROM PROJECT WHERE DEVICEID = (SELECT MIN(ID) FROM DEVICE WHERE NAME = deviceName) ORDER BY ID DESC LIMIT 1);     SET @workerId = (SELECT MIN(ID) FROM WORKER WHERE CARDNUMBER = cardUID);     SELECT @workerId;          SET @id = (SELECT MIN(ID) FROM WORKDAY WHERE WORKERID = @workerId AND PROJECTID = @projectId AND STOPTIME IS NULL AND STARTTIME IS NOT NULL);     IF (@id >= 0)         THEN             UPDATE WORKDAY SET STOPTIME = now() WHERE ID = @id;     ELSE         INSERT INTO WORKDAY (WORKERID, PROJECTID, STARTTIME) VALUES (@workerId, @projectId, now());     END IF; END; // DELIMITER ; 

When I call the procedure once, I get the result:

mysql> CALL INSERT_INTO_WORKDAY("Pepper_C1-1A6318", "045D91B22C5E80"); +-----------+ | @workerId | +-----------+ |         1 | +-----------+ 1 row in set (0.01 sec)  Query OK, 1 row affected (0.09 sec) 

From second run, is not working anymore:

mysql> CALL INSERT_INTO_WORKDAY("Pepper_C1-1A6318", "045D91B22C5E80"); +-----------+ | @workerId | +-----------+ |      NULL | +-----------+ 1 row in set (0.00 sec)  ERROR 1048 (23000): Column 'WORKERID' cannot be null 

I did try to isolate and run the procedure with only this two lines of code:

    SET @workerId = (SELECT MIN(ID) FROM WORKER WHERE CARDNUMBER = cardUID);     SELECT @workerId; 

And it behaves just like above, but if I try to run SELECT MIN(ID) FROM WORKER WHERE CARDNUMBER = "045D91B22C5E80"; alone, works without problems. The @projectId variable behaves normal everytime I call the stored procedure.

Can someone help me to find a solution? Thank you!

My setup:

mihai:~$   mysql -V mysql  Ver 8.0.22-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu)) 
mysql> describe WORKER; +------------+-------------+------+-----+---------+----------------+ | Field      | Type        | Null | Key | Default | Extra          | +------------+-------------+------+-----+---------+----------------+ | ID         | int         | NO   | PRI | NULL    | auto_increment | | FIRSTNAME  | varchar(15) | NO   |     | NULL    |                | | LASTNAME   | varchar(20) | NO   |     | NULL    |                | | CARDNUMBER | varchar(14) | NO   |     | NULL    |                | | POSITIONID | int         | NO   | MUL | NULL    |                | +------------+-------------+------+-----+---------+----------------+ 5 rows in set (0.01 sec)