How to modify this query to get the desired output format

I hv written a Query to display all the parent table names and their primary key columns(relevant to this foreign key of the child table).The query is given below...
SELECT DISTINCT(TABLE_NAME) AS PARENT_TABLE,COLUMN_NAME AS PARENT_COLUMN
FROM ALL_CONS_COLUMNS
WHERE CONSTRAINT_NAME IN (SELECT AC.R_CONSTRAINT_NAME
FROM ALL_CONSTRAINTS AC
WHERE AC.TABLE_NAME=TABLE_NAME
AND AC.TABLE_NAME='&TABLE'
AND AC.R_CONSTRAINT_NAME IS NOT NULL);
This query will display all the parent tables and their primary key columns.Now my problem is that how to modify this query to also display the foreign key column name of the child table.
I want the query result in the following format.The query should display the following columns.1)child table's name,2)child table's foreign key column name,3)the corresponding parent table's name,4)the parent table's primary key column name(which is the foreign key in the child table).
For Example I want the output as follows...
TAKE THE CASE OF SCOTT.EMP(AS INPUT TO YOUR QUERY)
CHILD_TABLE CHILD_COLUMN PARENT_TABLE PARENT_COLUMN
EMP DEPTNO DEPT DEPTNO
In this result I hv used alias name for the columns.The query should display this only for the foreign keys in the child table.In the query which I sent to you earlier will give the parent table and the parent column names,But I also want to append the child table and child column names there.
any help on how to tackle would be appreciated.

Try this query
SELECT c.table_name child_table,
     c.column_name child_column,
     p.table_name parent_table,
     p.column_name parent_column
FROM user_constraints a,user_constraints b,user_cons_columns c,
     user_cons_columns p
WHERE a.r_constraint_name=b.constraint_name and
      a.constraint_name=c.constraint_name and
      b.constraint_name=p.constraint_name and
      c.position=p.position
ORDER BY c.constraint_name,c.position
Anwar

