Mysql Error - Stored Procedures

Asked

Viewed 65 times

1

I am creating this process to run once a day, as I have no experience, I got an error in the code below:

    CREATE (definer omitido) PROCEDURE `MULTAOFF`()
    BEGIN 


    set @multado = (select `CPFAluno` from multa where `dataMultaFim` <= 
    CURDATE());

    update aluno set `StatusAluno` = '0' where @multado IN (`CPF`) and 
    StatusAluno = '2';

    END

As a result of calling Call MULTAOFF(); I have the following error:

Error Code: 1242. Subquery returns more than 1 row

What’s going on and how I can fix it?

  • You’re trying to update Status, but you’re also indicating that the WHERE clause takes Status where the CPF and the student’s Status is 2, so you can’t update and use Where with the same field. Change your WHERE clause

1 answer

1


Your error is in your subquery, so try to change your previous one this way.

CREATE (definer omitido) PROCEDURE `MULTAOFF`()
BEGIN 

UPDATE aluno SET `StatusAluno` = '0' where  CPF and 
StatusAlunos IN (select `CPFAluno` from multa where `dataMultaFim` <= 
CURDATE());

END

Browser other questions tagged

You are not signed in. Login or sign up in order to post.