简单问题,在线等 insert into table1(id,name) select col1,name from table2;col1字段不在table2中,是个虚拟的 自增字段 ,请问这个sql如何写可以是插入table1表的id数值,自增(1,2,3,4),谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 随便建个序列seq_yourname比如create sequence seq_yournameminvalue 1maxvalue 99999999999999start with 1increment by 1cache 20;然后insert into table1(id,name) select seq_yourname.nextval,name from table2; 晕,其实你直接插rownum就好了insert into table1(id,name) select rownum,name from table2; 用序列比较好,不用考虑并发问题如果用rownum也可以实现,不过最好是先检测目标表的MAX ID,然后在此基础+ROWNUM并且要考虑并发问题 晕,其实你直接插rownum就好了 insert into table1(id,name) select rownum,name from table2;这样的能用一次。。不能用第二次 先定义序列seq1再执行insert into table1(id,name) select seq1.nextval,name from table2; insert into table1(id,name) select rownum,name from table2;就可以了啊 不知道这样行不,没试过:insert into table1(id,name) values(select (select max(id)+1 from table1)+rownum ,name from table2; SQL 中相关子查询方面的问题 plsql 连接 vpn 下的ORACLE问题! windows 7 64位操作系统,数据库为oralce 11g,vs2010不能连接上 ora-01652错误怎么办? 警告: 创建的触发器带有编译错误。 oracle 数据恢复 求用VB连接ORACLE的代码,要求能执行SELECT,UPDATE,DELETE orcale pl/sql 中 ":" 符號用加在某變量前是作么用的 新手问一下一条sql查询语句 棘手的一个问题,有关 update上锁的问题,update 语句对表中记录修改时上exclusive锁! 谁能帮我优化下这段代码 数据库问题
比如
create sequence seq_yourname
minvalue 1
maxvalue 99999999999999
start with 1
increment by 1
cache 20;
然后
insert into table1(id,name) select seq_yourname.nextval,name from table2;
insert into table1(id,name) select rownum,name from table2;
如果用rownum也可以实现,不过最好是先检测目标表的MAX ID,然后在此基础+ROWNUM
并且要考虑并发问题
insert into table1(id,name) select rownum,name from table2;这样的能用一次。。不能用第二次
再执行
insert into table1(id,name) select seq1.nextval,name from table2;
insert into table1(id,name) values
(select (select max(id)+1 from table1)+rownum ,name from table2;