eport;
DECLARE CURSOR fkf IS
SELECT ID FROM SYS_FOREIGN WHERE ID >= :db FOR UPDATE;
DECLARE CURSOR fkr IS
SELECT REF_NAME,ID FROM SYS_FOREIGN WHERE REF_NAME >= :db FOR UPDATE
ORDER BY REF_NAME;
DECLARE CURSOR tab IS
SELECT ID,NAME FROM SYS_TABLES WHERE NAME >= :db FOR UPDATE;
DECLARE CURSOR idx IS
SELECT ID FROM SYS_INDEXES WHERE TABLE_ID = tid FOR UPDATE;
BEGIN
OPEN fkf;
WHILE 1 = 1 LOOP
  FETCH fkf INTO fk;
  IF (SQL % NOTFOUND) THEN EXIT; END IF;
  IF TO_BINARY(SUBSTR(fk, 0, LENGTH(:db)))<>TO_BINARY(:db) THEN EXIT; END IF;
  DELETE FROM SYS_FOREIGN_COLS WHERE TO_BINARY(ID)=TO_BINARY(fk);
  DELETE FROM SYS_FOREIGN WHERE CURRENT OF fkf;
END LOOP;
CLOSE fkf;
OPEN fkr;
FETCH fkr INTO fk_report();
CLOSE fkr;
OPEN tab;
WHILE 1 = 1 LOOP
  FETCH tab INTO tid,name;
  IF (SQL % NOTFOUND) THEN EXIT; END IF;
  IF TO_BINARY(SUBSTR(name, 0, LENGTH(:db))) <> TO_BINARY(:db) THEN EXIT; END IF;
  DELETE FROM SYS_COLUMNS WHERE TABLE_ID=tid;
  DELETE FROM SYS_TABLES WHERE ID=tid;
  OPEN idx;
  WHILE 1 = 1 LOOP
    FETCH idx INTO iid;
    IF (SQL % NOTFOUND) THEN EXIT; END IF;
    DELETE FROM SYS_FIELDS WHERE INDEX_ID=iid;
    DELETE FROM SYS_INDEXES WHERE CURRENT OF idx;
  END LOOP;
  CLOSE idx;
END LOOP;
CLOSE tab;
END;
