Вам нужно предложение WHERE
(и вы можете сделать все это одним оператором UPDATE
):
SQL Fiddle
Oracle 11gНастройка схемы R2 :
CREATE TABLE mytable ( start_period_date, end_period_date ) AS
SELECT DATE '2018-01-01', DATE '2018-01-02' FROM DUAL
/
CREATE OR REPLACE PROCEDURE CHANGE_DATES
AS
start_dates SYS.ODCIDATELIST;
end_dates SYS.ODCIDATELIST;
BEGIN
UPDATE ( SELECT m.*,
( SELECT m.start_period_date FROM DUAL ) AS old_start_date,
( SELECT m.end_period_date FROM DUAL ) AS old_end_date
FROM mytable m )
SET start_period_date = SYSDATE,
end_period_date = SYSDATE + INTERVAL '6' DAY
WHERE end_period_date < SYSDATE
RETURNING old_start_date, old_end_date
BULK COLLECT INTO start_dates, end_dates;
FOR i IN 1 .. start_dates.COUNT LOOP
DBMS_OUTPUT.PUT_LINE( 'Old Date:' || start_dates(i) ||' ' || end_dates(i) );
END LOOP;
-- Do not COMMIT in the procedure, COMMIT in the calling scope.
END;
/
Запрос 1 :
BEGIN
CHANGE_DATES;
COMMIT;
END;
Запрос 2 :
SELECT * FROM mytable
Результаты :
| START_PERIOD_DATE | END_PERIOD_DATE |
|----------------------|----------------------|
| 2018-05-21T09:06:05Z | 2018-05-27T09:06:05Z |