Oracle declare begin end 简单例子

时间:2025-04-20 12:49:54
declare 
--APP_ROLE_ID char(1000);
 cou number;
begin 
 for a in (select  id,name from 表1 ) --遍历表1
    loop --循环开始
      cou:=0;
       select count(*) into cou from 表2  where id= and name='小明';
       if(cou=0) then  ---表2中没有表一中一样id对应的小明,则插入进去
       insert into 表2  (id, name) values(xxx,'小明');
       end if;
       
      commit;
 end loop;
 
DBMS_OUTPUT.PUT_LINE('exe success ~~~');
end;