MySQL 如何更改mysql中的存储过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13970258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:52:01  来源:igfitidea点击:

How to Alter a stored procedure in mysql

mysql

提问by Tejaswi

How to Alter a stored procedurein Mysql.

如何改变一个存储过程mysql的

DROP PROCEDURE IF EXISTS sp_Country_UPDATE; 
CREATE PROCEDURE sp_Country_UPDATE 
  ( IN p_CountryId int, 
    IN p_CountryName nvarchar(25), 
    IN p_CountryDescription nvarchar(25), 
    IN p_IsActive bit, 
    IN p_IsDeleted bit ) 
  UPDATE 
    Country 
  SET 
    CountryName = p_CountryName , 
    CountryDescription=p_CountryDescription, 
    IsActive= p_IsActive, 
    IsDeleted=p_IsDeleted 
  WHERE 
    CountryId = p_CountryId ;

How to alter this Stored Procedure?

如何更改此存储过程?

回答by Pete

If you mean you want to edit the Procedure, then you can't according to the MySQL docs:

如果您的意思是要编辑程序,则不能根据 MySQL 文档:

This statement can be used to change the characteristics of a stored procedure. More than one change may be specified in an ALTER PROCEDURE statement. However, you cannot change the parameters or body of a stored procedure using this statement; to make such changes, you must drop and re-create the procedure using DROP PROCEDURE and CREATE PROCEDURE.

此语句可用于更改存储过程的特性。在 ALTER PROCEDURE 语句中可以指定多个更改。但是,您不能使用此语句更改存储过程的参数或主体;要进行此类更改,您必须删除并使用 DROP PROCEDURE 和 CREATE PROCEDURE 重新创建过程。

The Altersyntax lets you change the "characteristics" but not the actual procedure itself

Alter语法允许您更改“特色”,而不是实际的过程本身

http://dev.mysql.com/doc/refman/5.0/en/alter-procedure.html

http://dev.mysql.com/doc/refman/5.0/en/alter-procedure.html

Here's an example of creating, Altering (the comment) then dropping and recreating:

这是创建、更改(注释)然后删除和重新创建的示例:

DROP PROCEDURE myFunc;

DELIMITER //

CREATE PROCEDURE myFunc ()
COMMENT 'test'
BEGIN
SELECT 5;
END //

DELIMITER ;

ALTER PROCEDURE myFunc
COMMENT 'new comment';

CALL myFunc();

DROP PROCEDURE myFunc;

DELIMITER //

CREATE PROCEDURE myFunc ()
COMMENT 'last time'
BEGIN
SELECT 6;
END //

DELIMITER ;

CALL myFunc();

The above CALL myFunc()statments would return 5 and then 6.

上述CALL myFunc()语句将返回 5 和 6。

Viewing the stored procedure would show a comment of "test", "new comment" or "last time" depending on when you viewed the Procedure body (I'm not sure how to view the comments via the CLI but I can see them in the functionstab in Navicat)

查看存储过程会显示“测试”、“新评论”或“上次”的评论,具体取决于您查看过程正文的时间(我不确定如何通过 CLI 查看评论,但我可以在Navicat 中的功能选项卡)

回答by SagarPPanchal

ALTER PROCEDURE proc_name [characteristic ...]

characteristic:
    COMMENT 'string'
  | LANGUAGE SQL
  | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
  | SQL SECURITY { DEFINER | INVOKER }

回答by Riz

This is how you Create

这就是你创建的方式

CREATE PROCEDURE GetAllProducts()
BEGIN
SELECT *  FROM products;
END //

This is how you Alter

这就是你改变的方式

Alter PROCEDURE GetAllProducts()
BEGIN
SELECT *  FROM products;
END //