ORA-00913价值太多了

时间:2017-09-28 14:43:47

标签: sql oracle oracle12c

我有这个查询

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

2 个答案:

答案 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中的列应使用表名限定。

此外,子查询是不必要的。没有理由只将子查询写入文件管理器数据。