SELECT id=identity(int,1,1),* into #temp_audits FROM audits ORDER BY time最好能一条实现,要不多条也可以

解决方案 »

  1.   

    我的目的就是想给audits这张表按时间排序然后增加一个id列放在临时表中
      

  2.   


    select * , row_number() over(order by time) id from audits
      

  3.   

    谢谢ls的,不过怎样把select的内容放进新的临时表呢
      

  4.   

    oracle的临时表这样用的
    create temporary table tb
    as
    SELECT * FROM audits ORDER BY time
    on commit presever rows;

    create temporary table tb
    as
    SELECT * FROM audits ORDER BY time
    on commit delete rows;
     
      

  5.   

    那么组合起来是不是可以这样写
    create temporary table temp_audits
    as
    select * , row_number() over(order by time) id from audits
      

  6.   

    好像语法有问题啊SQL> create global temporary table temp_audits
      2  as
      3  select *,row_number() over(order by time) id from audits;
    select *,row_number() over(order by time) id from audits
            *
    ERROR at line 3:
    ORA-00923: FROM keyword not found where expected
      

  7.   

    现在问题是这样,好像×里面包括零长度的字段,我用其他表是可以成功的,audits会报这个错,那该怎么解决呢SQL> create global temporary table temp_audits
      2  on commit preserve rows
      3  as
      4  select * from audits;
    select * from audits
           *
    ERROR at line 4:
    ORA-01723: zero-length columns are not allowed
      

  8.   


    create temporary table temp_audits 
    as 
    (select * , row_number() over(order by time) id from audits)
      

  9.   

    我找到原因是因为audits这张表有一个字段定义的时候用NULL,那么如何解决啊