Home > Database > Mysql Tutorial > Oracle查看表结构的几种方法

Oracle查看表结构的几种方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:28:58
Original
5739 people have browsed it

Oracle查看表结构的几种方法 1,DESCRIBE 命令 使用方法如下: SQLgt; describe nchar_tst(nchar_tst为表名) 显示的结果如下:

Oracle查看表结构的几种方法

1,,DESCRIBE 命令
 使用方法如下:
 SQL> describe nchar_tst(nchar_tst为表名)
 显示的结果如下:
  名称                                      是否为空? 类型
  ----------------------------------------- -------- ----------------------------
  NAME                                              NCHAR(6)
  ADDR                                              NVARCHAR2(16)
  SAL                                                NUMBER(9,2)
 2,DBMS_METADATA.GET_DDL包
 使用方法如下:

SQL> SELECT DBMS_METADATA.GET_DDL('TABLE','NCHAR_TST') FROM DUAL;

如果显示的结果并未完整,如下:
  CREATE TABLE "SCOTT"."NCHAR_TST"
    (    "NAME" NCHAR(6),
        "ADDR" NVARCHAR2(16
 
那么修改如下:

SQL> SET LONG 9999
SQL> SELECT DBMS_METADATA.GET_DDL('TABLE','NCHAR_TST') FROM DUAL;

则显示如下的结果:
 DBMS_METADATA.GET_DDL('TABLE','NCHAR_TST')
 ------------------------------------------------------------------------------
  CREATE TABLE "SCOTT"."NCHAR_TST"
    (    "NAME" NCHAR(6),
        "ADDR" NVARCHAR2(16),
        "SAL" NUMBER(9,2)
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 LOGGING
  STORAGE(INITIAL 12288 NEXT 12288 MINEXTENTS 1 MAXEXTENTS 249 PCTINCREASE 50
  FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "SYSTEM"
 3,方法:
   通过Oracle中的user_tab_cols, user_col_comments, user_constraints, user_cons_columns表联合查询。
   user_tab_cols用来获取对应用户表的列信息;
   user_col_comments用来获取对应用户表列的注释信息;
   user_constraints用来获取用户表的约束条件;
   user_cons_columns约束中用户可访问列。
 

示例代码:

select t.table_name,t.column_name,t.data_type,t.data_length,t.nullable,t.column_id,c.comments,
      (SELECT CASE WHEN t.column_name=m.column_name THEN 1 ELSE 0 END FROM DUAL) iskey
      FROM user_tab_cols t, user_col_comments c, (select m.column_name from user_constraints s, user_cons_columns m
            where lower(m.table_name)='us_cities' and m.table_name=s.table_name
            and m.constraint_name=s.constraint_name and s.constraint_type='P') m
      WHERE lower(t.table_name)='us_cities'
            and c.table_name=t.table_name
            and c.column_name=t.column_name
            and t.hidden_column='NO'
 order by t.column_id

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template