我有这个查询
INSERT INTO hist_museum (SELECT * from of_owner.museum al
JOIN (SELECT vd.city_data_id
FROM of_owner.city_data vd
WHERE gps_full_date < add_months(SYSDATE,-12)) vd
ON al.city_data_id = VD.city_data_id);
和hist_museum和博物馆的表完全相同,但即使我得到了这个错误:
Error(10,19): PL/SQL: ORA-00913: demasiados valores
答案 0 :(得分:2)
使用“select * from al JOIN ...”,您将获得al和您加入的subrequest vd中的所有值。你想要的是
INSERT INTO hist_museum (SELECT al.* from of_owner.museum al
JOIN (SELECT vd.city_data_id
FROM of_owner.city_data vd
WHERE gps_full_date < add_months(SYSDATE,-12)) vd
ON al.city_data_id = VD.city_data_id);
答案 1 :(得分:2)
执行insert
时的最佳做法是明确列出列:
INSERT INTO hist_museum(col1, col2, . . . )
SELECT col1, col2, . . .
FROM of_owner.museum al JOIN
of_owner.city_data vd
ON al.city_data_id = VD.city_data_id
WHERE gps_full_date < add_months(SYSDATE, -12);
当然,SELECT
中的列应使用表名限定。
此外,子查询是不必要的。没有理由只将子查询写入文件管理器数据。