欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL存储过程带in和out参数

程序员文章站 2022-04-30 16:34:53
...

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 MySQL存储过程带in和out参数 最简单的例子: [html] mysql DELIMITER $$ mysql USE test $$ Database changed mysql DROP PROCEDURE IF EXISTS `sp_add`$$ Query OK, 0 rows affected (0.00 sec) mysq

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  MySQL存储过程带in和out参数

  最简单的例子:

  [html]

  mysql> DELIMITER $$

  mysql> USE test $$

  Database changed

  mysql> DROP PROCEDURE IF EXISTS `sp_add`$$

  Query OK, 0 rows affected (0.00 sec)

  mysql> CREATE PROCEDURE sp_add(a INT, b INT,OUT c INT)

  -> BEGIN

  -> SET c=a+ b;

  -> END$$

  Query OK, 0 rows affected (0.00 sec)

  mysql> DELIMITER ;

  [html]

  mysql> CALL sp_add (1,2,@c);

  Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @c;

  +------+

  | @c |

  +------+

  | 3 |

  +------+

  1 row in set (0.00 sec)

  一个稍微复杂的例子:

  [html]

  mysql> show create table t_BillNo;

  +----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

  | Table | Create Table |

  +----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

  | t_BillNo | CREATE TABLE `t_billno` (

  `SaleNo` bigint(20) DEFAULT NULL,

  `bmh` varchar(20) DEFAULT NULL

  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC |

  +----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

  1 row in set (0.00 sec)

  mysql> select * from t_BillNo;

  +--------+------+

  | SaleNo | bmh |

  +--------+------+

  | 1 | 2 |

  | 4 | 3 |

  | 4 | 5 |

  | 7 | 7 |

  | 12 | 8 |

  +--------+------+

  5 rows in set (0.00 sec)

  mysql>

  mysql> DELIMITER $$

  mysql> USE test $$

  Database changed

  mysql> DROP PROCEDURE IF EXISTS `sp_GetMaxNumber`$$

  Query OK, 0 rows affected (0.01 sec)

  DELIMITER $$

  USE test $$

  DROP PROCEDURE IF EXISTS `sp_GetMaxNumber`$$

  CREATE PROCEDURE sp_GetMaxNumber (IN v_bmh VARCHAR(6), OUT v_MaxNo INT)

  BEGIN

[1] [2]

MySQL存储过程带in和out参数