MySQL使用存储过程创建视图

时间:2014-07-01 04:04:33

标签: mysql

晚上好先生/夫人;

我试图创建一个更新MySQL视图的存储过程。简而言之,当trainingType数据库更新时,视图trsReq(其实质上是trainingType的员工数据透视表。培训记录存储在视图中,trs)需要更新。

SET @sql = NULL;
SET @@group_concat_max_len = 5000;
SELECT GROUP_CONCAT(DISTINCT CONCAT('max(IF(type =',id,', data, "")) AS "',shortDesc,'",max(IF(type =',id,', trs.status, "")) AS "',shortDesc,'_status"')) into @sql FROM trainingType where required=1;
SET @sql = CONCAT('create view trsReq as SELECT fName, lName, empId, ', @sql, ' FROM trs left join employee on trs.empId=employee.id where employee.inactive=0 GROUP BY empId order by lName, fName limit 100');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt; 

执行该组命令会产生以下结果:

ERROR 1142 (42000): ANY command denied to user `'user'@'localhost'` for table 

    '/var/mysqltmp/#sql_285f_0'

0 个答案:

没有答案