How to Alter a stored procedure in 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?
如何更改此存储过程?
3 个解决方案
#1
8
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 Alter
syntaax lets you change the "characteristics" but not the actual procedure itself
Alter syntaax允许您更改“特征”,但不能更改实际过程本身
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 functions tab in Navicat)
查看存储过程会显示“test”,“new comment”或“last time”的注释,具体取决于您查看过程主体的时间(我不知道如何通过CLI查看注释,但我可以在Navicat中的函数选项卡)
#2
0
ALTER PROCEDURE proc_name [characteristic ...]
characteristic:
COMMENT 'string'
| LANGUAGE SQL
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
#3
-3
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 //
#1
8
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 Alter
syntaax lets you change the "characteristics" but not the actual procedure itself
Alter syntaax允许您更改“特征”,但不能更改实际过程本身
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 functions tab in Navicat)
查看存储过程会显示“test”,“new comment”或“last time”的注释,具体取决于您查看过程主体的时间(我不知道如何通过CLI查看注释,但我可以在Navicat中的函数选项卡)
#2
0
ALTER PROCEDURE proc_name [characteristic ...]
characteristic:
COMMENT 'string'
| LANGUAGE SQL
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
#3
-3
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 //