Query taking too  long (database is huge)

Hi ,
Please let me know anybody have any recomentation please find my function:
FUNCTION QueryPatientsByName(p_family_name IN VARCHAR2
,p_gender IN VARCHAR2
,p_given_name IN VARCHAR2
,p_other_given_name IN VARCHAR2
,p_date_of_birth_range_from IN VARCHAR2
,p_date_of_birth_range_to IN VARCHAR2
,p_date_of_death_range_from IN VARCHAR2
,p_date_of_death_range_to IN VARCHAR2
) RETURN REF_CURSOR_TYPE
IS
people REF_CURSOR_TYPE;
BEGIN
OPEN people FOR
SELECT psbr.euid
FROM sbyn_personsbr psbr
WHERE psbr.personid in (
SELECT pmain.personid
FROM sbyn_person_hstsbr pmain
-- restict person to be person who has or did have specified name attributes
WHERE (
pmain.personid IN
(SELECT pinnerb.personid
FROM sbyn_name_hstsbr pinnerb
WHERE UPPER(pinnerb.family_name) LIKE UPPER(p_family_name)
AND (p_given_name IS NULL OR UPPER(pinnerb.given_name) LIKE UPPER(p_given_name))
AND (p_other_given_name IS NULL OR
UPPER(pinnerb.other_given_name) LIKE UPPER(p_other_given_name))
AND pmain.gender LIKE p_gender
--DOB AND DOD CHECK
* @todo need to change AS A FUNCTION INSTEAD OF LENGTHY CODE !
AND (p_date_of_birth_range_from IS NULL OR ( pmain.date_of_birth BETWEEN p_date_of_birth_range_from
AND p_date_of_birth_range_to
OR (LENGTH(pmain.date_of_birth)=c_len_year_month AND pmain.date_of_birth BETWEEN
SUBSTR(p_date_of_birth_range_from,1,c_len_year_month) AND
SUBSTR(p_date_of_birth_range_to,1,c_len_year_month) )
OR (LENGTH(pmain.date_of_birth)=c_len_year AND pmain.date_of_birth BETWEEN
SUBSTR(p_date_of_birth_range_from,1,c_len_year) AND
SUBSTR(p_date_of_birth_range_to,1,c_len_year) ))
AND (p_date_of_death_range_from IS NULL OR ( pmain.date_of_death BETWEEN p_date_of_death_range_from AND
p_date_of_death_range_to
OR (LENGTH(pmain.date_of_death)=c_len_year_month AND pmain.date_of_death BETWEEN
SUBSTR(p_date_of_death_range_from,1,c_len_year_month) AND
SUBSTR(p_date_of_death_range_to,1,c_len_year_month))
OR (LENGTH(pmain.date_of_death)=c_len_year AND pmain.date_of_death between
SUBSTR(p_date_of_death_range_from,1,c_len_year) AND
SUBSTR(p_date_of_death_range_to,1,c_len_year))
RETURN people;
END;

Hello
Using dynamic SQL would seem to be the way forward here. To get rid of the sub queries, you may be able to do something like this...
SELECT
     psbr.euid
FROM
     sbyn_personsbr psbr,
     sbyn_person_hstsbr pmain,
     sbyn_name_hstsbr pinnerb
WHERE
     psbr.personid = pmain.personid
AND
     pinnerb.personid = psbr.personid
AND
     UPPER(pinnerb.family_name) LIKE UPPER(p_family_name)
AND
          p_given_name IS NULL
     OR
          UPPER(pinnerb.given_name) LIKE UPPER(p_given_name)
AND
          p_other_given_name IS NULL
     OR
          UPPER(pinnerb.other_given_name) LIKE UPPER(p_other_given_name)
AND
     pmain.gender LIKE p_gender
AND
          p_date_of_birth_range_from IS NULL
     OR
               pmain.date_of_birth BETWEEN p_date_of_birth_range_from AND p_date_of_birth_range_to
          OR
                    LENGTH(pmain.date_of_birth)=c_len_year_month
               AND
                    pmain.date_of_birth BETWEEN SUBSTR(p_date_of_birth_range_from,1,c_len_year_month) AND SUBSTR(p_date_of_birth_range_to,1,c_len_year_month)
          OR
                    LENGTH(pmain.date_of_birth)=c_len_year
               AND
                    pmain.date_of_birth BETWEEN SUBSTR(p_date_of_birth_range_from,1,c_len_year) AND SUBSTR(p_date_of_birth_range_to,1,c_len_year)
AND
          p_date_of_death_range_from IS NULL
     OR
               pmain.date_of_death BETWEEN p_date_of_death_range_from AND p_date_of_death_range_to
          OR
                    LENGTH(pmain.date_of_death)=c_len_year_month
               AND
                    pmain.date_of_death BETWEEN SUBSTR(p_date_of_death_range_from,1,c_len_year_month) AND SUBSTR(p_date_of_death_range_to,1,c_len_year_month)
          OR
                    LENGTH(pmain.date_of_death)=c_len_year
               AND
                    pmain.date_of_death between SUBSTR(p_date_of_death_range_from,1,c_len_year) AND SUBSTR(p_date_of_death_range_to,1,c_len_year)
     )If you can't use that type of structure for the query, consider changing the
xxx.personid IN(select yyy.personidsubqueries to use
EXISTS(SELECT NULL FROM yyy WHERE yyy.personid = xxx.personidAlso see if you can restructure the tests that you are doing on the dates. Are they date columns? What is it you are trying to achieve with the tests on the dates?
And finally, the tests you are doing on the name columns UPPER(pinnerb.given_name) etc. Unless you have a function index on these columns, oracle will not be able to use any indexes, which may not be a problem if you are accessing the majority of the table, but if you are only dealing with a small subset, this could prove to be very time consuming.
HTH

Similar Messages

  • Query taking too long

    I am running a fairly complex query with several table joins
    and it is taking too long. What can I do to improve performance?
    Thanks.
    Frank

    Dan's first suggestion is key - if you are doing multiple
    table joins, you want to make sure your indexes are set up on your
    tables correctly. If you have access to the database, this should
    be your first step. Rationalize's stored procedure suggestion is
    also a great idea (again, if you have access to create and manage
    stored procedures on your DB).
    Other than than, most databases usually have some sort of SQL
    efficiency analysis tool. SQL server has one built into their Query
    Analyzer tool. I would recommend using something like that to
    streamline your SQL. Like Dan said, something as simple as the
    order of elements in your where clause might make a big
    difference.

  • Query taking too long a time

    Hi friends,
    the view I have created on a table is taking toooo long a time to gimme the results
    when am trying to select * from table_name
    Can some one suggest me a solution pls
    CREATE OR REPLACE VIEW XXKDD_LATEST_SAL
    (RN, MONTH, YEAR, EMPLOYEE_NUMBER, POSITION,
    PAYROLL_NAME, DEPT, STATUS, TERMINATION_DATE, FULL_NAME,
    TOP3, BASIC_SALARY)
    AS
    select "RN","MONTH","YEAR","EMPLOYEE_NUMBER","POSITION","PAYROLL_NAME","DEPT","STATUS","TERMINATION_DATE","FULL_NAME","TOP3","BASIC_SALARY" from (
    SELECT ROW_NUMBER() OVER (PARTITION BY employee_number ORDER BY employee_number) rn, tp.*
    FROM (SELECT MONTH, YEAR, employee_number, position, payroll_name, dept, status, termination_date, full_name,
    ROW_NUMBER () OVER (PARTITION BY employee_number, basic_salary ORDER BY YEAR , MONTH) top3,
    DECODE (basic_salary,
    100000, 4500,
    24000, 1921,
    basic_salary
    ) basic_salary
    FROM kdd_pay_hr_sal_vw
    order by employee_number,year desc) tp
    WHERE top3 <= 1
    select * from XXKDD_LATEST_SAL

    Read these informative threads:
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    And edit your post, add relevant details like database version, execution plan etc., it is all listed in the above links.
    And use the {noformat}{noformat}-tags, to keep your examples formatted and indented and readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Query taking too long, yet cost is low

    hi guys,
    I am running a query on two databases that were created the same way and have the same data.
    On one the cost is nearly a million, and it runs in a matter of a few seconds
    On the other, the cost is 40000, and it doesn't finish executing
    I have looked at the explain plan, and there is no cartesian merge join on the second query, yet it is taking so long. What can I do to investigate this?
    thanks

    Could you please post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
    In SQL*Plus:
    SET LINESIZE 130
    EXPLAIN PLAN FOR <your statement>;
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Note that the package DBMS_XPLAN.DISPLAY is only available from 9i on.
    In previous versions you could run the following in SQL*Plus (on the server) instead:
    @?/rdbms/admin/utlxplsA different approach in SQL*Plus:
    SET AUTOTRACE ON EXPLAIN
    <run your statement>;will also show the execution plan.
    In order to get a better understanding where your statement spends the time you might want to turn on SQL trace as described here:
    [When your query takes too long|http://forums.oracle.com/forums/thread.jspa?threadID=501834]
    and post the "tkprof" output here, too.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Query taking too long on Oracle9i

    Hi All
    I am running a query on our prod database (Oracle8i 8.1.7.4) and again running the same query on Test db (Oracle9i version 4). The query is taking too long(more then 10 min) in test db. Both the database are installed on the same machine IBM AIX V4 and table schema and data are same.
    Any help would be appreciated.
    Here are the results.
    FASTER ONE
    ORACLE 8i using Production
    Statistics
    864 recursive calls
    68 db block gets
    159855 consistent gets
    20297 physical reads
    0 redo size
    1310148 bytes sent via SQL*Net to client
    68552 bytes received via SQL*Net from client
    1036 SQL*Net roundtrips to/from client
    28 sorts (memory)
    1 sorts (disk)
    15525 rows processed
    SLOWER ONE
    ORACLE 9i using Test
    Statistics
    819 recursive calls
    80 db block gets
    22981568 consistent gets
    1361 physical reads
    0 redo size
    1194902 bytes sent via SQL*Net to client
    34193 bytes received via SQL*Net from client
    945 SQL*Net roundtrips to/from client
    0 sorts (memory)
    1 sorts (disk)
    14157 rows processed

    319404-
    To help us better understand the problem,
    1) Could you post your execution plan on the two different databases?
    2) Could you list indexes (if any, on these tables)?
    3) Are any of the objects in the 'from list' a view?
    If so, are you using a user defined function to create the view?
    4) Why are you using the table 'cal_instance_relationship' twice in the 'from ' clause'?
    5) Can't your query be the following?
    SELECT f.person_id, f.course_cd, cv.responsible_org_unit_cd cowner, f.fee_cal_type Sem, f.fee_ci_sequence_number seq_no,
    sua.unit_cd, uv.owner_org_unit_cd uowner, uv.supervised_contact_hours hours, 0 chg_rate, sum(f.transaction_amount) tot_fee,
    ' ' tally
    FROM unit_version uv,
    cal_instance_relationship cir1,
    chg_method_apportion cma,
    student_unit_attempt sua,
    course_version cv,
    fee_ass f
    WHERE f.fee_type = 'VET-MATFEE'
    AND f.logical_delete_dt IS NULL
    AND f.s_transaction_type IN ('ASSESSMENT', 'MANUAL ADJ')
    AND f.fee_ci_sequence_number > 400
    AND f.course_cd = cv.course_cd
    AND cv.version_number = (SELECT MAX(v.version_number) FROM course_version v
    WHERE v.course_cd = cv.course_cd)
    AND f.person_id = sua.person_id
    and f.course_cd = sua.course_cd
    AND f.fee_type = cma.fee_type
    AND f.fee_ci_sequence_number = cma.fee_ci_sequence_number
    AND cma.load_ci_sequence_number = cir1.sub_ci_sequence_number
    AND cir1.sup_cal_type = 'ACAD-YR'
    AND cir1.sub_cal_type = sua.cal_type
    AND cir1.sub_ci_sequence_number = sua.ci_sequence_number
    AND sua.unit_attempt_status NOT IN ('DUPLICATE','DISCONTIN')
    AND sua.unit_cd = uv.unit_cd
    AND sua.version_number = uv.version_number
    GROUP BY f.person_id, f.course_cd, cv.responsible_org_unit_cd , f.fee_cal_type, f.fee_ci_sequence_number,
    sua.unit_cd, uv.owner_org_unit_cd, uv.supervised_contact_hours;

  • Oracle - Query taking too long (Materialized view)

    Hi,
    I am extracting billing informaiton and storing in 3 different tables... in order to show total billing (80 to 90 columns, 1 million rows per month), I've used a materialized view... I do not have indexes on 3 billing tables - do have 3 indexes on Materialized view...
    at the moment it's taking too long to query the data (running a query via toad fails and shows "Out of Memory" error message; runing a query via APEX though is providing results but taking way too long)...
    Please advice how to make the query efficient...

    tparvaiz,
    Is it possible when building your materialized view to summarize and consolidate the data?
    Out of a million rows, what would your typical user do with that amount data if they could retrieve it readily? The answer to this question may indicate if and how to summarize the data within the materialized view.
    Jeff
    Edited by: jwellsnh on Mar 25, 2010 7:02 AM

  • Query taking too long to finish

    Hi,
    I'm running a query which is
    Delete from msg where ID IN (select ID from deletedtrans );
    It's taking too long to complete, it has been running for 24 hours already and not completed executing the query, I cancelled the query. I don't understand why it's taking too long, does anyone have any idea? I feel that this query should not take too long to complete

    That seems to be too small piece of information to comment anything.
    1. How many records are there in "deletedtrans" table ?
    2. How many records from "msg" table are expected to be deleted ?
    3. Are statistics up-to-date on "msg" and "deletedtrans" tables ?
    4. Is "ID" column defined as NULL or NOT NULL in both "msg" and "deletedtrans" tables ? (Not sure whether this will cause any problem, but...)
    5. Is this statement being executed when other users/applications are accessing/updating "msg" table ?

  • Loop with WMI Query taking too long, need to break out if time exceeds 5 min

    I've written a script that will loop through a list of computers and run a WMI query using the Win32_Product class. I am pinging the host first to ensure its online which eliminates wasting time but the issue I'm facing is that some of the machines
    are online but the WMI Query takes too long and holds up the script. I wanted to add a timeout to the WMI query so if a particular host will not respond to the query or gets stuck the loop will break out an go to the next computer object. I've added my code
    below:
    $Computers = @()
    $computers += "BES10-BH"
    $computers += "AUTSUP-VSUS"
    $computers += "AppClus06-BH"
    $computers += "Aut01-BH"
    $computers += "AutLH-VSUS"
    $computers += "AW-MGMT01-VSUS"
    $computers += "BAMBOOAGT-VSUS"
    ## Loop through all computer objects found in $Computes Array
    $JavaInfo = @()
    FOREACH($Client in $Computers)
    ## Gather WMI installed Software info from each client queried
    Clear-Host
    Write-Host "Querying: $Client" -foregroundcolor "yellow"
    $HostCount++
    $Online = (test-connection -ComputerName ADRAP-VSUS -Count 1 -Quiet)
    IF($Online -eq "True")
    $ColItem = Get-WmiObject -Class Win32_Product -ComputerName $Client -ErrorAction SilentlyContinue | `
    Where {(($_.name -match "Java") -and (!($_.name -match "Auto|Visual")))} | `
    Select-Object Name,Version
    FOREACH($Item in $ColItem)
    ## Write Host Name as variable
    $HostNm = ($Client).ToUpper()
    ## Query Named Version of Java, if Java is not installed fill variable as "No Java Installed
    $JavaVerName = $Item.name
    IF([string]::IsNullOrEmpty($JavaVerName))
    {$JavaVerName = "No Installed"}
    ## Query Version of Java, if Java is not installed fill variable as "No Java Installed
    $JavaVer = $Item.Version
    IF([string]::IsNullOrEmpty($JavaVer))
    {$JavaVer = "Not Installed"}
    ## Create new object to organize Host,JavaName & Version
    $JavaProp = New-Object -TypeName PSObject -Property @{
    "HostName" = $HostNm
    "JavaVerName" = $JavaVerName
    "JavaVer" = $JavaVer
    ## Add new object data "JavaProp" from loop into array "JavaInfo"
    $JavaInfo += $JavaProp
    Else
    {Write-Host "$Client didn't respond, Skipping..." -foregroundcolor "Red"}

    Let me give you a bigger picture of the script. I've included the emailed table the script produces and the actual script. While running the script certain hosts get hung up when running the WMI query which causes the script to never complete. From one of
    the posts I was able to use the Get-WmiCustom function to add a timeout 0f 15 seconds and then the script will continue if it is stuck. The problem is when a host is skipped I am not aware of it because my script is not reporting the server that timed out.
    If you look at ZLBH02-VSUS highlighted in the report you can see that its reporting not installed when it should say something to the effect query hung.
    How can I add a variable in the function that will be available outside the function that I can key off of to differentiate between a host that does not have the software installed and one that failed to query?
    Script Output:
    Script:
    ## Name: JavaReportWMI.ps1 ##
    ## Requires: Power Shell 2.0 ##
    ## Created: January 06, 2015 ##
    <##> $Version = "Script Version: 1.0" <##>
    <##> $LastUpdate = "Updated: January 06, 2015" <##>
    ## Configure Compliant Java Versions Below ##
    <##> $java6 = "6.0.430" <##>
    <##> $javaSEDEVKit6 = "1.6.0.430" <##>
    <##> $java7 = "7.0.710" <##>
    <##> $javaSEDEVKit7 = "1.7.0.710" <##>
    <##> $java8 = "8.0.250" <##>
    <##> $javaSEDDEVKit8 = "1.8.0.250" <##>
    ## Import Active Directory Module
    Import-Module ActiveDirectory
    $Timeout = "False"
    Function Get-WmiCustom([string]$computername,[string]$namespace,[string]$class,[int]$timeout=15)
    $ConnectionOptions = new-object System.Management.ConnectionOptions
    $EnumerationOptions = new-object System.Management.EnumerationOptions
    $timeoutseconds = new-timespan -seconds $timeout
    $EnumerationOptions.set_timeout($timeoutseconds)
    $assembledpath = "\\" + $computername + "\" + $namespace
    #write-host $assembledpath -foregroundcolor yellow
    $Scope = new-object System.Management.ManagementScope $assembledpath, $ConnectionOptions
    $Scope.Connect()
    $querystring = "SELECT * FROM " + $class
    #write-host $querystring
    $query = new-object System.Management.ObjectQuery $querystring
    $searcher = new-object System.Management.ManagementObjectSearcher
    $searcher.set_options($EnumerationOptions)
    $searcher.Query = $querystring
    $searcher.Scope = $Scope
    trap { $_ } $result = $searcher.get()
    return $result
    ## Log time for duration clock
    $Start = Get-Date
    $StartTime = "StartTime: " + $Start.ToShortTimeString()
    ## Environmental Variables
    $QueryMode = $Args #parameter for either "Desktops" / "Servers"
    $CsvPath = "C:\Scripts\JavaReport\JavaReport" + "$QueryMode" + ".csv"
    $Date = Get-Date
    $Domain = $env:UserDomain
    $HostName = ($env:ComputerName).ToLower()
    ## Regional Settings
    ## Used for testing
    IF ($Domain -eq "abc") {$Region = "US"; $SMTPDomain = "abc.com"; `
    $ToAddress = "[email protected]"; `
    $ReplyDomain = "abc.com"; $smtpServer = "relay.abc.com"}
    ## Control Variables
    $FromAddress = "JavaReport@$Hostname.na.$SMTPDomain"
    $EmailSubject = "Java Report - $Region"
    $computers = @()
    $computers += "ZLBH02-VSUS"
    $computers += "AUTSUP-VSUS"
    $computers += "AppClus06-BH"
    $computers += "Aut01-BH"
    $computers += "AutLH-VSUS"
    $computers += "AW-MGMT01-VSUS"
    $computers += "BAMBOOAGT-VSUS"
    #>
    ## Loop through all computer objects found in $Computes Array
    $JavaInfo = @()
    FOREACH($Client in $Computers)
    ## Gather WMI installed Software info from each client queried
    Clear-Host
    Write-Host "Querying: $Client" -foregroundcolor "yellow"
    $HostCount++
    $Online = (test-connection -ComputerName ADRAP-VSUS -Count 1 -Quiet)
    IF($Online -eq "True")
    $ColItem = Get-WmiCustom -Class Win32_Product -Namespace "root\cimv2" -ComputerName $Client -ErrorAction SilentlyContinue | `
    Where {(($_.name -match "Java") -and (!($_.name -match "Auto|Visual")))} | `
    Select-Object Name,Version
    FOREACH($Item in $ColItem)
    ## Write Host Name as variable
    $HostNm = ($Client).ToUpper()
    ## Query Named Version of Java, if Java is not installed fill variable as "No Java Installed
    $JavaVerName = $Item.name
    IF([string]::IsNullOrEmpty($JavaVerName))
    {$JavaVerName = "No Installed"}
    ## Query Version of Java, if Java is not installed fill variable as "No Java Installed
    $JavaVer = $Item.Version
    IF([string]::IsNullOrEmpty($JavaVer))
    {$JavaVer = "Not Installed"}
    ## Create new object to organize Host,JavaName & Version
    $JavaProp = New-Object -TypeName PSObject -Property @{
    "HostName" = $HostNm
    "JavaVerName" = $JavaVerName
    "JavaVer" = $JavaVer
    ## Add new object data "JavaProp" from loop into array "JavaInfo"
    $JavaInfo += $JavaProp
    Else
    {Write-Host "$Client didn't respond, Skipping..." -foregroundcolor "Red"}
    #Write-Host "Host Query Count: $LoopCount" -foregroundcolor "yellow"
    ## Sort Array
    Write-Host "Starting Array" -foregroundcolor "yellow"
    $JavaInfoSorted = $JavaInfo | Sort-object HostName
    Write-Host "Starting Export CSV" -foregroundcolor "yellow"
    ## Export CSV file
    $JavaInfoSorted | export-csv -NoType $CsvPath -Force
    $Att = new-object Net.Mail.Attachment($CsvPath)
    Write-Host "Building Table Header" -foregroundcolor "yellow"
    ## Table Header
    $list = "<table border=1><font size=1.5 face=verdana color=black>"
    $list += "<tr><th><b>Host Name</b></th><th><b>Java Ver Name</b></th><th><b>Ver Number</b></th></tr>"
    Write-Host "Building HTML Table" -foregroundcolor "yellow"
    FOREACH($Item in $JavaInfoSorted)
    Write-Host "$UniqueHost" -foregroundcolor "Yellow"
    ## Alternate Table Shading between Green and White
    IF($LoopCount++ % 2 -eq 0)
    {$BK = "bgcolor='E5F5D7'"}
    ELSE
    {$BK = "bgcolor='FFFFFF'"}
    ## Set Variables
    $JVer = $Item.JavaVer
    $Jname = $Item.JavaVerName
    ## Change Non-Compliant Java Versions to red in table
    IF((($jVer -like "6.0*") -and (!($jVer -match $java6))) -or `
    (($jName -like "*Java(TM) SE Development Kit 6*") -and (!($jName -match $javaSEDEVKit6))) -or `
    (($jVer -like "7.0*") -and (!($jVer -match $java7))) -or `
    (($jName -like "*Java SE Development Kit 7*") -and (!($jName -match $javaSEDEVKit7))))
    $list += "<tr $BK style='color: #ff0000'>"
    ## Compliant Java version are displayed in black
    ELSE
    $list += "<tr $BK style='color: #000000'>"
    ## Populate table with host name variable
    $list += "<td>" + $Item."HostName" + "</td>"
    ## Populate table with Java Version Name variable
    $list += "<td>" + $Item."JavaVerName" + "</td>"
    ## Populate table with Java Versionvariable
    $list += "<td>" + $Item."JavaVer" + "</td>"
    $list += "</tr>"
    $list += "</table></font>"
    $End = Get-Date
    $EndTime = "EndTime: " + $End.ToShortTimeString()
    #$TimeDiff = New-TimeSpan -Start $StartTime -End $EndTime
    $StartTime
    $EndTime
    $TimeDiff
    Write-Host "Total Hosts:$HostCount"
    ## Email Function
    Function SendEmail
    $msg = new-object Net.Mail.MailMessage
    $smtp = new-object Net.Mail.SmtpClient($smtpServer)
    $msg.From = ($FromAddress)
    $msg.ReplyTo =($ToAddress)
    $msg.To.Add($ToAddress)
    #$msg.BCC.Add($BCCAddress)
    $msg.Attachments.Add($Att)
    $msg.Subject = ($EmailSubject)
    $msg.Body = $Body
    $msg.IsBodyHTML = $true
    $smtp.Send($msg)
    $msg.Dispose()
    ## Email Body
    $Body = $Body + @"
    <html><body><font face="verdana" size="2.5" color="black">
    <p><b>Java Report - $Region</b></p>
    <p>$list</p>
    </html></body></font>
    <html><body><font face="verdana" size="1.0" color="red">
    <p><b> Note: Items in red do not have the latest version of Java installed. Please open a ticket to have an engineer address the issue.</b></p>
    </html></body></font>
    <html><body><font face="verdana" size="2.5" color="black">
    <p>
    $StartTime<br>
    $EndTime<br>
    $TimeDiff<br>
    $HostCount<br>
    </p>
    <p>
    Run date: $Date<br>
    $Version<br>
    $LastUpdate<br>
    </p>
    </html></body></font>
    ## Send Email
    SendEmail

  • Sql query taking too long to run

    I am not sure what to do. My app takes two long to run and the reason is right in front of me, but again, I don't know what to do or where to go. (VB.Net VS 2005)
    The main part of my query takes about 15 to 20 seconds to run. When I tack on this other part it slows the response to over 2 minutes.
    Even running this other part alone takes 2+ minutes. The query as two sum functions. Is it possible, some how, that this query can run building it's results into another table and then I use this new table with the results all ready to go and join into the first part of the main query?
    I am using oracle 9i with a Sql Developer. Which I am new to. Below is the culprit: Thanks
    Select adorder.primaryorderer_client_id,
    (sum(Case When insertion.insert_date_id >= 2648 and insertion.insert_date_id < 2683
    Then insertchargedetail.Amount_insertDetail Else 0 End)) As CurRev,
    (sum(Case When insertion.insert_date_id >= 2282 and insertion.insert_date_id < 2317
    Then insertchargedetail.Amount_insertDetail Else 0 End)) As LastRev
    from Adorder
    Inner Join insertion On Adorder.id=insertion.Adorder_id
    Inner Join insertchargesummary On insertion.id=insertchargesummary.insertion_id
    Inner Join insertchargedetail On insertchargesummary.id=insertchargedetail.insertchargesummary_id
    where ((insertion.insert_date_id >= 2282 and insertion.insert_date_id < 2317)
    Or (insertion.insert_date_id >= 2648 and insertion.insert_date_id < 2683))
    group by adorder.primaryorderer_client_id;

    How to post a tuning request:
    HOW TO: Post a SQL statement tuning request - template posting

  • Create table query taking too long..

    Hello experts...
    I am taking the backup of table A which consist of 135 million records...
    for this am using below query..
    create table tableA_bkup as select * from tableA;
    it is taking more than hour..still running....
    is there any other way to query fast....
    thanks in advance....

    CTAS is one of the fastest ways to do such a thing.
    Remember you duplicate data. THis means if your table holds 50GB of data then it will have to copy those 50GB of data.
    A different way could be to use EXPDP to create a backup dump file from this table data. However I'm not sure if there is a big performance difference.
    Both versions could profit from parallel execution.

  • SQL Query taking too long

    Hello there,
    Can someone please help me:
    I have this SQL query that is taking days to complete, and they say when it runs on the former DB version 8 it used to run for 1 hour but now we're using 10g ... it's taking days ... any help with that please?
    Texas

    Texas B wrote:
    | Id  | Operation                     | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                  |     1 |   119 |  3171   (2)| 00:00:39 |
    |   1 |  NESTED LOOPS                 |                  |     1 |   119 |  3171   (2)| 00:00:39 |
    |   2 |   MERGE JOIN CARTESIAN        |                  |     1 |    71 |  3097   (2)| 00:00:38 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| PS_JRNL_LN       |     1 |    41 |   388   (0)| 00:00:05 |
    |*  4 |     INDEX SKIP SCAN           | PS_JRNL_LN       |     6 |       |   388   (0)| 00:00:05 |
    |   5 |    BUFFER SORT                |                  |   116K|  3416K|  2709   (2)| 00:00:33 |
    |   6 |     TABLE ACCESS FULL         | PS_BI_HDR        |   116K|  3416K|  2709   (2)| 00:00:33 |
    |*  7 |   TABLE ACCESS BY INDEX ROWID | PS_BI_ACCT_ENTRY |     1 |    48 |    73   (0)| 00:00:01 |
    |*  8 |    INDEX RANGE SCAN           | PS_BI_ACCT_ENTRY |     1 |       |    73   (0)| 00:00:01 |
    A few comments:
    1. Please re-edit your post and add the "Predicate Information" section below the plan, so that the filter and access predicates can be seen. They're quite helpful to understand the execution plan better.
    2. You're using bind variables, therefore the EXPLAIN PLAN output is only of limited use, since EXPLAIN PLAN doesn't perform "bind variable peeking". With "bind variable peeking" the optimizer peeks at the actual values passed when determining the execution plan. If you have a histogram generated on PS_JRNL_LN.JOURNAL_ID (check DBA/ALL/USER_TAB_COLUMNS.HISTOGRAM) or the values used are "out-of-range" (less or greater than recorded min and max value of column) then you might get different execution plans depending on the actual values passed.
    3. You can get the actual execution plan(s) from the shared pool by obtaining the SQL_ID of the statement (e.g. check V$SESSION) and use the DBMS_XPLAN.DISPLAY_CURSOR function for this SQL_ID
    4. The optimizer estimates that out of the 11 million rows of PS_JRNL_LN more or less no rows corresponds to this predicate:
    A.JOURNAL_ID = :1
    AND A.JRNL_LINE_STATUS = '1'
    Since for the unknown bind variable a hard coded default selectivity of 5% is used which corresponds to a cardinality approx. 550,000 rows, the JRNL_LINE_STATUS = '1' predicate seems to be quite selective.
    Is this estimate in the right ballpark or way off?
    Due to this estimate the optimizer uses a cartesian join which could generate a very large intermediate set if the estimate is way off, e.g. if 1,000 rows are returned instead of 0 the cartesian join will already generate 1,000 * 116,000 => 116,000,000 rows.
    This row source will then be used as driving source of a nested loop which means that many times the index and table lookup to PS_BI_ACCT_ENTRY will be performed.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • SQL query taking too long to process

    dear guys. i have this one problem, where the sql statements really took very long time to be processed. It took more than 1 minute, depending on the total data in the table. I guest this have to do with the 'count' statements. here is the code:
    $sql = "SELECT company,theID,abbs,A as Active,N as Nonactive,(A+N) as Total
    FROM(
    select distinct D.nama As company, C.domID As theID, D.abbrew As abbs,
    count(distinct case when B.ids is NOT NULL THEN A.dauserid END) As A,
    count(distinct case when B.ids is NULL THEN A.dauserid END) As N
    FROM
    tableuser A LEFT OUTER JOIN tabletranscript B on (A.dauserid=B.dauserid)
    INNER JOIN thedommember C ON(C.entitybuktiID=1 AND C.mypriority=1 AND
    C.entitybuktiID=A.dauserid)
    INNER JOIN mydomain D ON (C.domID=".$getID.")
    GROUP BY D.nama, C.domID, D.abbrew
    ORDER BY company
    Hope any of you can simplify this statements into a query that doesnt take ages to be processed.

    What yours oracle version?
    Did you gather stats?
    stats are used by the optimizer for a better assessment query plan,if yours stats is stale then query plan behave inadvertly
    Can you paste yours this specific query tracer file by using tkprof here with wait events?
    Can you avoid DISTINCT clause from urs sequel,cause DISTINCT will always require a sort and sorting slows performance?
    More or less unless if you cant go through from above statment its hard to find whats the real issue with this sequel.
    Khurram

  • Query taking too long to execute

    Hi All,
    I have just moved a cube from DEV to Q and loaded the data(using INIT). I have created a query to test the data. When I execute the query, the initial result is showing up quickly but when I drill down using one char, say CHAR ABC, it is taking a lot time(I am waiting from last 25 min to see the result but it is still running). The same query is not taking any time when run in T. What could be the problem. This query is my first query in Q.
    Any suggestions would be highly appreciated.
    Best Rgds,
    James.

    GO to RSRV and you will see a an option " All combined tests.
    IN that, you will see " Check data for master data". Double click that and enter your CHAR* and run the test.
    Next under transaction data " run each of the tests" for the ODS / Cube that you run the report from.
    These tests usually will point to inconsistency. You may also want to look the design of cube / ODS. In ODS, you may have to check the key fields.
    Ravi Thothadri

  • Query taking too long time

    Hello all i hav a query which is taking result from 4 tables
    select name, date, emp_id, salary from table1, table2, table3,table4 where date= :date and other conditions
    but when im doing same query and changin date format
    select name, date, emp_id, salary from table1, table2, table3,table4 where date= TO_DATE(:date,'DD/MM/RRRR') and other conditions
    the query is gettin hang no response
    please advice.
    Thanks

    Execution Plan                                        
    Plan hash value: 2265139331                                        
          Id        Operation                                    Name                           Rows        Bytes       Cost (%CPU)      Time          
         0      SELECT STATEMENT                                                           14647       3146K       1443   (1)      00:00:18      
         1       HASH GROUP BY                                                             14647       3146K                                     
         2        CONCATENATION                                                                                                                    
         3         MERGE JOIN CARTESIAN                                                    8444       1814K        738   (1)      00:00:09      
         4          NESTED LOOPS                                                                                                                   
         5           NESTED LOOPS                                                          1     202        635   (1)      00:00:08      
         6            NESTED LOOPS                                                         1     138        633   (1)      00:00:08      
         7             NESTED LOOPS                                                        1     103        632   (1)      00:00:08      
         8              NESTED LOOPS                                                       1     85        631   (1)      00:00:08      
         9               VIEW                               table     3     84        628   (1)      00:00:08      
         10                UNION-ALL                                                                                                                
         * 11                  HASH JOIN                                                       1     37        279   (1)      00:00:04      
         * 12                   TABLE ACCESS BY INDEX ROWID     table     1     31          4   (0)      00:00:01      
         * 13                    INDEX RANGE SCAN               table     1                      3   (0)      00:00:01      
         14                  TABLE ACCESS FULL               table     9472     56832        275   (1)      00:00:04      
         * 15                  HASH JOIN                                                       1     37        319   (1)      00:00:04      
         * 16                   TABLE ACCESS BY INDEX ROWID     table     1     31         10   (0)      00:00:01      
         * 17                    INDEX RANGE SCAN               table     1                      9   (0)      00:00:01      
         18                  TABLE ACCESS FULL               table     36233        212K        308   (1)      00:00:04      
         * 19                  HASH JOIN                                                       1     43         31   (4)      00:00:01      
         * 20                   TABLE ACCESS BY INDEX ROWID     table     1     37          3   (0)      00:00:01      
         * 21                    INDEX RANGE SCAN               table     1                      2   (0)      00:00:01      
         22                  TABLE ACCESS FULL               table     2546     15276         27   (0)      00:00:01      
         23               TABLE ACCESS BY INDEX ROWID        table     1     57          1   (0)      00:00:01      
         * 24                 INDEX UNIQUE SCAN                 table     1                      0   (0)      00:00:01      
         25              TABLE ACCESS BY INDEX ROWID         table     1     18          1   (0)      00:00:01      
         * 26                INDEX UNIQUE SCAN                  table     1                      0   (0)      00:00:01      
         27             TABLE ACCESS BY INDEX ROWID          table     1     35          1   (0)      00:00:01      
         * 28               INDEX UNIQUE SCAN                   table     1                      0   (0)      00:00:01      
         * 29             INDEX RANGE SCAN                      table     2                      1   (0)      00:00:01      
         30           TABLE ACCESS BY INDEX ROWID            table     2     128          2   (0)      00:00:01      
         31          BUFFER SORT                                                            7977        140K        736   (1)      00:00:09      
         32           TABLE ACCESS FULL                      table     7977        140K        102   (0)      00:00:02      
         33         NESTED LOOPS                                                            310     68200        704   (1)      00:00:09      
         34          NESTED LOOPS                                                           1     202        635   (1)      00:00:08      
         35           NESTED LOOPS                                                          1     138        633   (1)      00:00:08      
         36            NESTED LOOPS                                                         1     103        632   (1)      00:00:08      
         37             NESTED LOOPS                                                        1     85        631   (1)      00:00:08      
         38              VIEW                                table     3     84        628   (1)      00:00:08      
         39               UNION-ALL                                                                                                                 
         * 40                 HASH JOIN                                                        1     37        279   (1)      00:00:04      
         * 41                  TABLE ACCESS BY INDEX ROWID      table     1     31          4   (0)      00:00:01      * 41             TABLE ACCESS BY INDEX ROWID table131     4   (0) 00:00:01
         * 42                   INDEX RANGE SCAN                table     1                      3   (0)      00:00:01      
         43                 TABLE ACCESS FULL                table     9472     56832        275   (1)      00:00:04      
         * 44                 HASH JOIN                                                        1     37        319   (1)      00:00:04      
         * 45                  TABLE ACCESS BY INDEX ROWID      table     1     31         10   (0)      00:00:01      
         * 46                   INDEX RANGE SCAN                table     1                      9   (0)      00:00:01      
         47                 TABLE ACCESS FULL                table     36233        212K        308   (1)      00:00:04      
         * 48                 HASH JOIN                                                        1     43         31   (4)      00:00:01      
         * 49                  TABLE ACCESS BY INDEX ROWID      table     1     37          3   (0)      00:00:01      
         * 50                   INDEX RANGE SCAN                table     1                      2   (0)      00:00:01      
         51                 TABLE ACCESS FULL                table     2546     15276         27   (0)      00:00:01      
         52              TABLE ACCESS BY INDEX ROWID         table     1     57          1   (0)      00:00:01      
         * 53                INDEX UNIQUE SCAN                  table     1                      0   (0)      00:00:01      
         54             TABLE ACCESS BY INDEX ROWID          table     1     18          1   (0)      00:00:01      
         * 55               INDEX UNIQUE SCAN                   table     1                      0   (0)      00:00:01      
         56            TABLE ACCESS BY INDEX ROWID           table     1     35          1   (0)      00:00:01      
         * 57              INDEX UNIQUE SCAN                    table     1                      0   (0)      00:00:01      
         58           TABLE ACCESS BY INDEX ROWID            table     2     128          2   (0)      00:00:01      
         * 59             INDEX RANGE SCAN                      table     2                      1   (0)      00:00:01      
         * 60           TABLE ACCESS FULL                       table     293     5274         68   (0)      00:00:01      
    Predicate Information (identified by operation id):                                        
       3 - access("a.id"="b.id")                                        
      12 - access("a.id"="b.id")                                        
      13 - filter("a.id"="b.id")                                        
      14 - access("a.id"="b.id")                                        
      16 - access("a.id"="b.id")                                        
      17 - filter("a.id"="b.id")                                        
      18 - access("a.id"="b.id")                                        
      20 - access("a.id"="b.id")                                        
      21 - filter("a.id"="b.id")                                        
      22 - access("a.id"="b.id")                                        
      25 - access("a.id"="b.id")AND ("a.id"="b.id")                                        
      27 - access("a.id"="b.id")                                        
      28 - access("a.id"="b.id")                                        
      32 - access("a.id"="b.id")                                        
      36 - access("a.id"="b.id")AND ("a.id"="b.id")                                        
      37 - filter("a.id"="b.id")                                        
      40 - access("a.id"="b.id")                                        
      41 - filter("a.id"="b.id")                                        
      42 - access("a.id"="b.id")                                        
      44 - access("a.id"="b.id")                                        
      45 - filter("a.id"="b.id")                                        
      46 - access("a.id"="b.id")                                        
      48 - access("a.id"="b.id")                                        
      49 - filter("a.id"="b.id")                                        
      50 - access("a.id"="b.id")                                        
    Statistics                                        
             71  recursive calls                                        
              0  db block gets                                        
           2975  consistent gets                                        
              0  physical reads                                        
              0  redo size                                        
           2172  bytes sent via SQL*Net to client                                        
            520  bytes received via SQL*Net from client                                        
              2  SQL*Net roundtrips to/from client                                        
              1  sorts (memory)                                        
              0  sorts (disk)                                        
              1  rows processed

  • Query taking too long to execute after clone

    Hi All,
    We have a query which is working fine in our development environment and taking around 15 secs to execute the query. When we run the same query with same parameters in a recently cloned instance, the query is taking 1200 secs to execute.
    Please help us on this issue.
    Thanks,
    Raghava

    Hi All,
    I have 4 unions in my query. individual sqls are running in very less time. But when i use all of them in UNION then im getting performance issue. Below is my query:
    SELECT /*+ parallel(xla_l) parallel(xla_h) leading(xla_h) */
    XLA_L.code_combination_id,
    gl.name,
    fnd_flex_ext.get_segs('SQLGL', 'GL#', gl.chart_of_accounts_id, xla_l.code_combination_id) ACCOUNT,
    xla_oa_functions_pkg.get_ccid_description (gl.chart_of_accounts_id, xla_l.code_combination_id) account_description ,
    xla_h.accounting_date,
    XLA_L.accounting_class_code,
    NVL(lk7.meaning, xla_l.accounting_class_code) accounting_class,
    xla_h.entity_id,
    xla_h.event_type_code,
    et.event_class_code,
    bud.budget_name,
    xla_h.ledger_id,
    xla_l.entered_dr,
    xla_l.entered_cr,
    te.ledger_id trx_ledger_id,
    te.legal_entity_id,
    et.entity_code,
    te.source_id_int_1,
    te.source_id_int_2,
    te.source_id_int_3,
    te.source_id_int_4,
    te.source_id_char_1,
    te.source_id_char_2,
    te.source_id_char_3,
    te.source_id_char_4,
    te.security_id_int_1,
    te.security_id_int_2,
    te.security_id_int_3,
    te.security_id_char_1,
    te.security_id_char_2,
    te.security_id_char_3,
    te.valuation_method,
    xla_h.application_id,
    xs.drilldown_procedure_name,
    GL_CUSTOM_DRILL_DOWN.get_trx_description(te.source_id_int_1,et.entity_code) description,
    null fleet_number,
    null Vendor_Name,
    xs.je_source_name JournalSource,
    xla_h.je_category_name JournalCategory,
    XLA_L.AE_LINE_NUM Line
    FROM xla.xla_ae_lines XLA_L,
    xla.xla_ae_headers xla_h,
    xla_gl_ledgers_v gl ,
    xla_lookups lk5 ,
    xla_lookups lk7,
    xla.xla_events xla_e ,
    xla.xla_event_types_tl et ,
    xla.xla_event_classes_tl ec ,
    xla.xla_transaction_entities te,
    gl_budget_versions bud ,
    --gl_import_references ir,
    xla.xla_subledgers xs
    --gl_je_lines gl_l
    where
    --ir.gl_sl_link_id=XLA_L.gl_sl_link_id
    --and ir.gl_sl_link_table=XLA_L.gl_sl_link_table
    --and gl.ledger_id       = xla_h.ledger_id
    --AND
    xla_h.ae_header_id = xla_l.ae_header_id
    AND xla_h.application_id = xla_l.application_id
    AND lk7.lookup_code(+) = xla_l.accounting_class_code
    AND lk7.lookup_type(+) = 'XLA_ACCOUNTING_CLASS'
    AND xla_e.event_id = xla_h.event_id
    AND xla_e.application_id = xla_h.application_id
    AND xs.application_id =xla_h.application_id
    AND te.entity_id =xla_h.entity_id
    AND te.application_id =xla_l.application_id --xla_h.application_id
    AND ec.application_id = et.application_id
    AND ec.entity_code = et.entity_code
    AND ec.event_class_code = et.event_class_code
    AND ec.language = USERENV('LANG')
    AND et.application_id = xla_h.application_id
    AND et.event_type_code = xla_h.event_type_code
    AND et.language = USERENV('LANG')
    AND lk5.lookup_code = NVL(xla_h.funds_status_code, 'REQUIRED')
    AND lk5.lookup_type = 'XLA_FUNDS_STATUS'
    AND bud.budget_version_id(+) = xla_h.budget_version_id
    and xs.je_source_name != 'Cost Management'
    and (xla_l.gl_sl_link_id,xla_l.gl_sl_link_table) in (select ir.gl_sl_link_id, ir.gl_sl_link_table from
    gl_import_references ir,
    gl_je_lines gl_l
    where ir.je_header_id = gl_l.je_header_id
    and gl_l.je_line_num=ir.je_line_num
    and gl_l.period_name =NVL(:1,gl_l.period_name)
    and gl_l.code_combination_id =:2)
    UNION
    SELECT
    lines.code_combination_id LINE_CODE_COMBINATION_ID,
    lr.target_ledger_name LEDGER_NAME,
    fnd_flex_ext.get_segs('SQLGL', 'GL#', b.chart_of_accounts_id, lines.code_combination_id) ACCOUNT,
    xla_oa_functions_pkg.get_ccid_description (b.chart_of_accounts_id, lines.code_combination_id) account_description,
    h.date_created,
    null,
    null,
    null,
    null,
    null,
    null,
    h.ledger_id LEDGER_ID,
    lines.entered_dr LINE_ENTERED_DR,
    lines.entered_cr LINE_ENTERED_CR,
    lines.ledger_id LINE_LEDGER_ID,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    lines.description LINE_DESCRIPTION,
    null FLEET_NUMBER,
    null Vendor_Name,
    h.je_source JournalSource,
    h.je_category JournalCategory,
    lines.JE_LINE_NUM Line
    FROM gl_period_statuses ps,
    gl_je_lines lines,
    gl_je_headers h,
    gl_je_batches b,
    gl_ledger_relationships lr
    WHERE lr.source_ledger_id = lr.target_ledger_id
    --AND lr.target_currency_code = DECODE ( GLR03300_pkg.get_ledger_currency, 'ALL123456789012345', lr.target_currency_code, GLR03300_pkg.get_ledger_currency )
    AND lr.application_id = 101
    AND b.average_journal_flag = 'N'
    AND b.je_batch_id = h.je_batch_id
    AND b.actual_flag = 'A'
    AND h.je_header_id = lines.je_header_id
    AND h.currency_code = DECODE ( GLR03300_PKG.get_entered_currency_code, 'ALL123456789012345', h.currency_code, NULL, h.currency_code, GLR03300_pkg.get_entered_currency_code )
    AND h.ledger_id = lr.source_ledger_id
    AND lines.period_name = ps.period_name
    and lines.period_name = NVL(:3,lines.period_name)
    AND ps.ledger_id = lines.ledger_id
    AND ps.application_id = 101
    AND lines.code_combination_id=:4
    AND h.je_source != 'Cost Management'
    UNION
    SELECT /*+ parallel(xla_l) parallel(xla_h) leading(xla_h) */ gl_l.code_combination_id LINE_CODE_COMBINATION_ID,
    gl.name,
    fnd_flex_ext.get_segs('SQLGL', 'GL#', gl.chart_of_accounts_id, xla_l.code_combination_id) ACCOUNT,
    xla_oa_functions_pkg.get_ccid_description (gl.chart_of_accounts_id, xla_l.code_combination_id) account_description,
    xla_h.accounting_date,--gjh.date_created,
    XLA_L.accounting_class_code,
    NVL(lk7.meaning, xla_l.accounting_class_code) accounting_class,
    null,
    null,
    null,
    null,
    xla_h.ledger_id LEDGER_ID,
    NVL(xla_l.entered_dr,0) LINE_ENTERED_DR,
    NVL(xla_l.entered_cr,0) LINE_ENTERED_CR,
    te.ledger_id trx_ledger_id,
    te.legal_entity_id,
    et.entity_code,
    te.source_id_int_1,
    te.source_id_int_2,
    te.source_id_int_3,
    te.source_id_int_4,
    te.source_id_char_1,
    te.source_id_char_2,
    te.source_id_char_3,
    te.source_id_char_4,
    te.security_id_int_1,
    te.security_id_int_2,
    te.security_id_int_3,
    te.security_id_char_1,
    te.security_id_char_2,
    te.security_id_char_3,
    te.valuation_method,
    xla_h.application_id,
    xs.drilldown_procedure_name,
    GL_CUSTOM_DRILL_DOWN.get_trx_description(te.source_id_int_1,et.entity_code) description,-- gl_l.description LINE_DESCRIPTION,
    cii.instance_number FLEET_NUMBER,
    (select a.vendor_name
    from RCV_VRC_TXS_VENDINT_V a
    where a.wip_entity_id = mmt.TRANSACTION_SOURCE_ID
    AND a.organization_id = mmt.organization_id
    and a.item_id = mmt.inventory_item_id) Vendor_Name,
    xs.je_source_name JournalSource,
    xla_h.je_category_name JournalCategory,
    gl_l.JE_LINE_NUM Line
    FROM xla.xla_ae_lines XLA_L,
    xla.xla_ae_headers xla_h,
    xla_gl_ledgers_v gl ,
    xla_lookups lk5,
    xla_lookups lk7,
    xla.xla_events xla_e ,
    xla.xla_event_types_tl et,
    xla.xla_event_classes_tl ec,
    xla.xla_transaction_entities te,
    gl_budget_versions bud,
    gl_import_references ir,
    xla.xla_subledgers xs,
    gl_je_lines gl_l,
    mtl_transaction_accounts mta,
    XLA_TRANSACTION_ENTITIES_upg xte,
    xla_distribution_links xdl,
    mtl_material_transactions mmt,
    WIP_ENTITIES WIE,
    WIP_DISCRETE_JOBS WDJ,
    csi_item_instances CII
    where
    ir.gl_sl_link_id=XLA_L.gl_sl_link_id
    and ir.je_header_id = gl_l.je_header_id
    and gl_l.je_line_num=ir.je_line_num
    and ir.gl_sl_link_table=XLA_L.gl_sl_link_table
    and gl_l.period_name =NVL(:5,gl_l.period_name)
    and gl_l.code_combination_id = :6
    and xla_h.ae_header_id = xla_l.ae_header_id
    AND xla_h.application_id = xla_l.application_id
    AND lk7.lookup_code(+) = xla_l.accounting_class_code
    AND lk7.lookup_type(+) = 'XLA_ACCOUNTING_CLASS'
    AND xla_e.event_id = xla_h.event_id
    AND xla_e.application_id = xla_h.application_id
    AND xs.application_id =xla_h.application_id
    AND te.entity_id =xla_h.entity_id
    AND te.application_id =xla_l.application_id --xla_h.application_id
    AND ec.application_id = et.application_id
    AND ec.entity_code = et.entity_code
    AND ec.event_class_code = et.event_class_code
    AND ec.language = USERENV('LANG')
    AND et.application_id = xla_h.application_id
    AND et.event_type_code = xla_h.event_type_code
    AND et.language = USERENV('LANG')
    AND lk5.lookup_code = NVL(xla_h.funds_status_code, 'REQUIRED')
    AND lk5.lookup_type = 'XLA_FUNDS_STATUS'
    AND bud.budget_version_id(+) = xla_h.budget_version_id
    AND mta.reference_account = gl_l.code_combination_id
    AND mmt.transaction_id = mta.transaction_id
    and mta.transaction_id = xte.source_id_int_1
    AND mta.inventory_item_id =mmt.inventory_item_id
    AND mta.organization_id = mmt.organization_id
    AND mmt.transaction_type_id = 35
    and xte.entity_id = xla_e.entity_id
    and xdl.source_distribution_type = 'MTL_TRANSACTION_ACCOUNTS'
    and xdl.source_distribution_id_num_1 = mta.inv_sub_ledger_id
    and xdl.APPLICATION_ID=707
    and xla_h.ae_header_id = xdl.ae_header_id
    and xdl.ae_header_id = XLA_L.ae_header_id
    and ir.gl_sl_link_table = 'XLAJEL'
    and ir.gl_sl_link_id = XLA_L.gl_sl_link_id
    and gl_l.je_header_id = ir.je_header_id
    and gl_l.je_line_num = ir.je_line_num
    and mmt.TRANSACTION_SOURCE_ID = wie.wip_entity_id
    AND mmt.organization_id = wdj.organization_id
    and wie.wip_entity_id = wdj.wip_entity_id
    and wdj.asset_group_id = cii.inventory_item_id
    and wdj.maintenance_object_id=cii.instance_id
    and xs.je_source_name = 'Cost Management'
    UNION
    SELECT /*+ parallel(XLA_L) parallel(xla_h) leading(xla_h) */ gl_l.code_combination_id LINE_CODE_COMBINATION_ID,
    gl.name,
    fnd_flex_ext.get_segs('SQLGL', 'GL#', gl.chart_of_accounts_id, xla_l.code_combination_id) ACCOUNT,
    xla_oa_functions_pkg.get_ccid_description (gl.chart_of_accounts_id, xla_l.code_combination_id) account_description,
    xla_h.accounting_date,--gjh.date_created,
    XLA_L.accounting_class_code,
    NVL(lk7.meaning, xla_l.accounting_class_code) accounting_class,
    null,
    null,
    null,
    null,
    xla_h.ledger_id LEDGER_ID,
    NVL(xla_l.entered_dr,0) LINE_ENTERED_DR,
    NVL(xla_l.entered_cr,0) LINE_ENTERED_CR,
    te.ledger_id trx_ledger_id,
    te.legal_entity_id,
    et.entity_code,
    te.source_id_int_1,
    te.source_id_int_2,
    te.source_id_int_3,
    te.source_id_int_4,
    te.source_id_char_1,
    te.source_id_char_2,
    te.source_id_char_3,
    te.source_id_char_4,
    te.security_id_int_1,
    te.security_id_int_2,
    te.security_id_int_3,
    te.security_id_char_1,
    te.security_id_char_2,
    te.security_id_char_3,
    te.valuation_method,
    xla_h.application_id,
    xs.drilldown_procedure_name,
    GL_CUSTOM_DRILL_DOWN.get_trx_description(te.source_id_int_1,et.entity_code) description,-- gl_l.description LINE_DESCRIPTION,
    cii.instance_number FLEET_NUMBER,
    (select a.vendor_name
    from RCV_VRC_TXS_VENDINT_V a
    where a.wip_entity_id = wta.wip_entity_id
    AND a.organization_id = wta.organization_id
    and a.item_id = cii.inventory_item_id) Vendor_Name,
    xs.je_source_name JournalSource,
    xla_h.je_category_name JournalCategory,
    gl_l.JE_LINE_NUM Line
    FROM xla.xla_ae_lines XLA_L,
    xla.xla_ae_headers xla_h,
    xla_gl_ledgers_v gl ,
    xla_lookups lk5,
    xla_lookups lk7,
    xla.xla_events xla_e ,
    xla.xla_event_types_tl et,
    xla.xla_event_classes_tl ec,
    xla.xla_transaction_entities te,
    gl_budget_versions bud,
    gl_import_references ir,
    xla.xla_subledgers xs,
    gl_je_lines gl_l,
    wip_transaction_accounts wta,
    XLA_TRANSACTION_ENTITIES_upg xte,
    xla_distribution_links xdl,
    -- mtl_material_transactions mmt,
    WIP_ENTITIES WIE,
    WIP_DISCRETE_JOBS WDJ,
    csi_item_instances CII
    where
    ir.gl_sl_link_table=XLA_L.gl_sl_link_table
    and gl_l.period_name =NVL(:7,gl_l.period_name)
    and gl_l.code_combination_id = :8
    and xla_h.ae_header_id = xla_l.ae_header_id
    AND xla_h.application_id = xla_l.application_id
    AND lk7.lookup_code(+) = xla_l.accounting_class_code
    AND lk7.lookup_type(+) = 'XLA_ACCOUNTING_CLASS'
    AND xla_e.event_id = xla_h.event_id
    AND xla_e.application_id = xla_h.application_id
    AND xs.application_id =xla_h.application_id
    AND te.entity_id =xla_h.entity_id
    AND te.application_id =xla_l.application_id --xla_h.application_id
    AND ec.application_id = et.application_id
    AND ec.entity_code = et.entity_code
    AND ec.event_class_code = et.event_class_code
    AND ec.language = USERENV('LANG')
    AND et.application_id = xla_h.application_id
    AND et.event_type_code = xla_h.event_type_code
    AND et.language = USERENV('LANG')
    AND lk5.lookup_code = NVL(xla_h.funds_status_code, 'REQUIRED')
    AND lk5.lookup_type = 'XLA_FUNDS_STATUS'
    AND bud.budget_version_id(+) = xla_h.budget_version_id
    AND wta.reference_account = gl_l.code_combination_id
    and wta.transaction_id = xte.source_id_int_1(+)
    and xte.entity_id = xla_e.entity_id
    and xdl.source_distribution_type = 'WIP_TRANSACTION_ACCOUNTS'
    and xdl.source_distribution_id_num_1 = wta.wip_sub_ledger_id(+)
    and xdl.APPLICATION_ID=707
    and xla_h.ae_header_id = xdl.ae_header_id
    and xdl.ae_header_id = XLA_L.ae_header_id
    and ir.gl_sl_link_table = 'XLAJEL'
    and ir.gl_sl_link_id = XLA_L.gl_sl_link_id
    and gl_l.je_header_id = ir.je_header_id
    and gl_l.je_line_num = ir.je_line_num
    and wie.wip_entity_id = wta.wip_entity_id
    AND wta.organization_id = wdj.organization_id
    and wie.wip_entity_id = wdj.wip_entity_id
    and wdj.asset_group_id = cii.inventory_item_id
    and wdj.maintenance_object_id=cii.instance_id
    and xs.je_source_name = 'Cost Management'
    Please help me in tuning the above query.
    Thanks
    Raghava

Maybe you are looking for

  • Urgent!!! cut function in JTextArea is not working

    In my project, I am using a JTextArea. To remove a particular text in text area, i was selecting the text and I was using cut() function to cut the selected text. This functionality was working fine when I was running the the project on JBuilder. But

  • How to format an account to show date format with MDX function @FORMATDATE

    Hello, I am working with an ASO cube where all accounts are set as numeric type. We have some accounts which hold date information for eg Date1 member which is a stored member will have data as 20120601 for June 1st 2012. In financial reports, i need

  • Has this happened to anyone? -1 emails?

    [IMG] http://i33.tinypic.com/2rervxu.jpg[/IMG] This is from my gmail account. Has anyone run across this problem? Just noticed it today, never happened before. Should I just delete the gmail account from the phone and open a new one in settings? Than

  • IPhoto will not import video clips from iPhoto

    I plugged in my iPhone to my computer.  I opened iPhoto to import the photos from my camera role.  It imported the photos just fine up said "The following files could not be imported.  The file is in an unrecognized format."  It is all the video file

  • Problem with iPod Updater 2006-08-28

    Hi, It seems that there is a bug in this version of the iPod Updater. I didn't know where to post so I came here as this problem may be the related to the fact that I use it on my Nano 1Go. When I restored my iPod, the iPod Updater created a void Sys