insert into table1(id,name,value) select rownum,count(*) from table2 where type=1;

解决方案 »

  1.   

    create sequence seq1;
    insert into table1(id,name,value)
     select seq1.nextval, '名字常量',count(*)
       from table2
      where type=1
      group by seq1.currval;
      

  2.   

    select max(id) maxid from table1
    /
    得到maxid
    insert into table1
    select rownum+maxid,'名字常量',count(*) from table2 where type=1
    /
      

  3.   

    补充说明:
    可能是字段名字引起的歧义,我这里的id不是表1的key word,而是一个可以重复的字段,就类似于“交易(transactional)”型数据的交易id一样。不知道如何手工生成和控制
      

  4.   

    to  KingSunSha(弱水三千) :我试了,但出现如下错误信息SQL> create sequence seq1;
    序列已创建。
    SQL> insert into table1(id,name,value)
      2      select seq1.nextval,'常量1',count(*)
      3          from table2
      4        where type=1
      5        group by seq1.currval;
          group by seq1.currval
                              *
    ERROR 位于第 5 行:
    ORA-02287: 此处不允许序号
      

  5.   

    insert into table1(id,name,value)
     select seq1.nextval, name, cnt
       from (select 'ABCD' name, count(*) cnt
               from table2
              where type=1);
      

  6.   

    成功,谢谢 KingSunSha(弱水三千)和各位