PostgreSQL, Oracle, and MySQL get the table structure through data dictionary

Source: Internet
Author: User

PostgreSQL, Oracle, and MySQL use data dictionaries to obtain the table structure. The schema name and table name are required.

PostgreSQL:
Select a. attname, pg_catalog.format_type (A. atttypid, A. atttypmod) as data_type
From pg_catalog.pg_attribute,
(Select C. OID
From pg_catalog.pg_class C
Left join pg_catalog.pg_namespace n
On n. OID = C. relnamespace
Where (C. relname) = lower ('cxf ')
And (N. nspname) = lower ('public') B
Where a. attrelid = B. OID
And a. attnum> 0
And not a. attisdropped order by A. attnum
 
Attname | data_type
--------- + ------------------------
A | integer
B | character varying (100)
(2 rows)

MySQL:
Create Table dwarch. cxf (A int, B varchar (100 ));
Select column_name, Concat (data_type, case when upper (data_type) like '% char %' Then Concat (', character_maximum_length,') else ''end) as datatype
From information_schema.columns
Where upper (table_schema) = upper ('test ')
And upper (table_name) = upper ('cxf ')

+ ------------- + -------------- +
| Column_name | datatype |
+ ------------- + -------------- +
| A | int |
| B | varchar (100) |
+ ------------- + -------------- +

ORACLE:
Select column_name, data_type | case when data_type like '% char % 'then' (' | data_length | ') 'end as data_type
From all_tab_columns
Where owner = upper ('test ')
And table_name = upper ('cxf ')
Order by 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.