create or replace PROCEDURE EMAIL_ADD
IS
CNT NUMBER;
BEGIN
FOR C IN (SELECT * FROM TAB WHERE TNAME LIKE 'EMAILS_%' ORDER BY TNAME) LOOP
SELECT COUNT(*) INTO CNT
FROM USER_TAB_COLS
WHERE TABLE_NAME = C.TNAME
AND COLUMN_NAME = 'SEND_IP';
IF CNT = 0 THEN
EXECUTE IMMEDIATE ' ALTER TABLE '||C.TNAME||' ADD SEND_IP VARCHAR(15) ';
COMMIT;
END IF;
SELECT COUNT(*) INTO CNT
FROM USER_TAB_COLS
WHERE TABLE_NAME = C.TNAME
AND COLUMN_NAME = 'SENDER';
IF CNT = 0 THEN
EXECUTE IMMEDIATE ' ALTER TABLE '||C.TNAME||' ADD SENDER VARCHAR(64) ';
COMMIT;
END IF;
END LOOP;
END;