Weird result of oracle query before and after function base index creation

Hi All,
Here is the unique situation we are facing after creating just an index.
The query result before the index and the query result after the index do not match.
This is very illogical situation. Shidhar and me have done lot of R&D, also tried to get lots info from Google but we couldn't decipher the reason for that.
I am giving you all the details about the query, index and tables with following steps.
Please let us know if anything is going wrong from our side or is it a bug at oracle level which is a rarest possibility but a possibility.
Step 1 :- Create table
create table TEMP_COMP
ID VARCHAR2(10),
GROUP_ID VARCHAR2(10),
TRAN_DATE DATE,
AMT_1 NUMBER,
AMT_2 NUMBER,
AMT_3 NUMBER
Step 2 :- Insert Sample data
set feedback off
set define off
prompt Deleting TEMP_COMP...
delete from TEMP_COMP;
commit;
prompt Loading TEMP_COMP...
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('01', 'G01', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('02', 'G01', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('03', 'G01', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('04', 'G01', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('05', 'G01', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('06', 'G01', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('07', 'G01', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('08', 'G01', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('09', 'G01', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('10', 'G01', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('01', 'G01', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('02', 'G01', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('03', 'G01', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('04', 'G01', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('05', 'G01', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('06', 'G01', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('07', 'G01', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('08', 'G01', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('09', 'G01', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('10', 'G01', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('01', 'G02', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('02', 'G02', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('03', 'G02', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('04', 'G02', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('05', 'G02', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('06', 'G02', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('07', 'G02', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('08', 'G02', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('09', 'G02', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('10', 'G02', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('01', 'G03', to_date('01-03-2007', 'dd-mm-yyyy'), 1, 11, 111);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('02', 'G03', to_date('02-03-2007', 'dd-mm-yyyy'), 2, 22, 222);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('03', 'G03', to_date('03-03-2007', 'dd-mm-yyyy'), 3, 33, 333);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('04', 'G03', to_date('04-03-2007', 'dd-mm-yyyy'), 4, 44, 444);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('05', 'G03', to_date('05-03-2007', 'dd-mm-yyyy'), 5, 55, 555);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('06', 'G03', to_date('01-03-2008', 'dd-mm-yyyy'), 6, 66, 666);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('07', 'G03', to_date('02-03-2008', 'dd-mm-yyyy'), 7, 77, 777);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('08', 'G03', to_date('03-03-2008', 'dd-mm-yyyy'), 8, 88, 888);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('09', 'G03', to_date('04-03-2008', 'dd-mm-yyyy'), 9, 99, 999);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('10', 'G03', to_date('05-03-2008', 'dd-mm-yyyy'), 10, 100, 1000);
insert into TEMP_COMP (ID, GROUP_ID, TRAN_DATE, AMT_1, AMT_2, AMT_3)
values ('11', 'G01', to_date('03-03-2008', 'dd-mm-yyyy'), 100, 200, 300);
commit;
prompt 41 records loaded
set feedback on
set define on
prompt Done.
Step 3 :- Execute the query.
SELECT GROUP_ID
, SUM(LAST_YR_REV) as "Year_2007_Amt"
, SUM(CURR_YR_REV) as "Year_2008_Amt"
FROM (
SELECT GROUP_ID,
CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200701'AND'200712'THEN SUM(AMT_1) ELSE 0 END AS LAST_YR_REV ,
CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200801'AND'200812'THEN SUM(AMT_1) ELSE 0 END AS CURR_YR_REV
FROM TEMP_COMP t
WHERE GROUP_ID ='G01'
AND TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200601'AND'200912'
GROUP BY GROUP_ID, TRAN_DATE
GROUP BY GROUP_ID
The result of above query
GROUP_ID Year_2007_Amt Year_2008_Amt
G01 30 180
Step 4 : Create composite index
create index GROUP_ID_TRAN_DATE_IDX on TEMP_COMP (GROUP_ID, TO_CHAR(TRAN_DATE,'YYYYMM'))
Step 5 : Execute once again query from step 3.
SELECT GROUP_ID
, SUM(LAST_YR_REV) as "Year_2007_Amt"
, SUM(CURR_YR_REV) as "Year_2008_Amt"
FROM (
SELECT GROUP_ID,
CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200701'AND'200712'THEN SUM(AMT_1) ELSE 0 END AS LAST_YR_REV ,
CASE WHEN TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200801'AND'200812'THEN SUM(AMT_1) ELSE 0 END AS CURR_YR_REV
FROM TEMP_COMP t
WHERE GROUP_ID ='G01'
AND TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200601'AND'200912'
GROUP BY GROUP_ID, TRAN_DATE
GROUP BY GROUP_ID
The result of above query
GROUP_ID Year_2007_Amt Year_2008_Amt
G01 0 210
Thanks
Sunil

I just wanted to make a comment. The predicates in both your queries are flawed I believe. You convert a date column to a character and then you say only pick the converted result between two sets of characters.
TO_CHAR(TRAN_DATE,'YYYYMM') BETWEEN'200601'AND'200912'It should be coded like this for a proper date range comparison:
TRAN_DATE BETWEEN TO_DATE('200601','YYYYMM') AND TO_DATE('200912','YYYYMM')That will eliminate the need for you to create FBI that you created. You should now be able to create a regular (B*Tree) index on the TRAN_DATE column.
Also, now that we have the structure of your tables and sample data, what business question are you trying to answer? I think there is a better query that can be written if we know the requirements.
Hope this helps!

Similar Messages

  • How to get the query result of improvement (Before and After ) using sql de

    how to get the query result of improvement (Before and After ) using sql developer.

    Check
    http://www.oracle.com/technetwork/articles/sql/exploring-sql-developer-1637307.html

  • Oracle Alert: Access before and after update values of a table column

    We have a requirement where a notification needs to be sent when 'END_DATE' attribute (column in a table X) is set, in an Oracle Applications form.
    I have defined an Event based Oracle Alert which fires 'On Update' of the table X.
    Could anyone please let me know as how to access the value of 'END_DATE' before and after update (i.e :new.END_DATE and :old.END_DATE) in the sql query of the alert.
    The need to use the before update and after update values of the attribute 'END_DATE' is that if we add the condition END_DATE is not null, the alert is sent even if any other attrbutes are updated in the Oracle form which is not the intended behavior.
    Appreciate any help.
    Thanks

    Hi
    use selectionlistener for your first table then add clientlistener and serverlistener so that you will get the rows on click in back bean.
    then get second table vo and and create and add row for that view object. add partial target to refresh your second table from back bean.
    on click of save call commit operation.

  • Xl reporter shows different result before and after Period-End Closing.

    Hi SAP experts,
    We have an issue with XL Reporter. When we ran Period-End closing and ran XL - PL Period & YTD (with the same parameters), XLR shows nil in the Actual YTD column and the monthly figures are out by a big difference (example pre-rollover it was $110K after rollover it shows negative $12M).
    This happens on 2 different clients running 2 different SAP B1 (2007A PL 42 and 8.8 PL 13) on the same XL Reporter which is possibly the default XL report that comes with the installation.
    I don't have any idea why the XLR is running 2 different figures altogether when running the same XLR using the same parameter before and after rolling the year over. The default SAP B1 P&L report stays the same before and after the rollover, I would have expect that the same would happen with the XLR.
    Please advise.
    Regards,
    Didy Arfiono

    Hi Julie,
    Thanks for the reply. I'm not entirely sure what you mean by excluding a certain transaction for closing entries as this would defeat the whole purpose of PEC which as you stated was to transfer P&L balances to retained earnings account to be carried forward.
    I've check at some guides including one from Orchestra Team (http://www.youtube.com/watch?v=e4tUo774eXg) and so far the process that I've done is exactly what it is.
    Regards,
    Didy

  • Counting values before and after an interval

    I posted this awhile back but I'm back to trying to solve the problem (didn't solve it), so apologies if that is bad etiquette! This forum has been so helpful though I thought I would try again:
    design/methodology question
    The short of it is I have a table with calls that happened, all have a start and end time.
    I want to take 1 min intervals over a given hour (say, 12-1pm) and (the part I need help with) count all calls that happened before and after that interval.
    That is to say, all calls that were 'active' during that interval (consider if I call started at 11:59 am and ended at 12:05) would need to be counted for the 12:00, 12:01, 12:02, 12:03, 12:04, and 12:05 intervals.
    So what I'm trying to construct is an SQL query that uses a 'variable' in this case (I think).
    That is, so I can saw 'where start_time < min_interval' and where 'end_time is > min_interval' and count those records to my total.
    But I'm at a loss on how to pull this off!
    Thoughts?

    If a call began at 15:01:01 and ended at 15:01:59, was it active at 15:01? Was it active at 15:02? Both? Neither?Is only active at 15:01.
    Do you need 4 separate numbers, or do you need 1 number, which is the total of these 4?I need 1 number which is the math formula (using the number above)
    1 + 2 - 3 + 4
    Oracle version is 10.2.0.4.0
    I will work on learning the CREATE TABLE and INSERT statements, as well as, the WITH one.
    Is the point of submitting those to understand the data set being worked with?
    Here is my attempt...
    Consider the following:
    WITH     my_call     AS
         SELECT     1 AS call_id     ,     to_date('10-may-2011 12:00:17'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             ) AS start_time      ,      to_date('10-may-2011 12:01:23'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 ) AS end_time  FROM dual     UNION ALL
         SELECT     2           ,      to_date('10-may-2011 12:00:45'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             )                 ,      to_date('10-may-2011 12:03:55'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 )           FROM dual     UNION ALL
         SELECT     3          ,      to_date('10-may-2011 12:01:01'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             )                 ,      to_date('10-may-2011 12:01:59'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 )           FROM dual     UNION ALL
         SELECT     4          ,      to_date('10-may-2011 12:01:45'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             )                 ,      to_date('10-may-2011 12:04:43'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 )           FROM dual     UNION ALL
         SELECT     5           ,      to_date('10-may-2011 12:02:33'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             )                 ,      to_date('10-may-2011 12:08:05'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 )           FROM dual     UNION ALL
         SELECT     6           ,      to_date('10-may-2011 12:02:35'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             )                ,      to_date('10-may-2011 12:04:56'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 )           FROM dual     UNION ALL
         SELECT     7           ,      to_date('10-may-2011 12:03:02'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             )                 ,      to_date('10-may-2011 12:05:13'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 )           FROM dual     UNION ALL
         SELECT     8           ,      to_date('10-may-2011 12:03:41'
                             , 'dd-mon-yyyy hh24:mi:ss'
                             )                 ,      to_date('10-may-2011 12:04:37'
                                                 , 'dd-mon-yyyy hh24:mi:ss'
                                                 )           FROM dual
    )then, to solve #1 (calls that started in each minute):
    select
      to_char(new_time(trunc(start_time, 'hh24') + (trunc(to_char(start_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi') as "Start Time",
      count(*) as "Start Time Count"
    from
      my_call
    group by
      to_char(new_time(trunc(start_time, 'hh24') + (trunc(to_char(start_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi')
    order by
      to_char(new_time(trunc(start_time, 'hh24') + (trunc(to_char(start_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi');would yield the following output (consider I am converting to GMT in this example):
    07:00     2
    07:01     2
    07:02     2
    07:03     2To solve 2, calls with end_time, I do the following:
    select
      to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi') as "End Time",
      count(*) as "End Time Count"
    from
      my_call
    GROUP BY to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi')
    order by
      to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi');which gives us:
    07:01     2
    07:03     1
    07:04     3
    07:05     1
    07:08     1# 3 (calls that started and ended in the same minute) is:
    select
      to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi') as "End Time",
      count(*) as "End Time Count"
    from
      my_call
    where
    to_char(new_time(trunc(start_time, 'hh24') + (trunc(to_char(start_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi') = to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi')
    GROUP BY to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi')
    order by
      to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi');which gives us:
    07:01     1Now, given the small data set (which, as a side note, I can see a little, now, why the WITH statement here is useful and important!) we know the final output should be
    (EXPECTED RESULT WHEN WE ARE DONE):
    07:00     2
    07:01     4
    07:02     4
    07:03     6
    07:04     5
    07:05     2
    07:06     1
    07:07     1
    07:08     1So what I am posting this forum is help in calculating #4 - calls that had a start time (trunc'd to the minute) before the minute interval and an end_time after.
    Something like this:
    select
      to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi') as "End Time",
      count(*) as "End Time Count"
    from
      my_call
    where
    to_char(new_time(trunc(start_time, 'hh24') + (trunc(to_char(start_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi') < minute_interval and
    to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi') > minute_interval
    GROUP BY to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi')
    order by
      to_char(new_time(trunc(end_time, 'hh24') + (trunc(to_char(end_time, 'mi')/1)*1)/24/60, 'GMT', 'CDT'), 'hh24:mi');where the expected output would be:
    07:00     0
    07:01     1
    07:02     2
    07:03     3
    07:04     2
    07:05     1
    07:06     1
    07:07     1
    07:08     0thoughts on accomplishing this?

  • Count before and after to certain occurance.

    I am trying to count the amount of units  studied before and after a certain Course was taken.
    So ID 1 did PREP in 2013 in the first period and has and also had done a unit in 2009 so reult be before prerp count 1
    ID 2 did PREP in 2012 first period and also an OTHER course in the same period as well as a OTHER in period 2. So when a PREP course appear in the same period and year as an OTHER course I would like it to count it as AFTER Prep.(see below(so when equal count as after PREP))
    ID 3 has done one unit before before PREP which is in 2011 and 2 Units after the first PREP course.
    I attepted this with not in and in statments basic I know but to no luck.
    Any help is greatly appreciated.
    Thanks
    CREATE TABLE DAN_DIRK_2
    (ID     VARCHAR2(8),
    YEAR    VARCHAR2(8),
    PERIOD VARCHAR2(8),
    COURSE VARCHAR2(12),
    UNIT VARCHAR2(12));
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (1,'2013','SP1','PREP','PLI');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (1,'2009','SP4','OTHER','DRI');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (2,'2012','SP1','OTHER','FER');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (2,'2012','SP2','OTHER','AQW');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (2,'2012','SP1','PREP','FGV');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2011','SP1','OTHER','GVW');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2012','SP2','PREP','FER');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2013','SP1','OTHER','FSW');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2013','SP1','PREP','FGH');
    GIVES:
    ID
    YEAR
    PERIOD
    COURSE
    UNIT
    1
    2013
    SP1
    PREP
    PLI
    1
    2009
    SP4
    OTHER
    DRI
    2
    2012
    SP1
    OTHER
    FER
    2
    2012
    SP2
    OTHER
    AQW
    2
    2012
    SP1
    PREP
    FGV
    3
    2011
    SP1
    OTHER
    GVW
    3
    2012
    SP2
    PREP
    FFR
    3
    2013
    SP1
    OTHER
    FSW
    3
    2013
    SP1
    PREP
    FGH
    WANT:
    ID
    BEFORE
    AFTER
    1
    1
    0
    2
    0
    2
    3
    1
    2

    Chloe_19 wrote:
    Get an Error
    ORA-32033: unsupported column aliasing
    32033. 00000 -  "unsupported column aliasing"
    *Cause:    column aliasing in WITH clause is not supported yet
    *Action:   specify aliasing in defintion subquery and retry
    Error at Line: 1 Column: 8
    Am using version:
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    because you use 10g, try this :
    WITH tt AS (
    select 1 ID,  2013 YR,  'SP1' PERIOD,  'PREP' COURSE,  'PLI' UNIT from dual union all
    select 1,  2009,  'SP4',  'OTHER',  'DRI' from dual union all
    select 2,  2012,  'SP1',  'OTHER',  'FER' from dual union all
    select 2,  2012,  'SP2',  'OTHER',  'AQW' from dual union all
    select 2,  2012,  'SP1',  'PREP',  'FGV' from dual union all
    select 3,  2011,  'SP1',  'OTHER',  'GVW' from dual union all
    select 3,  2012,  'SP2',  'PREP',  'FFR' from dual union all
    select 3,  2013,  'SP1',  'OTHER',  'FSW' from dual union all
    select 3,  2013,  'SP1',  'PREP',  'FGH' from dual ),
    tt2 AS (
    SELECT t.ID,
           min(t.YR) minyr, 
           min(replace(t.PERIOD,'SP','')) KEEP(DENSE_RANK FIRST ORDER BY T.YR) minpr
    FROM  tt t
    WHERE t.COURSE = 'PREP'
    GROUP BY t.ID)
        SELECT ID,
               NVL(COUNT(BEF),0) BEFORE,
               NVL(COUNT(AFT),0) AFTER
               FROM(          
                        SELECT t1.ID,
                               (CASE WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course='PREP' THEN NULL
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course!='PREP' THEN NULL
                                     WHEN t1.YR < t2.minyr THEN -1
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')<= t2.minpr THEN -1
                                 END) BEF,
                               (CASE WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course='PREP' THEN NULL
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course!='PREP' THEN 1
                                     WHEN t1.YR > t2.minyr THEN 1
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')>= t2.minpr THEN 1
                                 END) AFT        
                         FROM tt t1
                        LEFT JOIN tt2 t2
                               ON t2.id = t1.id
        GROUP BY ID
        ORDER BY 1

  • How to covert before and after image details from logdump to SQL

    Hi,
    Through logdump,i am able to retrieve below before and after image details for an update statement.
    Instead of below ascii format output, i need to know the complete sql statement before update and after update.
    Is there any command to covert below output to readable SQL sentence?
    2012/09/26 02:30:16.999.659 FieldComp Len 300 RBA 2528
    Name: TEST.TESTTABLE
    Before Image: Partition 4 GU m
    5e50 86f5 af70 9660 b6fa 785c e34f 8881 0497 9507 | ^P...p.`..x\.O......
    799f 2ee2 6399 d539 ea92 90de 828b 83d9 adc9 c8c4 | y...c..9............
    ca87 9632 7136 a5fc 826f 8cc7 6ddd 7f8a e02e 816a | ...2q6...o..m......j
    6ac4 739a 8011 5068 068a 4553 4937 93e7 cc5a d3d3 | j.s...Ph..ESI7...Z..
    6a2b 2540 3be9 1df7 6d0c 0f17 d795 efd4 e0c5 dae9 | j+%@;...m...........
    a488 a757 7c07 78a4 5f2a 1330 d2bb 5a05 7075 6b95 | ...W|.x._*.0..Z.puk.
    529c f681 97d8 df6f 58d5 37dc e36d 8bc0 19d5 c7f0 | R......oX.7..m......
    Bad compressed block, found length of 34549 (x86f5), RBA 2528
    Logdump 2335 >n
    Hdr-Ind : E (x45) Partition : . (x04)
    UndoFlag : . (x00) BeforeAfter: A (x41)
    RecLength : 300 (x012c) IO Time : 2012/09/26 02:30:16.999.659
    IOType : 15 (x0f) OrigNode : 255 (xff)
    TransInd : . (x01) FormatType : R (x52)
    SyskeyLen : 0 (x00) Incomplete : . (x00)
    AuditRBA : 24567 AuditPos : 4268948
    Continued : N (x00) RecCount : 1 (x01)
    2012/09/26 02:30:16.999.659 FieldComp Len 300 RBA 2947
    Name: TEST.TESTTABLE
    After Image: Partition 4 GU m
    5e50 86f5 af70 9660 b6fa 785c e34f 8881 0497 9507 | ^P...p.`..x\.O......
    799f 2ee2 6399 d539 ea92 90de 828b 83d9 adc9 c8c4 | y...c..9............
    ca87 9632 7136 a5fc 826f 8cc7 6ddd 7f8a e02e 816a | ...2q6...o..m......j
    6ac4 739a 8011 5068 068a 4553 4937 93e7 cc5a d3d3 | j.s...Ph..ESI7...Z..
    6a2b 2540 3be9 1df7 6d0c 0f17 d795 efd4 e0c5 dae9 | j+%@;...m...........
    a488 a757 7c07 78a4 5f2a 1330 d2bd 5a05 7075 6b95 | ...W|.x._*.0..Z.puk.
    529c f681 97d8 df6f 58d5 37dc e36d e8b8 19d5 1af0 | R......oX.7..m......
    Bad compressed block, found length of 34549 (x86f5), RBA 2947

    From the reference guide:
    *FORMATSQL*
    Valid for Extract
    Use the FORMATSQLparameter to output data in external SQL format, instead of the default
    Oracle GoldenGate canonical format. FORMATSQLgenerates SQLstatements (INSERT, UPDATE,
    DELETE) that can be applied to both SQLand Enscribe tables by utilities other than Oracle
    GoldenGate Replicat.
    NOTE Do not use FORMATSQL if the data will be processed by the Replicat process.
    Replicat expects the default canonical format. Do not use FORMATSQLif
    FORMATASCIIor FORMATXMLis being used.
    A FORMATSQL statement affects all extract files or trails defined after it.
    Default output
    Without options, FORMATSQLtransactions are output as follows, in comma-delimited format:
    ● The begin-transaction indicator, B.
    ● The timestamp at which the transaction was committed.
    ● The sequence number of the transaction log in which the commit was found.
    ● The relative byte address (RBA) of the commit record within the transaction log.
    ● The SQL statements.
    ● The commit indicator, C.
    ● A newline indicator.
    Every record in a transaction is contained between the begin and commit indicators. Each
    combination of commit timestamp and RBA isunique. You can customize the output
    format with optional arguments.
    Default See “Default output”
    Syntax FORMATSQL [<option>] [, ...]

  • Everyone:  This time repair your permissions before and after 10.4.8 update

    Hello All,
    Just a reminder for all those who are updating to OS 10.4.8.
    While many people do ignore all the recommendations that we provide and still come through fine, please do consider observing the following to minimize your problems.
    To insure the best chance of success, please consider downloading the Combo Updater for your computer instead of using Software update.
    For PowerPC Mac's, this would be:
    http://www.apple.com/support/downloads/macosx1048comboupdateppc.html
    For Intel Macs, this would be:
    http://www.apple.com/support/downloads/macosx1048comboupdateintel.html
    The benefit of using the Combo Updater, is that it replaces all system files that have been changed since the last major release (in this case since 10.4.0).
    So, if you have any system files that have become corrupted, the Combo Updater will very likely over-write those, and spare you the headaches that come from updating an operating system that has problems that just haven't come to the surface yet.
    In many cases, you can have problems that have not come to the surface, and the "Delta" or Software update method will bring them out to bite you. The reason for this, is because the Delta / Software Update version only changes files that have changed since 10.4.7. And, it works more in a "patch" fashion. So, if there is a problem in one of the files being patched, then the update will cause you some major headaches.
    Going with the larger "Combo" update over-writes almost all the System files with clean versions instead of just making patches. So, it is frequently much more successful.
    Now, with that said, before you update, you should make sure your permissions are all set properly. If your permissions are wrong, then your update will likely have trouble.
    So, go into "Disk Utility" in the Applications --> Utilities folder and repair your permissions.
    Start by selecting your hard drive on the left window of Disk Utility. Then, go down and click on the "Repair Permissions" button. Once it's completed, then exit Disk Utility.
    Now, it is also extremely important to make sure all running programs are closed before you install any system update. So, go ahead and restart your computer.
    Restarting will make sure that all programs are closed, and that nothing weird is stuck in memory before you install.
    If you have anti-virus programs running, then disable or deactivate them first (you don't want them interpreting this as unauthorized modification or it might prevent certain files from being updated).
    Now, with your computer freshly restarted, install the Combo updater you downloaded.
    When prompted, click on the "Restart" button when prompted.
    Now, the computer will startup, but sit at the spinning wheel for several minutes. It will eventually restart again on it's own. And, finally, it will start-up all the way and you'll be back at your desktop.
    Now, immediately go back to Disk Utility and repair permissions as you did in the previous step. You will likely see several permissions that have been repaired. In my case, I had dozens of CoreAudio, Widgets, and other permissions that needed repair. Once permissions have been repaired, go ahead and restart one last time. This makes sure that everything is set and then cleaned-up.
    Once it reboots, begin using it and enjoy.
    Now, this may sound like a lot. But, it really is simple. It just reads like a lot of stuff.
    And, of course, you are free to ignore this and just install it however you like. Many people have their own ideas here. And, many people say you don't have to do anything to prepare. But, for those that have had huge problems in the past, these extra steps will usually save you the major headaches that tons of people inevitably have with every new update.
    Anyway, I hope this helps to save at least a few of you any problems. If you don't agree with the ideas above, just ignore it and do as you like.
    But, if you want a little extra piece-of-mind and a better chance at success, then please consider exercising this extra caution.
    And, for the record, I have updated my machines to 10.4.8 (within minutes of the update being available) and it is working perfectly smooth on my systems.
    I hope you find this helpful.

    mhunter, thanks and good that you take the time and effort again to remind everyone that it does take an effort to do a major OS update, to ensure maximum stability.
    So far my 10.4.8 Update is a-okay, and I have had many trouble-free updates since installing 10.4
    I too practice rigourously and "religiously" before and after an OS or Security Update, but I normally use Software Update, equally successful:
    1. Before Startup, UNPLUG all external devices, left only keyboard, mouse and internet connection, unless they are all wireless.
    2. Startup, disable NAV if any, Repair Disk Permission. Restart again, Repair Permission again.
    3. Do Software Update
    4. Restart, Repair Permission
    5. Shutdown, plug everything back
    6. Startup Mac, use Mac
    So far these steps have been keeping all my macs both at home and at work very very stable and healthy.
    Maybe, just maybe if everyone here, all mac users were to follow these steps, yes they can be a hassle, yes they can take up some time, but then there will be less less complains and "blasts" at Apple, just because perhaps themselves have been too careless or negligance in performing updates.
    Cheers

  • How to create a loop to run total of records for before and after unconstant date

    Post Author: Ann2
    CA Forum: Formula
    Here is the data sample:
    ID period code date
    1  00  I    01/01/1999
    1 00   Z   01/02/1999
    1 00  G   12/05/1999
    1 00  M   01/01/2000
    There are many students with many periods and many codes. I need to save a date when code = 'G' and count separateley records per student/period 2 times - before and equal that date and after that date, so in the end for period 00 I will have 2 values: 3 (before) and 1(after).
    There are periods from 00 to 08. I am counting students abscencies before and after warning letter was sent (code G).
    The result data should look : 00 01 02 03 04 05 06  07  08              00 01 02 03 04 05 06  07  08     Total
                                                3  0   0   0   0   0   0   0   0                 1 0    0   0   0   0   0   0   0        4
    Please help me.
    Thank you.
    Ann2

    Post Author: Ann2
    CA Forum: Formula
    Thank you for your answer, but I do care about the date the 'G' happened, because I need to reset count.
    The logic behind is this:if a student absent for more than 8 times per period - the letter will be sent out to the parents , that will be code 'G' with period '-1' (it may happen that there will never be code 'G' , but I need to track all absencies). Once the letter is sent, the count starts over (the count starts over the next day after code 'G'). The absencies which happened before or the date the letter sent should count toward 'previous'  abscenices, all other - absenices after the letter.
    So basically I need total per period and total per period before or the day with code 'G'.  Running total with reset with formula code = 'G' does not work.
    I created a formula field which has global date (when code 'G' happenned) and it says if globaldate >= periodDate then date (1900,01,01) else (2100,01,01) and that formula is ok, but I can not use it in running total or can not create group on it and insert total.
    Please help me with this. Thank you.
    Ann2

  • How Can I Blink Between Before and After in Liquify?

    I think I've done this before (in prior versions), but I'm drawing a blank...  Is there a quick way to blink between before and after results in Liquify?
    Thanks.
    -Noel

    There are several ways i can think of
    1. Alt click on the cancel button and the Ctrl+Z
    2. Hit the Restore All button then Crtl+Z
    3. If you have the advanced options showing you could use Show Backdrop and then toggle the Show Image

  • Before and After insert or update rowcount

    Hi
    I have several extract objects procs which are calling various build objects procs which in turn are inserting or updating the tables...now when i run these objects sometimes i get no errors and everything seems to be running perfectly but the tables do not get updated ? now what i am trying to achieve here is get some kind of summary where i can see the before and after rowcount..for that i have created a table of every extract object proc and another table with the coressponding tables being updated by tht proc...can anyone pls tell me how should i look into these procs and how do i get the rowcount for a particular table before and after the procedure was run ?
    Thanks a lot in advance

    Hi,
    On which version of RDBMS are you working , because if you're on 10g then just enable auditing or even FGA on the tables were you want to see the changes,
    Then query the DBA-AUDIT (not sure of the name anymore) view.
    If not then create a audit package yourself.
    something like
    create or replace package pck$audit as
    procedure prc$check_tablecount(p_tablename IN VARCHAR2, p_status IN VARCHAR2);
    end;
    create or replace package body pck$audit as
    procedure prc$check_tablecount(p_tablename IN VARCHAR2,p_status IN VARCHAR2) IS
    sqlstr VARCHAR2(100);
    v_count NUMBER;
    begin
    sqlstr := 'SELECT COUNT(*) FROM '||p_tablename;
    EXECUTE IMMEDIATE sqlstr into v_count; --could by 'using v_count' check syntax for this
    INSERT INTO audit_table(table_name,total_count,status,time_stamp)
    VALUES(p_tablename,v_count,p_status,SYSTIMESTAMP);
    COMMIT;
    end;
    end;
    you can elaborate on this creating additional procedure checking differences in total_count on same table at same time.
    Now call this procedure before starting your insert-delete- on your table make sure you put the parameters correct eg p_status => 'begin procedure'
    and call it again after your commit in your procedure.
    Hope this helps you out
    Erwin

  • How to compare value before and after

    hi,
    one of the queried Values ​​is the number of defective frames.Here, this value is compared with a previously sampled value
    If now (after 10 s) this value is bigger than previous one ,then It saves new value otherwise loop will be continue.If again after (10s) the new value is bigger than  previous  new value then again saves this new point.how can i comapre value before and after?thanks.
    Tadhika

    Do you know what a shift register is? It preserves a value from one loop iteration to the next. Please read the LabVIEW Help on shift registers. There's is also a simple example that ships with LabVIEW that will give you the basic idea (Help -> Find Examples).
    You can also use a Feedback Node in lieu of a shift register. Same concept, different implementation.

  • Printing count of records before and after a command in a PL/SQL

    Hi: I have the following PL/SQL script
    declare
    l_sysdate date := sysdate;
    begin
    INSERT INTO a_mnsnotes SELECT * from mnsnotes where TKT_NBR in (
    select TKT_NBR from mnsinterface where MNS_STATUS=5 and CLOSED_DATE < (((l_sysdate-30) - to_date('01-JAN-1970','DD-MON-YYYY')) * 86400));
    delete from mnsnotes Where
    TKT_NBR in (select TKT_NBR from mnsinterface where MNS_STATUS=5 and CLOSED_DATE < (((l_sysdate-30) - to_date('01-JAN-1970','DD-MON-YYYY')) * 86400));
    commit;
    end;
    /I want to assign the number of records in the two table (a_mnsnotes and mnsnotes) to two variables so I can print in one line the numberof records for both tables before and after the procedure. How do I set the output of a sql command (select count(*) from mnsnotes) to a variable within the pl/sql?
    Thanks
    Ravi

    Also I'm guessing this:
    (((l_sysdate-30) - to_date('01-JAN-1970','DD-MON-YYYY')) * 86400);
    is because closed_date is stored as number of seconds since 01-JAN-1970, which should be turned into a date ASAP. Never store dates as anything other than DATE datatype (or maybe TIMESTAMP in more recent versions).
    It's not right, as sysdate will have a time component so if this code is run at 8am it will give different results to if it is run at 9pm. And not all months have 30 days.
    Have you considered TRUNC(add_months(sysdate,-1)) instead of l_sysdate-30 ?

  • My camera is producing blurry photos before and after ios5. What to do?

    My camera is producing blurry photos before and after ios5. What to do?

    Jp0man-
    There are several reasons a photo might be blurry.  It might be out-of-focus, the iPad or subject might have been moving when the photo was taken, or the blur might actually be noise resulting from not having enough light.
    Try taking a photo of a fixed object 3 or 4 feet away with a lot of light, with the iPad propped against something solid.  If you still get a blurry image, you may have a defective iPad and should contact Apple about it.  If you can demonstrate the problem to an Apple Store Genius, you may get a new iPad on the spot.
    Fred

  • Detecting Before and After Field Images

    Is there a way within ADDT to find the value of screen fields prior to update?  I've tried using the custom trigger BEFORE and STARTER events; BEFORE is too late, the field is already changed, STARTER is too early, the field value is NULL.
    I don't believe using straight PHP is an option either because I believe ADDT changes the names of the fields for occurence purposes.
    I would like to produce a detail log of the fields that change.  Comparing them before and after seems like the only way.

    Heya,
    I've really been having a hard time trying to understand exactly what it is you are trying to do. I read your post a few times and caught this line:
    I would like to produce a detail log of the fields that change.
    For this I would go about it by using an update record SB combined with insert into two tables SB. This would update the record of the user and also insert the info into a second table, the 'changed fields' table...
    In 'changed fields' table insert logged in users id via session variable, a timestamp, and whatever fields were updated in the update record SB form and there you'd have it - your record updated and a detailed record of what fields were updated and when with complete backlog for all users. Query 'changed fields' table sorted by user id and you'd see who changed what when.
    Hope that helps!

Maybe you are looking for