Files
Customer/CONN/Once/conn#610.sql
2006-01-09 11:21:30 +00:00

104 lines
4.1 KiB
SQL

DECLARE
CURSOR c_cursor
IS
SELECT DISTINCT b.bes_bestelopdr_key
FROM bes_bestelopdr b, bes_bestelopdrstatuses s, prs_bedrijf be
WHERE be.prs_bedrijf_key = b.prs_bedrijf_key and (0=0)
AND b.bes_bestelopdr_status = s.bes_bestelopdrstatuses_key
AND b.bes_bestelopdr_key IN (
SELECT bes_bestelopdr_key
FROM bes_bestelling_item
WHERE bes_bestelling_key IN (
SELECT bes_bestelling_key
FROM bes_bestelling))
AND b.bes_bestelopdr_key IN (
SELECT bes_bestelopdr_key
FROM bes_bestelling_item
WHERE bes_bestelling_key IN (
SELECT bes_bestelling_key
FROM bes_bestelling
WHERE bes_bestelling_datum < TO_DATE('20051101', 'YYYYMMDD')
AND bes_bestelling_status IN
(3, 4, 5)));
CURSOR c_cursor2 (pBestelopdr_key IN NUMBER)
IS
SELECT boi.bes_bestelopdr_item_key, bi.bes_bestelling_item_key
FROM ins_tab_discipline d,
ins_srtgroep g,
bes_mod_rep r,
ins_srtdeel s,
prs_bedrijf bd,
bes_bestelopdr b,
mld_adres m,
bes_bestelling_item bi,
bes_bestelopdr_item boi,
bes_bestelling bes
WHERE ( d.ins_discipline_module = 'REP'
OR d.ins_discipline_module = 'BES'
)
AND (0=0)
AND d.ins_discipline_verwijder IS NULL
AND d.ins_discipline_key = g.ins_discipline_key
AND g.ins_srtgroep_key = s.ins_srtgroep_key
AND s.ins_srtdeel_key = bi.ins_srtdeel_key
AND s.ins_srtdeel_key = boi.ins_srtdeel_key
AND bi.bes_bestelling_key = bes.bes_bestelling_key
AND b.bes_bestelopdr_key = boi.bes_bestelopdr_key
AND bi.bes_bestelopdr_key = b.bes_bestelopdr_key
AND s.prs_bedrijf_key = bd.prs_bedrijf_key
AND m.mld_adres_key(+) = b.mld_adres_key_lev
AND r.bes_bestelling_item_key(+) = bi.bes_bestelling_item_key
AND b.bes_bestelopdr_key = pBestelopdr_key;
next_record c_cursor%ROWTYPE;
next_record2 c_cursor%ROWTYPE;
oracle_err_num NUMBER;
oracle_err_mes VARCHAR2 (200);
v_errormsg VARCHAR2 (1024);
BEGIN
FOR next_record IN c_cursor LOOP
BEGIN
FOR next_record2 IN c_cursor2(next_record.bes_bestelopdr_key) LOOP
BEGIN
UPDATE bes_bestelopdr_item b
SET bes_bestelopdr_item_aantalontv = bes_bestelopdr_item_aantal
,bes_bestelopdr_item_ontvangen = SYSDATE
WHERE bes_bestelopdr_item_key = next_record2.bes_bestelopdr_item_key;
UPDATE bes_bestelling_item
SET BES_BESTELLING_ITEM_AANTALONTV = bes_bestelling_item_aantal
WHERE bes_bestelling_item_key = next_record2.bes_bestelling_item_key;
EXCEPTION
WHEN OTHERS
THEN
oracle_err_num := SQLCODE;
oracle_err_mes := SUBSTR (SQLERRM, 1, 100);
v_errormsg :=
'(ORACLE error ' || oracle_err_num || '/' || oracle_err_mes
|| ')';
END;
END LOOP;
END;
END LOOP;
commit;
END;
/