MYSQL procedures

1
delimiter //

create procedure elimdato(in id_emple int(6),cp varchar(5))

begin

DELETE FROM empleado WHERE cp=cp;
end //

call elimdato(1,40855);

At the time of executing this procedure, I delete all the information of the table used, I would like to know how to delete only the specified data from the column.

    
asked by Daniel Horta 31.05.2018 в 03:00
source

1 answer

1

The problem occurs because you have a field called cp and you have also created a local variable in MySQL that has the same name. This in MySql is an error since the manager ends up interpreting the reference to the field of the table as the newly created variable.

Where cp=cp

You are interpreting it as the cp field of the table used, equal to cp , which is the locally defined variable for the stored procedure.

Now MySql "understands" it as the local variable defined cp is equal to the defined variable cp

You solve your problem by changing the name of your local variable to another one. For example:

delimiter //

create procedure elimdato(in id_emple int(6),nocp varchar(5))

begin

DELETE FROM empleado WHERE cp=nocp;
end //

call elimdato(1,40855);

I hope it helps. A greeting!

    
answered by 31.05.2018 / 03:15
source