我的存储过程有问题(在 MySQL 上)。如果记录存在,我需要表的数据更新过程,否则插入记录。我有:
DELIMITER //
CREATE PROCEDURE saveorUpdate(in product varchar(30), price int, stock int, active varchar(5))
BEGIN
DECLARE id int;
SELECT id_pro FROM products WHERE product=product into id;
IF(id_pro=id)THEN
UPDATE products SET product=product, price=price, stock=stock, active=active
WHERE id_pro=id;
ELSE
INSERT INTO products (product, price, stock, active) VALUES
(product, price, stock, active);
END IF;
END
有任何想法吗?