gpt4 book ai didi

mysql - 我在 sql 的存储过程中遇到带有下划线的语法错误

转载 作者:行者123 更新时间:2023-11-29 09:31:11 25 4
gpt4 key购买 nike

String insertStoredProcedure = "BEGIN " + 
"SELECT COUNT(p.PassengerID) " +
"INTO numpeople " +
"FROM tripcodes as tc " +
"INNER JOIN trip_directory as td on tc.tripType = td.tripType " +
"INNER JOIN trip t on td.tripnum = t.tripnum " +
"INNER JOIN locations as loc on t.departureloccode = loc.locationcode " +
"INNER JOIN trip_people as tp on t.date = tp.date AND t.tripnum=tp.tripnum " +
"INNER JOIN passenger as p on tp.passengerid = p.passengerid " +
"WHERE tc.typename = transportation; " +
"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 'SELECT COUNT(p.PassengerID) INTO numpeople FROM tripcodes as tc INNER JOIN trip_' at line 1"

我不太确定如何解决这个问题,如果有人可以帮助我,我将非常感激。谢谢!

最佳答案

在MySQL中,BEGIN/END用于编程 block 。编程 block 并不简单地存在。它们必须是某些存储程序的一部分。我想到的是:

  • 存储过程
  • 用户定义的函数
  • 程序

如果您想要一个存储过程(如标题所示),那么您需要 CREATE PROCEDURE 。 。 .BEGIN之前。

您的代码不需要存储过程。我建议删除 BEGINENDINTO。只需执行查询并读取结果集即可。

关于mysql - 我在 sql 的存储过程中遇到带有下划线的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58684034/

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