H5W3
当前位置:H5W3 > 问答 > 正文

MySQL8.0如何创建存储过程(create procedure)

以下代码报错

# MySQL 8.0.21
# Workbench 8.0.21
select * FROM products;
CREATE  PROCEDURE  fn ()
BEGIN
select prod_id FROM products
END;

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4

回答

MySQL Shell 一样需要使用delimiter

# MySQL 8.0.21
# Workbench 8.0.21

delimiter //
CREATE  PROCEDURE  fn ()
BEGIN 
    select prod_id FROM products;
END
//
# 不加会影响到后续的单行执行
delimiter ;

call fn();

本文地址:H5W3 » MySQL8.0如何创建存储过程(create procedure)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址