31

I've tried :

select * from user_tab_comments;

and it returns me 3 columns "TABLE_NAME", "TABLE_TYPE", and "COMMENTS", but the "TABLE_NAME" column is like "encrypted", I need clear table names :

TABLE_NAME                      TABLE_TYPE  COMMENTS

BIN$IN1vjtqhTEKcWfn9PshHYg==$0  TABLE       Résultat d'intégration d'une photo numérisée
BIN$PUwG3lb3QoazOc4QaC1sjw==$0  TABLE       Motif de fin d'agrément de maître de stage

When I use select * from user_tables; TABLE_NAME is not "encrypted".

2

2 Answers 2

38

Since 10g Oracle doesn't immediately drop tables when we issue a DROP TABLE statement. Instead it renames them like this BIN$IN1vjtqhTEKcWfn9PshHYg==$0 and puts them in the recycle bin. This allows us to recover tables we didn't mean to drop. Find out more.

Tables in the recycle bin are still tables, so they show up in ALL_TABLES and similar views. So if you only want to see comments relating only to live (non-dropped) tables you need to filter by table name:

select * from all_tab_comments
where substr(table_name,1,4) != 'BIN$'
/

"I can't believe there isn't a flag column so you could do and is_recycled = 0 or something. "

You're right, it would be incredible. So I checked the documentation it turns out Oracle 10g added a column called DROPPED to the USER_/ALL_/DBA_TABLES views.

select tc.* 
from all_tab_comments tc
     join all_tables t
     on tc.owner = t.owner
     and tc.table_name = t.table_name
where t.dropped = 'NO'
/

Check out the documentation. Obviously the need to join to the ALL_TABLES view requires more typing than filtering on the name, so depending on our need it might just be easier to keep the original WHERE clause.

5
  • 3
    I can't believe there isn't a flag column so you could do and is_recycled = 0 or something. Or is there? Commented Dec 10, 2015 at 14:05
  • @AndrewSpencer: ...sort of...you could specifically exclude tables in the recycle bin: select * from all_tab_comments atc where not exists (select null from dba_recyclebin drb where drb.owner = atc.owner and drb.object_name = atc.table_name);
    – Gerrat
    Commented May 16, 2018 at 20:20
  • @AndrewSpencer - rather belatedly I checked the documentation and lo! there is such a flag. We learn something every day :)
    – APC
    Commented May 17, 2018 at 5:46
  • 1
    @APC Nice. Of course when I wrote, "I can't believe," what I really meant was "I could only too well believe." Otherwise ... presumably ... I would have taken 2 minutes to read the documentation myself ... I hope. Commented May 17, 2018 at 9:28
  • @APC: Even better! Didn't think to check there.
    – Gerrat
    Commented May 17, 2018 at 12:18
0

SELECT t.table_name,t.comments FROM USER_TAB_COMMENTS t WHERE TABLE_NAME = 'SS_DEPT';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.