How can I describe a table in Oracle without using the DESCRIBE command?

前端 未结 4 2010
我寻月下人不归
我寻月下人不归 2020-11-29 04:16

I\'m having a hard time with a class I am taking. We need to write an Oracle script that will act just like the DESCRIBE command. The book we are using describes how to work

4条回答
  •  野性不改
    2020-11-29 04:54

    Newly introduced in Oracle SQLcl is the information command or simply INFO table_name. It has a simple syntax like DESC[RIBE]:

    SQL> info
    INFORMATION
    --------
    
    This command is like describe but with more details about the objects requested.
    
    INFO[RMATION] {[schema.]object[@connect_identifier]}
    INFO+ will show column statistics
    

    Its output is far superior and descriptive compared to DESCRIBE. It Lists more detailed information about the column definitions for a table, view or synonym, or the specifications for a function or procedure.

    For eg: This is the output I get in SQLcl: Release 18.1.1 when I run

    info employees

    SQL> info employees;
    TABLE: EMPLOYEES 
         LAST ANALYZED:2018-05-26 15:07:58.0 
         ROWS         :107 
         SAMPLE SIZE  :107 
         INMEMORY     :DISABLED 
         COMMENTS     :employees table. Contains 107 rows. References with departments, 
                           jobs, job_history tables. Contains a self reference. 
    
    Columns 
    NAME             DATA TYPE           NULL  DEFAULT    COMMENTS
    *EMPLOYEE_ID     NUMBER(6,0)         No               Primary key of employees table.
     FIRST_NAME      VARCHAR2(20 BYTE)   Yes              First name of the employee. A not null column.
     LAST_NAME       VARCHAR2(25 BYTE)   No               Last name of the employee. A not null column.
     EMAIL           VARCHAR2(25 BYTE)   No               Email id of the employee
     PHONE_NUMBER    VARCHAR2(20 BYTE)   Yes              Phone number of the employee; includes country
                                                          code and area code
     HIRE_DATE       DATE                No               Date when the employee started on this job. A not
                                                          null column.
     JOB_ID          VARCHAR2(10 BYTE)   No               Current job of the employee; foreign key to job_id
                                                          column of the jobs table. A not null column.
     SALARY          NUMBER(8,2)         Yes              Monthly salary of the employee. Must be greater
                                                          than zero (enforced by constraint emp_salary_min)
     COMMISSION_PCT  NUMBER(2,2)         Yes              Commission percentage of the employee; Only
                                                          employees in sales department elgible for
                                                          commission percentage
     MANAGER_ID      NUMBER(6,0)         Yes              Manager id of the employee; has same domain as
                                                          manager_id in departments table. Foreign key to
                                                          employee_id column of employees table.(useful for
                                                          reflexive joins and CONNECT BY query)
     DEPARTMENT_ID   NUMBER(4,0)         Yes              Department id where employee works; foreign key to
                                                          department_id column of the departments table
    
    Indexes
    INDEX_NAME             UNIQUENESS   STATUS   FUNCIDX_STATUS   COLUMNS                 
    HR.EMP_JOB_IX          NONUNIQUE    VALID                     JOB_ID                  
    HR.EMP_NAME_IX         NONUNIQUE    VALID                     LAST_NAME, FIRST_NAME   
    HR.EMP_EMAIL_UK        UNIQUE       VALID                     EMAIL                   
    HR.EMP_EMP_ID_PK       UNIQUE       VALID                     EMPLOYEE_ID             
    HR.EMP_MANAGER_IX      NONUNIQUE    VALID                     MANAGER_ID              
    HR.EMP_DEPARTMENT_IX   NONUNIQUE    VALID                     DEPARTMENT_ID           
    
    
    References
    TABLE_NAME    CONSTRAINT_NAME   DELETE_RULE   STATUS    DEFERRABLE       VALIDATED   GENERATED   
    DEPARTMENTS   DEPT_MGR_FK       NO ACTION     ENABLED   NOT DEFERRABLE   VALIDATED   USER NAME   
    EMPLOYEES     EMP_MANAGER_FK    NO ACTION     ENABLED   NOT DEFERRABLE   VALIDATED   USER NAME   
    JOB_HISTORY   JHIST_EMP_FK      NO ACTION     ENABLED   NOT DEFERRABLE   VALIDATED   USER NAME   
    

    Here is a screen shot with info+:

提交回复
热议问题