SET @im := (SELECT items->"$.one" From fruits where id = 12);
//it's working and saved result into @im variable
但我需要用函数中的变量来获取它 我尝试过但失败了.. 我尝试了 concat,它也不起作用, 我尝试准备执行 stmt,它也不起作用。
SET @p := "one";
SET @im := (SELECT items->"$."@p From fruits where id = 12);
//it's not working
"$.one" ==> "$."@p
//difference..
帮帮我,有什么办法可以得到这个..
最佳答案
尝试一下这个方法,应该可行。
SET @p = 'one';
SET @sql = '(SELECT items->"$.@p" into @im From fruits where id = 12)';
SET @sql = replace(@sql,'@p',@p);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
select @im;
关于mysql - 未获取以变量作为 json 键的 Mysql json 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53700590/