利用job并行执行Oracle存储过程

2019-05-25 19:42:27 浏览数 (1)

  1. -- 建立测试表
  2. CREATE TABLE t (a NUMBER);
  3. -- 建立存储过程
  4. CREATE OR REPLACE PROCEDURE p_parallel (p_min IN NUMBER, p_max IN NUMBER)
  5. IS
  6. BEGIN
  7. INSERT INTO t
  8. SELECT TRUNC (DBMS_RANDOM.VALUE (p_min, p_max)) FROM DUAL;
  9. COMMIT;
  10. END p_parallel;
  11. /
  12. -- 建立job
  13. DECLARE
  14. x NUMBER;
  15. BEGIN
  16. sys.DBMS_JOB.submit (
  17. job => x,
  18. what => 'p_parallel(1,20);p_parallel(21,40);p_parallel(41,60);p_parallel(61,80);',
  19. next_date => TO_DATE ('14-05-2013 00:00:00', 'dd-mm-yyyy hh24:mi:ss'),
  20. interval => 'trunc(sysdate 1)',
  21. no_parse => FALSE);
  22. SYS.DBMS_OUTPUT.put_line ('Job Number is: ' || TO_CHAR (x));
  23. COMMIT;
  24. END;
  25. /
  26. -- 测试
  27. TRUNCATE TABLE t;
  28. EXEC dbms_job.run(101);
  29. SELECT * FROM t;

0 人点赞