我在pb中用嵌入式sql   :   insert into table_1 (select c_1,c_2,c_3 from table_2 order  by asc )
執行總是出錯,我只要把 排序    :order  by asc 去掉變成
insert into table_1 (select c_1,c_2,c_3 from table_2 )
就可以了,不知道怎麼原因,各位大俠指教。環境為Pb9 + Oracle10g

解决方案 »

  1.   

    奇怪.
    SQL> insert into emp
      2  (select * from emp order by empno asc);
     
    insert into emp
    (select * from emp order by empno asc)
     
    ORA-00907: È±Ê§ÓÒÀ¨ºÅ
     
    SQL> 
    SQL> insert into emp
      2  (select * from emp) order by empno asc;
     
    14 rows inserted
     
    SQL> 
    SQL> insert into emp
      2  select * from emp order by empno asc;
     
    28 rows inserted
     
    SQL> 
    SQL> insert into emp
      2  (select * from emp) ;
     
    56 rows inserted
      

  2.   

    order by 没有写那个字段
      

  3.   

    不好意思insert into table_1 (select c_1,c_2,c_3 from table_2 order by  c_1 asc )丟三落四的壞習慣,確實是只要加入排序就出錯。
      

  4.   

    難道沒有 辦法寫sql排序後插入嗎?
      

  5.   

    其实控制insert语句的select子句记录顺序没什么意义.即使你排序了也没法保证查询的顺序.
    奇怪的是order by为啥有时候报错有时候不报错
      

  6.   

    外面再嵌套一层泥排序后的结果,再insert:
    insert into table_1 (select * from (select c_1,c_2,c_3 from table_2 order by c_1 asc ))
      

  7.   


    insert into t_test    select material_id  from material_prod where rownum < 10   order by material_id  
    insert into t_test   ( select material_id  from material_prod where rownum < 10 ) order by material_id desc
    這兩個sql插入的內容不一樣,前者是對material_prod排序後插入的最前9條,後者好像沒有什麼順序。
      

  8.   

    insert into table_1 select c_1,c_2,c_3 from table_2 order by c_1 asc 
      

  9.   


    insert into table_1 select c_1,c_2,c_3 from table_2 order by 列名没有你的 asc
      

  10.   

    只能有一个原因,就是你排序的字段,表没有,你把你排序的字段放到select中去,试看下