Home » RDBMS Server » Server Administration » UnUsed column in the database
|
|
|
Re: UnUsed column in the database [message #667640 is a reply to message #667638] |
Tue, 09 January 2018 06:34   |
 |
Michel Cadot
Messages: 68757 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
The column name no more exists in the dictionary.
You can either get it from a previous backup: restore part of the database before the alter table (SYSTEM, SYSAUX, UNDO, TEMP and tablespace containing the table).
Or, if you know about when the column was set unused, flashback the table SYS.COL$ knowing that to set the column as unused Oracle updates the associated row in this table.
For example:
SQL> alter table t set unused column col;
Table altered.
SQL> alter table t set unused column col2;
Table altered.
SQL> select undo_sql from FLASHBACK_TRANSACTION_QUERY
2 where table_owner='SYS' and table_name='COL$'
3 and undo_sql like 'update%'
4 and trunc(COMMIT_TIMESTAMP) = trunc(sysdate)
5 order by commit_scn;
UNDO_SQL
------------------------------------------------------------------------------------------------------------------------
update "SYS"."COL$" set "COL#" = '2', "SEGCOL#" = '2', "SEGCOLLENGTH" = '22', "NAME" = 'COL', "TYPE#" = '2', "LENGTH" =
'22', "FIXEDSTORAGE" = '0', "PRECISION#" = NULL, "SCALE" = NULL, "NULL$" = '0', "DEFLENGTH" = NULL, "PROPERTY" = '0', "C
HARSETID" = '0', "CHARSETFORM" = '0', "SPARE1" = '0', "SPARE2" = '0', "SPARE3" = '0' where ROWID = 'AAAAACAABAAAZEYAAH';
------------------------------------------------------------------------------------------------------------------------
update "SYS"."COL$" set "COL#" = '2', "SEGCOL#" = '3', "SEGCOLLENGTH" = '22', "NAME" = 'COL2', "TYPE#" = '2', "LENGTH" =
'22', "FIXEDSTORAGE" = '0', "PRECISION#" = NULL, "SCALE" = NULL, "NULL$" = '0', "DEFLENGTH" = NULL, "PROPERTY" = '0', "
CHARSETID" = '0', "CHARSETFORM" = '0', "SPARE1" = '0', "SPARE2" = '0', "SPARE3" = '0' where ROWID = 'AAAAACAABAAAZEYAAI'
;
------------------------------------------------------------------------------------------------------------------------
2 rows selected.
You see the previous name of the columns in the UNDO_SQL ("NAME" = 'COL', "NAME" = 'COL2').
To know which table, you can use the rowid in these statements:
SQL> select u.name owner, o.name table_name
2 from sys.user$ u, sys.obj$ o
3 where u.user# = o.owner#
4 and o.obj# in
5 (select obj# from sys.col$ where rowid in ('AAAAACAABAAAZEYAAH','AAAAACAABAAAZEYAAI'))
6 /
OWNER TABLE_NAME
------------------------------ ------------------------------
MICHEL T
|
|
|
|
|
|
Re: UnUsed column in the database [message #667652 is a reply to message #667640] |
Tue, 09 January 2018 08:49   |
 |
Michel Cadot
Messages: 68757 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
If your database is in ARCHIVELOG mode (and it should) and you know about when the modification have been made, you can retrieve the statement using Log Miner:
SQL> begin
2 sys.dbms_logmnr.add_logfile (logfilename=>'E:\ORACLE\BASES\MIKB2\RL_G1_1.RDO',
3 options=>sys.dbms_logmnr.NEW);
4 sys.dbms_logmnr.add_logfile (logfilename=>'E:\ORACLE\BASES\MIKB2\RL_G2_1.RDO',
5 options=>sys.dbms_logmnr.ADDFILE);
6 sys.dbms_logmnr.add_logfile (logfilename=>'E:\ORACLE\BASES\MIKB2\RL_G3_1.RDO',
7 options=>sys.dbms_logmnr.ADDFILE);
8 sys.dbms_logmnr.add_logfile (logfilename=>'E:\ORACLE\BASES\MIKB2\RL_G4_1.RDO',
9 options=>sys.dbms_logmnr.ADDFILE);
10 sys.dbms_logmnr.start_logmnr (
11 startTime => trunc(sysdate),
12 endTime => sysdate,
13 options => sys.dbms_logmnr.skip_corruption
14 + sys.dbms_logmnr.committed_data_only
15 + sys.dbms_logmnr.dict_from_online_catalog
16 );
17 end;
18 /
PL/SQL procedure successfully completed.
SQL> col seg_owner format a10
SQL> col sql_redo format a80
SQL> select seg_owner, sql_redo
2 from v$logmnr_contents
3 where ( operation like 'ALTER%' or operation = 'DDL' )
4 and lower(sql_redo) like '%set unused%'
5 /
SEG_OWNER SQL_REDO
---------- --------------------------------------------------------------------------------
MICHEL alter table t set unused column col;
MICHEL alter table t set unused column col2;
2 rows selected.
SQL> exec sys.dbms_logmnr.end_logmnr;
PL/SQL procedure successfully completed.
|
|
|
|
Goto Forum:
Current Time: Sun May 04 00:44:45 CDT 2025
|