Similar Messages

  • To write a single query to get the desired output.

    Hi,
    I have table by name "employees" it contains 20 records meaning 20 employee details.
    some of the column it contains are employee_id,Hiredate as below.
    EMPLOYEE_ID|HIRE_DATE
    100|6/17/1987
    101|9/21/1989
    102|1/13/1993
    103|1/3/1993
    104|5/21/1991
    107|2/7/1999
    124|11/16/1999
    141|10/17/1995
    142|1/29/1997
    143|3/15/1998
    144|7/9/1998
    149|1/29/2000
    174|5/11/1996
    176|3/24/1998
    178|5/24/1999
    200|9/17/1987
    201|2/17/1996
    202|8/17/1997
    205|6/7/1994
    206|6/7/1994
    The query should display the total number of employees, employees hired in 1995,1996,1997 and 1998 some thing like below.
    output
    Total     1995     1996     1997     1998
    20     1     2     2     3
    please let me know the query.
    Thanks
    Dinesh

    SQL> select * from employees;
             EMPLOYEE_ID HIRE_DATE
                     100 17-JUN-1987 00:00:00
                     101 21-SEP-1989 00:00:00
                     102 13-JAN-1993 00:00:00
                     103 03-JAN-1993 00:00:00
                     104 21-MAY-1991 00:00:00
                     107 07-FEB-1999 00:00:00
                     124 16-NOV-1999 00:00:00
                     141 17-OCT-1995 00:00:00
                     142 29-JAN-1997 00:00:00
                     143 15-MAR-1998 00:00:00
                     144 09-JUL-1998 00:00:00
                     149 29-JAN-2000 00:00:00
                     174 11-MAY-1996 00:00:00
                     176 24-MAR-1998 00:00:00
                     178 24-MAY-1999 00:00:00
                     200 17-SEP-1987 00:00:00
                     201 17-FEB-1996 00:00:00
                     202 17-AUG-1997 00:00:00
                     205 07-JUN-1994 00:00:00
                     206 07-JUN-1994 00:00:00
    20 rows selected.
    SQL> select count(*) total_employees
      2        ,sum(case when to_char(hire_date,'YYYY') = '1995' then 1 else 0 end) hired_1995
      3        ,sum(case when to_char(hire_date,'YYYY') = '1996' then 1 else 0 end) hired_1996
      4        ,sum(case when to_char(hire_date,'YYYY') = '1997' then 1 else 0 end) hired_1997
      5        ,sum(case when to_char(hire_date,'YYYY') = '1998' then 1 else 0 end) hired_1998
      6  from   employees;
         TOTAL_EMPLOYEES           HIRED_1995           HIRED_1996           HIRED_1997           HIRED_1998
                      20                    1                    2                    2                    3Edited by: SomeoneElse on Jan 6, 2009 8:09 AM

  • How to run this query to get the minutes between two hours?

    Hi all,
    Hope doing well,
    sir i am running one query which is:
    v_TotalHrsMin1 := LPAD((extract(minute from TO_TIMESTAMP (v_Temphrs,'HH24:mi:ss')) - extract(minute from TO_TIMESTAMP (v_Outtime1,'HH24:mi:ss'))), 2, '0');--select to_date(v_temphrs,'YYYY-MM-DD HH:mi:ss')-to_date(v_OutPunch,'YYYY-MM-DD HH:mi:ss')*1440;
    in this v_TotalHrsMin1 is number datatype and v_Temphrs is varchar2 which is storing this value: 12:00:00
    and v_Outtime1 is varchar2 which is storing 06:00:00
    now i want the minute difference between both times
    and insert into v_Totalmin1.
    but getting null value in v_totalmin1.
    thanks

    952646 wrote:
    Hi Sir,
    i used query like this: v_TotalHrsMin1 := extract(hour from time_interval) * 60 + extract(minute from time_interval) from (select to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS') time_interval from dual);That is not a query - that is a PL/SQL assignment expression. You should learn the differences between SQL and PL/SQL and how they work together ;-)
    When doing it in PL/SQL, you do not need a query at all. Why would you do a select from dual in the PL/SQL assignment.
    But you should be able to take the SQL example I gave you and write the equivalent PL/SQL code.
    We do not want to do your work for you - we want to teach you how to do it yourself.
    You should try and understand the examples we give you - not just cut-and-paste it and cry for help when you are cut-and-pasting a SQL example into PL/SQL code.
    Anyway - here's a way to do it in PL/SQL:
    declare
       v_outtime1  varchar2(8);
       v_temphrs   varchar2(8);
       v_interval  interval day to second;
       v_totalhrsmin1 number;
    begin
       v_outtime1 := '06:00:00';
       v_temphrs  := '12:00:00';
       v_interval := to_timestamp(v_temphrs,'HH24:MI:SS')-to_timestamp(v_outtime1,'HH24:MI:SS');
       v_totalhrsmin1 := extract(hour from v_interval) * 60 + extract(minute from v_interval);
    end;
    /What's so difficult about taking my SQL example, understanding what the differenct functions do, and then write that piece of PL/SQL? ;-)

  • How to set Back ground job & get my desired output layout in sm36 & sm37 ?

    Hai SAP ABAP/BASIS Gurus,
    I am currently taking ME2N PO Pending value Report by setting variant in input screen & setting my own output layout  ie only four field ie.Plant, Material,Currency,Still to be delivered value will be visible in output screen
    I set Back ground in sm36 using my variant & i saw my output in sm37.. But I cant get output as my desired field..
    This is my problem..
    1) I Cant Get the Same output in shedule job [sm36 & sm37] like When i run in foreground for ME2n.
        I am using ALV Scope of list..
    2) If I use BEST Layout in Scope of list means i get the desired Output field layout as same as my foreground output field..
    I want to get the output layout as desired & also in ALV format[ Useful for excel work]
    Kindly guide me.
    Thanks in advance..
    swetha
    Edited by: Swetha SAP Girl on Jul 2, 2009 5:06 PM

    Hi Swetha,
    To get the missed fields in the spool, while creating the background job(execute in background option) you can see the printer setting block at the end of the background job settings window, in that check the 'Spool Request Max. Width 255 char' check box and then continue. It will generate the spool list with maximum width and you can see all the fields in the spool output.
    Thanks,
    Muthu
    Edited by: Muthu Prabakaran Selvam on Jul 3, 2009 2:35 PM

  • How to correctly perform a join to get the desired output

    Hi,
    I have the following query which gives me the desired output.
    SELECT
    Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
    Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
    'Store' As DRIVER_TYPE,
    'OPS GOAL' As DRIVER,
    SUM(OPS_GOAL) As ROW_TOTAL
    FROM Planning.TEDW_F_STORE_OPS_GOAL
    left outer join
    edw.Calendar.TEDW_D_DATE_TYPE_1
    ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
    left outer join
    [EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
    ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
    where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
    group by
    TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
    TEDW_D_DATE_TYPE_1.DATE_SHORT
    order by LOCATION_NUM desc
    , DATE_SHORT desc
    The output of the above query will be like this
    3646 2014-04-17 Store OPS GOAL 2598.00000
    3646 2014-04-16 Store OPS GOAL 2475.00000
    3646 2014-04-15 Store OPS GOAL 2497.00000
    3646 2014-04-14 Store OPS GOAL 2691.00000
    But the problem with this query is it brings back the OPS Goal for all the dates,but i have to limit the OPS goals to some particular date range which must match to this table Staging.TEDW_S_EMPOWER.So,I made the above query join to this table like this
    SELECT
    Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
    Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
    'Store' As DRIVER_TYPE,
    'OPS GOAL' As DRIVER,
    SUM(OPS_GOAL) As ROW_TOTAL
    FROM Planning.TEDW_F_STORE_OPS_GOAL
    left outer join
    edw.Calendar.TEDW_D_DATE_TYPE_1
    ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
    left outer join
    [EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
    ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
    left outer join
    Staging.TEDW_S_EMPOWER
    on TEDW_D_DATE_TYPE_1.DATE_SHORT = TEDW_S_EMPOWER.DATE_SHORT
    and TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_S_EMPOWER.LOCATION_NUM
    where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
    group by
    TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
    TEDW_D_DATE_TYPE_1.DATE_SHORT
    having TEDW_D_DATE_TYPE_1.DATE_SHORT between MIN(TEDW_S_EMPOWER.date_short) and MAX(TEDW_S_EMPOWER.date_short)
    order by LOCATION_NUM desc
    , DATE_SHORT desc
    Now the output of this query will be like this
    3646 2014-04-17 Store OPS GOAL 7794.00000
    3646 2014-04-16 Store OPS GOAL 7425.00000
    3646 2014-04-15 Store OPS GOAL 7491.00000
    3646 2014-04-14 Store OPS GOAL 8073.00000
    If you can observe the OPS Goal Sum values have changed drastically, i was able to limit the date range i wanted but now i dont get the correct OPS Goal values.
    Can someone please help me with this?
    Thanks

    Hi RJP,
    Yes you are absolutely correct, in the "Staging.TEDW_S_EMPOWER"
    we have 3 rows for every date and location,so i changed my second sql to be something like this
    SELECT
    Cast(TEDW_F_STORE_OPS_GOAL.LOCATION_NUM As Varchar) As LOCATION_NUM,
    Cast(TEDW_D_DATE_TYPE_1.DATE_SHORT As Varchar) As DATE_SHORT,
    'Store' As DRIVER_TYPE,
    'OPS GOAL' As DRIVER,
    SUM(OPS_GOAL) /3 As ROW_TOTAL
    FROM Planning.TEDW_F_STORE_OPS_GOAL
    cross join
    EDW.Utility.TEDW_J_PROCESS_DATE
    inner join
    edw.Calendar.TEDW_D_DATE_TYPE_1
    ON TEDW_F_STORE_OPS_GOAL.DATE_KEY = TEDW_D_DATE_TYPE_1.DATE_KEY
    left outer join
    [EDW].[Location].[TEDW_D_LOCATION_TYPE_1_NEW]
    ON TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_NUM
    left outer join
    Staging.TEDW_S_EMPOWER
    on TEDW_D_DATE_TYPE_1.DATE_SHORT = TEDW_S_EMPOWER.DATE_SHORT
    and TEDW_F_STORE_OPS_GOAL.LOCATION_NUM = TEDW_S_EMPOWER.LOCATION_NUM
    where TEDW_D_LOCATION_TYPE_1_NEW.LOCATION_TYPE_DESC = 'FULL PRICE STORE'
    group by
    TEDW_F_STORE_OPS_GOAL.LOCATION_NUM,
    TEDW_D_DATE_TYPE_1.DATE_SHORT
    having TEDW_D_DATE_TYPE_1.DATE_SHORT between MIN(TEDW_S_EMPOWER.date_short) and MAX(TEDW_S_EMPOWER.date_short)
    order by LOCATION_NUM desc
    , DATE_SHORT desc
    Now i receive the correct values as i am doing divided
    by 3,but may be in the future the empower tablemay have more than 3 ,is there any other effective way i can do this?
    below is the sample query and sample data from empower table.
    select * from Staging.TEDW_S_EMPOWER
    where DATE_SHORT = '2014-04-17'
    and LOCATION_NUM = 3020
    DRIVER_TYPE DRIVER DATE_SHORT
    store Sales 2014-04-17
    store Transactions 2014-04-17
    store Traffic 2014-04-17
    Thanks

  • How to Modify this Query to make it loop through Certain defined intervals

    hI ALL,
    I have a TABLE1 with one Column as ColumnA which will always have values either Value1,Value2,Value3.
    TABLE1:
    ColumnA CreationDateandTime
    Value1 8:56
    Value1 8:51
    Value3 8:49
    Value1 8:47
    Value2 8:45
    Value3 8:30
    I am using the below query to retrieve the count of how many Value1's,Value2's and Value3's exist in the ColumnA for the Given point of Time by using a 'where' condition to get the count between specified Time.
    SELECT
    COUNT (case when A.ColumnA ='Value1' THEN 0 ELSE NULL END) Value1,
    COUNT (case when A.ColumnA ='Value2' THEN 0 ELSE NULL END) Value2,
    COUNT (case when A.ColumnA ='Value3' THEN 0 ELSE NULL END) Value3
    from TABLE1 A
    WHERE A.CASECREATIONDATEANDTIME
    between '19-JUL-2006 8:00:00 pM' and '19-JUL-2006 9:00:00 PM' .
    Result::
    Value1 value2 Value3
    3 2 1
    Right now i am Manually changing the TimeLimits for every 1hour to find the Count of Values at that particular perioud of Time, I would like to know how can i Loop it so that I will get it for every one hour and also i want to Add a Dummy Column before the Value1 as my First Column which should show me the Lower Time Limit....
    Expected Result should be some thing like this..(for some imaginary existance of values for the ColumnA Field)
    LowerTimeLimit Value1 value2 Value3
    8:00P.M 3 2 1
    9:00 P.M 1 4 5
    10:00P.M 0 0 0 (Since the Time is only 9:30 by now)
    NOte;; It should not go into an Infinite Loop as i would be risking My job.
    Thanks in Advance,
    vJ

    Certain Time Limit say 4:00PM . How do i restrict that...
    Hope this will help you....
    SQL> select * from tbl;
    V          DT
    value1     8:41 AM
    value1     8:45 AM
    value2     8:46 AM
    value1     8:46 AM
    value2     8:49 AM
    value2     8:50 AM
    value3     8:50 AM
    value3     9:05 AM
    value1     9:35 AM
    value3     9:45 AM
    value2     10:33 AM
    value2     9:33 AM
    value3     10:45 AM
    value1     01:01 PM
    value1     01:15 PM
    value2     01:59 PM
    value3     04:12 PM
    value1     04:52 PM
    18 rows selected.
    SQL> select to_char(trunc(to_Date(dt,'HH:MI AM'),'HH')+interval '1' hour,
      2  'HH:MI AM') Hours,
      3  sum(decode(v,'value1',1,0)) value1,
      4  sum(decode(v,'value2',1,0)) value2,
      5  sum(decode(v,'value3',1,0)) value3 from tbl
      6  where to_char(to_date(dt,'HH:MI AM'),'HH24')<16
      7  group by to_char(trunc(to_Date(dt,'HH:MI AM'),'HH')+
      8  interval '1' hour,'HH:MI AM')
      9  /
    HOURS     VALUE1  VALUE2  VALUE3
    02:00 PM          2       1       0
    09:00 AM          3       3       1
    10:00 AM          1       1       2
    11:00 AM          0       1       1
    "though hours are not sorted..."

  • How to write a query to get the total as a last row

    Hi,
    I need to get something like this ....
    |TEAM LEADER| TEAM | OCT TRN | EMPS| YTD% |
    |_____________|__________|__________|______|_______|
    | JOHN | JD Team | 12 | 12 | 100 |
    |_____________|__________|__________|______|_______|
    | Total |      | 12 | 12 | 100 |
    |_____________|__________|__________|______|_______|
    I have to get the last row as total adding the number columns ...
    Thanks in advance ...

    Take a look at the GROUP BY ROLLUP feature:
    create table t1
    (team_name      varchar2(30)
    ,wins           number
    ,losses         number
    insert into t1 values ('Hornets',3,1);
    insert into t1 values ('Panthers',4,0);
    insert into t1 values ('Wolves',2,2);
    insert into t1 values ('Badgers',0,4);
    insert into t1 values ('Hornets',1,3);
    commit;
    select decode(team_name,
                 NULL,'TOTAL',
                 team_name) team_name, sum(wins), sum(losses)
    from   t1
    group by rollup(team_name);
    TEAM_NAME                                 SUM(WINS)          SUM(LOSSES)
    Badgers                                           0                    4
    Hornets                                           4                    4
    Panthers                                          4                    0
    Wolves                                            2                    2
    TOTAL                                            10                   10

  • How to execute this Procedure and get the output?

    I have created a Procedure the source code of the same is furnished below.
    create or replace procedure vin_test( p_deptno IN number
    , p_cursor OUT SYS_REFCURSOR)
    as
    v_res Emp%rowtype;
    begin
    open p_cursor FOR
    select *
    from emp
    where deptno = p_deptno;
    end vin_test;
    Now, if i want to see the out put of this Proc
    i will first set the Serveroutput on and then..
    Exec vin_test(10);
    I am getting an error saying wrong number of arguments,so can anybody tell me what parameter value should i pass on so that i can get desired output.
    Thanks in Advance
    OraCrazy

    In sqlplus you can do like this.
    SQL> create or replace procedure vin_test( p_deptno IN number, p_cursor OUT SYS_REFCURSOR)
      2  as
      3     v_res Emp%rowtype;
      4  begin
      5     open p_cursor for
      6     select *
      7       from emp
      8      where deptno = p_deptno;
      9  end;
    10  /
    Procedure created.
    SQL> var lcur refcursor
    SQL> exec vin_test(30,:lcur)
    PL/SQL procedure successfully completed.
    SQL> print lcur
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO        DIV
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30         10
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30         10
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30         10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30         10
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30         10
    6 rows selected.Thanks,
    Karthick.

  • How to write a query to get the time difference of two varchar type time columns

    Hi,
    I want to get the time difference between the two varchar type columns.please see the attached image for more details:
    My requirement is like:
    timestarted
    timeended
    timediff
    9:00:00
    10:00:00
    1:00
    9:15
    9:30:00
    0:15

    Storing time alone as VARCHAR2 value is a incorrect design. Always store it as DATE or TIMESTAMP.
    If you already have a messed up design and cant change it, then you need to convert your VARCHAR2 time into a DATE or TIMESTAMP and find the difference. I have converted it to TIMESTAMP and obtained the difference as INTERVAL.
    SQL> with t
      2  as
      3  (
      4  select '09:00:00' timestarted, '10:00:00' timeended from dual
      5  union all
      6  select '09:15:00' timestarted, '09:30:00' timeended from dual
      7  )
      8  select timestarted
      9       , timeended
    10       , (timeended - timestarted) day to second diff
    11    from (
    12          select to_timestamp('01011900' || timeended, 'ddmmyyyyhh24:mi:ss') timeended
    13               , to_timestamp('01011900' || timestarted, 'ddmmyyyyhh24:mi:ss') timestarted
    14            from t
    15         );
    TIMESTARTED                                        TIMEENDED                                          DIFF
    01-JAN-00 09.00.00.000000000 AM                    01-JAN-00 10.00.00.000000000 AM                    +00 01:00:00.000000
    01-JAN-00 09.15.00.000000000 AM                    01-JAN-00 09.30.00.000000000 AM                    +00 00:15:00.000000
    SQL>

  • How to get the desire output from sql query

    Consider an Order Table: ...
    Order Table:
    Order Id Item Qty
    O1 A1 5
    O2 A2 1
    O3 A3 3
    Please provide SQL which will explode the above data into single unit level records as shown below
    Desired Output:
    Order Id Order Id Qty
    O1 A1 1
    O1 A1 1
    O1 A1 1
    O1 A1 1
    O1 A1 1
    O2 A2 1
    O3 A3 1
    O3 A3 1
    O3 A3 1

    How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • SQL Query to get the desired result

    Can someone give the SQL to get this output.
    input is like this in table.
    cola     colb     fromdate     todate
    1     100     1/5/2010     1/9/2010
    1     101     1/10/2010     1/25/2010
    1     102     1/26/2010     12/31/2900
    2     201     3/1/2011     3/10/2011
    2     202     3/11/2011     12/31/2900
    3     301     1/5/2010     1/9/2010
    3     302     1/10/2010     1/25/2010
    3     303     1/26/2010     1/28/2010
    3     304     1/29/2010     12/31/2900
    I want to get the output like this.
    cola     colb     fromdate     todate
    1     100     1/5/2010     1/9/2010
    2     201     3/1/2011     3/10/2011
    3     301     1/5/2010     1/9/2010
    More info:
    I want to get the rows where fromdate is the min(fromdate) from each cola's unique values i.e. 1,2,3
    Please let me know the SQL.
    Thanks.
    [email protected]

    This way!!!
    with data(cola, colb, st_dt, ed_dt) as
    select 1,     100,     to_date('01/05/2010', 'MM/DD/YYYY'),     to_date('01/09/2010', 'MM/DD/YYYY') from dual union all
    select 1,     101,  to_date('01/10/2010', 'MM/DD/YYYY'),     to_date('01/25/2010', 'MM/DD/YYYY') from dual union all
    select 1,     102,     to_date('01/26/2010', 'MM/DD/YYYY'),     to_date('12/31/2900', 'MM/DD/YYYY') from dual union all
    select 2,     201,     to_date('03/01/2011', 'MM/DD/YYYY'),     to_date('03/10/2011', 'MM/DD/YYYY') from dual union all
    select 2,     202,     to_date('03/11/2011', 'MM/DD/YYYY'),     to_date('12/31/2900', 'MM/DD/YYYY') from dual union all
    select 3,     301,     to_date('01/05/2010', 'MM/DD/YYYY'),     to_date('01/09/2010', 'MM/DD/YYYY') from dual union all
    select 3,     302,     to_date('01/10/2010', 'MM/DD/YYYY'),     to_date('01/25/2010', 'MM/DD/YYYY') from dual union all
    select 3,     303,     to_date('01/26/2010', 'MM/DD/YYYY'),     to_date('01/28/2010', 'MM/DD/YYYY') from dual union all
    select 3,     304,     to_date('01/29/2010', 'MM/DD/YYYY'),     to_date('12/31/2900', 'MM/DD/YYYY') from dual
    select cola, colb, st_dt, ed_dt
      from (
            select cola, colb, st_dt, ed_dt,
                   row_number() over (partition by cola order by st_dt) rn
              from data
           ) a
    where a.rn = 1;
    COLA COLB ST_DT     ED_DT  
       1  100 05-JAN-10 09-JAN-10
       2  201 01-MAR-11 10-MAR-11
       3  301 05-JAN-10 09-JAN-10

  • How to get the given output format..

    Hi,I want to write a code in ABAP in such a way that I should get the output in the right side format.
    Ex:
    1200 - > 1,200
    12000  - > 12,000
    120000 ->  120,000
    1200000 -> 1,200,000
    12000000 -> 12,000,000
    120000000 - > 120,000,000
    Thanks.

    HI tushar,
    1. I don't know whether i understood u r question !
    2. FOr writing with COMMA,
      if we use simple WRITE,
      then it will show just as u want !
    regards,
    amit m.

  • I run this query to get  the result like below, but even though my query is running fine I dont get the expected result.

    I am looking for only column compare for making my target table same as source table.
    My query:
    select case when column_name_s is null and column_name_t is not null
                then 'alter table GRADE_CONVERSION drop ' || column_name_t || ';'
                when column_name_s is not null and column_name_t is null
                then 'alter table GRADE_CONVERSION add ' || column_name_s || ' ' || data_type_s ||';'
                else 'alter table GRADE_CONVERSION modify ' || column_name_t || ' ' || data_type_t ||';'
           end alterations
      from (select s.column_name column_name_s,t.column_name column_name_t,
                   s.data_type data_type_s,t.data_type data_type_t
              from (select column_id,column_name,data_type
                      from all_tab_cols@database
                     where owner = 'erhan'
                       and table_name = 'GRADE_CONVERSION'
                   ) s
                   full outer join
                   (select column_id,column_name,data_type
                      from all_tab_cols@database
                     where owner = 'sarigul'
                       and table_name = 'GRADE_CONVERSION'
                   ) t
                on s.column_name = t.column_name
    Tables:
    Target table:         GRADE_CONVERSION table in sarigul@database
    LETTER_GRADE
    VARCHAR2(2)
    GRADE_POINT
    NUMBER(3,2)
    MAX_GRADE
    NUMBER(3)
    MIN_GRADE
    NUMBER(3)
    Source table:       GRADE_CONVERSION table in erhan@database
    LETTER_GRADE
    VARCHAR2(2)
    GRADE_POINT
    NUMBER(3,2)
    MAX_GRADE
    NUMBER(3)
    MIN_GRADE
    NUMBER(3)
    CREATED_BY
    VARCHAR2(30)
    CREATED_DATE
    DATE
    MODIFIED_BY
    VARCHAR2(30)
    MODIFIED_DATE
    DATE
    want to see the result similar to this *(please ignore the column names here this is just a plain exemple:)
    Alter table Target_table modify BOOK_ID Varchar2 (4);
    Alter table Target_table add ISBN_10 Varchar2(13), null;
    Alter table Target_table drop TITLE;

    I am looking for only column compare for making my target table same as source table.
    My query:
    select case when column_name_s is null and column_name_t is not null
                then 'alter table GRADE_CONVERSION drop ' || column_name_t || ';'
                when column_name_s is not null and column_name_t is null
                then 'alter table GRADE_CONVERSION add ' || column_name_s || ' ' || data_type_s ||';'
                else 'alter table GRADE_CONVERSION modify ' || column_name_t || ' ' || data_type_t ||';'
           end alterations
      from (select s.column_name column_name_s,t.column_name column_name_t,
                   s.data_type data_type_s,t.data_type data_type_t
              from (select column_id,column_name,data_type
                      from all_tab_cols@database
                     where owner = 'erhan'
                       and table_name = 'GRADE_CONVERSION'
                   ) s
                   full outer join
                   (select column_id,column_name,data_type
                      from all_tab_cols@database
                     where owner = 'sarigul'
                       and table_name = 'GRADE_CONVERSION'
                   ) t
                on s.column_name = t.column_name
    Tables:
    Target table:         GRADE_CONVERSION table in sarigul@database
    LETTER_GRADE
    VARCHAR2(2)
    GRADE_POINT
    NUMBER(3,2)
    MAX_GRADE
    NUMBER(3)
    MIN_GRADE
    NUMBER(3)
    Source table:       GRADE_CONVERSION table in erhan@database
    LETTER_GRADE
    VARCHAR2(2)
    GRADE_POINT
    NUMBER(3,2)
    MAX_GRADE
    NUMBER(3)
    MIN_GRADE
    NUMBER(3)
    CREATED_BY
    VARCHAR2(30)
    CREATED_DATE
    DATE
    MODIFIED_BY
    VARCHAR2(30)
    MODIFIED_DATE
    DATE
    want to see the result similar to this *(please ignore the column names here this is just a plain exemple:)
    Alter table Target_table modify BOOK_ID Varchar2 (4);
    Alter table Target_table add ISBN_10 Varchar2(13), null;
    Alter table Target_table drop TITLE;

  • How to build a query to get the item properties is tick or not?

    hello everybody. i'm 1 of the sap b1 user. i face a problem in build a query to check one of the item properties is tick or not? pls help...

    Hi Grace,
    your query could look like this:
    Select itemcode from oitm where qrygroup1= "Y"
    qrygroup1 is item property 1, qrygroup2 is item property 2 etc.
    Regards
    Ad

  • I broke the back to my iphone 4 how much will this cost to get the back panel fixed

    i got my iphone in october so it should still be in warranty ? and how much is it to get a new back panel put on?

    warranty doesn't cover accidental damage.  In the US, the back cover can be replaced for $29.00 at the Genius Bar

Maybe you are looking for

  • 2010 Mac Mini OS 10.10.1 screen is stretched out

    Hi, I have a 2010 Mac Mini that I use at work and I also use a second monitor via an adapter through USB. The setup worked until I installed Yosemite (10.10.1) on Friday. When I go to Settings / Displays I don't get all the resolution options I had b

  • Unrestricted Stock of issuing Storage Location in reservation

    Hi Experts, We have a requirement, we want that unresticted stock of issuing storage location is printed on reservation (MB23) Thru MB25. How it is possible. Kindly help me out, can we use sqvi or something else. Regards GR

  • Another Possible Issue with NwSapSetup.exe ??

    This is on SAPGui for Windows 7.20 when installed on Windows 7 front end. Installation server is at Patch 8 with latest SapSetup_Patch.exe applied I am getting an error pop up at end of the install on the front end regarding NwSapSetupUserNotificatio

  • Disabling node in JTree

    Hi! I have a program and I want to disable a specific node in the tree when the user presses a button. My nodes are derived from IconNode, a class that extends DefaultMutableTreeNode. I�ve tried to redefine setEnabled(state) in IconNode, but without

  • FRM-18122 Form Builder Debugger failed to Initialize

    Dear Sir/Madam, I got above erorr message when form start. What the problem ? Everybody can help me. The version is 10g. best regards boris