script takes a long time to run

Hi friends,



We have a record of leave in the following way:



name date leaves

----- ----- -------

ABC 1 October 08 1

ABC 2 October 08 1

ABC 3 October 08 1

ABC October 4 08 1

ABC 5 October 08 1

ABC 10 October 08 1

ABC 18 October 08 1

ABC, 19 October 08 1

ABC 20 October 08 1

ABC October 25 08 1

ABC 26 October 08 1

ABC 27 October 08 1

ABC October 28 08 1



and we need an output in the following way:



output

-------



Name FromDate date leaves

---- -------- ------ -------

ABC 1 October 08 5 October 08 5

ABC October 10 08 10 October 08 1

ABC 18 October 08 20 October 08 3

ABC 25 October 08 28 October 08 4





The previously mentioned code logic is the following:

=======================================================

=======================================================

procedure KPM_AB_LWP_PROC (p_err_buf OUT VARCHAR2, p_ret_code OUT NUMBER) is

number of diff;

date of prev_date;

date of p_prev_date;

date first_date;

date of last_date;

date DT;

total_leaves number: = 0;

ECODE varchar2 (20);

Ename varchar2 (240);



cursor ab_lwp_cur (the process_from_date date, process_to_date date, e_code varchar2) is

Select

AB. EMPCODE,

AB. RECORD_DATE,

AB. FIRST_HALF,

AB. SECOND_HALF,

(em.last_name |) ', ' || EM. TITLE | ' '|| EM. FIRST_NAME. EM. EMP_NAME MIDDLE_NAME)

Of

kpm_hr_absent_record ab, kpm_hr_emp_mst em

where

AB. EMPCODE = em. EMPCODE

(AB. FIRST_HALF in ("AB", "LWP") or ab. SECOND_HALF ("AB", "LWP"))

and ab. EMPCODE as e_code

and ab.record_date between process_from_date and process_to_date;



cursor active_emp is

Select empcode

of kpm_hr_emp_mst

When status = 'Active'.

order by empcode;

Start

for emp loop active_emp

Start

Select min (ab. RECORD_DATE), max (ab. RECORD_DATE)

in prev_date, last_date

kpm_hr_absent_record AB

where (ab. FIRST_HALF in ("AB", "LWP") or ab. SECOND_HALF ("AB", "LWP"))

and ab. EMPCODE as emp.empcode;

exception

while others then

prev_date: = null;

last_date: = null;

end;



DT: = prev_date;



