To find no of columns in a table

Hi
Please let me know how could i find number of columns in a table,ie how many fields the table has.
Thank you
Mary

Let us have a guess. "Interview question" i.e. "How do you [insert standard, common task here] without using [insert standard solution here]"
..is there any other way to find without using user_tab_columns. Use the ALL_tab_columns view

Similar Messages

  • How to Find Two Matching Columns in Two Table(to create a JOIN)

    Hi Guys!
    I just wondering if it is possible to have a SQL query to find two matches columns in two table to create any type of joins?!
    Let's say I have two tables CUSTOMER + INVOICE is it possible to run a SQL query to find two join able columns without scanning the tables visually?!
    Best Regards,

    Well, there's the Data Dictionary you could query for foreign key columns/constraints.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:661009003696

  • How can I find number of columns in a table using a query

    Hi
    I want to find the number of columns in a table using a query.
    Any help in this regard is much appreciated.
    Cheers

    Hi,
    This is the output i get when i executed ur query
    OWNER     OBJECT_NAME     OBJECT_TYPE
    SMLDBO     T2311_SURVEY_QUESTIONS     TABLE
    select OWNER,OBJECT_NAME,OBJECT_TYPE
    from all_objects
    where OBJECT_NAME = 'T2311_SURVEY_QUESTIONS';
    works Fine.
    But if i use the below query it returns : 0
    SELECT count(*) FROM user_tab_columns
    WHERE table_name =upper( 'T2311_SURVEY_QUESTIONS');
    What could be problem.
    The table exists + name of the table is correct + it resides in my schema itself.
    Any guess !!!

  • How to find diffrence in columns from two tables

    Hello,
    I have table TABLE1 and TABLE2 with same columns. One of the columns in both tables is ID
    Now there are records in table TABLE1 with ID=1
    and in table TABLE 2 with ID=-1
    Now I want to find if there are any column differing in values in tables TABLE1 for ID=1(for TABLE1) and TABLE2 for ID = -1 (for TABLE2)
    What is the best way to find the diffrence?
    Thanks in advance.

    Hello Subhash,
    Why don't you try NOT EXISTS functionality? Its quite performance effective too.
    select * from table1
    where NOT EXISTS
    (select 1 from table 2
    where table1.ID = table2.ID)
    UNION
    select * from table2
    where NOT EXISTS
    (select 1 from table 2
    where table1.ID = table2.ID)You can go for UNION if required, or else you can use them separately.

  • How can i find number of columns in a table ....... it's higer priority

    hi
    i wnat find the number of columns in a table.
    is there any predefine fiunction. pls tell me

    Thanks for correction!
    I asked myself that question after posting previous post... started to search in Documentation but you were faster.
    Thanks again!
    Message was edited by:
    Faust
    Edit:
    Dear thread users!
    You have here (in my post in this thread - see above) good example for inappropriate post in one thread.
    I posted to fast - I didn't realise am I sure what I wrote!
    Consequence was that, after posting, I asked myself is it correct my statement about rights on SYS-objects, I started to search for answer, etc.
    So what I want to say is: if you don't want to find yourself foolish, like I found myself, don't post before you are sure is it correct what you wrote!
    Cheers!

  • How to find out the NULL columns in the table?

    Hi,
    Please provide the query to find the null columns in the table. Here, all rows in the table have same column as null. It won't change.
    Table
    c1 c2 c3 c4
    X C 10
    T D 20
    I wanna find out as C2 is the nullable column.
    Thanks in advance !!
    Regards,
    Vissu....

    Below code might be solution for finding NULL valued in columns in a table and if it is solution .kindly give me points for the same.
    declare
    cursor col_cur is
    select column_name
    from user_tab_cols -- all_tables can also be used in case the table is present in own schema
    where table_name = 'TABLE_NAME'; --provide the TABLE_NAME  
    stmt varchar2(1000):= '';
    v_count number;
    count_null number;
    begin
    execute immediate 'select count(*) from TABLE_NAME' into v_count; --provide the TABLE_NAME  
    for rec in col_cur loop
    execute immediate 'select count(*) from TABLE_NAME' where --provide the TABLE_NAME  
    '||rec.column_name||' IS NULL' into count_null;
    if count_null = v_count then
    stmt :=stmt|| rec.column_name ||chr(13);
    end if;
    end loop;
    dbms_output.put_line(stmt);
    end ;

  • How to get the column name and table name with value

    Hi All
    I have one difficult requirement
    I have some column values and they have given some alias column names but i need to find the correct column name and table name from the database.
    For example value is "SRI" and i dont know the table and exact column name so is there any possibilities to find the column name and table name for the given value
    Thanks & Regards
    Srikkanth.M

    Searching all the database for a word...
    Courtesy of michaels...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    11g upwards
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('EMP', 'DEPT')),
           xmltable (str columns result varchar2(10) path '.')
    TABLE_NAME                     COLUMN_NAME                    SEARCH_STRING                    RESULT   
    DEPT                           DNAME                          es                               RESEARCH 
    EMP                            ENAME                          es                               JAMES    
    EMP                            JOB                            es                               SALESMAN 
    EMP                            JOB                            es                               SALESMAN 
    4 rows selected.

  • How do i find out  what is the data type of a column of a Table in oracle or SQL?

    a) What if i want to find out the  Datatype of a specific column in the Table.
    b) How do i find the Column Datatypes?
    Can anyone please help me. I am new to oracle and Trying to Learn some stuff

    Hi,
    How about doing
    SQL> desc <table_name>
    SQL> desc emp
    Name                                      Null?    Type
    EMPNO                                     NOT NULL NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO                                             NUMBER(2)

  • How to find the frequently updated columns in a table

    Hi ,
    I need to find out all the columns of a tables which are frequently getting updated.
    is there any way that I can achieve this ? I am not sure if any meta data information for DML operations exist in Oracle 9 i. Any input is welcome.
    Thanks in Advance !!

    Thank u , i am thinking the same, Thanks for the suggestion.
    any other idea.... like is there any system table which we can query to get details about these dml operations on a table ?are there any kind of system audit tables in oracle where these get recorded ?

  • How to find columns in a table ?

    Hi
    I want a sql query to find a columns in specfic table
    all i hav in hand is the name of the table and a value which i know is in the columns but dont know which column
    for example i know there is table named student with 15 columns and a value of a column is 'ABC' but i dont have the name of the column
    how to find the table using SQL query
    Thanks in Advance
    Bala

    SELECT column_name,
      table_name
       FROM user_tab_cols
      WHERE table_name IN ('<yourtablenamehere>')
    AND extractvalue(dbms_xmlgen.getxmltype('select ''Found'' col from '|| table_name ||' where rownum=1 and ' || CASE WHEN data_type IN
          ( SELECT DISTINCT data_type FROM user_tab_cols WHERE data_type NOT LIKE 'TIME%' AND data_type != 'DATE' )
        THEN column_name ELSE 'to_char('||column_name||',''DD-MM-YYYY HH24:MI:ss'')'  END
      ||' = ''<yourcolumnvaluetobefound>'' '),'//COL')='Found';Fill <yourtablenamehere> and <yourcolumnvaluetobefound> in the above query and get the result.
    Ravi Kumar

  • How to find the column name and table name with a value

    Hi All
    How to find the column name and table name with "Value".
    For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
    Any help is highly appricatable
    Thanks & Regards
    Srikkanth.M

    2 solutions by Michaels (the latter is 11g upwards only)...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • How to find the creation date of a column in a table?

    Hi,
    i scroll all the view and table of the Oracle RDBMS catalog and i didn't find how i can find when a column has been added to a table.
    Is there a way i can find this info?
    The column added is not the same date tehn the date of the table creation or the analyse column.
    Thanks

    Hi,
    Something like this
    select table_name, created from user_objects where object_type = 'TABLE'Regards
    Anurag Tibrewal
    Oops: I did not see the requirement correctly. If auditing is not the option for you then logminer (if archive is present) else no other option i can think of.
    Edited by: Anurag Tibrewal on Oct 6, 2009 8:37 PM

  • Query to find the no of columns in a table

    Is there a query to find the total number of columns in a table?

    Dou you know read?
    -- the number of rows in a table named yourtable:
    select count(1) from yourtable;
    -- the number of columns in a table
    -- If is a user's table:
    select count(1)
    from user_tab_columns
    where table_name='YOURTABLE'
    --If it is´t
    select count(1)
    from DBA_tab_columns
    where owner = 'USEROWNER'
    and table_name='YOURTABLE'

  • DBMS_CDC find only the columns that are changed along with the primary key in the table

    Hello,
    We are having a requirement to find the change data in the production environment.
    We are planning to use the DBMS_CDC utility.
    But for  example in the create change table 1 picked emp_id,ename, address, salary,dob.
    I have a sample data of
    empid
    ename
    address
    salary
    DOB
    1
    test1
    24 test street
    2000
    20-Jan-98
    2
    test2
    25 test street
    2500
    15-Aug-97
    if ename for empid 1 is changed to test1_test3 from test1.
    My CDC is capturing  the values in the old and new values in the 5 columns.
    But i need to get only the empid (primary key of the source table) and the ename column as only that's been updated not the rest of the 3 columns.
    Can i accomplish this.
    Please advice.

    Hello,
    Thanks for the information.
    but if i change the change table  then i will miss the other columns right?
    I want to get the columns( empid and ename) only if ename is changed. i.e when ever any column in emp table changes i need to get all the columns where the data is changed along with the primary key columns empid.
    Is there any way i can tweak the parameters so that i can achieve this or is there any other way using the cdc i can get this data.
    Thanks

  • How to find the partition column in a partitioned table

    Hi,
    I have a partition table and I need to find out what column was used to partition the table. Range partition.
    Thanks,
    Maria Sanchez

    select *
    from dba_part_key_columns

Maybe you are looking for