Guest User

Untitled

a guest
Dec 11th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 3.25 KB | None | 0 0
  1. /* equInContainer is a function that returns equipment contained in a container */
  2.  
  3. FUNCTION equInContainer (verSet IN NUMBER, contSids IN numberTable, contVers IN numberTable, contOtdTypes IN stringTable, resOtdTypes IN stringTable, contOtds IN numberTable, resOtds IN numberTable, useOtdSid IN NUMBER)
  4.     RETURN stringTable pipelined IS
  5.  
  6.     objInfo objInfoType;
  7.  
  8.     CURSOR c1(contSid IN NUMBER,contVer IN NUMBER) IS
  9.     SELECT
  10.         a.equ_otdtype, a.equ_sid, a.equ_ver, a.equ_otd
  11.     FROM
  12.         (
  13.         SELECT
  14.             *
  15.         FROM
  16.             repl_equ_equ_eqt a1
  17.         WHERE (
  18.                 verSet = 2 AND a1.equ_ver IN (SELECT * FROM TABLE(PLANNEDVERSET))
  19.                 OR verSet = 3 AND a1.equ_ver IN (SELECT * FROM TABLE(LTPLANNEDVERSET))
  20.                 OR verSet = 1 AND a1.equ_ver IN (SELECT * FROM TABLE(EXISTVERSET))
  21.             ) AND (
  22.                 contOtdTypes IS NULL AND resOtdTypes IS NULL
  23.                 OR contOtdTypes IS NOT NULL AND a1.equ_otdtype IN (SELECT * FROM TABLE(contOtdTypes))
  24.                 OR resOtdTypes IS NOT NULL AND a1.equ_otdtype IN (SELECT * FROM TABLE(resOtdTypes))
  25.             )
  26.         ) a
  27.     START WITH
  28.         a.cont_sid = contSid AND a.cont_ver = contVer
  29.     CONNECT BY
  30.         a.cont_sid = PRIOR a.equ_sid AND a.cont_ver = PRIOR a.equ_ver;
  31.  
  32.     CURSOR c2(contSid IN NUMBER,contVer IN NUMBER) IS
  33.     SELECT
  34.         a.equ_otdtype, a.equ_sid, a.equ_ver, a.equ_otd
  35.     FROM
  36.         (
  37.         SELECT
  38.             *
  39.         FROM
  40.             repl_equ_equ_eqt a1
  41.         WHERE (
  42.                 verSet = 2 AND a1.equ_ver IN (SELECT * FROM TABLE(PLANNEDVERSET))
  43.                 OR verSet = 3 AND a1.equ_ver IN (SELECT * FROM TABLE(LTPLANNEDVERSET))
  44.                 OR verSet = 1 AND a1.equ_ver IN (SELECT * FROM TABLE(EXISTVERSET))
  45.             ) AND (
  46.                 contOtds IS NULL AND resOtds IS NULL
  47.                 OR contOtds IS NOT NULL AND a1.equ_otd IN (SELECT * FROM TABLE(contOtds))
  48.                 OR resOtds IS NOT NULL AND a1.equ_otd IN (SELECT * FROM TABLE(resOtds))
  49.             )
  50.         ) a
  51.     START WITH
  52.         a.cont_sid = contSid AND a.cont_ver = contVer
  53.     CONNECT BY
  54.         a.cont_sid = PRIOR a.equ_sid AND a.cont_ver = PRIOR a.equ_ver;
  55.  
  56. BEGIN
  57.     FOR j IN 1..contSids.COUNT LOOP
  58.         IF (useOtdSid = 0) THEN
  59.             -- qualify on combination of otd and sub-type
  60.             OPEN c1(contSids(j),contVers(j));
  61.             LOOP
  62.                 FETCH c1 INTO objInfo;
  63.                 EXIT WHEN
  64.                     c1%notfound;
  65.  
  66.                 IF (contOtdTypes IS NULL AND resOtdTypes IS NULL) THEN
  67.                     pipe ROW(TO_CHAR(objInfo.sid) || ' ' || TO_CHAR(objInfo.ver) || ' ' || TO_CHAR(objInfo.otd));
  68.                 ELSIF (resOtdTypes IS NOT NULL) THEN
  69.                     FOR i IN 1..resOtdTypes.COUNT LOOP
  70.                         IF (resOtdTypes(i) = objInfo.otdtype) THEN
  71.                             pipe ROW(TO_CHAR(objInfo.sid) || ' ' || TO_CHAR(objInfo.ver) || ' ' || TO_CHAR(objInfo.otd));
  72.                             EXIT;
  73.                         END IF;
  74.                     END LOOP;
  75.                 END IF;
  76.             END LOOP;
  77.             CLOSE c1;
  78.         ELSE
  79.             -- qualify on otd only
  80.             OPEN c2(contSids(j),contVers(j));
  81.             LOOP
  82.                 FETCH c2 INTO objInfo;
  83.                 EXIT WHEN
  84.                     c2%notfound;
  85.  
  86.                 IF (contOtds IS NULL AND resOtds IS NULL) THEN
  87.                     pipe ROW(TO_CHAR(objInfo.sid) || ' ' || TO_CHAR(objInfo.ver) || ' ' || TO_CHAR(objInfo.otd));
  88.                 ELSIF (resOtds IS NOT NULL) THEN
  89.                     FOR i IN 1..resOtds.COUNT LOOP
  90.                         IF (resOtds(i) = objInfo.otd) THEN
  91.                             pipe ROW(TO_CHAR(objInfo.sid) || ' ' || TO_CHAR(objInfo.ver) || ' ' || TO_CHAR(objInfo.otd));
  92.                             EXIT;
  93.                         END IF;
  94.                     END LOOP;
  95.                 END IF;
  96.             END LOOP;
  97.             CLOSE c2;
  98.         END IF;
  99.     END LOOP;
  100.  
  101.     RETURN;
  102. EXCEPTION
  103.   WHEN OTHERS THEN
  104.     RETURN;
  105. END;
Add Comment
Please, Sign In to add comment