Count the No.of Columns in a Table

Hi,Is it possible to write a Select statement
that returns back the number of columns in a table?
Or is there any other way on knowing the number of
columns in a table?

Hi
Subtle point:
USER_TAB_COLUMNS returns information relating only to tables owned by the current user.
ALL_TAB_COLUMNS includes all the tables which the current user can select from, whether owned by the current user or not.
DBA_TAB_COLUMNS, if the user has access to it, gives information about all tables in all schemas, regardless of whether the current user can select from them or not.
...so USER_TAB_COLUMNS may or may not be the best view to use.
regards
Andrew
UK

Similar Messages

  • 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'

  • Can you programmatically change the width of columns in a table control\indicator

    Is it possible to programmatically change the width of columns in a table control\indicator ie to fit to width of the data or in my case the header information.

    Create a property node (or reference) and use the 'Active Cell' property to select which column you want to change and then use the 'Cell size'--> 'Width' property to change the size.
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
    Attachments:
    table.vi ‏33 KB

  • Changing the order of columns in a table

    Can anyone tell me how to change the order of column in a table.
    I want a new column to be added in a table in 2nd position.
    Is there any way out for it?

    1) Does this have something to do with security? If not, it really ought to be posted in a more appropriate forum (Database - General for example).
    2) Why? If you care about the order of columns in a table, you're almost certainly doing something wrong. You can control the order of columns in a view, however, so you can put a view layer on top of the table to present the columns in a friendly fashion.
    3) Not without recreating the table. You can use the DBMS_REDEFINITION package to recreate the table with zero or minimal downtime but behind the scenes, you're really just creating a new table, copying the data over, dropping the old table, and renaming the new table to use the old table's name. DBMS_REDEFINITION does some extra work to track changes so that the original table can be available until the last possible moment.
    Justin

  • Counting the number of occurences in a table column

    Hi All
    I have a table with a column that contains approx. 5000 6-digit codes. A number of these codes are duplicted in the column, and I want to count the number of occurences of each code. The column looks a bit like -
    WCID
    940042
    920012
    940652
    940199
    188949
    155146
    155196
    174196
    152148
    151281
    196209
    174015
    182163
    195465
    195318
    182008
    189589
    150675
    There can be mulitple instances of each WCID and I need to count the number of instances of each. I also have access to another table that also has a column of each WCID, but only once - ie no multiple instances. The second table is identical except that there are only single instances of each WCID.
    I thought I could either loop through on the table to be counted, from 100000 to 999999 and count each occurence that way, but it would be very inefficient. The other way I thought would be to perhaps select a WCID from the unique table, count the occurence of that, select the next WCID from the unique table, count that and so on, however I'm not sure how to do it in PL/SQL. Perhaps select the WCID from the unique table into a cursor, loop through that and compare it with the original table and count the instances?
    I hope this makes some sense, any help would be really appreciated
    Thanks
    Bill

    Hi, Bill,
    That sounds like a job for GROUP BY:
    SELECT    wcid
    ,         COUNT (*)       AS num_found
    FROM      table_x
    GROUP BY  wcid
    ORDER BY  wcid
    I hope that answers your question.
    If not, post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data.

  • How do i know the number of columns in a table??

    dont think the question is too odd for me to post here..
    i am a new bee to oracle..
    so i just to know is there some way by which i can know the the total number of columns in a table..
    Thnks in advance for any solutions given

    did you try it whaterver is suggested?
    SQL> desc dept;
    Name                                                                          
    DEPTNO                                                                        
    DNAME                                                                         
    LOC                                                                           
    SQL> SELECT c.TABLE_NAME,c.COLUMN_NAME,c.COLUMN_ID FROM user_tab_columns c
      2  WHERE table_name='DEPT';
    TABLE_NAME                     COLUMN_NAME                     COLUMN_ID
    DEPT                           DEPTNO                                  1
    DEPT                           DNAME                                   2
    DEPT                           LOC                                     3
    SQL> SELECT COUNT(c.COLUMN_NAME) FROM user_tab_columns c
      2  WHERE table_name='DEPT';
    COUNT(C.COLUMN_NAME)
                       3

  • 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 ?

  • Count the number of columns return in an user-input sql query

    I need to do something like this
    I let an user input a sql query and then execute it
    assuming the sql query is always correct, it will return a Resultset
    then a table will pop up to accomodate the number of columns the resultset will produce
    i'm stuck at the part on how to check how many columns of data will be return in the resultset

         ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
         ResultSetMetaData rsmd = rs.getMetaData();
         int numberOfColumns = rsmd.getColumnCount();

  • Count the number of rows in each table

    I have a list of table names, how to I write a query to find out the row count of each table.
    select table_name from all_tables a where owner='XXX' and num_row > 100
    or
    select table_name from all_tables a where owner='XXX' and sample_size > 100
    doesn't quite work.
    Why?
    Thanks in advance,
    Edited by: mpt_fz on Jan 12, 2010 12:06 PM

    Well, then another method learned from Michael ;)
    scott@ORCL>
    scott@ORCL>select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    Elapsed: 00:00:00.14
    scott@ORCL>
    scott@ORCL>
    scott@ORCL>select table_name,
      2         DBMS_XMLGEN.getxmltype(
      3                                 'select count(*) c from '||table_name
      4                               ).extract('//text()').getnumberval() tot_rows
      5  from user_tables
      6  where iot_type is null
      7  or iot_type != 'IOT_OVERFLOW';
    TABLE_NAME                       TOT_ROWS
    A_TEST_TB_CASHFLOW                     14
    TEST_DUMMY                              1
    A_TEST_TB_CASHFLOW_N                    1
    TEST_CAST                               1
    DEPT                                    4
    EMP                                    14
    BONUS                                   0
    SALGRADE                                5
    EMP_DETAILS                             3
    T_EMP                                   0
    AUDIT_T                                 0
    TABLE_NAME                       TOT_ROWS
    C_C                                     4
    TRAIN_DET                               2
    TEST_COM_IMP                            2
    TIME_P                                  1
    PRI_UQ                                  4
    TEST_CHK                                0
    ANSHUMANSAHAISGENIOUS                   1
    T                                       1
    XEUROPE                                 2
    D_D                                     8
    PUBLICTRANSPORT                         4
    TABLE_NAME                       TOT_ROWS
    XASIA                                   2
    TF1                                     0
    TEST_HH                                14
    TEST_SWAP                               4
    REVIVE_XML                              3
    XGMT                                    1
    CUSTOMER_DET                            1
    FOURWHEELER                             2
    SPOOL_LOG                              13
    CITYTRANSPORT                           8
    T1                                      2
    TABLE_NAME                       TOT_ROWS
    T2                                      2
    A_A                                     1
    B_B                                     2
    AUTOMOBILE                              1
    XDUAL                                   1
    S_TEMP                                  0
    39 rows selected.
    Elapsed: 00:00:08.78
    scott@ORCL>Regards.
    Satyaki De.

  • Populate dates within the date range columns in a table

    Hi ,
    I have a Students table with StudentID, StartDate and EndDate. For one of the requirements, I need to populate all the dates within and includeing the StartDate and EndDate for all the students. Please find the DDL for the source table samples and also below
    samples of Source table columns and how the output should be.
    create table #Students (ID int,startdate date,Enddate date)
    insert into #Students values (1000, '2014-01-01',
    '2014-01-10')
    insert into #Students values (1000, '2014-02-22',
    '2014-02-28')
    insert into #Students values (1001, '2013-07-01',
    '2013-07-12')
    insert into #Students values (1001, '2013-08-01',
    '2013-08-03')
    insert into #Students values (1001, '2014-04-01',
    '2014-04-05')
    --select * from #Students order by id,startdate
    --drop table #students
    Thanks in advance  for your help!

    Hi vskindia,
    A recursive way to achieve the expected output.
    create table #Students (ID int,startdate date,Enddate date)
    insert into #Students values (1000, '2014-01-01',
    '2014-01-10')
    insert into #Students values (1000, '2014-02-22',
    '2014-02-28')
    insert into #Students values (1001, '2013-07-01',
    '2013-07-12')
    insert into #Students values (1001, '2013-08-01',
    '2013-08-03')
    insert into #Students values (1001, '2014-04-01',
    '2014-04-05')
    ;WITH cte AS
    SELECT ID,startdate,Enddate FROM #Students
    UNION ALL
    SELECT ID,DATEADD(DAY,1,startdate) AS startdate,Enddate FROM cte
    WHERE startdate<Enddate
    SELECT id,startdate FROM CTE ORDER BY ID,startdate
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • How to Update the oracle toad column value in table by using SSRS 2008

    Hi Team,
    How to update the oracle DB table column value by using SSRS 2008.
    Can any one help me on this.
    Thanks,
    Manasa.
    Thank You, Manasa.V

    Hi veerapaneni,
    According to your description, you want to use SSRS to update data in database table. Right?
    Though Reporting Services is mostly used for rendering data, your requirement is still can be achieved technically. You need to create a really complicated stored procedure. Pass insert/delete/update and the columns we need to insert/delete/update as
    parameters into the stored procedure. When we click "View Report", the stored procedure will execute so that we can execute insert/delete/update inside of the stored procedure. Please take a reference to two related articles below:
    Update Tables with Reporting Services – T-SQL Tuesday #005
    SQL Server: Using SQL Server Reporting Services to Manage Data
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Get the arrow on column header data table

      <t:commandSortHeader columnName="spclMngmtAreaNm" arrow="true"
                                  immediate="true">i am using <t:commandSortHeader with t:dataTable ,
    when form intialize this arrow on datatable not showing.
    when i click on column header only showing arrow .
    how to show arrow on datatable column by form inilize.
    thanks
    siva

    The easiest way to do this: set a default value for the sort column in your backing bean.
    Example:
         private String sortColumn="firstName";
         public String getSortColumn() {
              return sortColumn;
         <t:dataTable sortColumn="#{yourBean.sortColumn}" ... />On page load, the arrow is set by default to the firstname column.
    Best Regards,
    Dimi

  • Workflow Manager with Project Server error Exception Starting Workflow: The value for column _WORKFLOW_INSTANCE_UID_ in table _WorkflowInstance_ is DBNull

    Hello,
    The project server workflows were running fine on my servers (2 App and 2 WFE). suddenly workflows are not working anymore.
    and I am getting the below error:
    DBNull.. Trace: at Microsoft.Office.Project.Server.Schema.WorkflowDataSet.WorkflowInstanceRow.get_WORKFLOW_INSTANCE_UID() at Microsoft.Office.Project.Server.BusinessLayer.Workflow.StartWorkflow(Guid projectGuid, Guid enterpriseProjectTypeUid, Boolean
    isNewProject, Guid previousEntepriseProjectTypeUid, Boolean skipStage, Guid stageToSkipTo):
    WorkflowExceptionStartingWorkflow (35115). Details: id='35115' name='WorkflowExceptionStartingWorkflow' uid='047a6f2d-8a44-e411-8bf4-0050568b37eb'.
    I checked all DBs; all running fine. Also I tried to re-register the workflow with my site collection. but nothing worked.
    Any suggestions?
    Twitter : @MShoubaki | http://jo.linkedin.com/in/mshoubaki

    Hi Mohammad, 
    I was able to resolve my issue by installing KB2880963.  I did not have any of the other updates mentioned installed, but it did resolve the issue. 
    Note: I did need to restart my servers.  
    See Below from
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/b189e4b8-bb9e-4ade-a3d5-cd2e0f90e93f/workflow-not-working-after-installing-service-pack-1-and-patches?forum=sharepointadmin 
    Here is
    the security update which you will need to install.
    Update 2880963 for SharePoint Server 2013
    http://support.microsoft.com/kb/2880963
    Chcek the link for details.
    http://expertsharepoint.blogspot.de/2014/08/workflow-not-working-after-installing.html

  • Join query to get the constraint type ,column type and table name

    Hi ,This is my query
    select
    table_name  , column_name  from user_cons_columns where table_name='EMP_CLASS'
    table_name     column_name
    emp_class        empno
    emp_class        deptno
    select constraint_type,table_name  from user_constraints where table_name='EMP_CLASS'
    constraint_type    table_name
    p                        emp_class
    u                        emp_class
    I need query for this out put combining above two query.
    constraint_type        column_name   table_name
    p                             empno            emp_class
    u                            deptno             emp_classThanks,
    Deekay.

    Hi,
    Try this:
    select a.table_name  , a.column_name ,b.constraint_type from user_cons_columns a, user_constraints b
    where a.table_name=b.table_name and a.table_name='EMP_CLASS'How about reading the JOIN documentation??
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/queries006.htm#SQLRF30046
    Cheers,
    Avinash

  • How to: Count columns in a table?

    Quite simple question actually. How do I count the number of columns in a table using SQL?

    For AdventureWorks2012 tables & views:
    SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COUNT(COLUMN_NAME ) ColCount
    FROM INFORMATION_SCHEMA.COLUMNS
    GROUP BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME
    ORDER BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME;
    TABLE_SCHEMA TABLE_NAME ColCount
    dbo AWBuildVersion 4
    dbo DatabaseLog 8
    dbo ErrorLog 9
    HumanResources Department 4
    HumanResources Employee 16
    HumanResources EmployeeDepartmentHistory 6
    HumanResources EmployeePayHistory 5
    HumanResources JobCandidate 4
    HumanResources Shift 5
    HumanResources vEmployee 18
    HumanResources vEmployeeDepartment 10
    HumanResources vEmployeeDepartmentHistory 11
    HumanResources vJobCandidate 16
    HumanResources vJobCandidateEducation 13
    HumanResources vJobCandidateEmployment 11
    Person Address 9
    Person AddressType 4
    Person BusinessEntity 3
    Person BusinessEntityAddress 5
    Person BusinessEntityContact 5
    Person ContactType 3
    Person CountryRegion 3
    Person EmailAddress 5
    Person Password 5
    Person Person 13
    Person PersonPhone 4
    Person PhoneNumberType 3
    Person StateProvince 8
    Person vAdditionalContactInfo 17
    Person vStateProvinceCountryRegion 7
    Production BillOfMaterials 9
    Production Culture 3
    Production Document 14
    Production Illustration 3
    Production Location 5
    Production Product 25
    Production ProductCategory 4
    Production ProductCostHistory 5
    Production ProductDescription 4
    Production ProductDocument 3
    Production ProductInventory 7
    Production ProductListPriceHistory 5
    Production ProductModel 6
    Production ProductModelIllustration 3
    Production ProductModelProductDescriptionCulture 4
    Production ProductPhoto 6
    Production ProductProductPhoto 4
    Production ProductReview 8
    Production ProductSubcategory 5
    Production ScrapReason 3
    Production TransactionHistory 9
    Production TransactionHistoryArchive 9
    Production UnitMeasure 3
    Production vProductAndDescription 5
    Production vProductModelCatalogDescription 25
    Production vProductModelInstructions 11
    Production WorkOrder 10
    Production WorkOrderRouting 12
    Purchasing ProductVendor 11
    Purchasing PurchaseOrderDetail 11
    Purchasing PurchaseOrderHeader 13
    Purchasing ShipMethod 6
    Purchasing Vendor 8
    Purchasing vVendorWithAddresses 9
    Purchasing vVendorWithContacts 12
    Sales CountryRegionCurrency 3
    Sales CreditCard 6
    Sales Currency 3
    Sales CurrencyRate 7
    Sales Customer 7
    Sales PersonCreditCard 3
    Sales SalesOrderDetail 11
    Sales SalesOrderHeader 26
    Sales SalesOrderHeaderSalesReason 3
    Sales SalesPerson 9
    Sales SalesPersonQuotaHistory 5
    Sales SalesReason 4
    Sales SalesTaxRate 7
    Sales SalesTerritory 10
    Sales SalesTerritoryHistory 6
    Sales ShoppingCartItem 6
    Sales SpecialOffer 11
    Kalman Toth Database & OLAP Architect
    sqlusa.com
    Paperback / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012

Maybe you are looking for

  • Return Type of Applet's getParameter() method

    Hello I am having win7 machine with a jre 6 update 24 on it . I tried to execute method getParameter("DOCBASE") on Ie8(32bit) as well on IE8(64) bit. I am amazed to see DIFFERENT return value (NULL for 32 bit and Empty String for 64 bit)for both conf

  • Installing updates

    The latest update will not install. Any suggestions please.

  • Can't buy new subscription

    I have only 6 mins left of my 100 mins landlines subscription, so I'm trying to buy a bigger package, but I can't, because it's only showing me Skype Premium and Skype Credit. Where are those options for 100, 200, 300 minutes landline subscription?

  • Want the fieldnames in purchase order

    Hello Friends, Im creating one formula for alternate calculation type for a particular procedure. Now to create the formula i want the techincal names of pricing elements in conditions tab in PO : like how to trace out grosprice , thn total duty, thn

  • Z table updation

    i have to update some ztables through flat file. I created a report program for this. Before adding a record in the table i have to validate every field with a check table. Please suggest me regarding this Task. Thanks Srik