mysql的存储过程放在哪里_mysql存储过程求解,错误在哪里?
DELIMITER $$
ALTER PROCEDURE `sp_test`(vdnId CHAR(2),startTimeStr CHAR(8))
BEGIN
DECLARE v_startTime DATETIME;
DECLARE v_endTime DATETIME;
DECLARE v_VDNName CHAR(2);
DECLARE v_sql VARCHAR(1000);
/*判斷輸入參數的合法性*/
SELECT t.VDN_name INTO v_VDNName FROM gdmdw.t_dim_vdn t WHERE t.vdn_key = vdnId;
SELECT STR_TO_DATE(startTimeStr, '%Y%m%d') INTO v_startTime;
SELECT DATE_ADD(v_startTime,INTERVAL 1 DAY) INTO v_endTime;
/*實現業務邏輯*/
-- 整理時長
SET v_sql = CONCAT('
INSERT INTO tmp_',v_VDNName,'_tagentopr
(kpi_key,time_key,agent_key,kpi_value)
(
SELECT "work_time_key",th.time_key,t.agentid, SUM(
CASE
WHEN (th.fulldate_key>=t.actbegin AND th.fulldate_key
THEN UNIX_TIMESTAMP(t.actend)-UNIX_TIMESTAMP(th.fulldate_key)
WHEN (th.fulldate_keyt.actend)
THEN? UNIX_TIMESTAMP(t.actend)-UNIX_TIMESTAMP(t.actbegin)
WHEN (DATE_ADD(th.fulldate_key,INTERVAL 1 DAY)>t.actbegin) AND (DATE_ADD(th.fulldate_key,INTERVAL 1 DAY)
THEN UNIX_TIMESTAMP(DATE_ADD(th.fulldate_key,INTERVAL 1 DAY)) - UNIX_TIMESTAMP(t.actbegin)
END
) AS worktime
FROM (SELECT time_key,fulldate_key
FROM gdmdw.t_dim_time th WHERE th.fulldate_key >=? ?
AND th.fulldate_key ) th LEFT JOIN (
SELECT t.agentid,t.actbegin,t.actend FROM gdmods.tagentoprinfo t
WHERE OperateType="0"
AND t.actend>= ?
AND t.actend
UNION ALL
SELECT t.agentid,MAX(t.actbegin),? ?
FROM gdmods.tagentoprinfo t WHERE (OperateType="1" OR OperateType="0")
AND t.actend>=?
AND t.actend
GROUP BY t.agentid
HAVING MAX(t.actbegin)=MAX(t.actend)
) t
ON??? ( (DATE_ADD(th.fulldate_key,INTERVAL 1 DAY) >=t.actbegin)? AND? th.fulldate_key < t.actend)
AND t.actend IS NOT NULL
GROUP BY agentid,time_key');
SET @a = v_startTime;
SET @b = v_endTime;
SET @c = v_startTime;
SET @d= v_endTime;
SET @e=v_endTime;
SET @f= v_startTime;
SET @g = v_endTime;
SELECT v_sql;
SET @SQL = v_sql;
PREPARE s1 FROM @SQL;
EXECUTE s1 USING @a,@b,@c,@d,@e,@f;
DEALLOCATE PREPARE s1;
END$$
DELIMITER ;
2010年12月10日 15:05
總結
以上是生活随笔為你收集整理的mysql的存储过程放在哪里_mysql存储过程求解,错误在哪里?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html设置一个随机数的抽奖,随机数的运
- 下一篇: api网关 android,如何通过An