gpt4 book ai didi

mysql - 存储过程变量未在 MySQL 中返回预期值?

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

我正在调试这段代码

create procedure create_view ( IN t varchar(50)) 
BEGIN
prepare stmt from 'select @cnt= count( weight ) from test where url = ?;';
execute stmt using @t;
set @base = @cnt /4;
set @offset = @cnt / 2;
set @query = concat('create or replace view view_by_url as select url, weight from test where url = ',@t,' order by weight limit ',@base,' , ',@offset,' ;');
select t as 'param';
select cnt as 'count';
select @base as 'base';
select @offset as 'offset';
select @query as 'query';
-- prepare stmt from @query;
-- execute stmt ;
END;
call create_view('a');

@t 在结果集中返回 'a' 但 @cnt、@base 和 @offset 不返回。我无法解释自己为什么。你能帮我一些忙吗?

最佳答案

在存储过程结束时尝试单个 SELECT:

  SELECT 
t as 'param',
@cnt as 'count',
@base as 'base',
@offset as 'offset',
@query as 'query';

关于mysql - 存储过程变量未在 MySQL 中返回预期值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7054054/

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