Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

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    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...