当我使用 delete 语句时,我的程序删除了所有行
My procedure deletes all rows when I use delete statement
那是我的 table:
create table if not exists Ditte(nome varchar(30), luogo varchar(30), ZIP int);
这是我的程序:
delimiter //
create procedure deleteDitta(zip int)
begin
DECLARE newZIP int;
SET newZIP = zip;
DELETE from Ditte where ZIP = newZIP;
end;
//
delimiter ;
这是我在 table 中添加的内容:
insert ignore into Ditte values ("Ditta1", "city1", 6828);
insert ignore into Ditte values ("Ditta2", "city2", 12345);
当我调用我的程序 deleteDitta
并将“12345”作为参数(如下所示:call deleteDitta(12345);
)时,该程序应该只删除 table 中的第二行 "Ditte",但是它删除了table的所有内容。
我该如何解决?
这似乎是 MySQL 对列名和变量名感到困惑。将您的过程更改为此可以解决问题:
create procedure deleteDitta(dzip int)
begin
DELETE from Ditte where ZIP = dzip;
end;
那是我的 table:
create table if not exists Ditte(nome varchar(30), luogo varchar(30), ZIP int);
这是我的程序:
delimiter //
create procedure deleteDitta(zip int)
begin
DECLARE newZIP int;
SET newZIP = zip;
DELETE from Ditte where ZIP = newZIP;
end;
//
delimiter ;
这是我在 table 中添加的内容:
insert ignore into Ditte values ("Ditta1", "city1", 6828);
insert ignore into Ditte values ("Ditta2", "city2", 12345);
当我调用我的程序 deleteDitta
并将“12345”作为参数(如下所示:call deleteDitta(12345);
)时,该程序应该只删除 table 中的第二行 "Ditte",但是它删除了table的所有内容。
我该如何解决?
这似乎是 MySQL 对列名和变量名感到困惑。将您的过程更改为此可以解决问题:
create procedure deleteDitta(dzip int)
begin
DELETE from Ditte where ZIP = dzip;
end;