-- ---------------------------------------------
-- Grundstruktur eines PL/SQL-Blockes, um eine
-- Liste (Array, Collection) abzuarbeiten.
--
-- Eine FOR-Schleife gibt alle DB-User aus,
-- die das SELECT-Statement zurückgibt.
-- ---------------------------------------------
set serveroutput on;--
DECLARE
BEGIN
FOR i IN (SELECT username FROM all_users)
LOOP
dbms_output.put_line(i.username);
END LOOP;
EXCEPTION
WHEN others THEN
dbms_output.put_line('sqlerrm : '||sqlerrm);
END;
-- ---------------------------------------------
-- Die Grundstruktur eines PL/SQL-Blockes, um
-- eine Matrix (2-dimensionales Array), zu be-
-- arbeiten.
--
-- Die Main - FOR-Schleife gibt alle DB-User an
-- die Sub - FOR-Schleife. Diese 2. Schleife gibt
-- dann den Usernamen und die Tabellen, die dem
-- DB-User gehören aus.
-- ---------------------------------------------
DECLARE
BEGIN
FOR i IN (SELECT username FROM all_users)
LOOP
FOR j IN (SELECT table_name FROM all_tables
WHERE owner = i.username
AND table_name LIKE 'XML%'
ORDER BY table_name)
LOOP
dbms_output.put_line(i.username || ' ' || j.table_name);
END LOOP;
END LOOP;
EXCEPTION
WHEN others THEN
dbms_output.put_line('sqlerrm : '||sqlerrm);
END;
BEGIN
FOR i IN (SELECT username FROM all_users)
LOOP
FOR j IN (SELECT table_name FROM all_tables
WHERE owner = i.username
AND table_name LIKE 'XML%'
ORDER BY table_name)
LOOP
dbms_output.put_line(i.username || ' ' || j.table_name);
END LOOP;
END LOOP;
EXCEPTION
WHEN others THEN
dbms_output.put_line('sqlerrm : '||sqlerrm);
END;
-- ---------------------------------------------
-- Das geht natürlich einfacher und viel schneller,
-- weil der Kontext-Switch zwischen PL/SQL und SQL-
-- Engine wegfällt ...
-- ---------------------------------------------
SELECT au.username
, allt.table_name
FROM all_users au
, all_tables allt
WHERE allt.owner = au.username
and table_name like 'XML%'
order by table_name
;
-- ---------------------------------------------
-- oder evtl. auf diesem Weg ...
-- ---------------------------------------------
SELECT table_name
FROM all_tables
WHERE owner NOT IN ('SYSTEM'
, 'SYS'
, 'SYSAUX'
, 'ORDSYS'
, 'WMSYS'
, 'MDSYS'
, 'EXFSYS'
, 'TSMSYS'
, 'XDB'
, 'DBSNMP'
, 'OUTLN'
, 'CTXSYS'
, 'APPQOSSYS')
AND table_name LIKE 'VOLL%'
OR table_name LIKE '%VOLL%'
ORDER BY owner
;