执行select语句创建的命令

时间:2018-03-03 16:01:37

标签: sql database stored-procedures mariadb

我有以下用于创建SQL命令的select语句(在存储过程中):

CREATE DEFINER=`Dord`@`localhost` PROCEDURE `offline_quiz_results`(IN EXAM_EVENT_ID CHAR(255))
BEGIN
SELECT
  CONCAT('UPDATE `bpmspace_coms_v1`.`coms_participant_exam_event` SET `coms_participant_info`=concat(`coms_participant_info`," IMPORT: ',CURDATE() , " - ",
  bpmspace_coms_v1.coms_exam_event.coms_exam_event_id,"-",
  moodle.mdl_offlinequiz.name,"-",
  moodle.mdl_user.firstname,"-",
  moodle.mdl_user.lastname,"-",
  moodle.mdl_user.email,"-",
  moodle.mdl_user.idnumber,"-",
  bpmspace_coms_v1.coms_exam.coms_exam_name,' - SUMM POINTS: ',
  TRUNCATE(moodle.mdl_offlinequiz_results.sumgrades,3),' - MAX POINTS: ',
  bpmspace_coms_v1.coms_exam.coms_exam_max_points,' - PASS MARK: ',
  bpmspace_coms_v1.coms_exam.coms_exam_pass_mark,"\")", ', `state_id`="',
  IF(bpmspace_coms_v1.coms_exam.coms_exam_pass_mark <= moodle.mdl_offlinequiz_results.sumgrades, '31', '32'),'" , coms_participant_exam_event_percent=\"', (moodle.mdl_offlinequiz_results.sumgrades/bpmspace_coms_v1.coms_exam.coms_exam_max_points*100) ,
  ' "where `coms_participant_exam_event`.`coms_exam_event_id` ="' ,  EXAM_EVENT_ID , '" AND `coms_participant_exam_event`.`coms_participant_id`="' , LEFT(moodle.mdl_user.idnumber,length(moodle.mdl_user.idnumber)-3), '"'
  ) AS SQL_CMD
FROM
  ((moodle.mdl_offlinequiz_results
  JOIN moodle.mdl_user ON moodle.mdl_offlinequiz_results.userid = moodle.mdl_user.id)
  JOIN moodle.mdl_offlinequiz ON moodle.mdl_offlinequiz_results.offlinequizid = moodle.mdl_offlinequiz.id)
  JOIN bpmspace_coms_v1.coms_exam_event ON bpmspace_coms_v1.coms_exam_event.coms_exam_event_name =
    moodle.mdl_offlinequiz.name
  INNER JOIN bpmspace_coms_v1.coms_exam ON bpmspace_coms_v1.coms_exam_event.coms_exam_id =
    bpmspace_coms_v1.coms_exam.coms_exam_id
WHERE
  bpmspace_coms_v1.coms_exam_event.coms_exam_event_id = EXAM_EVENT_ID;
END

但我仍然需要使用创建的输出手动执行2步

UPDATE `bpmspace_coms_v1`.`coms_participant_exam_event` SET `coms_participant_info`=concat(`coms_participant_info`,\" IMPORT: 2018-03-03 - 8765-2017-10-25 - [006A] - EN - ICO ITSec Foundation 2015 - mITSM-Robert-NONAM@NOANME.COM-109287377385-ICO ITSec Foundation 2015 - SUMM POINTS: 21.000 - MAX POINTS: 30 - PASS MARK: 20\"), `state_id`=\"31\" , coms_participant_exam_event_percent=\"70.000000000 \"where `coms_participant_exam_event`.`coms_exam_event_id` =\"876065\" AND `coms_participant_exam_event`.`coms_participant_id`=\"113097\"
  1. 替换\&#34; - &GT; &#34;
  2. 复制sql语句并粘贴执行
  3. 有人能告诉我如何直接执行命令吗?

    谢谢Rob

0 个答案:

没有答案