ORA-00913 too many values

后端 未结 2 856
傲寒
傲寒 2021-01-28 12:37

I have this query

INSERT INTO hist_museum (SELECT * from of_owner.museum al
                                JOIN (SELECT vd.city_data_id 
                                


        
相关标签:
2条回答
  • 2021-01-28 12:49

    With "select * from al JOIN ..." you get all values from al and your joined subrequest vd. What you want is

    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);
    
    0 讨论(0)
  • 2021-01-28 13:01

    The best-practice when doing an insert is to list the columns explicitly:

    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);
    

    Of course, the columns in the SELECT, should be qualified with the table name.

    In addition, the subquery is unnecessary. There is no reason to write a subquery just to filer data.

    0 讨论(0)
提交回复
热议问题