gpt4 book ai didi

mysql - MySQL 存储过程的 INOUT 示例

转载 作者:行者123 更新时间:2023-11-29 03:50:45 24 4
gpt4 key购买 nike

能否给我一个MySQL存储过程中INOUT的简单例子?

最佳答案

我认为搜索 Google 会为您提供大量示例!!
一个(取自here)

DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`get_users` $$
CREATE PROCEDURE `get_users`(
IN firstName VARCHAR(100),
OUT totalUsers INT
)
BEGIN
SELECT COUNT(*) INTO totalUsers
FROM users
WHERE first_name = firstName;
SELECT * FROM users
WHERE first_name = firstName;
END $$
DELIMITER ;

帖子说:

Notice there are two statements in the body of this stored procedure. The first select count(*) statement counts the total number of people who’s first name is equal to the in variable firstName. Once it’s gets the count, it sets the out variable totalUsers to that value.

The next statement is a simple select. This will select all fields for users who’s first name is equal to the in variable firstName and return the recordset. So by calling this stored procedure and passing in two parameters (first name, total), a recordset will be returned and an out variable will be set – that can then be queried.

已编辑:
MySQL website :

CREATE PROCEDURE p (OUT ver_param VARCHAR(25), INOUT incr_param INT)
BEGIN
# Set value of OUT parameter
SELECT VERSION() INTO ver_param;
# Increment value of INOUT parameter
SET incr_param = incr_param + 1;
END;

关于mysql - MySQL 存储过程的 INOUT 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9579058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com