1
我調試的代碼存儲過程變量不在MySQL中返回期望值?
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沒有。我無法解釋自己爲什麼。你能給我一些幫助嗎?
不解決問題。不管怎麼說,還是要謝謝你。 – munch
@munch:聲明瞭@ cnt'?我看到你正在使用一個動態的SQL查詢,你有沒有聲明過它?如果沒有 - 嘗試在查詢之前聲明 – sll