是不是这样:
alter table b add(age,number);
update b set b.age=(select age from a)+1 where a.id=b.id;
alter table b add(age,number);
update b set b.age=(select age from a)+1 where a.id=b.id;
调试欢乐多
不是什么事情都要一体sql解决的。
你写的是不是不对呀,你那是更新的,楼主要求的是插入的。
bzszp(SongZip) :
你的就更不对了,误人子弟。
楼主的意思是不是插入到表B时,除了年龄数加工1,其余的都不变呢?
呵呵,不过我也不会做,观注中。
select * from
(select age+1 from a
union
select age+2 from a
union
..... age+x from a
)
as
--cursor t_sor is
select age from a;
begin
for i in 1..p loop
insert into b select age+i from a;
end loop;
end;
/begin
name_pro(6);
end;
/
------------------------------
insert into b select age+nn from a,(select rownum nn from 表c) where nn<=account;其中:表c表示另外一个有足够记录的表,既然是年龄,我想大概有100条记录的也就差不多了,如果表a记录够多,也可以用表a,也就是:
------------------------------
insert into b select age+nn from a,(select rownum nn from 表c) where nn<=account;如果实在没有,随便建一个或找个系统表就好了!
( select a.col1,a.col2,a.age+1,..
from a,( select rownum no from all_objects ) c
where c.no < a.account+1
)
改造: Lastdrop(空杯) 的语句
insert into b
( select a.col1,a.col2,a.age+1,..
from a,( select rownum no from
(select rownum no from all_objects
union all
select rownum no from all_objects
union all
select rownum no from all_objects--注多少个union all 根据你自己的具体情况定
)
) c
where c.no < a.account+1
)
我的意思是age循环加1,即第一条为1,第二条为2,第三条为3…….直到最后一条记录的age值等于account的值!
( select a.col1,a.col2,a.age+c.no,..
from a,( select rownum no from all_objects ) c
where c.no < ( a.account - a.age ) + 1
)
我还没有验证你的SQL语句,因为没有数据。