I did try to create a stored procedure in oracle 10g database, that selects data from dba_segments
and inserts into another table (viz. table_space).
CREATE OR REPLACE PROCEDURE P_DAILY_ENTRY IS an_job_id number; BEGIN INSERT INTO table_space(table_name, max_size, date_of_max_size) SELECT table_name, TRUNC(SUM(bytes)/1024) max_size, sysdate date_of_max_size FROM ( SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type = 'TABLE' UNION ALL SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type = 'INDEX' ) WHERE owner IN ('CARAT') GROUP BY table_name, owner ORDER BY SUM(bytes) DESC; EXCEPTION WHEN OTHERS THEN ROLLBACK; END P_DAILY_ENTRY;
Whin I run the above it shows following two errors:
- line 05 | Execution | PL/SQL: SQL Statement ignored
- line 12 | Execution | PL/SQL: ORA00942: table or view does not exist
However, if INSERT
statement is executed separately, it populates the table_space table.