各位好.请教一个问题
我有表store,储存店铺号码;表download,储存门店资料下发
select storecode from store
---------------------------
storecode
1001
1002
1003
...
select * from download
----------------------
storecode date type reciver
2000 sysdate normal sysdba
2001 sysdate normal sysdba
2002 sysdate normal sysdba
现在想做一个function,能够将select storecode from store的结果,
匹配到insert into download values ('storecode',sysdate,'normal','sysdba')
也就是类似三个insert 语句,想到了循环,但是不知怎么写,求助
表达可能不清楚,在线等各位协助
------解决方案--------------------
你是想把store的storecode都插到download 还是download里面存在的storecode就不用插了,对于后者你可以直接sql语句
insert into download
select storecode, sysdate, 'normal', 'sysdba'
from store b
where not exists
(select 1 from download a where b.storecode = a.storecode)
当然你也可以用function,可以使用游标循环
------解决方案--------------------
for rec in (select * from store) loop
insert into download values (rec.storecode,sysdate,'normal','sysdba');
end loop;
commit;