FND_FILE. PUT_LINE (FND_FILE. OUT, 'salaried worker | Chr (9) | Chr (9) | "Name" | Chr (9) | Chr (9) | 'Count '. Chr (9) | Chr (9) | "To this day". Chr (9) | Chr (9) | 'Sheets' total);

FND_FILE. PUT_LINE (FND_FILE. OUT,'-'. Chr (9) | Chr (9) | '-----' || Chr (9) | Chr (9) | '----------' || Chr (9) | Chr (9) | '---------' || Chr (9) | Chr (9) | '-------------');



While dt & lt; = last_date loop

first_date: = dt;

total_leaves: = 0;



for m loop (prev_date, last_date, emp.empcode) ab_lwp_cur

ECODE: = m.empcode;

Ename: = m.emp_name;

diff: = m.record_date - prev_date;



If diff = 0 then

If m.first_half ("AB", "LWP") then

total_leaves: = total_leaves + 0.5;

end if;

If m.second_half ("AB", "LWP") then

total_leaves: = total_leaves + 0.5;

end if;

prev_date: = prev_date + 1;

on the other

prev_date: = m.record_date;

GoTo print_leave;

end if;



p_prev_date: = prev_date-1;

end loop;



& lt; & lt; print_leave & gt; & gt;



If total_leaves & gt; 0 then

FND_FILE. PUT_LINE (FND_FILE. OUTPUT, ecode | Chr (9) | Chr (9) | Ename | Chr (9) | Chr (9) | first_date | Chr (9) | Chr (9) | p_prev_date | Chr (9) | Chr (9) | total_leaves);

end if;



DT: = prev_date;

end loop;

end loop;

exception

while others then

FND_FILE. PUT_LINE (FND_FILE. JOURNAL,' error: '. SQLERRM);

end KPM_AB_LWP_PROC;

=======================================================

=======================================================





The problem is that this code takes about 24 hours to run, which is not accepted.

Please suggest another technique to apply the same logic.



For your reference, the KPM_HR_ABSENT_RECORD table has about 3,75,000 files inside.

Also, we have created a few clues about certain column as recommended by explaining the plans.



Thanks in advance

Ankur
with t as (select 'ABC' as nm, to_date('01-oct-08','dd-mon-yy') as dt, 1 as leaves from dual union all
               select 'ABC',to_date('02-oct-08','dd-mon-yy'), 1 from dual union all
               select 'ABC',to_date('03-oct-08','dd-mon-yy'), 1 from dual union all
               select 'ABC',to_date('04-oct-08','dd-mon-yy'), 1 from dual union all
               select 'ABC',to_date('05-oct-08','dd-mon-yy'), 1 from dual union all
               select 'ABC',to_date('10-oct-08','dd-mon-yy'), 1 from dual union all
              select 'ABC',to_date('18-oct-08','dd-mon-yy'), 1 from dual union all
               select 'ABC',to_date('19-oct-08','dd-mon-yy'), 1 from dual union all
               select 'ABC',to_date('20-oct-08','dd-mon-yy'), 1 from dual union all
              select 'ABC',to_date('25-oct-08','dd-mon-yy'), 1 from dual union all
              select 'ABC',to_date('26-oct-08','dd-mon-yy'), 1 from dual union all
              select 'ABC',to_date('27-oct-08','dd-mon-yy'), 1 from dual union all
              select 'ABC',to_date('28-oct-08','dd-mon-yy'), 1 from dual)
   -- end of sample data
select nm, min(dt), max(dt), sum(leaves)
from
(
   select nm, dt, max(group_id) over(partition by nm order by dt) group_id
            , leaves
   from
   (
      select nm, dt, case when trunc(dt) - 1 != lag(trunc(dt),1,trunc(dt))
                                                                 over(partition by nm order by dt)
                           then rownum
                           end group_id
             , leaves
      from t
   )
)
group by nm, group_id
order by 1,2;

I hope this helps.

@Blushadow, thanks a lot for the test data.

Concerning

REDA

PS: For more information visit this link
http://www.Oracle.com/technology/oramag/Oracle/04-Mar/o24asktom.html

and search this page for "Analytical to the rescue (again)".

Published by: R.Subramanian on October 22, 2008 04:52
Account function has changed function Sum

Tags: Database

Similar Questions

  • OWB mapping takes a long time to run

    Hello

    I'm developing an application of storage/storage.
    I created a few dimensions and cubes.
    But the problem comes when I try to load the cube by running the mapping.
    The data is small (10K lines) and the dimension loading through the mapping runs very fast (1 minute maximum).
    But when I try to load the cube by running the cube mapping, it takes hours (and it shows 'Running' State forever)

    The possible reasons for this behavior?

    My source is target of 10g 11g.

    Thank you

    Check the plan, noticed in the past there was no unique key on the operational column of the lowest level of the dimension table, in order to make the full sweep of the table on the research dimension table when in fact loading. If so, stick a UK on level business key column further down.

    See you soon
    David

  • Select the query takes a long time to run the second time

    Hi all

    I have Oracle 11 GR 1 material in windows server 2008 R2.
    I have a few tables with 10 million documents. When I run the select query to the tables of first time, it gives me a result in 15 seconds, but if I run the script even twice in the same session, I get the result in 15 minutes to complete...

    Why it's happening? What can be the solution for this?

    Thank you and best regards,
    Vikash jain (DBA Junior)

    What I know is that this feedback from cardinality generates more problems than improving the performance is, in fact, its main objective. But first look at which is was written in the link I posted above

    "Return of cardinality was introduced in the Oracle 11 g database 2. The purpose of this function is to automatically improve plans for queries that are executed repeatedly, _For that the optimizer does not estimate the cardinalities in the properly_ plan"

    If the cardinality feedback kiks in your case it is certainly because you do not have an exact statistics. Get the command the explain plans that I have shown you with the E-lines and A-lines (lines estimates and actual lines) and see where things are poorly estimated.

    If you want to disable the cardinality feedback then add the indicator according to your request

    /*+ opt_param('_optimizer_use_feedback','false') */
    

    Best regards

    Mohamed Houri
    www.hourim.WordPress.com

    Published by: Mohamed Houri on November 22, 2012 02:11
    Published by: I was looking for the exact indication of how do I deactivate the cardinality feedback and I foud in an ot the Dominic post in otn :-)

    Published by: Mohamed Houri on November 22, 2012 02:15

  • Query taking a long time to run

    Hello

    I have a query that takes a long time to run. There are 191 000 records. This is static data only. This is the query.


    SELECT X_FIRST_NAME,
    X_LAST_NAME,
    X_MIDDLE_NAME,
    X_MEMBERSHIP_ID,
    X_ASSOCIATE_ID,
    X_MEMBER_KY,
    X_MEMBER_EXP_DATE,
    X_JOIN_CLUB_DATE,
    X_MEMBERSHIP_KY,
    X_ADDRESS1,
    X_ADDRESS2,
    X_CITY,
    X_STATE,
    X_ZIP,
    X_DELIVERY_ROUTE

    OF Canceled_Customers S
    WHERE THERE ARE
    (SELECT 'Y' FROM Canceled_Customers WHERE)
    (By SELECTING COUNT (P.X_MEMBERSHIP_KY) IN Canceled_Customers P)
    WHERE P.X_ADDRESS1 = S.X_ADDRESS1
    AND P.X_ADDRESS2 = S.X_ADDRESS2
    AND P.X_CITY = S.X_CITY
    AND P.X_STATE = S.X_STATE
    (AND P.X_ZIP = S.X_ZIP) > 1);


    Thank you

    Kelly

    Kelly wrote:
    I'm trying to capture duplicates. However, only the address information will be duplicated.

    For example:

    There might be a Jody Smith and Tim Smith with different Membership_Ky with the same address. I need to find these documents.

    Hi Kelly,

    Then you can try this statement instead, which uses only a full table on your table scan:

    select x_first_name
         , x_last_name
         , x_middle_name
         , x_membership_id
         , x_associate_id
         , x_member_ky
         , x_member_exp_date
         , x_join_club_date
         , x_membership_ky
         , x_address1
         , x_address2
         , x_city
         , x_state
         , x_zip
         , x_delivery_route
      from ( select x_first_name
                  , x_last_name
                  , x_middle_name
                  , x_membership_id
                  , x_associate_id
                  , x_member_ky
                  , x_member_exp_date
                  , x_join_club_date
                  , x_membership_ky
                  , x_address1
                  , x_address2
                  , x_city
                  , x_state
                  , x_zip
                  , x_delivery_route
                  , count(*) over (partition by x_address1, x_address2, x_city, x_state, x_zip) cnt
               from canceled_customers
           )
     where cnt > 1
    

    Note: not tested.

    Kind regards
    Rob.

  • After that effects 2015.3 takes a long time to open, left after the closing process running

    My AE 2015.3 takes very long time to start. He gets the message "Initializing MediaCore" on the splash screen and then hangs there for 1-3 minutes. It opens also a ton of "Adobe After Effects 2015.3" tasks in the Task Manager, leaving them running even after I quit the program.

    Here is what my task manager looks at this time (no AE running)

    AECrazy.jpg

    So far, what I've done:

    1 uninstalled all Adobe software, including Adobe CC Panel

    2 uninstalled all 3rd party plugins, scripts, and presets

    3. manually deleted all files from adobe - complete cleaning

    4. re-installed AE and some other programs

    (all with reboot between the two).

    No difference.

    Help?

    Apparently, nVidia GeForce drivers are at fault. The break of v368.81 WHQL way Adobe applications communicate with Media Core, make After Effects, first and slow speed Grade, leaving the additional processes in their wake and spoil some plugins 3rd party.

    Returning to a previous driver nVidia solved all the problems.

  • My CPU runs at 100% without no reason and programs take a long time to open.

    A FEW TIMES WHEN I TRYING TO OPEN A PROGRAM FOR EXPLORER MOMENT HE TAKES A LOT OF TIME IT OPENS

    original title: RUN MY CPU to 100% BY MOMENTS AND PROGRAM TAKES a long TIME TO LOAD what COULD BE WRONG

    Hello

     
    You can try the steps in the following link and check if it solves the problem:
     
    Important: Running chkdsk on the drive if bad sectors are found on the disk hard when chkdsk attempts to repair this area if all available on which data can be lost.
    Note: The data files that are infected must be cleaned only by removing the file completely, which means that there is a risk of data loss.
     
    I hope this helps!
  • How can I stop my computer to go to the screen saver when I for example runs a scan of the computer, sometimes my scan takes a long time to finish?

    My problem is? How can I stop my computer to go to the screen saver when I for example runs a scan of the computer, sometimes my scan takes a long time to finish? Example I have Microsoft Security Essentials set allow to run daily on 1200 AM and until he finishes my computer goes to screen saver Mode. and when I click on my mouse, I must sign completely new in my computer > how to stop this from happening, I want to keep my Security Scan open until there finishes?

    All the solutions for this?

    Original title: Windows Vista systems

    Hello

    This can help you:

    "Enable or disable the screen saver.

    http://Windows.Microsoft.com/en-us/Windows/turn-screen-saver-on-off#1TC=Windows-Vista

    And this is how do to change the time to wait before the screensaver comes on (article 8) and how to disable the password to logon to him (art. 9):

    http://www.Vistax64.com/tutorials/85539-screen-saver.html

    "How to disable or enable Protection by password on Wake Up in Vista"

    http://www.Vistax64.com/tutorials/102686-password-protection-wakeup.html

    See you soon.

  • Firefox takes a long time to close since a recent update and memory of pigs.

    Since the recent updates that have begun to use containers of plugin, Firefox takes a long time to close. If I try to go back there, he said that it is still running. I have liik in the Manager of tasks and about seven containers plugin. exe is running, and I turned off or disabled mostplugins and addons, same Quicktime. Firefox uses an obscene amount of RAM on my XP machine and rendered sluggish. I use XP SP3. This started after you added the plugin container in one of the recent updates earlier in the year. For the features it offers me or does not offer me, instead, it uses far too much RAM and is too slow. And takes a long time to close when I close the browser. It uses about twice as much RAM as it was.

    Upgrade your Firefox 9 browser and check

  • The system preference takes a long time to load

    As the title suggests, end of 2013 (10.11.4) System Preferences on my iMac takes a long time to load, even after a fresh reinstall and/or reboot (tried both). It takes about 20 seconds to one minute each time to open (except when I close it and immediately open it once again, as it is always loaded in memory). This problem existed only after the upgrade to El Capitan, and I saw many other people with iMacs with the same problem. I tried to remove cache for before system preferences files, but that did not help at all. I don't have a FileVault if it makes a difference, even if I did before reinstall, but never turned back (persistent question anyway). Any recommendations would be useful. Thank you!

    Data sheet:

    iMac (end 2013)

    Intel Core i5 at 2.7 GHz

    8 GB 1600 MHz DDR3

    1 TB 5400 RPM HARD DRIVE

    Intel Pro Iris 1536 MB

    I found it is the State of affairs in 10.11 if running a HD spinning.  Don't feel alone.

    I suspect that it is a function of low priority in the memory compressed algorithm.

    Upgrading to an SSD and it will rise to attention.

  • Satellite M300 PSMDCA takes a long time to start

    I have a Toshiba Satellite M300 PSMDCA - 01800C and there are some problems with it.

    First of all, when you start the computer, it takes a long time to start and activate Outlook.
    I am running Windows 7Home Premium.
    Computers arrow where I bought the computer told me that it can take up to three hours to go back through each process at startup?

    Is it normal that all I wanted was a simple portable easy fast, but it seems that I am stuck again.

    Also, when I go back to the computer, even after some time the mouse it does not provide new and pushing the Start button just a blank screen. Alt + Ctrl + delete, then he activates Windows again and then after having put my password and I have to wait for that be again loaded everything that takes so long. Any ideas?

    Also I often get the message when the computer starts "error has occurred in Toshiba PC Health Monitor. He will leave the application. "Main.frm.cpp (184). Any ideas?

    Quite often when I am scrolling with the mouse, the screen will turn black and flash and a message «the NVIDIA display driver... couldn't Reg...» "and he will correct itself after awhile. Frustrating!
    Quite often when scrolling on the websites of the page I'm going to freeze?

    I use MS Office 2010 and there is a problem trying to save Word documents and a message comes up with "a file permission error.

    Any thoughts? Thanks, Shirl51

    > First of all, when you start the computer, it takes a long time to start and activate Outlook. I am running Windows 7Home Premium. Computers arrow where I bought the computer told me that it can take up to three hours to go back through each process at startup?

    This nonsense!
    The system should boot up quickly my laptop needs 30 seconds to start.
    In my opinion, the system is screwed

    In your case, I recommend to reinstall the system.
    Did you create the recovery disk?
    If this isn't the case, I think that detailed instructions should be placed in the user's manual.

    After the recovery of disk has been created, restore the system, BUT save the data before doing so because the recovery disk would be to format the HARD drive and you lose data!

  • XY graph sometimes takes a long time to update legend

    Hello

    I wrote a small piece of code that highlights (changes line width) the plot on the graph when we click a mouse on its name in the legend of the plot. The code works well except when I the legend scroll bar is visible and its position is not 0, then when I click on the name of the parcel, the chart takes a long time(>4s) to change the width of the plot on the legend. The plot on the graph is updated instantly. Its only the legend of the plot that takes a long time to get updated.

    I enclose the code here... Please, run it and see if you also see the same behavior.

    Thank you

    Ritesh

    Hi Ritesh,

    The patch of f2 is already released. http://www.NI.com/download/LabVIEW-development-system-2015/5656/en/

    We will inform you of the R & D of your first question, but unfoturnately we cannot provide information on future products releases.

    Kind regards

  • desktop computer takes a long time to load after uninstall of netware

    Dear Pascal, recently, by chance, I installed the client service for Netware on my PC. He asked to restart the computer, and after reboot, logon screens became classic. I uninstalled netware by accessing the properties of LAN. I managed to restore logon screens using Microsoft resources available on the net. However, my PC now takes * for long time for the desktop icons and toolbar are displayed. I use Microsoft Windows XP Version 2002 SP3, Intel Core2Duo processor P8600 @2.40 Ghz with 2 GB of RAM on Lenovo Thinkpad R400. I understand that it is after uninstalling the netware client that my office is very very slow. Help me for a faster loading of the desktop computer. Best regards, Reba Shankar

    Hey Reba,

    Thanks for choosing Microsoft Community!

    You have reached the right forum. Try to solve this problem.

    If I understand correctly, you have some performance issues on windows XP computer.

     

    Let us try the following steps:

     

    Method 1: Any installed program must be uninstalled from Add and remove programs. You can just remove shortcuts from other places like LAN properties.

    Run the following fix - it to uninstall client services for Netware.

    Solve problems with programs that cannot be installed or uninstalled:

    http://support.Microsoft.com/mats/program_install_and_uninstall

     

    Method 2: See the following article:

     

    How to make a computer faster: 6 ways to speed up your PC:

    http://www.Microsoft.com/atwork/maintenance/speed.aspx#fBid=uQRRD6ZPxkC

     

    Important notes:

    ·         Running chkdsk on the drive if bad sectors are found on the disk hard when chkdsk attempts to repair this area if all available on which data can be lost.

    ·         The data files that are infected must be cleaned only by removing the file completely, which means that there is a risk of data loss.

    Hope the helps of information. Don't answer if you need assistance, we will be happy to help you.

  • Programs to freeze or take a long time to respond

    When I run new programs that they can take a long time to start or they freeze. This happens sporadically, but enough to be a nusiance. I followed all the steps listed under the section "fixit" of Vista Hoem premium and the maintence of the Vista Help sections section: I've defragmented, wipe the drive, run the system performance (overall score of 5.4 due to memory all other 5.9), has increased to 8000 MB swap file and several other steps. If I try to click on the program, while the little circle turns, my screen becomes a pale white and I can't do anythingfor several minutes

    Has anyone else had this problem and solved? I have a lot of space (free 400 G) and 4G of RAM.

    This happens anytime, not only after the machine has been for some time, given the previous answers to this question.

    Daniel Dixon III

    Hi Daniel,.

    What application are you trying to access?

    You can perform the clean boot, and then check if the problem persists. It will start Windows Vista by using a minimal set of drivers and startup programs and helps eliminate software conflicts.

    The following link has steps showing how to perform the clean boot: http://support.microsoft.com/kb/929135

    Note: Please make sure that the computer is configured to start as usual according to step 7 of the article: how to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7: http://support.microsoft.com/kb/929135

    Reference:optimize Windows Vista for better performance

    Hope the helps of information. Please post back and we do know.

    Concerning
    Joel S
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • my laptop take a long time to begin to have Windows 7

    Windows 7 OS take a lot of time at the start.
    How can I start quickly.

    Hello

    If you mean that it takes a long time to start and load the desktop computer, read this information.

    Read this information.

    http://www.blackviper.com/service-configurations/black-vipers-Windows-7-service-configurations/

    ____________________________________________________

    Many programs under Tools > Options have an option "run at Windows startup" which you can uncheck too

    For what programs you start at startup, we know not what you have installed, but you will know what is installed and you need to start at startup:

    «How to use MSCONFIG in Windows 7»

    http://netsquirrel.com/Msconfig/msconfig_win7.html

    You can also use this free program to do, too:

    "Autoruns for Windows V12.03"

    http://TechNet.Microsoft.com/en-us/sysinternals/bb963902.aspx

    See you soon.

  • My computer may take a long time to stop.

    * Original title: Shut down

    My computer off button does not work correctly. My computer may take a long time to stop.

    Do not press the power button to turn off the computer or to solve a gel. Click on the ORB at the bottom left of the desktop and click stop. If you are having shutdown problems, then select the hotkey Ctrl + Shift + Esc to bring up the Task Manager and click the Applications place the cursor on a running application to select and click on the end task button. As the application is removed from the list, repeat the procedure on the next application in the list until all are gone from the list. If you use the taskbar to access programs simply close all open windows. Then, you should be able to shut down your computer.

    http://Windows.Microsoft.com/en-in/Windows7/turning-off-your-computer-properly

Maybe you are looking for

  • Unable to connect to my old account

    I wiped my Mac to install Yosemite. I checked my firefox login information before I did to make sure that I could recover my favorites. It was related to my email, [email protected]. But now when I try to recover my account name or password us

  • Blank page in the virtual store of Toshiba

    Hello I was unable to connect to the virtual store. It makes me a blank page and 70.jt1.ca-My personal account 4343 + The message was edited: translated into English.

  • (Redirected) Alienware Alpha - monitor or TV

    I'm looking for comments and suggestions. I just bought 2 i5 Alienware Alpha for my 2 boys. They have screens VGA, that they can use, or they can use their HDMI TV. If we have to abandon the VGA they finally to have replacements for TV. Or, we leave

  • Trial version Microsoft Collage

    I can remove the tag at the bottom of the collage

  • Problem with the HP Pavilion G6 VGA Driver

    Hi dear customer service I bought a laptop model: HP Pavilion g6. I had some problems with my VGA driver after I installed windows 8 on it. I have downloaded my driver VGA of ATI in the link below http://support.AMD.com/us/gpudownload/Windows/pages/r