将结果存储在动态查询的变量中

时间:2019-06-18 12:11:03

标签: mysql stored-procedures

我希望将结果保存在变量中,而不是执行查询

set @countdata = createtb 

请帮助,抱歉英语不好

定界符

CREATE DEFINER=root@% PROCEDURE proc_tbl_exam_given_ext_test11_first(
    IN get_mock_test_id VARCHAR(255),
    IN get_user_id int(11),
    IN get_question_id int(11),
    IN get_answered TEXT charset utf8,
    IN get_current_datetime DATETIME,
    IN get_exam_in_language VARCHAR(50),
    IN get_exam_type CHAR(1),
    IN get_subject INT,
    IN get_chapter INT,
    IN get_timetaken INT, 
    IN get_email_first char(1)
)
BEGIN

    -- DECLARE ext_table_name varchar(255);
    -- set ext_table_name =  concat('tbl_exam_given_ext_',get_email_first); 

    SET @answergiven2 = CONCAT( "SELECT count(*) as total FROM tbl_exam_given_ext_",get_email_first, " WHERE mock_test_id= '", get_mock_test_id, "' AND user_id = ", get_user_id, " AND question_id = ", get_question_id);
    PREPARE createtb FROM @answergiven2 ; 
     EXECUTE createtb ; 
    DEALLOCATE PREPARE createtb ;
    -- select @answergiven2; 

END;

此代码给出了输出,但是我想存储在变量中以在同一过程中执行另一项任务

0 个答案:

没有答案