Oracle queries all tables in the database

Source: Internet
Author: User

SELECT a.table_name English name,
A.tab_comments Chinese name,
a.column_id serial number,
A.column_name English name,
A.comments Chinese name,
B.primary_key primary KEY,
substr (A.data_type,1,instr (A.data_type, ' (')-1) data type,
Case when substr (A.data_type,1,instr (A.data_type, ' (')-1) = ' TIMESTAMP "then" when substr (A.data_type,1,instr (a.data_ TYPE, ' (')-1) = ' datatime ' Then ' else substr (a.data_type,instr (A.data_type, ' (') +1,length (a.data_type)-instr (a.data_ TYPE, ' (')-1) End length,
"Units,
Whether the a.nullable is free,
"Default,
' Upper limit,
' Lower limit '

From (SELECT X.table_name,
Z.comments Tab_comments,
X.COLUMN_ID,
X.column_name,
X.data_type | |
DECODE (X.data_type,
' Number ',
DECODE (sign (X.data_scale),
0,
' (' | |
DECODE (LENGTH (To_char (x.data_precision)),
1,
To_char (x.data_precision),
To_char (x.data_precision, ' FM00 ')) | | ‘)‘,
1,
' (' | |
DECODE (LENGTH (To_char (x.data_precision)),
1,
To_char (x.data_precision),
To_char (x.data_precision, ' FM00 ')) | | ', ' | |
To_char (X.data_scale, ' FM0 ') | | ‘)‘,
‘‘),
' (' | | DECODE (LENGTH (To_char (x.data_length)),
1,
To_char (X.data_length),
To_char (x.data_length, ' FM9900 ')) | | ') as Data_type,
X.nullable,
Y.comments
From User_tab_columns X, user_col_comments Y, user_tab_comments Z
WHERE X.table_name = Y.table_name
and x.column_name = Y.column_name
and x.table_name = z.table_name) A,
(SELECT x.table_name table_name,
X.column_name column_name,
MAX (DECODE (Y.constraint_type,
' P ',
' PK ' | | To_char (x.position, ' FM9 '),
")) Primary_key,
MAX (DECODE (Y.constraint_type,
' R ',
' FK ' | | To_char (x.position, ' FM9 '),
")) Foreign_key
From User_cons_columns X, user_constraints Y
WHERE X.table_name = Y.table_name
and x.constraint_name = Y.constraint_name
and Y.constraint_type <> ' C '
GROUP by X.table_name, X.column_name) B
WHERE A.table_name = b.table_name (+)
and A.column_name = B.column_name (+)
/*and a.table_name = Upper (' tp_planmonth ') */
ORDER by A.table_name, a.column_id

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.