[英]insert into temporary table not working in mysql stored procedure
i have the following stored procedure: 我有以下存储过程:
create temporary table logData (table_name varchar(50), column_name varchar(50), changed_date date, changed_by char(10), old_value varchar(50), new_value varchar(50))
insert into logData SELECT table_name, column_name, changed_date, changed_by, old_value, new_value FROM log WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate
UNION
SELECT "reservation_flight", column_name, changed_date, changed_by, old_value, new_value FROM reservation_flight_log WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate
UNION
SELECT "ticket", column_name, changed_date, changed_by, old_value, new_value FROM ticket_log WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate
UNION
SELECT "passenger_record", column_name, changed_date, changed_by, old_value, new_value FROM passenger_record_log WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate
select * from logData order by changed_date;
In the above sql select statement empId
, startDate
and endDate
are the input parameters for this stored procedure. 在上面的sql select语句empId
, startDate
和endDate
是此存储过程的输入参数。 This is showing error please help? 这显示错误请帮助? Thank You! 谢谢!
I believe you are missing two semicolons: one at the end of the first statement and another at the end of the before-last line. 我相信您缺少两个分号:一个在第一个语句的末尾,另一个在前一个最后一行的末尾。 You may rewrite it like the following: 您可以像下面这样重写它:
CREATE temporary TABLE logData (table_name varchar(50),
column_name varchar(50),
changed_date date,
changed_by char(10),
old_value varchar(50),
new_value varchar(50));
INSERT INTO logData
SELECT table_name, column_name, changed_date, changed_by, old_value, new_value
FROM log
WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate
UNION
SELECT "reservation_flight", column_name, changed_date, changed_by, old_value, new_value
FROM reservation_flight_log
WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate
UNION
SELECT "ticket", column_name, changed_date, changed_by, old_value, new_value
FROM ticket_log
WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate
UNION
SELECT "passenger_record", column_name, changed_date, changed_by, old_value, new_value
FROM passenger_record_log
WHERE changed_by=empId AND changed_date BETWEEN startDate AND endDate;
SELECT * FROM logData ORDER BY changed_date;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.