Row wise date calculation

Hello all the seniors, i am using Oracle 10g & Form 6i;
create table empl
(code varchar2(4), dob date);
insert into empl values ('1095',to_date('12/02/1960','dd/mm/yyyy');
insert into empl values ('1098',to_date('02/09/1952','dd/mm/yyyy');
insert into empl values ('1099',to_date('28/04/1956','dd/mm/yyyy');
insert into empl values ('1104',to_date('16/02/1965','dd/mm/yyyy');
insert into empl values ('1115',to_date('02/02/1966','dd/mm/yyyy');
insert into empl values ('1116',to_date('23/02/1956','dd/mm/yyyy');
insert into empl values ('1786',to_date('07/05/1974','dd/mm/yyyy');
insert into empl values ('1721',to_date('14/01/1983','dd/mm/yyyy');
I want the query result to be like this;
CODE     DOB        AGE YMD      Round Y/M MX  Y/M     MNTHS
1095   12/02/1960  49/10/11        49/10       60   10/2    122
1098   02/09/1952  57/03/21        57/4       60     2/8      32
1099   28/04/1956  53/07/25        53/8       60     6/4      76
1104   16/02/1965  44/10/07        44/10       60    15/2    182
1115   02/02/1966  43/10/21        43/11       60    16/1    193
1116   23/02/1956  53/10/00        53/10       60     6/2      74
1786   07/05/1974  35/07/16        35/8       60    24/4    292
1721   14/01/1983  26/11/09    26/11       60    33/1    397AGE YMD should be calculated upto sysdate.
Y/M = MX - Round YM
MNTHS = Y/M * 12
please help.
TY & regards.

Merry Christmas!
If you like Ravikumar's solution, but you like Blushadow's formatting better, then compare how Ravikumar and Blushadow use TO_CHAR differently, and do what Blushadow does.
It helps if you format the code so that you can tell what the arguments to each function are.
You'll notice that Blusadow starts the 2nd argument to TO_CHAR with 'fm', but Ravikumar does not. Normally, TO_CHAR leaves room for a sign in its output; 'fm' tells it not to do that, so you can modify Ravikumar's solution like this:
...to_char ( TRUNC ( months_between (sysdate,d ob)
             / 12
       , 'FM00'     -- FM added
|| '/' 
|| to_char ( mod ( TRUNC ( months_between (sysdate,dob)
           , 12
        , 'FM00'     -- FM added
|| '/' 
|| to_char ( ROUND ( sysdate
             - add_months ( dob
                    , floor (months_between (sysdate, dob))     -- Don't use TO_CHAR here
        , 'FM00'     -- FM added
     )      AS "AGE YMD",WITH clauses are very useful, and a great programming practice. If your version of Forms doesn't allow them, then you can write a view using a WITH clause in the database, and simply wuery the view within forms.
If you really have to avoid the WITH clause, you can usually re-write it using in-line views.
For example:
select code, dob, age_ymd
      ,case when round_m = 13 then to_char(yr+1,'fm09')||'/00'
       else to_char(yr,'fm09')||'/'||to_char(round_m,'fm09')
       end as round_y_m
      ,mx
      ,to_char(mx-(yr+1),'fm09')||'/'||to_char(case when round_m = 13 then 0
                                               else 12-round_m
                                               end
                                              ,'fm09') as y_m
      ,((mx-(yr+1))*12)+case when round_m = 13 then 0 else 12-round_m end as mnths
from      (     -- Begin in-line view t3
        select code, dob
                  ,to_char(yr,'fm09')||'/'||to_char(mt,'fm09')||'/'||to_char(dy,'fm09') as age_ymd
                  ,case when mt in (1,3,5,7,8,10,12) then case when dy <= 15 then mt else mt+1 end
                   when mt in (4,6,9,11) then case when dy < 15 then mt else mt+1 end
                   else case when dy < 14 then mt else mt+1 end
                  end as round_m
                 ,60 as mx
                 , yr, mt, dy
            from      (     -- Begin in-line view t2
                          select code, dob, yr, mt
                                ,case when dy < 0 then
                                   case when mt in (1,3,5,7,8,10,12) then 31+dy-1
                                        when mt in (4,6,9,11) then 30+dy-1
                                   else 28+dy-1
                                   end
                                 else dy end as dy
                          from     (     -- Begin in-line view t
                      select code, dob
                                         ,to_number(to_char(sysdate,'YYYY'))-to_number(to_char(dob,'YYYY')) as yr
                                         ,floor(mod(months_between(sysdate, dob),12)) as mt
                                         ,to_number(to_char(sysdate,'DD'))-to_number(to_char(dob,'DD')) as dy
                                  from empl
                    )     -- End in-line view t
               )     -- End in-line view t2
     )     -- End in-line view t3
;Start with the main query.
Where Blushadow said
FROM  t3substitute:
FROM    (
            SELECT  ...  -- Put the code of sub-query t3 here
        )but where sub-query t3 originally said
FROM    t2you'll say
FROM    (
            SELECT  ...  -- Put the code of sub-query t2 here
        )and so on.

Similar Messages

  • Row wise Date Difference

    Hi
    I have one column which contains Date field. and I want date difference between two rows like (1st row- 2nd row),(2st row- 3nd row) 3-4,4-5 like that.
    How I can get this
    Thanks
    Siddhartha P

    As for the minutes calculation it doesn't take Einstein to know that the number of minutes in a day = 24 (hours) * 60 (minutes)
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as id, sysdate-10 as dt from dual union all
      2             select 2, sysdate-7.4 from dual union all
      3             select 3, sysdate-6.45 from dual union all
      4             select 4, sysdate-2.82 from dual union all
      5             select 5, sysdate from dual)
      6  -- END OF TEST DATA
      7  select id
      8        ,dt
      9        ,dt-lag(dt) over (order by id) as dt_diff_days
    10        ,(dt-lag(dt) over (order by id))*(24*60) as dt_diff_minutes
    11* from t
    SQL> /
            ID DT                  DT_DIFF_DAYS DT_DIFF_MINUTES
             1 30/11/2007 13:07:37
             2 03/12/2007 03:31:37          2.6            3744
             3 04/12/2007 02:19:37          .95            1368
             4 07/12/2007 17:26:49         3.63          5227.2
             5 10/12/2007 13:07:37         2.82          4060.8
    SQL>

  • Row wise data insertion

    Hi,
    I have a query like this
    select
    wwv_flow_item.display_saveas(1,TXT,50,500) "Date"
    FROM
    WITH all_months AS
    SELECT ADD_MONTHS ( TRUNC ( TO_DATE ('1-JAN-09','dd-MON-YY')
    , 'MM'
    , LEVEL - 1
    )      AS dt
    , LEVEL      AS rn
    FROM dual
    CONNECT BY LEVEL <= MONTHS_BETWEEN ( TO_DATE ('1-APR-09', 'dd-Mon-YY')
    , TO_DATE ('1-JAN-09', 'dd-Mon-YY')
    ) + 1
    SELECT TRANSLATE (SYS_CONNECT_BY_PATH ( TO_CHAR (dt, 'Mon-YY')
    ) AS txt
    FROM     all_months
    WHERE     CONNECT_BY_ISLEAF = 1
    START WITH     rn = 1
    CONNECT BY     rn = PRIOR rn + 1
    The output generated by this query is like this
    Jan-09 Feb-09 Mar-09 Apr-09
    There is table create resource_plan
    which is having a structure like this ID Dates Commnets
    data is getting stored like this Jan-09 Feb-09 Mar-09 Apr-09
    I need to insert the data in this fashion Jan-09
    Feb-09
    Mar-09
    Apr-09
    How to split the data and save please suggest
    This is the insert query i am writing
    insert into resource_plan
    ( id,dates,comments)
    values
    (1,wwv_flow.g_f01,'');
    Please suggest me how to split the row data and insert in column wise.
    Thanks
    Sudhir.

    Sudhir_N wrote:
    My requirement was not with query i need to display the data in the same fashion how is getting populated only reqirement of mine was when getting stored into the table it must store in this order in the table
    01-JAN-09
    01-FEB-09
    01-MAR-09
    01-APR-09
    Thanks
    Sudhir.And the following didn't help you in that?
    Message From OP's previous thread:
    Hope the following code helps:
    SQL> WITH test_tab AS
    2       (SELECT '01-Jan-2008' start_date, '01-Dec-2009' end_date
    3          FROM DUAL)
    4  SELECT     ADD_MONTHS (TO_DATE (start_date, 'DD-Mon-YYYY'), LEVEL - 1) date
    _1
    5        FROM test_tab
    6  CONNECT BY LEVEL <=
    7                  MONTHS_BETWEEN (TRUNC (TO_DATE (end_date, 'DD-Mon-YYYY')),
    8                                  TRUNC (TO_DATE (start_date, 'DD-Mon-YYYY'))
    9                                 )
    10                + 1
    11  /
    DATE_1
    01-JAN-08
    01-FEB-08
    01-MAR-08
    01-APR-08
    01-MAY-08
    01-JUN-08
    01-JUL-08
    01-AUG-08
    01-SEP-08
    01-OCT-08
    01-NOV-08
    DATE_1
    01-DEC-08
    01-JAN-09
    01-FEB-09
    01-MAR-09
    01-APR-09
    01-MAY-09
    01-JUN-09
    01-JUL-09
    01-AUG-09
    01-SEP-09
    01-OCT-09
    DATE_1
    01-NOV-09
    01-DEC-09
    24 rows selected.
    SQL>
    Please explain what you didn't understand.
    Regards,
    Jo

  • Transpose Columnwise data to row wise date in 10g

    Hi,
    How can I transpose the below type of data to
    ID     MOTNH      YEAR     Pram1     Param2 Parm2
    10000     11     2012 200     300     500
    10001     11     2012     700     800 100
    to
    ID     MONTH     YEAR PARAMETER TARGET     
    10000     11     2013     Pram1          200          
    10000     11     2013     Pram2          300          
    10000     11     2013 Pram3          500          
    10001     11     2013 Pram1     700          
    10001     11     2013     Pram2     800          
    10001     11     2013     Pram3     100
    Regards,
    Tarun

    Basic think in converting column to row is you need to know the number of columns up front. In your case its 3. Now you have to create a dummy table that will have three rows and cross join this with your original table. Then you need to manipulate your data with a DECODE or CASE statement.
    below is an example.
    with my_table
    as
    select 10000 id, 11 mth, 2012 yr, 200 prm1, 300 prm2, 500 prm3 from dual union all
    select 10001 id, 11 mth, 2012 yr, 700 prm1, 800 prm2, 100 prm3 from dual
    ), cross_join_table
    as
    select level no
      from dual
    connect by level <= 3 -- This will change based on number of param columns in my_table
    select id, mth, yr, decode(no, 1, prm1, 2, prm2, 3, prm3) prm
      from my_table
      cross
      join cross_join_table
    order by id, mth, yr, no

  • Calculating Row wise %

    Hi Experts,
    I am unable to find a solution on calculating row wise percentage.
    My requirement goes like this
    CUSTOMER---------VALUE----------------PERCENT
    CUSTA------------------7--------------------(7/21)*100
    CUSTB------------------5--------------------(5/21)*100
    CUSTC------------------9--------------------(9/21)*100
    TOTAL-----------------21
    I am unable to do calculate the PERCENT.
    I am using a pivot view...
    Please let me know your views on how to achieve this...
    Appreciate your immediate response...
    -Thanks!

    Hello,
    go to pivot view,
    Duplicate the VALUE column in measures block. Now you find 2 columns with the same name.
    And for duplicated column (the 2nd one) go to More Options.. > Show Data As > Percent of > Column.
    You find automatically it calculates the % value...
    Ad if you want you can change the 2nd column heading to precise manner.

  • How to display the data in row wise in smartform

    Hi,
        I have to make a modification a smartform of poprinting and i want to display the row wise . At present it is displaying the  
        column wise. Actually there is a text which i want to display the data row wise.
        It is possible to display the data in row wise of the text .
    Edited by: nav009 on Oct 8, 2009 10:39 AM

    Hello ,
    I  assume that your requiremen is related to smartform.the below is the solution i suggest.
    As per my understanding of your requirement ,It's clear that as of now there is some description field which is also getting displayed along with other PO fields.
    However you would like to display the description field in a new line since the length of this field is longer than other fields as a result the data is getting scattered .
    Therefore one better option could be: since the whole data from PO would be in a loop you can display all other fields in one line type of the table as per the intial requirement and you display the description line alone in a new line type wth the desired length so that data would not be scattered and no data loss would happen.
    I assume you are aware of creating of line types for table.
    Thanks
    M.Naveen.

  • Output data in row wise instead of column

    hi all,
    i need to get the output data in row wise which is getting now as column wise.
    for eg:
    below is my final internal table.
    HEADING      DATE   MATNR   BUKRS   DMBTR
    jan/08        200801    567       10       800
    feb/08       200802    567       10       900
    mar/08      200803    567       10       200
    apr/09       200804    567       10       400 
    the output should come as
    MATNR  BUKRS   Jan/08   Feb/08   Mar/08   Apr/08
    567      10       800    900       200      400.
    instead of column wise the output should display as row as above.
    please help how to get this.
    thanks in advance

    Hi Vignesh,
    Please use below program which I created for you reference. It will work for your requirement.
    DATA:BEGIN OF it_test OCCURS 1,
         date(6),
         matnr(5),
         bukrs(3),
         END OF it_test.
    it_test-date = 'jan/08'.
    it_test-matnr = '01234'.
    it_test-bukrs = 'AE1'.
    APPEND it_test.
    it_test-date = 'feb8'.
    it_test-matnr = '56789'.
    it_test-bukrs = 'AE1'.
    APPEND it_test.
    it_test-date = 'mar8'.
    it_test-matnr = '23478'.
    it_test-bukrs = 'AE1'.
    APPEND it_test.
    START-OF-SELECTION.
      LOOP AT it_test.
        WRITE :/ 'DATE', 'MATNR', 'BUKRS', it_test-date, it_test-matnr,  it_test-bukrs .
      ENDLOOP.
    Output Will be as follows :-
    DATE MATNR BUKRS jan/08 01234 AE1
    DATE MATNR BUKRS feb8   56789 AE2
    DATE MATNR BUKRS mar8   23478 AE3
    Please set to resolve if this satisfies your requirement.
    Regards
    Abhii..

  • Row wise total in editable ALV

    hello all,
                I am workin on editable alv, the user need to enter the values in the editable fields and in the last column(non-editable) i need to populate the total row wise,as soon as user enters a value and goes to next editable cell or on entering a vale and press enter.how to accomplish this task...
    with regards,
    sandeep akella.
    Edited by: sandeep akella on Aug 20, 2009 1:58 PM

    You need to Implement the OnCellAction event.follow these steps;
    1. Goto WDDOMODIFYVIEW and place the following code
    IF first_time IS INITIAL.
        DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
        lo_cmp_usage =   wd_this->wd_cpuse_usg_alv( ).
        IF lo_cmp_usage->has_active_component( ) IS INITIAL.
          lo_cmp_usage->create_component( ).
        ENDIF.
        DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
        lo_interfacecontroller =   wd_this->wd_cpifc_usg_alv( ).
        DATA lo_value TYPE REF TO cl_salv_wd_config_table.
        lo_value = lo_interfacecontroller->get_model(
        CALL METHOD lo_value->if_salv_wd_table_settings~set_cell_action_event_enabled
         EXPORTING
            value = abap_true.
      ENDIF.
    2. Implement the onCellAction event as follows;
        Goto Methods tab, create a new method. Method Type- Event Handler , Event - ON_CELL_ACTION
    3. Now in this  method retrive the contents of the row and calculate the value as follows.
    DATA: l_element TYPE REF TO if_wd_context_element.
      DATA:ls_stru TYPE wd_this->element_cn_alv.
      DATA: l_node TYPE REF TO if_wd_context_node.
      l_node  = wd_context->get_child_node( 'CN_ALV' ).
      l_element = l_node->get_element(  r_param->index ).
      l_element->get_static_attributes( IMPORTING static_attributes = ls_stru ).
      ls_stru-last_col = ls_stru-col1+ls_stru-col2....+ ls_stru-col5. " add all the cells data
      l_element->set_static_attributes( exporting static_attributes = ls_stru ).

  • Regarding Logical level key and row wise initialization

    Hi Gurus,
    What is the purpose of row wise initialization in external table authentication and when we have to go for row wise initialization.
    Why we have to enable logical level key in hierarchy is this only for getting drill down to the next level if we make two columns as logical level key what will happens. If we want to enable a column as a logical level key what are the character sticks that column should satisfy.
    Thanks,

    1) Row Wise Initialization used to hold multiple values in a variable. Let says SQL gives 4 rows (A,B,C,D) as output. Now I want to hold 4 value in a variable to get this happen we need to go for RowwiseIniziation. If you do not do this at any point in time Variable holds only value A not others. Simply it works as Array.
    2) Level keys define the unique elements in each level and provide the context for drill down. You can make two logical columns as logical key but you need to make sure what to be displayed in your hierarchy by selecting DISPLAY. If you make to as separate logical keys and set Display for both you get two columns in the hierarchy
    http://gerardnico.com/wiki/dat/obiee/hierarchy_level_based

  • How 2 Change of column wise o/p  to row wise output in ABAP?

    Hi all,
    I am getting the output in column wise as normally but how can I get the ouput in row wise.in ABAP.
    its urgent. can any one help me how to change the output layout?
    thanks in advance,
    Sakthi.C

    if it is normal report  .then
    go through the write  statents  . one of that is below 
    Loop at itab .
    write  : itab  .
    endloop.
    if it is  ALV  then you have to  define an internal table which are the fieldds  you  want palce in the  Row .
    so  that  
    data  c type  i value    '1'.
    loop at  itab .
    fieldcatalog-fieldname   = itab-field.
    fieldcatalog-col_pos     = c.
    append fieldcatalog to fieldcatalog.
    clear  fieldcatalog
    c = c + 1.
    endloop.
    so that  the Col_pos  will be increased  and the  Column data will be moved into Row .
    reward  points if it is usefull...
    Girish

  • Date Calculation in BEx

    Hello All,
    In my report, User wants to see a day counter which is the dfference of a date (date coming from cube) and Current date. For current date  we are using 0f_aday sap exit. How we can we acheive this, does it involve any User exits at the back end or can I use a calculated keyfigure to find the difference between these two dates.
    Please reply to this as it is very Urgent Issue
    thank you

    HI AL,
    Thanks for the udpate. But I believe we can update any thread if its related with the same subject if its less than 3 years. Is it not right ? I have a mail in my inbox, from some moderator confirming the same. That is the reason I have updated this thread...as its related to the same question and this thread is created n 2011.
    Anyway, thanks for the answer. I will change the dimension to date and calculate the difference from the 2 variables.
    Reg another doubt, from the below link...
    https://docs.google.com/viewer?a=v&q=cache:YQS2jPhWysAJ:www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/705734f2-4e85-2e10-2ebf-891d0110de74%3FQuickLink%3Dindex%26overridelayout%3Dtrue+&hl=en&gl=au&pid=bl&srcid=ADGEESjL8dx81tAAJNL0Ln4c2MW4k3yZRDNFsop1pptOc3bQf1xU0Le9e3loFsZXJi5rWuYt3j7yoStGMktsL5XEdV9T3ONzdKay0x5yrIbaUBB3Dpz1Fr6xuggf_IZX-S0Q4WONpBhN&sig=AHIEtbTZfXXLN4gZCsw7qpZXgrkjeCYLcA
    what is the field used for Interval ( from, to , range) . You have missed my other question, why am I getting X below the result while doing the date calculation . I mean I am getting the result, but below every row, there is a X . Any ideas ?
    Thanks,
    DR

  • Year Wise Data in SQL Express

    Hi...
    Can any one help for How to maintain year wise data in sql server. 
    In my project i manage year wise data i.e 1st April to 31 march.
    At the end of the year the current year closing balances need to update as opening balance for the next year and previous data wont be changed.
    And i dont know how to  create year wise folders in one database....
    Please show me some suggestion...

    Hi
    According to your description, we got that you want to manage year wise data in one database. You can try to create a partitioned table with a Year column to store all the data. The partitioning feature is supported in SQL Server 2005 and later versions of
    SQL Server. There are four major steps for implementing partitioning.
    1. Create a filegroup or filegroups and corresponding files that will hold the partitions specified by the partition scheme.
    2. Create a partition function that maps the rows of a table into partitions based on the values of a specified column.
    3. Create a partition scheme that maps the partitions of a partitioned table to the new filegroups.
    4. Create or modify a table and specify the partition scheme as the storage location.
    For how to create a partitioned table, please review the following links:
    Create Partitioned Tables and Indexes:http://msdn.microsoft.com/en-us/library/ms188730.aspx
    Creating a table with horizontal partitioning in SQL Server:
    http://www.mssqltips.com/sqlservertip/1796/creating-a-table-with-horizontal-partitioning-in-sql-server/
    Thanks
    Lydia Zhang

  • How to display 7 values of  single field in row wise.

    hi,
    how to display 7 values of  single field in row wise.
    thankx in advance.

    hi ,
    do it like this :
    1 Place ur UI element in tranparent container with Layout as Row Data and Layout Data as Row Head Data
    2 Ur first  UI , which contains the first value as Row Head Data ,
    3 Others as Row Data
    u can do it with Matrix Data as well
    if u want to give space , u can use HORIZONTAL GUTTER and set its width to medium / large / Xlarge
    also there is a UI element "INVISIBLE ELEMENT" ,
    1 u can use this UI element to provide space between ur other UI elements in the view
    2 u can insert a text element as well , and in the Text property of the element press ALT + 0160.
    u can give the space bw UIs as desired.
    regards,
    amit

  • Abt Row - Wise initialization

    Hi Gurus,
    What is the use of row wise initialization when we have go for this can i have one scenario for better under standing.
    Thanks,

    Check these
    http://gerardnico.com/wiki/dat/obiee/row-wise
    http://docs.oracle.com/cd/E12103_01/books/admintool/admintool_Variables6.html
    http://obiee10grevisited.blogspot.com/2012/03/row-wise-initialization.html

  • Row-Wise Session Variable Initialization Block (Max Rows)

    Hi, we have a problem with Row-Wise Session Variable.
    We'll try to implemented the security with a External Query and a Row-Wise Initialization Block. But when we'll try to open the Web Obiee and the rows of result of the query is more than 3000 rows, the browser is broken. The access is very slowly.
    When the result of Query to Row-Wise Variable is more than 3000 rows and we'll try to open the Web Obiee, we have to close NQServer.EXE process of Obiee Server.
    Is there a best practise or a limit rows in the Row-Wise Initialization Block?.
    Thanks.

    You're Right, the people can't be in 3000 groups.
    Is possible I don't explain my problem correctly.
    We use this Row-Wise Variable for implement Data Level Security. .
    For Example :
    I have a fact table with Offices and Office's Sales.
    And each Obiee User can see many Offices according to their level of security.
    I want filter the fact table using a external SQL table implemented in a Session Row-Wise Variable and a User can have X Offices (In the worst case, 3000 Offices).

Maybe you are looking for

  • Xml to Oracle (Update more than one row)

    Hi, I want to update more than one row in table from .xml file. My xml file is as follows: <ROOT> <PROFILE PROFILEMASTER_PKEY="54" DB_MSTR_PKEY="2" PROFILE_NAME="Bhushans" DELIMETER="~" PRE_PROCESSOR="1" POST_PROCESSOR="10" PRE_PROCESSOR_TYPE="1" POS

  • Xmlcg

    I was under the impression that xmlcg would provide both set and get methods for each of the elements/attributes. However this does not seem to be the case as only set and add methods are generated. Please would someone confirm this and also mention

  • Mouse Hover in some browsers displayed...

    I noticed something funny while testing my website in browser labs. I have some css rules to change some background colors for mouse hover. In the browsers I tested, Firefox 4.0 for Windows seems to show these rules for approximately the center of th

  • Why is the battery draining so fast?

    Everything in safari is shut down, all multi-tasking is turned off too. My phone is only 7 months old & has worked fine up until today when I noticed the battery draining so fast.

  • N82 Auto Rotate (Accelerometer) Problem !

    Anyone has problem with auto rotate? My N82 its kinda very hard to auto rotate. I do know it will not rotate on stand by screen and only rotate anti clock wise. The phone is just 2 weeks old, the auto rotate just work fine for the first week. Suddenl