identify difference from NUMBER(5) and NUMBER(8,2) USER_TAB_COLUMNS

后端 未结 3 1080
猫巷女王i
猫巷女王i 2021-01-28 07:47

I want to get the columns names and datatype and its datatype\'s length .as example

if there is a table

SQL> create table TestTable(
  2    ID                


        
相关标签:
3条回答
  • 2021-01-28 08:16

    There are data_precision and data_scale columns there.
    Please take a look at this example:

    create table qwer(
      x number,
      y number(8,2),
      z number(5,0),
      a int,
      b decimal(5,3)
    );
    
    SELECT column_name, data_type, data_precision, data_scale
    FROM USER_TAB_COLUMNS
    WHERE Table_name = 'QWER'
    ;
    
    COLUMN_NAME   DATA_TYPE DATA_PRECISION DATA_SCALE
    ------------- --------- -------------- ----------
    B             NUMBER     5             3
    A             NUMBER
    X             NUMBER         
    Y             NUMBER     8             2
    Z             NUMBER     5             0
    

    EDIT


    To find primary key columns you need to join two dictionary views, please see the below example:

    CREATE TABLE pk1(
      id int primary key,
      name varchar2(10)
    );
    
    CREATE TABLE pk2(
      id int ,
      pk1 number(10,0),
      pk2 varchar2(5),
      name varchar2(10),
      constraint my_composite_pk primary key (id, pk1, pk2 )
    );
    
    SELECT c.table_name, cols.column_name, cols.position 
    FROM user_constraints c
    JOIN USER_CONS_COLUMNS cols
    USING ( CONSTRAINT_NAME )
    WHERE c.table_name IN ('PK1', 'PK2' )
      and c.constraint_type = 'P' /* P - means PRIMARY KEY */
    ORDER BY 1,3
    ; 
    
    TABLE_NAME COLUMN_NAME   POSITION
    ---------- ----------- ----------
    PK1        ID                   1
    PK2        ID                   1
    PK2        PK1                  2
    PK2        PK2                  3
    
    0 讨论(0)
  • 2021-01-28 08:17

    Why don't you try SELECT * FROM information_schema.columns ?

    It has columns "table_schema, table_name, column_name, ordinal_position, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, datetime_precision", etc.

    0 讨论(0)
  • 2021-01-28 08:33

    If this is only for Geetting information then just Press ALT+F1 on the name of the table this will show you the names of the columns with length and data types.

    0 讨论(0)
提交回复
热议问题