Query to get the data of all the columns in a table except any one column

Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
For Example:
Let us consider the EMP table.,
From this table except the column comm all the remaining columns of the table should be listed
For this we can write a query like this..
Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
Is there any other way of writing the query to get the required result..?
Thanks..

Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
If you really need to list all the columns for a table because you don't want to type them, just use something like...
SQL> ed
Wrote file afiedt.buf
  1  select trim(',' from sys_connect_by_path(column_name,',')) as columns
  2  from (select column_name, row_number() over (order by column_id) as column_id
  3        from user_tab_cols
  4        where column_name not in ('COMM')
  5        and   table_name = 'EMP'
  6       )
  7  where connect_by_isleaf = 1
  8  connect by column_id = prior column_id + 1
  9* start with column_id = 1
SQL> /
COLUMNS
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
SQL>

Similar Messages

  • How to get the columns from SYS.ALL_COLUMNS and use it in COALESCE() Function.

    Hi,
    I have table called Employe. And the Columns are Emp_ID,EMP_NAME,SRC_SYS_CD,DOB
    I have Query like
    Select
    COALESCE(MAX(CASE WHEN src_sys_cd='1' THEN Emp_id END), MAX(CASE WHEN src_sys_cd='2' THEN Emp_Id END))Emp_Id,
    COALESCE(MAX(CASE WHEN src_sys_cd='1' THEN Emp_name END), MAX(CASE WHEN src_sys_cd='2' THEN Emp_Name END))Emp_name,
    COALESCE(MAX(CASE WHEN src_sys_cd='1' THEN dob END), MAX(CASE WHEN src_sys_cd='2' THEN dob END))dob ,
    from Employe
    group by dob.
    I want to generalize the query like get the columns from SYS.ALL_COLUMNS table for that table name and want to pass it to COALEACE() function. I tried with Cursor. But i didnt get the appropriate results.
    Is there any way to achieve this? Please help me out in this regard.
    Thanks,

    Is this the kinda thing you're after?
    Add a filter to the queries to get just a single table/
    WITH allCols AS (
    SELECT s.name as sName, o.name AS oName, c.name AS cName, column_id,
    CASE WHEN st.name in ('float','bigint','tinyint','int','smallint','bit','datetime','money','date','datetime2','uniqueidentifier','sysname','geography','geometry') THEN st.name
    WHEN st.name in ('numeric','real') THEN st.name + '('+CAST(c.scale AS VARCHAR)+','+CAST(c.precision AS VARCHAR)+')'
    WHEN st.name in ('varbinary','varchar','binary','char','nchar','nvarchar') THEN st.name + '(' + CAST(ABS(c.max_length) AS VARCHAR) + ')'
    ELSE st.name + ' unknown '
    END + ' '+
    CASE WHEN c.is_identity = 1 THEN 'IDENTITY ' ELSE '' END +
    CASE WHEN c.is_nullable = 0 THEN 'NOT ' ELSE '' END + 'NULL' AS bText,
    f.name AS fileGroupName
    FROM sys.columns c
    INNER JOIN sys.objects o
    ON c.object_id = o.object_id
    AND o.type = 'U'
    INNER JOIN sys.systypes st
    ON c.user_type_id = st.xusertype
    INNER JOIN sys.schemas s
    ON o.schema_id = s.schema_id
    INNER JOIN sys.indexes i
    ON o.object_id = i.object_id
    AND i.index_id = (SELECT MIN(index_id) FROM sys.indexes WHERE object_ID = o.object_id)
    INNER JOIN sys.filegroups f
    ON i.data_space_id = f.data_space_id
    ), rCTE AS (
    SELECT sName, oName, cName, column_id, CAST(cName + ' ' + bText AS VARCHAR(MAX)) as bText, CAST(cName AS VARCHAR(MAX)) AS colList, fileGroupName
    FROM allCols
    WHERE column_id = 1
    UNION ALL
    SELECT r.sName, r.oName, r.cName, c.column_id, CAST(r.bText +', ' + c.cName + ' ' +c.bText AS VARCHAR(MAX)), CAST(r.colList+ ', ' +c.cName AS VARCHAR(MAX)), c.fileGroupName
    FROM allCols c
    INNER JOIN rCTE r
    ON c.oName = r.oName
    AND c.column_id - 1 = r.column_id
    ), allIndx AS (
    SELECT 'CREATE '+CASE WHEN is_unique = 1 THEN ' UNIQUE ' ELSE '' END+i.type_desc+' INDEX ['+i.name+'] ON ['+CAST(s.name COLLATE DATABASE_DEFAULT AS NVARCHAR )+'].['+o.name+'] (' as prefix,
    CASE WHEN is_included_column = 0 THEN '['+c.name+'] '+CASE WHEN ic.is_descending_key = 1 THEN 'DESC' ELSE 'ASC' END END As cols,
    CASE WHEN is_included_column = 1 THEN '['+c.name+']'END As incCols,
    ') WITH ('+
    CASE WHEN is_padded = 0 THEN 'PAD_INDEX = OFF,' ELSE 'PAD_INDEX = ON,' END+
    CASE WHEN ignore_dup_key = 0 THEN 'IGNORE_DUP_KEY = OFF,' ELSE 'IGNORE_DUP_KEY = ON,' END+
    CASE WHEN allow_row_locks = 0 THEN 'ALLOW_ROW_LOCKS = OFF,' ELSE 'ALLOW_ROW_LOCKS = ON,' END+
    CASE WHEN allow_page_locks = 0 THEN 'ALLOW_PAGE_LOCKS = OFF' ELSE 'ALLOW_PAGE_LOCKS = ON' END+
    ')' as suffix, index_column_id, key_ordinal, f.name as fileGroupName
    FROM sys.indexes i
    LEFT OUTER JOIN sys.index_columns ic
    ON i.object_id = ic.object_id
    AND i.index_id = ic.index_id
    LEFT OUTER JOIN sys.columns c
    ON ic.object_id = c.object_id
    AND ic.column_id = c.column_id
    INNER JOIN sys.objects o
    ON i.object_id = o.object_id
    AND o.type = 'U'
    AND i.type <> 0
    INNER JOIN sys.schemas s
    ON o.schema_id = s.schema_id
    INNER JOIN sys.filegroups f
    ON i.data_space_id = f.data_space_id
    ), idxrCTE AS (
    SELECT r.prefix, CAST(r.cols AS NVARCHAR(MAX)) AS cols, CAST(r.incCols AS NVARCHAR(MAX)) AS incCols, r.suffix, r.index_column_id, r.key_ordinal, fileGroupName
    FROM allIndx r
    WHERE index_column_id = 1
    UNION ALL
    SELECT o.prefix, COALESCE(r.cols,'') + COALESCE(', '+o.cols,''), COALESCE(r.incCols+', ','') + o.incCols, o.suffix, o.index_column_id, o.key_ordinal, o.fileGroupName
    FROM allIndx o
    INNER JOIN idxrCTE r
    ON o.prefix = r.prefix
    AND o.index_column_id - 1 = r.index_column_id
    SELECT 'CREATE TABLE ['+sName+'].[' + oName + '] ('+bText+') ON [' + fileGroupName +']'
    FROM rCTE r
    WHERE column_id = (SELECT MAX(column_id) FROM rCTE WHERE r.oName = oName)
    UNION ALL
    SELECT prefix + cols + CASE WHEN incCols IS NOT NULL THEN ') INCLUDE ('+incCols ELSE '' END + suffix+' ON [' + fileGroupName +']'
    FROM idxrCTE x
    WHERE index_column_id = (SELECT MAX(index_column_id) FROM idxrCTE WHERE x.prefix = prefix)

  • I have an amazing number of duplicates - not photo - but other.  How can I get rid of them?   Virtually all kinds if data is duplicated often 20- to 50 times. The duplicates are bot restricted to any one kind of data.

    I have an amazing number of duplicates - not photo - but other.  How can I get rid of them?   Virtually all kinds if data is duplicated often 20- to 50 times. The duplicates are bot restricted to any one kind of data.

    https://discussions.apple.com/message/25888564#25888564

  • Can I get a query to get the output data like 4th column instead of 3rd col

    Can I get a query to get the output data like 4th column instead of 3rd column ?
    SQL&gt; select emp.deptno, empno, rownum from emp, dept where emp.deptno=dept.deptno;
    DEPTNO EMPNO ROWNUM
    10 7782 *1* *1*
    10 7839 *2* *2*
    10 7934 *3* *3*
    20 7369 *4* *1*
    20 7876 *5* *2*
    20 7902 *6* *3*
    20 7788 *7* *4*
    20 7566 *8* *5*
    30 7499 *9* *1*
    30 7698 *10* *2*
    30 7654 *11* *3*
    30 7900 *12* *4*
    30 7844 *13* *5*
    30 7521 *14* *6*
    14 rows selected.

    SQL> select emp.deptno, emp.empno,
      2    row_number() over(order by emp.deptno, emp.empno) rn,
      3    row_number() over(partition by emp.deptno order by emp.empno) dept_rn
      4  from emp, dept
      5  where emp.deptno=dept.deptno
      6  order by emp.deptno, emp.empno;
        DEPTNO      EMPNO         RN    DEPT_RN
            10       7782          1          1
            10       7839          2          2
            10       7934          3          3
            20       7369          4          1
            20       7566          5          2
            20       7788          6          3
            20       7876          7          4
            20       7902          8          5
            30       7499          9          1
            30       7521         10          2
            30       7654         11          3
            30       7698         12          4
            30       7844         13          5
            30       7900         14          6
    14 rows selected.Regards,
    Dima

  • Help in query to get the max(date)

    Hi I have query like below and based on the query I get the following results,
    SELECT a.UsageId,a.product,ProductDate
    FROM dbo.table1 a
    JOIN dbo.table2 b ON a.SID= b.SID
    JOIN dbo.table3 c ON b.CID = c.CID
    UsageId        Product          UsageDate
    1 Yellow 2014-01-01
    2 Yellow 2014-01-02
    3 Yellow 2014-01-03
    4 Yellow 2014-01-04
    5 Red 2014-01-01
    6 Red 2014-01-02
    7 Blue 2014-01-03
    8 Blue
    2014-01-04
    Now I want to add a new column which gives me the Max(UsageDate) of the column Prdouct last Usage.
    UsageId        Product          UsageDate          Max(UsageDate)
    1 Yellow
    2014-01-01          2014-01-04
    2 Yellow
    2014-01-02    2014-01-04
    3 Yellow
    2014-01-03          2014-01-04
    4 Yellow
    2014-01-04          2014-01-04
    5 Red 2014-01-01          2014-01-02 
    6 Red 2014-01-02          2014-01-02
    7 Blue
    2014-01-03          2014-01-04
    8 Blue
    2014-01-04          2014-01-04

    Simply use:
    SELECT a.UsageId,a.product,ProductDate, MAX(ProductDate) OVER (PARTITION BY a.ProductID) as [Latest Product Usage Date]
    FROM dbo.table1 a
    JOIN dbo.table2 b ON a.SID= b.SID
    JOIN dbo.table3 c ON b.CID = c.CID
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Query to get the record with latest date

    I have
    ACCOUNT_TABLE
    account_number
    account_event
    event_date
    ACCOUNT_TABLE
    1,Open,12 Jan 2006
    1,Open,13 Jan 2006
    1,Open,14 Jan 2006
    1,Open,15 Jan 2006
    1,Open,16 Jan 2006
    How can I get the latest record(16 Jan 2006) in one sql statement.
    Thx
    m

    if you have more account_event's then...
    SQL> with t as
      2   (select 1 account_number,'Open' account_event,'12 Jan 2006' event_date from dual union all
      3   select 1,'Open','13 Jan 2006' from dual union all
      4   select 1,'Open','14 Jan 2006' from dual union all
      5   select 1,'Open','15 Jan 2006' from dual union all
      6   select 1,'Open','16 Jan 2006' from dual union all
      7   select 1,'Close','17 Jan 2006' from dual union all
      8   select 1,'Close','18 Jan 2006' from dual union all
      9   select 2,'Open','19 Jan 2006' from dual)
    10   select * from t a
    11   where (a.account_number, account_event,a.event_date) in
    12   ((select b.account_number, account_event,max(b.event_date) from t b group by b.account_number,account_event))
    13  order by account_number;
    ACCOUNT_NUMBER ACCOU EVENT_DATE
                 1 Close 18 Jan 2006
                 1 Open  16 Jan 2006
                 2 Open  19 Jan 2006

  • Get the column names of a query (in own plugin)

    Hi,
    I'm developing my first plugin. It is a region plugin where the plugin-user passes a sql query as the source that the plugin will turn into a formated report.
    I found how to retreive the query result by using APEX_PLUGIN_UTIL.GET_DATA functions. Since it is an array, it is simple to cycle through the data rows. But how can i figure out
    1) how many columns the query returns
    2) whats the name of the columns is?
    Thanks a lot in advance for any hint...
    Cheers, Hans

    Hi Hans,
    the package APEX_PLUGIN_UTIL provides everything you need. No need to do your own DBMS_SQL handling!
    Have a look at the API documentation and the example of GET_DATA at http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_plugin_util.htm#BABFBIJD
    The t_column_value_list record type is a two dimensional array defined as
    type t_column_value_list  is table of wwv_flow_global.vc_arr2 index by pls_integer;The first array contains an entry for each column.
    l_column_value_list.COUNTcan be used to get the number of columns.
    l_column_value_list(1).COUNTcan be used to get the number of rows. An example to iterate over all columns and rows:
    for l_column in 1 .. l_column_value_list.count loop
        for l_row in 1 .. l_column_value_list(l_column).count loop
            sys.htp.p('column#=' || l_column || ' row=' || l_row || ' value: ' || l_column_value_list(l_column)(l_row));
        end loop;
    end loop;If you need the name of the columns and maybe the original data type and not everything converted to VARCHAR2 you have to use the more sophisticated GET_DATA2. See http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_plugin_util.htm#BABFJHAI
    This function returns the record type t_column_value_list2 which is defined as
    type t_value is record (
        varchar2_value      varchar2(32767),
        number_value        number,
        date_value          date,
        timestamp_value     timestamp,
        timestamp_tz_value  timestamp with time zone,
        timestamp_ltz_value timestamp with local time zone,
        interval_y2m_value  interval year to month,
        interval_d2s_value  interval day to second,
        blob_value          blob,
        bfile_value         bfile,
        clob_value          clob );
    type t_value_list is table of t_value index by pls_integer;
    type t_column_values is record (
        name       varchar2(32767),
        data_type  varchar2(20), /* use c_data_type_* constants to compare */
        value_list t_value_list );
    type t_column_value_list2 is table of t_column_values         index by pls_integer;Again, it's some kind of two dimensional array. The first dimensions are the columns. But this time you also get some details of the parsed column. For example:
    for l_column in 1 .. l_column_value_list2.COUNT loop
        sys.htp.p('Column Name: ' || l_column_value_list2(l_column).name || ' Data Type: ' || l_column_value_list2(l_column).data_type );
    end loop;Will return you all the columns of the SQL statement. Using "name" and "data_type" you can get the column name and the data type. To access the values you can use
    for l_column in 1 .. l_column_value_list2.COUNT loop
        sys.htp.p('Column Name: ' || l_column_value_list2(l_column).name || ' Data Type: ' || l_column_value_list2(l_column).data_type );
        for l_rows in 1 .. l_column_value_list2(l_column).value_list.COUNT loop
            sys.htp.p(
                'row=' || l_row || ' value: ' ||
                apex_plugin_util.get_value_as_varchar2 (
                    p_data_type => l_column_value_list2(l_column).data_type,
                    p_value     => l_column_value_list2(l_column).value_list(l_row) );
        end loop;
    end loop;I used apex_plugin_util.get_value_as_varchar2 to always get a VARCHAR2, independent of the actual data type of the column. If you need the original data type, use "number_value", ... of the t_value record type.
    Hope that gives you a direction
    Patrick
    Regards
    Patrick
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • SQL query to get the Datetime 06 hours prior to the table Datetime value

    Hi Experts,
                    I'm just trying to create a SQL query to get the Datetime which should be 06 hours prior to my Table column value(Executiontime),
    Eg: my Executiontime(column) value is 07:00AM means, this query should fetch the detail of first VMName from table at 01:00AM, 
    SQL Table Name: TestTable
    Columns: VMName(varchar),status(varchar) Executiontime(Datetime)
    SQL Query : Select Top 1 VMName from
    TestTable where convert(date,Exeutiontime)=convert(date,getdate()) and
    status='0' and ExecutionTime > dateadd(hour,6,getdate())
    Request someone to alter this Query to my requirement or give me the new one.
    Regards,
    Sundar
    Sundar

    Hi All,
            Thanks for your Prompt response. I tried the below queries, but still I don't have any luck. Actually the queries are returning the value before the condition met (say when the time difference is more than 06 hours). I want the
    query to return exactly @ 06 hour difference or less than 06 hours,
    Query 01: Select Top 1 VMName from TestTable where
    convert(date,Exeutiontime)=convert(date,getdate())
    and status='0'
    and ExecutionTime >
    dateadd(hour,-6,getdate())
    Query 02: Select
    Top 1 VMName from TestTable where
    status='0'
    and ExecutionTime >
    dateadd(hour,-6,getdate())
    Query 03: Select
    Top 1 VMName from TestTable where status='0'
    and ExecutionTime >
    dateadd(hour,-6,ExecutionTime)
              Can someone point out the mistake please.
    Regards,
    Sundar
    Sundar

  • Needs Query to get the cycle time automatically based on the value provided in the UDF on OWOR  table

    Dear all,
    Need a query to get the Cycle time in hr based on the value provide in the udf on OWOR table.
    Details of UDF:-
    1.Start date =10/07/14  (Field Name U_EA_REST)   
    2.Start time =10:00        (Field Name U_EA_REASTARTTIME)
    3.End date =11/07/14    (Field Name U_EA_REET)
    4.End Time=14:00          (Field Name U_EA_REAENDTIME
    Cycle Time=_______      (Field Name U_EA_REACYCLETIME)
    Regards,
    BanugopanRajendran

    Dear all,
    Need a query to get the Cycle time in hr based on the value provide in the udf on OWOR table.
    Details of UDF:-
    1.Start date =10/07/14  (Field Name U_EA_REST)   -  Date Type
    2.Start time =10:00        (Field Name U_EA_REASTARTTIME) - Hour Type
    3.End date =11/07/14    (Field Name U_EA_REET) - Date Type
    4.End Time=14:00          (Field Name U_EA_REAENDTIME - Hour Type
    Cycle Time=_______      (Field Name U_EA_REACYCLETIME) - Hour Type
    Regards,
    BanugopanRajendran

  • SQL or Powershell query to get the SCOM management group id for SCOM 2007 R2 & 2012 / 2012 R2

    Hi All,
    Can any one provide me the SQL or Powershell query to get the SCOM management group id for SCOM 2007 R2 & 2012 / 2012 R2
    I had a SQL query which will query the data from data warehouse and give the management group id but i have lost it for all 3 above.
    Gautam.75801

    Hi Gautam,
    Hope it helps:
    http://blog.tyang.org/2013/03/13/data-aggregation-field-became-empty-in-opsmgr-2007-linked-performance-report/
    http://blog.tyang.org/2012/09/05/mp-authoring-targeting-rms-or-ms/
    Natalya
    ### If my post helped you, please take a moment to Vote as Helpful and\or Mark as an Answer

  • Query to get the user profile

    Hello
    I would like to know the query to get the complete user profile, for example the user password, all the privileges it has, etc
    Thank you

    Go to tahiti.oracle.com
    Drill down to your selected product and version
    There, find the complete documentation set
    There, find the find Reference Manual
    There, find a complete description of all the data dictionary view.
    Browse through the names of those view for something that looks like a likely candidate (thing with "user" or "priv" in the name)
    Edited by: EdStevens on Oct 23, 2009 8:20 PM

  • How to modify the query to get the output in a single row

    Hi All,
    Below is the query i have written it works fine
    select DISTINCT right(left(CTACCT,13),4) AS LocationNum,
    tODS_GLBalance.FiscalYearId AS FiscalYearId,
    tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
    --tods_GLMetadata.Metric,
    Case when
    tods_GLMetadata.Metric = 'Gross Margin'
    Then SUM(Balance)
    Else 0
    END AS GrossMargin,
    Case when
    tods_GLMetadata.Metric = 'Occupancy'
    Then SUM(Balance)
    Else 0
    END AS Occupancy,
    Case when
    tods_GLMetadata.Metric = 'Payroll Dollars'
    Then SUM(Balance)
    Else 0
    END AS Payroll,
    Case when
    tods_GLMetadata.Metric = 'CF Sales'
    Then SUM(Balance)
    Else 0
    END AS OperatingSales,
    Case when
    tods_GLMetadata.Metric = 'Operations'
    Then SUM(Balance)
    Else 0
    END AS OperatingExpenses
    -- 0 as payroll
    from ods.[JJill].[tODS_GLBalance]
    inner join ods.Staging.tODS_INF_GLPCT ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
    inner join ods.JJill.tods_GLMetadata ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
    where
    (tODS_GLBalance.FiscalYearId = 2012) and
    (tODS_GLBalance.FiscalMonthOfYearId = 2) and
    (right(left(CTACCT,13),4)= 3020)
    group by
    right(left(CTACCT,13),4),
    tODS_GLBalance.FiscalYearId,
    tODS_GLBalance.FiscalMonthOfYearId,
    tods_GLMetadata.Metric
    This is the sample output,
    LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
    3020 2012 2 -112477.00 0.00 0.00 0.00 0.00
    3020 2012 2 0.00 0.00 0.00 -158288.94 0.00
    3020 2012 2 0.00 0.00 0.00 0.00 5625.44
    3020 2012 2 0.00 0.00 24185.79 0.00 0.00
    3020 2012 2 0.00 31075.53 0.00 0.00 0.00
    But, i am expecting the output to be something like this
    LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
    3020 2012 2 -112477.00 31075.53 24185.79 -158288.94 5625.44
    Can someone please help me with changing my query to get the desired output?
    Please let me know if you have any questions.
    Thanks

    Try this:
    SELECT DISTINCT
    RIGHT(LEFT(CTACCT,13),4) AS LocationNum, tODS_GLBalance.FiscalYearId AS FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Gross Margin' THEN Balance ELSE 0 END ) AS GrossMargin,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Occupancy' THEN Balance ELSE 0 END ) AS Occupancy,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Payroll Dollars' THEN Balance ELSE 0 END ) AS Payroll,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'CF Sales' THEN Balance ELSE 0 END ) AS OperatingSales,
    SUM(CASE WHEN tods_GLMetadata.Metric = 'Operations' THEN Balance ELSE 0 END ) AS OperatingExpenses
    FROM ods.[JJill].[tODS_GLBalance]
    INNER JOIN ods.Staging.tODS_INF_GLPCT
    ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
    INNER JOIN ods.JJill.tods_GLMetadata
    ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
    WHERE tODS_GLBalance.FiscalYearId = 2012
    AND tODS_GLBalance.FiscalMonthOfYearId = 2
    AND RIGHT(LEFT(CTACCT,13),4) = 3020
    GROUP BY right(left(CTACCT,13),4), tODS_GLBalance.FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId, tods_GLMetadata.Metric

  • Query to get the hierarchical results

    Hi,
    Please help me in writing a Query to get the hierarchical results. I want a result like follows...
    course-----groupname---TotalMembers---NotStarted---INProgress---Completed
    Course1---country1--------12---------------6----------3-------------3
    Course1-----state11-------12---------------6----------3-------------3
    Course1------District111--10---------------5----------0-------------0
    Course1--------City1111----0---------------0----------0-------------0
    Course1--------City1112----1---------------0----------0-------------1
    Course1--------City1113----6---------------3----------2-------------1
    Course1---country2--------12---------------6----------3-------------3
    Course1----state21--------12---------------6----------3-------------3
    Course1------District211--10---------------5----------0-------------0
    Course1--------City2111----0---------------0----------0-------------0
    Course1--------City2112----1---------------0----------0-------------1
    Course1--------City2113----6---------------3----------2-------------1
    Course2---country1--------12---------------6----------2-------------3
    Course2----state11--------12---------------6----------2-------------3
    Course2------District111--10---------------5----------0-------------0
    Course2--------City1111----0---------------0----------0-------------0
    Course2--------City1112----1---------------0----------0-------------1
    Course2--------City1113----6---------------3----------1-------------2
    Course2---country2--------12---------------6----------3-------------3
    Course2-----state21-------12---------------6----------3-------------3
    Course2------District211--10---------------5----------0-------------0
    Course2--------City2111----0---------------0----------0-------------0
    Course2--------City2112----1---------------0----------0-------------1
    Course2--------City2113----6---------------3----------2-------------1
    These are the Tables available to me.
    (I have just given some examle data in tables, to get the idea)
    "Groups" Table (This table gives the information of the group)
    GROUPID-----NAME-------PARENTID
    1---------Universe--------1
    2---------country1--------1
    3---------state11---------2
    4---------District111-----3
    5---------City1111--------4
    6---------City1112--------4
    7---------City1113--------4
    8---------country2--------1
    9---------state21---------8
    10--------District211-----9
    11--------City2111--------10
    12--------City2112--------10
    13--------City2113--------10
    "Users" Table (This table provides the user information)
    userID----FIRSTNAME---LASTNAME
    user1-----------Jim-------Carry
    user2-----------Tom-------lee
    user3-----------sunny-----boo
    user4-----------mary------mall
    "User-Group" Tables (This table provides the relation between the groups
    and the members)
    GROUPID---userID
    3-------------user1
    3-------------user2
    3-------------user4
    4-------------user5
    5-------------user6
    5-------------user7
    user_score (This table provides the user scores of different courses)
    USERID----course-----STATUS
    user1------course1-----complete
    user1------course2-----NotStarted
    user2------course1-----NotStarted
    user2------course2-----complete
    user3------course1-----complete
    user3------course2-----InProgress
    user4------course2-----complete
    user4------course1-----NotStarted
    I will explain the first four lines of the above result.
    Course1---country1--------12---------------6----------4-------------2
    Course1-----state11-------12---------------6----------4-------------2
    Course1------District111--10---------------5----------3-------------2
    Course1--------City1111----0---------------0----------0-------------0
    Course1--------City1112----1---------------0----------0-------------1
    Course1--------City1113----6---------------3----------2-------------1
    # "city1111" group has 0 members
    # "city1112" group has 1 member (1 member completed the course1)
    # "city1113" group has 6 members(3 members notStarted,2 members
    InProgress,1 member completed the course1)
    # "District111" is the parent group of above three groups, and has 3
    members.(2 members NotStarted,1 member InProgress the course1). But this
    group has child groups, so the scores of this group has to rollup the
    child groups scores also. Thats why it has 2+3+0+0=6 members Not
    Started,1+2+0+0=3 members InProgress,0+0+1+1=2 members completed.
    # "state11" group also same as the above group.
    I am able to get the group hierarchy by using "Connect By" like follows
    "select name,groupid,parentid from groups_info start with groupid=1 connect by parentid = prior groupid;"
    But i want to get the result as i have mentioned in the begining of this discussion.
    I am using oracle 8i (oracle8.1.7).
    Thank you for any help
    Srinivas M

    This may not be exactly what you want,
    but it should be fairly close:
    SET      LINESIZE 100
    SET      PAGESIZE 24
    COLUMN   groupname FORMAT A20
    SELECT   INITCAP (user_score.course) "course",
             groupnames.name "groupname",
             COUNT (*) "TotalMembers",
             SUM (NVL (DECODE (UPPER (user_score.status), 'NOTSTARTED', 1), 0)) "NotStarted",
             SUM (NVL (DECODE (UPPER (user_score.status), 'INPROGRESS', 1), 0)) "InProgress",
             SUM (NVL (DECODE (UPPER (user_score.status), 'COMPLETE', 1), 0)) "Completed"
    FROM     user_score,
             user_group,
             (SELECT ROWNUM rn,
                     name,
                     groupid
              FROM   (SELECT     LPAD (' ', 2 * LEVEL - 2) || name AS name,
                                 groupid
                      FROM       groups
                      START WITH groupid = 1
                      CONNECT BY PRIOR groupid = parentid)) groupnames
    WHERE    user_score.userid = user_group.userid
    AND      user_group.groupid IN
             (SELECT     groupid
              FROM       groups
              START WITH groupid = groupnames.groupid
              CONNECT BY PRIOR groupid = parentid)
    GROUP BY user_score.course, groupnames.name, groupnames.rn
    ORDER BY user_score.course, groupnames.rn
    I entered the minimal test data that you
    provided and a bit more and got this result
    (It was formatted as you requested,
    but I don't know if it will display properly
    on this post, or wrap around):
    course  groupname            TotalMembers NotStarted InProgress  Completed
    Course1 Universe                        6          2          0          4
    Course1   country1                      5          2          0          3
    Course1     state11                     5          2          0          3
    Course1       District111               2          0          0          2
    Course1         City1112                1          0          0          1
    Course1         City1113                1          0          0          1
    Course1   country2                      1          0          0          1
    Course1     state21                     1          0          0          1
    Course1       District211               1          0          0          1
    Course1         City2113                1          0          0          1
    Course2 Universe                        5          1          1          3
    Course2   country1                      4          1          1          2
    Course2     state11                     4          1          1          2
    Course2       District111               1          0          1          0
    Course2         City1113                1          0          1          0
    Course2   country2                      1          0          0          1
    Course2     state21                     1          0          0          1
    Course2       District211               1          0          0          1
    Course2         City2113                1          0          0          1
    Here is the test data that I used, in case
    anyone else wants to play with it:
    create table groups
      (groupid  number,
       name     varchar2(15),
       parentid number)
    insert into groups
    values (1,'Universe',null)
    insert into groups
    values (2,'country1',1)
    insert into groups
    values (3,'state11',2)
    insert into groups
    values (4,'District111',3)
    insert into groups
    values (5,'City1111',4)
    insert into groups
    values (6,'City1112',4)
    insert into groups
    values (7,'City1113',4)
    insert into groups
    values (8,'country2',1)
    insert into groups
    values (9,'state21',8)
    insert into groups
    values (10,'District211',9)
    insert into groups
    values (11,'City2111',10)
    insert into groups
    values (12,'City2112',10)
    insert into groups
    values (13,'City2113',10)
    create table user_group
      (groupid number,
       userid  varchar2(5))
    insert into user_group
    values (3,'user1')
    insert into user_group
    values (3,'user2')
    insert into user_group
    values (3,'user4')
    insert into user_group
    values (4,'user5')
    insert into user_group
    values (5,'user6')
    insert into user_group
    values (5,'user7')
    insert into user_group
    values (7,'user8')
    insert into user_group
    values (13,'user9')
    insert into user_group
    values (11,'use11')
    insert into user_group
    values (6,'use6')
    create table user_score
      (userid varchar2(5),
       course varchar2(7),
       status varchar2(10))
    insert into user_score
    values ('use6','course1','complete')
    insert into user_score
    values ('user9','course1','complete')
    insert into user_score
    values ('user9','course2','complete')
    insert into user_score
    values ('user8','course1','complete')
    insert into user_score
    values ('user8','course2','InProgress')
    insert into user_score
    values ('user1','course1','complete')
    insert into user_score
    values ('user1','course2','NotStarted')
    insert into user_score
    values ('user2','course1','NotStarted')
    insert into user_score
    values ('user2','course2','complete')
    insert into user_score
    values ('user3','course1','complete')
    insert into user_score
    values ('user3','course2','InProgress')
    insert into user_score
    values ('user4','course2','complete')
    insert into user_score
    values ('user4','course1','NotStarted')

  • Query to get the blocker and holder info

    Hi All,
    I have framed the following query to get the blocker and holder info.I intend to use this query in a auto-generated mail which executes every 15 mins
    I have put an outer join on the holder because the holder query might have been executed at the time the auto mail configuration fires this query
    I am not a dba and was apprehensive is there is some mistake in the logic of my query. I was also expecting to join v$sql_bind_capture using sql_hash_value and sql_address just the way in which I have joined v$sqlarea
    Looking forward to your kind help in vetting the below query
    Select distinct waiting_session,
    dba_waiters.holding_session,
    decode(to_char(session_waiting_info.STATE),'0','waiter is currently waiting','-2','duration of last wait by waiter is unknown','-1','waiter waited for a short time',' waiter waited long time') "waiters waiting state",
    decode(session_waiting_info.WAIT_TIME,0,'waiter waiting') "waiters last wait time",
    decode(to_char(session_holding_info.STATE),'0','holder is currently waiting','-2','duration of last wait by holder is unknown','-1','holder waited for a short time','holder waited long time') "holders waiting state",
    decode(session_holding_info.WAIT_TIME,0,'waiter waiting') "holders last wait time",
    sql_waiting_info.sql_text "query of the waiter",
    sql_holding_info.sql_text "query of the holder",
    session_waiting_info.STATUS "waiting STATUS",
    session_holding_info.STATUS "holding STATUS",
    session_waiting_info.process "waiting process",
    session_waiting_info.PROGRAM "waiting PROGRAM",
    session_holding_info.process "holding process",
    session_holding_info.PROGRAM "holding PROGRAM",
    session_waiting_info.ROW_WAIT_OBJ# "waiting object",
    session_waiting_info.ROW_WAIT_ROW# "waiting row",
    session_holding_info.ROW_WAIT_OBJ# "holding object",
    session_holding_info.ROW_WAIT_ROW# "holding row",
    session_waiting_info.BLOCKING_SESSION_STATUS "waiting session status",
    session_holding_info.BLOCKING_SESSION_STATUS "holding session status",
    session_waiting_info.username "holding os username",
    session_holding_info.username "waiting os username",
    session_waiting_info.MACHINE "waiting MACHINE",
    session_waiting_info.TERMINAL "waiting TERMINAL",
    session_holding_info.MACHINE "holding MACHINE",
    session_holding_info.TERMINAL "holding TERMINAL",
    session_waiting_info.TYPE "waiting TYPE",
    session_holding_info.TYPE "holding TYPE"
    from dba_waiters,
    v$session session_holding_info,
    v$session session_waiting_info,
    v$sqlarea sql_waiting_info,
    v$sqlarea sql_holding_info
    Where dba_waiters.waiting_Session = session_waiting_info.sid
    and dba_waiters.holding_Session = session_holding_info.sid
    And session_waiting_info.sql_hash_value = sql_waiting_info.hash_value
    And session_waiting_info.sql_address = sql_waiting_info.address
    and session_holding_info.sql_hash_value = sql_holding_info.hash_value(+)
    And session_holding_info.sql_address = sql_holding_info.address(+)
    and dba_waiters.mode_held <> 'None'
    Regards,
    Vishal
    Edited by: user11924113 on Feb 18, 2011 2:39 AM

    Query to track the holder and waiter info
    People who reach this place for a similar problem can use the above link to find their answer
    Regards,
    Vishal

  • SQL query to get the list of approvals

    Hi,
    Could someone let me know the SQL query to get the list of all the pending approvals for a user in OIM 11g R2.
    Thanks

    There are a few ways to do this:
    -  The easiest would be to use a Relationship Query from the CMC. To do this, go to the Universes section on the CMC, right click on the relevant universe, select tools >> Check Relationships.
    - Use Query Builder. You will need more than one query to pull the information you need. You could try something like the below (for Webi)
    SELECT SI_NAME, SI_WEBI, SI_DATACONNECTION FROM CI_APPOBJECTS
    WHERE SI_KIND = 'universe' and SI_NAME = 'Universe Name'
    This will give you a list of Webi Reports by SI_ID.
    You'll need another query to list Webi report names:
    SELECT SI_NAME FROM CI_INFOOBJECTS WHERE SI_ID IN (SI_ID from query above)
    - This is trivial via Auditing / the Activity universe. This of course will only return reports that have already run.
    Best.
    Srinivas

Maybe you are looking for

  • My Whatsapp has dissapeared

    After updating Whatsapp the App dissapeared from my phone.. In the App store it states that I've purchased it but if i click on OPEN nothing happens. What can be the reason? How do I solve this?

  • What is HMI stands for

    In the post-processing of PI,  There is a step to create remote connection in SM59, a connection name INTEGRATION_DIRECTORY_HMI which used to update run time cache when activate ID objects, what  is HMI stands for?

  • Problem in referring the methods of jar during runtime in OSB 10gR3

    Hi, I have to use the methods of a certain Jar File. During Development, I import the jar in my OSB Project and refer the methods. But at runtime, I want to remove this jar, place the jar in domain and refer using classpath. when I do this I get erro

  • How to convert wma in iTunes for MAC to mp3

    The iTunes support manual mysteriously indicates that iTunes for MAC can convert WMA files to other formats, but doesn't tell me how! How do I convert the WMA files to mp3? When I google, I keep getting links to other sites and I'm not sure how to pi

  • How to maximize report

    Hi, could someone help with my reports. I have created a form that calls my report Plese find below command that I execute in my pushbutton DECLARE pl_id ParamList; BEGIN pl_id := Get_Parameter_List('tempdata'); IF NOT Id_Null(pl_id) THEN Destroy_Par