gpt4 book ai didi

MySQL 错误 1064 : near NULL at line 1

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

我一直在努力弄清楚我在 beloe 程序中做错了什么

CREATE  PROCEDURE `example`(IN col_n char(50),IN p_cont char(50),IN p_ud int)
BEGIN

set @S = CONCAT('select rn.emp_id as emp_id,controller,perma,permb,permc,permd,order from emp n
join resource_emp rn on rn.emp_id = n.emp_id
join resource r on r.resource_id = rn.resource_id
join u_resource ur on ur.resource_id = r.resource_id
join user u on u.u_id = ur.ur_id
join(
select title,min(order) as pr from emp n
join resource_emp rn on rn.emp_id = n.emp_id
join resource r on r.resource_id = rn.resource_id
join u_resource ur on ur.resource_id = r.resource_id
join user u on u.u_id = ur.ur_id
where u.u_id = ',@p_ud,' group by title)a on a.title = n.title and a.pr = order
where u.u_id = ',@p_ud,' n.con = ''',@p_cont,''' and ,@col_n,' = 1
group by n.title order by n.order');

PREPARE stmt1 FROM @S;

EXECUTE stmt1;

DEALLOCATE PREPARE stmt1;
END

我正在尝试执行下面的过程但出现错误

call hop_thlc_t.auth('perma', 'submit', 2);

错误代码:1064。您的 SQL 语法有误;检查与您的 MySQL 服务器版本对应的手册,了解在第 1 行的“NULL”附近使用的正确语法

虽然发生这种情况,但我仍然可以通过使用以下参数将上述过程作为查询运行来执行相同的操作并获得所需的结果

 set @col_n ='perma';
set @p_cont = 'submit' ;
set @p_ud =2;

感谢任何解决问题的帮助

最佳答案

正如 Sami Kuhmonen 在评论中建议的那样,只需将作为过程参数的变量的 @ 去掉即可。

存储过程中的局部变量名称前没有@。如果您使用像 @col_n 这样的变量,它与 col_n 不是同一个变量,后者是您的过程参数的变量。

带有@ 的变量称为Session Variables .它们的作用域超出了您的存储过程。您发现可以在调用过程之前设置该值。同样,如果您在过程中设置此变量的值,它在您的过程返回后仍将具有该值。

我在这里的回答中发布了一个演示:https://stackoverflow.com/a/41925146/20860

不幸的是,每条规则都有异常(exception)。当您使用 PREPARE 时,您必须使用 session 变量。局部变量不适用于 PREPARE

关于MySQL 错误 1064 : near NULL at line 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42172688/

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