创建存储过程以查看 MYSQL 中的数据时出错
Error when creating stored procedure to view data in MYSQL
我在处理这个存储过程的语法时遇到了很多麻烦,它应该return 来自一个名为 Country 的 table 的所有信息,并试图使用一个参数进行比较:
Create Procedure CountrybyPK (country char(50))
begin
Select * From Country
Where Country.Name=country
end;
我得到的错误状态:
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 'end' at line 5
您需要在 SELECT
语句和 END
之间使用语句分隔符。
Create Procedure CountrybyPK (country char(50))
begin
Select * From Country
Where Country.Name=country;
end;
但是由于分隔符也会终止整个程序,因此您需要使用 DELIMITER
命令切换到另一个分隔符:
DELIMITER $$
Create Procedure CountrybyPK (country char(50))
begin
Select * From Country
Where Country.Name=country;
end$$
但是因为你的过程只有一个语句,所以你根本不需要 begin
和 end
,你可以这样做:
Create Procedure CountrybyPK (country char(50))
Select * From Country
Where Country.Name=country;
我在处理这个存储过程的语法时遇到了很多麻烦,它应该return 来自一个名为 Country 的 table 的所有信息,并试图使用一个参数进行比较:
Create Procedure CountrybyPK (country char(50))
begin
Select * From Country
Where Country.Name=country
end;
我得到的错误状态:
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 'end' at line 5
您需要在 SELECT
语句和 END
之间使用语句分隔符。
Create Procedure CountrybyPK (country char(50))
begin
Select * From Country
Where Country.Name=country;
end;
但是由于分隔符也会终止整个程序,因此您需要使用 DELIMITER
命令切换到另一个分隔符:
DELIMITER $$
Create Procedure CountrybyPK (country char(50))
begin
Select * From Country
Where Country.Name=country;
end$$
但是因为你的过程只有一个语句,所以你根本不需要 begin
和 end
,你可以这样做:
Create Procedure CountrybyPK (country char(50))
Select * From Country
Where Country.Name=country;