데이터베이스 생성 저장 프로세스, 정시 작업으로

1897 단어
1. 저장 프로세스:
create or replace procedure SYNC_WORKGROUP
as
v_org_id number(15);
v_group_id number(15);
v_org_users number(9);
v_group_uers number(9);
cursor orgGroups is select a.id as orgid, b.id as workgroupid from usi_organization a, usi_workgroup b where instr(b.name, '('||a.id||')') > 0;

begin
   for orgGroup in orgGroups loop
       v_org_id := orgGroup.orgid;
       v_group_id := orgGroup.workgroupid;
       select count(1) into v_org_users from usi_user t
              where t.del_flag = 0 and t.org_id in(select id from usi_organization start with parentid = v_org_id connect by
              prior id = parentid union select id from usi_organization where id = v_org_id);
       select count(1) into v_group_uers from usi_workgroup_user t where t.state = 0 and t.workgroupid = v_group_id;
       if v_org_users <> v_group_uers then
          delete from usi_workgroup_user t where t.workgroupid = v_group_id;
          insert into usi_workgroup_user (
                 select seq_usi_workgroup_user.nextval, v_group_id, t.user_code, 0, sysdate, sysdate
                        from usi_user t
                        where t.del_flag = 0
                        and t.org_id in(select id from usi_organization start with parentid = v_org_id
                            connect by prior id = parentid union select id from usi_organization where id = v_org_id));
       end if;
   end loop;
end;

2、시간제 퀘스트 창설, 매일 집행
명령 창에서 명령 실행:job 선언
variable   jobno   number;
begin   
dbms_job.submit(:jobno,'sync_workgroup;',trunc(sysdate)-1/1440,'trunc(sysdate)-1/1440+1');
end;   
/

job 시작
begin   
dbms_job.run(:jobno);   
end;   
/

3. PS: "select job,next date,next sec,broken from user jobs"를 사용할 수 있습니다.정시 작업 상태 보기

좋은 웹페이지 즐겨찾기