[英]Flexible Update Stored Procedure Mysql
I am looking for a flexible update stored procedure. 我正在寻找一种灵活的更新存储过程。 I made this one. 我做了这个。 When i call this CALL spUpdatePage(1,'a','b','c''d') it works fine. 当我将此调用称为spUpdatePage(1,'a','b','c'd')时,它可以正常工作。
Do i have to pass always in this example 5 params? 在此示例中,我是否必须始终通过5个参数?
Can i also do this 我也可以这样做吗
CALL spUpdatePage(1,'a','c')
and that the stored procedure knows that i only want to update the columns name and description? 并且该存储过程知道我只想更新列的名称和描述?
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUpdatePage`(
IN `pKey` INT(4),
IN `name` VARCHAR(255),
IN `title` VARCHAR(255),
IN `description` VARCHAR(255),
IN `keywords` VARCHAR(255))
UPDATE
pages
SET
name = COALESCE(name, name),
title = COALESCE(title, title),
description = COALESCE(description, description),
keywords = COALESCE(keywords, keywords)
WHERE
id = pKey
Do I have to pass always in this example 5 params? 在此示例中,我是否必须始终通过5个参数?
Can I also do this? 我也可以这样做吗?
CALL spUpdatePage(1,'a','c')
For your posted stored procedure, you must pass all 5 parameters. 对于发布的存储过程,必须传递所有5个参数。 No, you can't just pass name
and description
(to your posted stored procedure). 不,您不能仅将name
和description
(传递到您发布的存储过程中)。 However, you could write a stored procedure that only updates name
and description
. 但是,您可以编写一个仅更新name
和description
的存储过程。 Something like, 就像是,
CREATE DEFINER=`root`@`localhost` PROCEDURE `spUpdatePageNameTitle`(
IN `pKey` INT(4),
IN `name` VARCHAR(255),
IN `title` VARCHAR(255))
UPDATE
pages
SET
name = COALESCE(name, name),
title = COALESCE(title, title)
WHERE
id = pKey
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.