急丫 。。 oracle 10g plsql 中 两张表 一张主表 ,一张从表。主表out_Id 字段有值 而 从表的out_Id 应该和主表是一样的 ,问题是现在从表out_Id 都是空的 ,我想把主表的值插入到从表去,我不想一条一条用where去插。 我怎么用一句sql 或 存储过程,全部插入到从表。是用到 序列么 应该有for 循环 吧 本人菜鸟 请 各位兄台给点意见 ,,,, 要 不就丢大人了。。
调试欢乐多
v_id tbl_pos_stock_removal.id%type;
v_outId tbl_pos_stock_removal.out_man%type;
cursor c_cur is select t.id, t.out_man from tbl_pos_stock_removal t ;
begin
open c_cur;
loop
fetch c_cur into v_id,v_outId;
exit when c_cur%notfound;
update tbl_store_pos p set p.user_id = v_outId
where p.id in(select d.pos_id from tbl_pos_stock_removal_detail d
where d.master_id = v_id) ; end loop;
close c_cur;
commit;
end;
哈哈 搞好了 用游标 大家看看啊
insert into 从表名(out_Id) select out_Id from 主表名;这样应该就行了
完全可以用sql搞定 简单的复杂化
update tbl_store_pos p set p.user_id=(select out_man from tbl_pos_stock_removal_detail d where p.id=d.pos_id)
where exists(select 1 from tbl_pos_stock_removal_detail f where p.id=f.pos_id)