How to get comments for table & column from oracle DB from its metadata?
Asked Answered
C

4

5

I am working on a Java Application. I have connected to an Oracle DB using JDBC Connection and fetched it metadata. I am fetch information like tables, columns, views, etc from its metadata.

Now I want to fetch Comments for tables and columns separately in the application from metadata. How can I fetch this details?

Celloidin answered 3/2, 2016 at 7:38 Comment(1)
Did you see this question about retrieving REMARKS metadata from Oracle with JDBC - https://mcmap.net/q/1922226/-how-to-get-column-comments-in-jdbcFeltner
D
9

Now I want to fetch Comments for tables and columns separately in the application from metadata. How can I fetch this details?

For table comments, use [DBA|ALL|USER]_TAB_COMMENTS view.

Example:

SQL> SELECT table_name,
  2    comments
  3  FROM dba_tab_comments
  4  WHERE owner   ='OE'
  5  AND table_name='INVENTORIES';

TABLE_NAME  COMMENTS
----------- ---------------------------------------------------------------
INVENTORIES Tracks availability of products by product_it and warehouse_id.

For column comments, use [DBA|ALL|USER]_COL_COMMENTS view.

SQL> SELECT table_name,
  2    column_name,
  3    comments
  4  FROM dba_col_comments
  5  WHERE owner   ='OE'
  6  AND table_name='INVENTORIES';

TABLE_NAME  COLUMN_NAME          COMMENTS
----------- -------------------- ----------------------------------------------------------------------------
INVENTORIES PRODUCT_ID           Part of concatenated primary key, references product_information.product_id.
INVENTORIES WAREHOUSE_ID         Part of concatenated primary key, references warehouses.warehouse_id.
INVENTORIES QUANTITY_ON_HAND
Dreda answered 3/2, 2016 at 8:24 Comment(0)
D
3
SELECT *
  FROM user_tab_comments;

SELECT *
  FROM user_col_comments;

You can also use all|dba prefix instead of user.

Deville answered 3/2, 2016 at 7:42 Comment(0)
H
2

if the other answers didn't work you should probably try:

  1. Retrieving comments from tables and views

     SELECT * FROM ALL_TAB_COMMENTS 
    
  2. Retrieving comments from Columns

     SELECT * FROM ALL_COL_COMMENTS
    

This worked for me in an Oracle-RDS (AWS).

Hygrophilous answered 9/9, 2022 at 14:12 Comment(0)
B
1

Try dbms_metadata package. With it you can extract comments, grants and other things from db. SELECT DBMS_METADATA.GET_DEPENDENT_DDL('COMMENT','TABLE_NAME','SCHEMA') FROM DUAL

Blakemore answered 3/2, 2016 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.