这是mysql存储过程,只是从select查询中打印获取的val。不确定我哪里出错,它总是打印null
DELIMITER $$
DROP PROCEDURE IF EXISTS test $$
CREATE PROCEDURE test(IN input VARCHAR(5000),OUT output VARCHAR(5000))
BEGIN
DECLARE detail_id VARCHAR(128);
DECLARE val VARCHAR(128);
SET output = CONCAT(output, "0", ':', "Starting");
select split_string_new(input,':', 1) into val;
SET output = CONCAT(output, "detail_id0---",detail_id,"....");
SET detail_id = "";
SELECT `dtl_id` FROM detail_tbl WHERE `dtl_val` = val INTO detail_id;
SET output = CONCAT(output, "detail_id1---",detail_id,"....");
END $$
DELIMITER ;
call test('123',@output);SELECT @output;
我尝试了在stackoverflow上找到的几个解决方案,只有下面和更多,但仍然不成功。任何有关这方面的帮助将不胜感激! MySQL Stored procedure variables from SELECT statements MySql SELECT INTO Variable: returns null
答案 0 :(得分:1)
尝试在INTO
子句之前放置FROM
子句。
SELECT `dtl_id` INTO detail_id FROM detail_tbl WHERE `dtl_val` = val;