SQL needs to go retro

I have the following SQL which works in SQL Server 2005, but I need to replicate the functionality for SQL Server 2000. Unfortunately, the "row_number()" and "with partitioned as" syntaxes don't exist in the older version of SQL Server, so I can't build my tables or run my reports. I tried using the identity function in the first step (building the avg_days table) with the order by clause, but the row numbers are out of order (I want to order by customer_key asc, calendar_date asc, transaction_id asc). Any ideas would be welcomed as I am out of them and need an answer asap.
Thanks!
-------------------- AVG_DAYS -------------------
Select distinct A.customer_key, b.transaction_id, c.calendar_dt
into avg_days
From crdw_customer A, crdw_txn_header B, crdw_date_time C
Where A.customer_key = B.customer_key
And B.time_key = C.time_key
-------------------- AVG_DAYS_1 -----------------
WITH Partitioned AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY customer_key, calendar_dt ORDER BY customer_key, calendar_Dt) AS RowNumber
FROM avg_days)
SELECT *,
CASE
WHEN RowNumber > 1 THEN 0
ELSE COALESCE(DATEDIFF(DAY, (SELECT MAX(calendar_dt) FROM avg_days WHERE calendar_dt < a.calendar_dt AND customer_key = a.customer_key), a.calendar_dt), 0)
END AS Days_between
into avg_days_1
FROM Partitioned a

One of the possible way is using IDENTITY Function...
here it is...
Code Snippet
Select
  Identity(int,1,1) RowId,
  Cast(Null as int) RowNumber
into
  #Partitioned
From
  Avg_Days
ORDER BY
  customer_key, calendar_Dt;
Update #Partitioned
Set
  RowNumber = RowNumber - (Select Min(RowNumber)-1 From #Partitioned Sub
            Where #Partitioned.customer_key = sub.customer_key
              And #Partitioned.calendar_dt = Sub.calendar_dt)
SELECT
  CASE
  WHEN RowNumber > 1 THEN 0
  ELSE COALESCE(DATEDIFF(DAY, (SELECT MAX(calendar_dt) FROM avg_days WHERE calendar_dt < a.calendar_dt AND customer_key = a.customer_key), a.calendar_dt), 0)
  END AS Days_between
into
  avg_days_1
FROM
  #Partitioned a

Similar Messages

  • SQL: Need help putting single quote around string

    I want to put single quotes around string in my output.
    I am running the following command as a test:
    select ' ' hello ' ' from dual;
    My expectation is to get 'hello' (Single quote around hello)
    However I am getting the following error:
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    When I do SHOW ALL at my SQL command prompt, the escape is set as follows:
    escape "\" (hex 5c)
    I even tried: select '\'hello\'' from dual;
    I get back: select ''hello'' from dual
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected

    Hi,
    user521525 wrote:
    I want to put single quotes around string in my output.
    I am running the following command as a test:
    select ' ' hello ' ' from dual;
    My expectation is to get 'hello' (Single quote around hello)You probably read that you can get a single-quote within a string literal by using two of them in a row.
    That's true, but they really have to be in a row (no spaces in between), and you still need the single-quotes at the beiginning and end of the literal.
    So what you want is
    SELECT  '''hello'''
    FROM    dual;Starting in Oracle 10, you can also use Q-notation, For example:
    SELECT  Q'['hello']'
    FROM    dual;

  • Parse XML in PL/SQL need help

    Hi All,
    I'm new to PL/SQL. I need to call a web service from within the PL/SQL and then need to parse the response XML. I was able to call the web service and now I have returned SOAP response XML in CLOB. I searched on google for way to parse this XML and create some kind of list or array or collection with all the values so that later on that collection or array can be used in displaying the data or storing the data, but I couldn't found the right information, rather I got very confused.
    Please help me in parsing this XML and creating some kind collection or array for later use.
    Thanks
    XML is
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
    <getMemberResponse effectiveDate="1970-10-01" endDate="2010-12-31" xmlns="http://abc.org/schema/Member/GetMember/V1">
    <responseHeader xmlns="http://abc.org/schema/common/v1">
    <serviceVersion>2.0.1</serviceVersion>
    <actionRequested AR="QUERY" xmlns:v1="http://abc.org/schema/Member/V1" xmlns:v11="http://abc.org/schema/common/v1" xmlns:v12="http://abc.org/schema/common/v1">
    <v11:transactionName>GetMemberRequest</v11:transactionName>
    </actionRequested>
    <requestResults>
    <resultStatus>Success</resultStatus>
    <resultCodes>
    <resultCode TYPE="HIPAA">00000</resultCode>
    <resultCode TYPE="LEGACY">00000</resultCode>
    <resultCode TYPE="SDI">00000</resultCode>
    </resultCodes>
    <resultMessage>Success</resultMessage>
    </requestResults>
    <accounting xmlns:v1="http://abc.org/schema/Member/V1" xmlns:v11="http://abc.org/schema/datatypes/v1" xmlns:v12="http://abc.org/schema/common/v1">
    <transactionId>ec3542e7-3191-430c-bd69-69dd5d18bf75</transactionId>
    <v12:timeStamp>2011-05-23T11:52:22</v12:timeStamp>
    </accounting>
    </responseHeader>
    <requestID>ec3542e7-3191-430c-bd69-69dd5d18bf75</requestID>
    <memberDetails xmlns:v1="http://abc.org/schema/Member/V1" xmlns:v11="http://abc.org/schema/datatypes/v1" xmlns:v12="http://abc.org/schema/common/v1">
    <v1:ids>
    <v1:id memberIdType="SSN">00000000</v1:id>
    <v1:id memberIdType="PARTYID">111111</v1:id>
    <v1:id memberIdType="PARTYNUMBER">222222</v1:id>
    </v1:ids>
    <v1:demographics>
    <v1:memberDemographicType effDate="2010-05-09" maintType="UPDATE">
    <v1:name>
    <v1:nameDetails>
    <v11:firstName>Keith</v11:firstName>
    <v11:middleName>M</v11:middleName>
    <v11:lastNames>
    <v11:lastName>
    <v11:name>Thompson</v11:name>
    </v11:lastName>
    </v11:lastNames>
    <v11:formattedName>Keith M Thompson</v11:formattedName>
    </v1:nameDetails>
    <v1:createDate>2010-05-09T14:23:17</v1:createDate>
    <v1:updateDate>2010-08-08T02:40:24</v1:updateDate>
    </v1:name>
    <v1:birthDate>1954-12-24</v1:birthDate>
    <v1:genderTypeCode>Male</v1:genderTypeCode>
    <v1:createDate>2010-05-09T14:23:17</v1:createDate>
    <v1:updateDate>2010-08-08T02:40:24</v1:updateDate>
    </v1:memberDemographicType>
    </v1:demographics>
    <v1:originalContractEffDate>2010-04-01</v1:originalContractEffDate>
    <v1:addresses>
    <v1:address maintType="QUERY">
    <v1:location addresseeType="MEMBER" effDate="1901-01-01" endDate="9999-12-31" locationUseType="HOME" primaryPerType="Y">
    <v11:addressLines>
    <v11:addressLine>BAY VIEW AVENUE</v11:addressLine>
    </v11:addressLines>
    <v11:cityName>PLYMOUTH</v11:cityName>
    <v11:stateCode>TX</v11:stateCode>
    <v11:postalCode>58654</v11:postalCode>
    </v1:location>
    <v1:createDate>2011-05-23T11:52:22</v1:createDate>
    <v1:updateDate>2011-05-23T11:52:22</v1:updateDate>
    </v1:address>
    <v1:address maintType="QUERY">
    <v1:location addresseeType="SUBSCRIBER" effDate="1901-01-01" endDate="9999-12-31" locationUseType="HOME" primaryPerType="Y">
    <v11:addressLines>
    <v11:addressLine>AY VIEW AVENUE</v11:addressLine>
    </v11:addressLines>
    <v11:cityName>PLYMOUTH</v11:cityName>
    <v11:stateCode>TX</v11:stateCode>
    <v11:postalCode>58654</v11:postalCode>
    </v1:location>
    <v1:createDate>2011-05-23T11:52:22</v1:createDate>
    <v1:updateDate>2011-05-23T11:52:22</v1:updateDate>
    </v1:address>
    </v1:addresses>
    <v1:policies>
    <v1:policy effDate="2010-04-01" maintType="ADD" type="MEMBER">
    <v1:ids>
    <v1:id type="MEMBERID">CPIT000456</v1:id>
    <v1:id type="POLICY">CPIT</v1:id>
    </v1:ids>
    <v1:contractType>F</v1:contractType>
    <v1:dependentType>01</v1:dependentType>
    <v1:offerings>
    <v1:offering offeredBy="abc" offeringIdType="INSURANCE_TYPE" selected="Y">
    <v1:offeringId>IV</v1:offeringId>
    </v1:offering>
    <v1:offering effDate="2010-04-01" maintType="ADD" offeredBy="abc" offeringIdType="BOC" selected="Y">
    <v1:offeringId>GK</v1:offeringId>
    <v1:recordInfo>
    <v1:internalRecId>82326287</v1:internalRecId>
    </v1:recordInfo>
    <v1:createDate>2010-05-09T14:23:17</v1:createDate>
    <v1:updateDate>2010-05-09T14:23:17</v1:updateDate>
    </v1:offering>
    </v1:offerings>
    <v1:customer>
    <v1:relation type="EMPLOYMENT">
    <v1:customer>
    <v1:id idType="ACCOUNTID">C11204</v1:id>
    <v1:id idType="DIVISION">0208290000</v1:id>
    <v1:customerName>BC Group</v1:customerName>
    </v1:customer>
    </v1:relation>
    </v1:customer>
    <v1:physicianRelations>
    <v1:physicianRelation effDate="2010-04-01" endDate="9999-12-31" type="PCP">
    <v1:ids>
    <v1:id type="NPI">0</v1:id>
    <v1:id type="AFFILIATIONID">1313 0025</v1:id>
    <v1:id type="PROVIDERID">1313</v1:id>
    <v1:id type="TIN">0</v1:id>
    </v1:ids>
    <v1:recordInfo>
    <v1:internalRecId>98151812</v1:internalRecId>
    </v1:recordInfo>
    <v1:createDate>2010-10-23T01:10:13</v1:createDate>
    <v1:updateDate>2010-10-23T01:10:13</v1:updateDate>
    </v1:physicianRelation>
    </v1:physicianRelations>
    <v1:maintainReasonCode>AC</v1:maintainReasonCode>
    <v1:recordInfo>
    <v1:internalRecId>82326286</v1:internalRecId>
    </v1:recordInfo>
    <v1:createDate>2010-05-09T14:23:17</v1:createDate>
    <v1:updateDate>2010-05-09T14:23:17</v1:updateDate>
    </v1:policy>
    <v1:policy effDate="2010-04-01" maintType="QUERY" type="SUBSCRIBER">
    <v1:ids>
    <v1:id type="POLICY">CPIT</v1:id>
    </v1:ids>
    <v1:hashCode>82326284</v1:hashCode>
    <v1:contractType>F</v1:contractType>
    <v1:maritalStatus>UNKNOWN</v1:maritalStatus>
    <v1:offerings>
    <v1:offering effDate="2010-04-01" maintType="QUERY" offeredBy="abc" offeringIdType="INSURANCE_TYPE" selected="Y">
    <v1:offeringId>IV</v1:offeringId>
    <v1:recordInfo>
    <v1:internalRecId>82326285</v1:internalRecId>
    </v1:recordInfo>
    <v1:createDate>2010-05-09T14:23:17</v1:createDate>
    <v1:updateDate>2011-01-20T04:53:52</v1:updateDate>
    </v1:offering>
    </v1:offerings>
    <v1:customer>
    <v1:relation type="EMPLOYMENT">
    <v1:customer>
    <v1:id idType="ACCOUNTID">C11204</v1:id>
    <v1:id idType="DIVISION">0208290000</v1:id>
    <v1:customerName>BC Group</v1:customerName>
    </v1:customer>
    </v1:relation>
    </v1:customer>
    <v1:maintainReasonCode>AC</v1:maintainReasonCode>
    <v1:recordInfo>
    <v1:internalRecId>82326284</v1:internalRecId>
    </v1:recordInfo>
    <v1:createDate>2010-05-09T14:23:17</v1:createDate>
    <v1:updateDate>2011-01-20T04:53:52</v1:updateDate>
    </v1:policy>
    </v1:policies>
    <v1:recordInfo>
    <v1:internalRecId>8364745</v1:internalRecId>
    <v1:objectVersionNo>1</v1:objectVersionNo>
    </v1:recordInfo>
    <v1:restrictedMemberIndicator>N</v1:restrictedMemberIndicator>
    <v1:createDate>2010-05-09T14:23:17</v1:createDate>
    <v1:updateDate>2010-08-08T02:40:24</v1:updateDate>
    </memberDetails>
    </getMemberResponse>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    Hi A_Non,
    Thanks so much for giving me the hint about that "text()" in XPath.
    I have new question for you with same XML I'm parsing right now.
    I have extracted a part(Policies) of whole XML and put it in one XMLTYPE variable. Below is that part XML.
    My question is I need to look only into that policy which is active right now. In the <policy> tag there are two attributes "effDate" and "endDate". "effDate" tag will always be there for every policy and for all inactive policies also "endDate" will be there always. Problem is with the active ones, "endDate" may or may not be there. If "endDate" is there so it will be greater than or equal to sysdate and if it is not there that means it is open ended. I need to fetch only that policy which is active right now and if there is no tag as such that means member is not active as of today.
    If "endDate" attribute is there then I think below XPath will work, but I'm not sure about how to handle when "endDate" attribute is not there.
    /d:policies/d:policy[@type="MEMBER" and number(translate(@effDate,"-",""))<=number(translate("'||l_currDate||'","-","")) and number(translate(@endDate,"-",""))>=number(translate("'||l_currDate||'","-",""))]I have Oracle 10.1.0.4, in this in XPath comparison operators are not working so I'm using XPath functions.
    Here is the XML
    <v1:policies>
       <v1:policy effDate="1999-05-01" endDate="1999-12-31" maintType="ADD" type="MEMBER">
           <v1:ids>
               <v1:id type="MEMBERID">SDF000414600</v1:id>
               <v1:id type="POLICY">SDF0004146</v1:id>
           </v1:ids>
           <v1:contractType>F</v1:contractType>
           <v1:dependentType>01</v1:dependentType>
           <v1:offerings>
               <v1:offering offeredBy="ABC" offeringIdType="INSURANCE_TYPE" selected="Y">
                   <v1:offeringId>IH</v1:offeringId>
               </v1:offering>
               <v1:offering effDate="1999-05-01" endDate="1999-12-31" maintType="ADD" offeredBy="ABC" offeringIdType="BOC" selected="Y">
                   <v1:offeringId>HA</v1:offeringId>
                   <v1:recordInfo>
                      <v1:internalRecId>39077481</v1:internalRecId>
                   </v1:recordInfo>
                   <v1:createDate>2010-05-01T01:27:04</v1:createDate>
                   <v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
               </v1:offering>
           </v1:offerings>
           <v1:customer>
               <v1:relation type="EMPLOYMENT">
                   <v1:customer>
                      <v1:id idType="ACCOUNTID">AS35423</v1:id>
                      <v1:id idType="DIVISION">0621730000</v1:id>
                      <v1:customerName>Medical Associates</v1:customerName>
                   </v1:customer>
               </v1:relation>
           </v1:customer>
           <v1:physicianRelations>
               <v1:physicianRelation effDate="1999-05-01" endDate="1999-12-31" type="PCP">
                   <v1:ids>
                      <v1:id type="NPI">0</v1:id>
                      <v1:id type="AFFILIATIONID">66759       0014</v1:id>
                      <v1:id type="PROVIDERID">231231</v1:id>
                      <v1:id type="TIN">0</v1:id>
                   </v1:ids>
                   <v1:recordInfo>
                      <v1:internalRecId>87796651</v1:internalRecId>
                   </v1:recordInfo>
                   <v1:createDate>2010-10-22T21:56:44</v1:createDate>
                   <v1:updateDate>2010-10-22T21:56:44</v1:updateDate>
               </v1:physicianRelation>
           </v1:physicianRelations>
           <v1:maintainReasonCode>MD</v1:maintainReasonCode>
           <v1:recordInfo>
               <v1:internalRecId>39077480</v1:internalRecId>
           </v1:recordInfo>
           <v1:createDate>2010-05-01T01:27:04</v1:createDate>
           <v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
       </v1:policy>
       <v1:policy effDate="2000-01-01" endDate="2000-12-31" maintType="ADD" type="MEMBER">
           <v1:ids>
               <v1:id type="MEMBERID">SDF000414600</v1:id>
               <v1:id type="POLICY">SDF0004146</v1:id>
           </v1:ids>
           <v1:contractType>F</v1:contractType>
           <v1:dependentType>01</v1:dependentType>
           <v1:offerings>
               <v1:offering offeredBy="ABC" offeringIdType="INSURANCE_TYPE" selected="Y">
                   <v1:offeringId>IH</v1:offeringId>
               </v1:offering>
               <v1:offering effDate="2000-01-01" endDate="2000-12-31" maintType="ADD" offeredBy="ABC" offeringIdType="BOC" selected="Y">
                   <v1:offeringId>HA</v1:offeringId>
                   <v1:recordInfo>
                      <v1:internalRecId>39077483</v1:internalRecId>
                   </v1:recordInfo>
                   <v1:createDate>2010-05-01T01:27:04</v1:createDate>
                   <v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
               </v1:offering>
           </v1:offerings>
           <v1:customer>
               <v1:relation type="EMPLOYMENT">
                   <v1:customer>
                      <v1:id idType="ACCOUNTID">C35423</v1:id>
                      <v1:id idType="DIVISION">0621730000</v1:id>
                      <v1:customerName>Medical Associates</v1:customerName>
                   </v1:customer>
               </v1:relation>
           </v1:customer>
           <v1:physicianRelations>
               <v1:physicianRelation effDate="2000-01-01" endDate="2000-12-31" type="PCP">
                   <v1:ids>
                      <v1:id type="NPI">0</v1:id>
                      <v1:id type="AFFILIATIONID">66759       0014</v1:id>
                      <v1:id type="PROVIDERID">3213213</v1:id>
                      <v1:id type="TIN">0</v1:id>
                   </v1:ids>
                   <v1:recordInfo>
                      <v1:internalRecId>87796652</v1:internalRecId>
                   </v1:recordInfo>
                   <v1:createDate>2010-10-22T21:56:44</v1:createDate>
                   <v1:updateDate>2010-10-22T21:56:44</v1:updateDate>
               </v1:physicianRelation>
           </v1:physicianRelations>
           <v1:maintainReasonCode>MD</v1:maintainReasonCode>
           <v1:recordInfo>
               <v1:internalRecId>39077482</v1:internalRecId>
           </v1:recordInfo>
           <v1:createDate>2010-05-01T01:27:04</v1:createDate>
           <v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
       </v1:policy>
       <v1:policy effDate="2001-01-01" maintType="ADD" type="MEMBER">
           <v1:ids>
               <v1:id type="MEMBERID">SDF000414600</v1:id>
               <v1:id type="POLICY">SDF0004146</v1:id>
           </v1:ids>
           <v1:contractType>F</v1:contractType>
           <v1:dependentType>01</v1:dependentType>
           <v1:offerings>
               <v1:offering offeredBy="ABC" offeringIdType="INSURANCE_TYPE" selected="Y">
                   <v1:offeringId>IH</v1:offeringId>
               </v1:offering>
               <v1:offering effDate="2001-01-01" endDate="2001-03-31" maintType="ADD" offeredBy="ABC" offeringIdType="BOC" selected="Y">
                   <v1:offeringId>HC</v1:offeringId>
                   <v1:recordInfo>
                      <v1:internalRecId>39077485</v1:internalRecId>
                   </v1:recordInfo>
                   <v1:createDate>2010-05-01T01:27:04</v1:createDate>
                   <v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
               </v1:offering>
           </v1:offerings>
           <v1:customer>
               <v1:relation type="EMPLOYMENT">
                   <v1:customer>
                      <v1:id idType="ACCOUNTID">C35423</v1:id>
                      <v1:id idType="DIVISION">0621730000</v1:id>
                      <v1:customerName>Medical Associates</v1:customerName>
                   </v1:customer>
               </v1:relation>
           </v1:customer>
           <v1:physicianRelations>
               <v1:physicianRelation effDate="2001-01-01" endDate="2001-03-31" type="PCP">
                   <v1:ids>
                      <v1:id type="NPI">0</v1:id>
                      <v1:id type="AFFILIATIONID">66759       0014</v1:id>
                      <v1:id type="PROVIDERID">61232132</v1:id>
                      <v1:id type="TIN">0</v1:id>
                   </v1:ids>
                   <v1:recordInfo>
                      <v1:internalRecId>87796653</v1:internalRecId>
                   </v1:recordInfo>
                   <v1:createDate>2010-10-22T21:56:44</v1:createDate>
                   <v1:updateDate>2010-10-22T21:56:44</v1:updateDate>
               </v1:physicianRelation>
           </v1:physicianRelations>
           <v1:maintainReasonCode>LE</v1:maintainReasonCode>
           <v1:recordInfo>
               <v1:internalRecId>39077484</v1:internalRecId>
           </v1:recordInfo>
           <v1:createDate>2010-05-01T01:27:04</v1:createDate>
           <v1:updateDate>2010-05-01T01:27:04</v1:updateDate>
       </v1:policy>
    </v1:policies>Thanks

  • Have working PL/SQL, need to create a PDF

    I am a newbie to Oracle Reports, and I need to generate a report that is beyond the basic reports scenario. I am having no luck with the GUI or web editor (I can't even get anchors and expandable sections to work), but I have a working PL/SQL routine that writes the output to html and does everything I want except to format the data in a .PDF file and make the output available via a URL. Oracle Reports did a great job of formatting the original version of what we need, but the few modifications are not so simple with reports.
    Old simple scheme:
    Group info item 1
    Group info item 2
    [Table of entries for this group]
    new page in PDF if more groups...
    New scheme:
    Group info item 1
    Group info item 2
    boilerplate text.....
    SQL query based on this group item 1
    more boilerplate text...
    [Table of entries for this group]
    more boilerplate text
    new page in PDF if more groups...
    What is the best approach for getting Oracle Reports to use what I already have in PL/SQL (cursors, etc.)?
    Thanks for any suggestions!

    You may re-use your working pl/sql code to populate global temporary tables from AfterParameterForm trigger and write a simple RDF to read data from those tables.

  • After DB migration(Informix to Oracle), SQLs need to review & change?

    Dear all,
    We migrate our system DB from Informix to Oracle 9i.
    The current problem is: All data in CHAR fields will have "SPACE".
    For example,
    There is a table named TABLE1, and one field named FIELD_1 in it.
    The type of FIELD_1 is CHAR, 4 characters.
    In Informix, the data in TABLE1 is
    FIELD_1
    ===============
    CM
    ALL
    TEST
    After migrate to Oracle, the data "looks like the same".
    FIELD_1
    ===============
    CM
    ALL
    TEST
    But, when using TOAD or SQL/PLUS to query the length of these data, like:
    SELECT LENGTH(FIELD_1) AS LEN, FIELD_1 FROM TABLE1;
    And, the return result is:
    LEN FIELD_1
    ==== ==============
    4 CM
    4 ALL
    4 TEST
    All length is 4..........Orz......
    So, all SQL in current AP need to review and change(if necessary).
    for example, the statement likes:
    WHERE FIELD_1 = 'CM' will change to WHERE TRIM(FIELD_1) = 'CM'
    Does anybody have the same probelm?
    And another question is, if we always use TRIM in the WHERE statement, will cause bad performance or not?
    (because I try to change one SQL and get the return result.....takes more time than before)
    Thanks a lot.
    Best Regards,
    Claire

    The current solution is review all codes in AP and change the WHERE statement.Don't do that! You'll have all kinds of problems and any new code you develop, you'll have to remember this hack. Instead, fix the tables once so they are correct. Continuing my example:
    SQL> alter table t modify (object_name varchar2(30));
    Table altered.
    SQL> update t
      2  set object_name = trim(object_name);
    7852 rows updated.
    SQL> commit;
    Commit complete.
    SQL> select length(object_name), count(*)
      2  from t
      3  group by length(object_name);
    LENGTH(OBJECT_NAME)             COUNT(*)
                       1                    1
                       3                   22
                       4                   14
                       5                   33
                       6                   46
                       7                  213
                       8                  283
                       9                  266
                      10                  295
                      11                  288
                      12                  291
                      13                  339
                      14                  354
                      15                  367
                      16                  428
                      17                  396
                      18                  368
                      19                  377
                      20                  348
                      21                  340
                      22                  353
                      23                  306
                      24                  347
                      25                  320
                      26                  325
                      27                  269
                      28                  332
                      29                  299
                      30                  232
    29 rows selected.For each table, you can do one modify and one update statement to fix it. With a little clever use of the data dictionary, you might even be able to script it.
    Much easier than hacking your code.
    Message was edited by:
    Eric H

  • SQL - Need Tunning tips for group by [LATEST EXECUTION PLAN IS ATTACHED]

    Hi All Experts,
    My SQL is taking so much time to execute. If I remove the group by clause it is running within a minute but as soon as I am putting sum() and group by clause it is taking ages to run the sql. Number of records are wihout group by clause is almost 85 Lachs (8 Million). Is hugh dataset is killing this? Is there any way to tune the data on Group by clause. Below is my Select hints and execution plan. Please help.
    SQL
    SELECT /*+ CURSOR_SHARING_EXACT gather_plan_statistics all_rows no_index(atm) no_expand
    leading (src cpty atm)
    index(bk WBKS_PK) index(src WSRC_UK1) index(acct WACC_UK1)
    use_nl(acct src ccy prd cpty grate sb) */
    EXECUTION PLAN
    PLAN_TABLE_OUTPUT
    SQL_ID 1y5pdhnb9tks5, child number 0
    SELECT /*+ CURSOR_SHARING_EXACT gather_plan_statistics all_rows no_index(atm) no_expand leading (src cpty atm) index(bk
    WBKS_PK) index(src WSRC_UK1) index(acct WACC_UK1) use_nl(acct src ccy prd cpty grate sb) */ atm.business_date,
    atm.entity legal_entity, TO_NUMBER (atm.set_of_books) setofbooksid, atm.source_system_id sourcesystemid,
    ccy.ccy_currency_code ccy_currency_code, acct.acct_account_code, 0 gl_bal, SUM (atm.amount)
    atm_bal, 0 gbp_equ, ROUND (SUM (atm.amount * grate.rate), 4) AS
    atm_equ, prd.prd_product_code, glacct.parentreportingclassification parentreportingclassification,
    cpty_counterparty_code FROM wh_sources_d src,
    Plan hash value: 4193892926
    | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
    | 1 | HASH GROUP BY | | 1 | 1 | 471 |00:31:38.26 | 904M| 76703 | 649K| 649K| 1149K (0)|
    | 2 | NESTED LOOPS | | 1 | 1 | 8362K|00:47:06.06 | 904M| 76703 | | | |
    | 3 | NESTED LOOPS | | 1 | 1 | 10M|00:28:48.84 | 870M| 17085 | | | |
    | 4 | NESTED LOOPS | | 1 | 1 | 10M|00:27:56.05 | 849M| 17084 | | | |
    | 5 | NESTED LOOPS | | 1 | 8 | 18M|00:14:10.93 | 246M| 17084 | | | |
    | 6 | NESTED LOOPS | | 1 | 22 | 18M|00:11:58.96 | 189M| 17084 | | | |
    | 7 | NESTED LOOPS | | 1 | 22 | 18M|00:10:24.69 | 152M| 17084 | | | |
    | 8 | NESTED LOOPS | | 1 | 1337 | 18M|00:06:00.74 | 95M| 17083 | | | |
    | 9 | NESTED LOOPS | | 1 | 1337 | 18M|00:02:52.20 | 38M| 17073 | | | |
    |* 10 | HASH JOIN | | 1 | 185K| 18M|00:03:46.38 | 1177K| 17073 | 939K| 939K| 575K (0)|
    | 11 | NESTED LOOPS | | 1 | 3 | 3 |00:00:00.01 | 11 | 0 | | | |
    | 12 | TABLE ACCESS BY INDEX ROWID | WH_SOURCES_D | 1 | 3 | 3 |00:00:00.01 | 3 | 0 | | | |
    |* 13 | INDEX RANGE SCAN | WSRC_UK1 | 1 | 3 | 3 |00:00:00.01 | 2 | 0 | | | |
    |* 14 | TABLE ACCESS BY INDEX ROWID | WH_COUNTERPARTIES_D | 3 | 1 | 3 |00:00:00.01 | 8 | 0 | | | |
    |* 15 | INDEX UNIQUE SCAN | WCPY_U1 | 3 | 1 | 3 |00:00:00.01 | 5 | 0 | | | |
    | 16 | PARTITION RANGE SINGLE | | 1 | 91M| 91M|00:00:00.08 | 1177K| 17073 | | | |
    |* 17 | TABLE ACCESS FULL | WH_ATM_BALANCES_F | 1 | 91M| 91M|00:00:00.04 | 1177K| 17073 | | | |
    |* 18 | TABLE ACCESS BY INDEX ROWID | WH_PRODUCTS_D | 18M| 1 | 18M|00:01:43.88 | 37M| 0 | | | |
    |* 19 | INDEX UNIQUE SCAN | WPRD_UK1 | 18M| 1 | 18M|00:00:52.13 | 18M| 0 | | | |
    |* 20 | TABLE ACCESS BY GLOBAL INDEX ROWID| WH_BOOKS_D | 18M| 1 | 18M|00:02:53.01 | 56M| 10 | | | |
    |* 21 | INDEX UNIQUE SCAN | WBKS_PK | 18M| 1 | 18M|00:01:08.32 | 37M| 10 | | | |
    |* 22 | TABLE ACCESS BY INDEX ROWID | T_SDM_SOURCEBOOK | 18M| 1 | 18M|00:03:43.66 | 56M| 1 | | | |
    |* 23 | INDEX RANGE SCAN | TSSB_N5 | 18M| 2 | 23M|00:01:11.50 | 18M| 1 | | | |
    |* 24 | TABLE ACCESS BY INDEX ROWID | WH_CURRENCIES_D | 18M| 1 | 18M|00:01:51.21 | 37M| 0 | | | |
    |* 25 | INDEX UNIQUE SCAN | WCUR_PK | 18M| 1 | 18M|00:00:49.26 | 18M| 0 | | | |
    | 26 | TABLE ACCESS BY INDEX ROWID | WH_GL_DAILY_RATES_F | 18M| 1 | 18M|00:01:55.84 | 56M| 0 | | | |
    |* 27 | INDEX UNIQUE SCAN | WGDR_U2 | 18M| 1 | 18M|00:01:10.89 | 37M| 0 | | | |
    | 28 | INLIST ITERATOR | | 18M| | 10M|00:22:40.03 | 603M| 0 | | | |
    |* 29 | TABLE ACCESS BY INDEX ROWID | WH_ACCOUNTS_D | 150M| 1 | 10M|00:20:19.05 | 603M| 0 | | | |
    |* 30 | INDEX UNIQUE SCAN | WACC_UK1 | 150M| 5 | 150M|00:10:16.81 | 452M| 0 | | | |
    | 31 | TABLE ACCESS BY INDEX ROWID | T_SDM_GLACCOUNT | 10M| 1 | 10M|00:00:50.64 | 21M| 1 | | | |
    |* 32 | INDEX UNIQUE SCAN | TSG_PK | 10M| 1 | 10M|00:00:26.17 | 10M| 0 | | | |
    |* 33 | TABLE ACCESS BY INDEX ROWID | WH_COMMON_TRADES_D | 10M| 1 | 8362K|00:18:52.56 | 33M| 59618 | | | |
    |* 34 | INDEX UNIQUE SCAN | WCTD_PK | 10M| 1 | 10M|00:03:06.56 | 21M| 5391 | | | |
    Edited by: user535789 on Mar 17, 2011 9:45 PM
    Edited by: user535789 on Mar 20, 2011 8:33 PM

    user535789 wrote:
    Hi All Experts,
    My SQL is taking so much time to execute. If I remove the group by clause it is running within a minute but as soon as I am putting sum() and group by clause it is taking ages to run the sql. Number of records are wihout group by clause is almost 85 Lachs (*8 Million*). Is hugh dataset is killing this? Is there any way to tune the data on Group by clause. Below is my Select hints and execution plan. Please help.I doubt that your 8 million records are shown within minutes.
    I guess that the output started after a few minutes. But this does not mean that the full resultset is there. It just means the database is able to return to you the first few records after a few minutes.
    Once you add a group by (or an order by) then this requires that all the rows need to be fetched before the database can start showing them to you.
    But maybe you could run some tests to compare the full output. I find it useful to SET AUTOTRACE TRACEONLY for such a purpose (in sql plus). This avoids to print the selection on the screen.

  • Merge Two SQL - need help

    Hi All,
    Need some tips - like i have two different process runing with just only a SQL query on each.
    The both the process SQL Query is 90% similar Rather the Second sql has extra two columns
    and few filterning conditions is different which is Marked in bold. My question is there any way that
    i can write a single SQL statement that works for my both process. The Difference between the
    Query 1 and Query 2 have marked in Bold/underlined.
    Query 1
    SELECT SUBCON.MEME_CK,MEMBER_ID,LINE_NUMBER,RECIPIENT_NUMBER,MEMBER_LAST_NAME,MEMBER_FIRST_NAME,MEMBER_MIDDLE_INIT,MEMBER_SSN,MEMBER_DOB,
           MEMBER_ADDRESS_1,MEMBER_ADDRESS_2,MEMBER_CITY,MEMBER_STATE,MEMBER_ZIP_CODE,MEMBER_COUNTY_CODE,MEMBER_SEX,MEMBER_PHONE_NUMBER,
           HH_LAST_NAME,HH_FIRST_NAME,RELATIONSHIP_CODE,PCP_ID_NUMBER,PCP_NAME,PCP_PHONE_NUMBER,PCP_ADDRESS_1,PCP_ADDRESS_2,PCP_CITY,
           PCP_STATE,PCP_ZIP_CODE,PCP_COUNTY_CODE,PCP_EFFECTIVE_DATE,PCD_ID_NUMBER,PCD_NAME,PCD_PHONE_NUMBER,PCD_ADDRESS_1,
           PCD_ADDRESS_2,PCD_CITY,PCD_STATE,PCD_ZIP_CODE,PCD_COUNTY_CODE,PCD_EFFECTIVE_DATE,GROUP_EFF_DATE,GROUP_TERM_DATE,
           GROUP_NUMBER,PROGRAM_STATUS_CODE,LANGUAGE_INDICATOR,VISION_IMP_IND,HEARING_IMP_IND,SPECIAL_NEEDS_FLAG,ELIG_EFF_DATE,
           ELIG_TERM_DATE,BEN_GROUP_NO,BEN_GROUP_EFF_DT,MEDICARE_IND,TPL_RX_PAYER,TPL_RX_PAYER_EFF_DT,TPL_RX_PAYER_NAME,INSURANCE_CODE,
           POLICY_NUMBER,TYPE_OF_COVERAGE,LOB,COUNTY_STATE_RECORD,STATE_RECORD_NUMBER,GROUP_CODE,REV_CATEGORY_CODE,AQ_IND,MECD_CSCS_ID,
           MECB_EFF_DT,MCRE_ID,MECB_TERM_DT,rtrim(SBAD_PHONE) as "SBAD_PHONE"
    FROM      EXT_MEGD_SBCN_ELG_DLY SUBCON,
              CMC_MECD_MEDICAID MECD,
              CMC_SBAD_ADDR SBAD,
              CMC_MEME_MEMBER MEME
    WHERE     SUBCON.MEME_CK = MECD.MEME_CK
    AND        DATEDIFF(mm,MEMBER_DOB, DATEADD(mm,  1,GETDATE())) < 25_
    AND        Right(MECD_MCTR_AIDC,2) not in ('31', '33')
    AND        MECD_MCTR_AIDC Not in ('PC36','J36')
    AND        SUBCON.MEME_CK = MEME.MEME_CK
    AND        MEME.SBSB_CK *= SBAD.SBSB_CK
    AND        SBAD.SBAD_TYPE = "1"
    AND        SBAD.SBAD_PHONE <> " "
    AND        SBAD.SBAD_PHONE <> "0000000000"
    AND        CHAR_LENGTH(RTRIM(SBAD_PHONE)) < 11Query 2
    SELECT SUBCON.MEME_CK,MEMBER_ID,LINE_NUMBER,RECIPIENT_NUMBER,MEMBER_LAST_NAME,MEMBER_FIRST_NAME, MEMBER_MIDDLE_INIT,MEMBER_SSN,MEMBER_DOB,
           MEMBER_ADDRESS_1,MEMBER_ADDRESS_2,MEMBER_CITY,MEMBER_STATE,MEMBER_ZIP_CODE,MEMBER_COUNTY_CODE,MEMBER_SEX,MEMBER_PHONE_NUMBER,
           HH_LAST_NAME,HH_FIRST_NAME,RELATIONSHIP_CODE,PCP_ID_NUMBER,PCP_NAME,PCP_PHONE_NUMBER,PCP_ADDRESS_1,PCP_ADDRESS_2,PCP_CITY,
           PCP_STATE,PCP_ZIP_CODE,PCP_COUNTY_CODE,PCP_EFFECTIVE_DATE,PCD_ID_NUMBER,PCD_NAME,PCD_PHONE_NUMBER,PCD_ADDRESS_1,PCD_ADDRESS_2,
           PCD_CITY,PCD_STATE,PCD_ZIP_CODE,PCD_COUNTY_CODE,PCD_EFFECTIVE_DATE,GROUP_EFF_DATE,GROUP_TERM_DATE,GROUP_NUMBER,PROGRAM_STATUS_CODE,
           LANGUAGE_INDICATOR,VISION_IMP_IND,HEARING_IMP_IND,SPECIAL_NEEDS_FLAG,ELIG_EFF_DATE,ELIG_TERM_DATE,BEN_GROUP_NO,BEN_GROUP_EFF_DT,
           MEDICARE_IND,TPL_RX_PAYER,TPL_RX_PAYER_EFF_DT,TPL_RX_PAYER_NAME,INSURANCE_CODE,POLICY_NUMBER,TYPE_OF_COVERAGE,LOB,COUNTY_STATE_RECORD,
           STATE_RECORD_NUMBER,GROUP_CODE,REV_CATEGORY_CODE,AQ_IND,MECD_CSCS_ID,MECB_EFF_DT,MCRE_ID,MECB_TERM_DT,RTRIM(SBAD_PHONE) as "SBAD_PHONE",
           PRCF_MCTR_SPEC,PRAD_FAX
    FROM      EXT_MEGD_SBCN_ELG_DLY SUBCON,
              CMC_MECD_MEDICAID MECD,
              CMC_SBAD_ADDR SBAD,
              CMC_MEME_MEMBER MEME,
              CMC_PRPR_PROV    PRPR,_
              CMC_PRAD_ADDRESS PRAD_
    WHERE     SUBCON.MEME_CK = MECD.MEME_CK
    AND        Right(MECD_MCTR_AIDC,2) not in ('31', '33')
    AND        MECD_MCTR_AIDC Not in ('PC36','J36')
    AND        SUBCON.MEME_CK = MEME.MEME_CK
    AND        SUBCON.PCP_ID_NUMBER  = PRPR.PRPR_ID*_
    AND        SUBCON.PCP_ID_NUMBER  = PRAD.PRAD_ID*_
    AND        PRAD.PRAD_TYPE = 'PRI'_
    AND        (CONVERT(CHAR(10),GETDATE(),101))  BETWEEN PRAD.PRAD_EFF_DT AND PRAD.PRAD_TERM_DTAND        MEME.SBSB_CK *= SBAD.SBSB_CK_AND        SBAD_TYPE = "1"
    AND        SBAD_PHONE <> " "
    AND        SBAD_PHONE <> "0000000000"
    AND        CHAR_LENGTH(RTRIM(SBAD_PHONE)) < 11Any suggestions Welcome.
    Edited by: USER_X on May 18, 2009 11:03 AM

    Hi,
    The simplest thing, and perhaps the fastest, is to do a UNION, as Someoneelse suggested.
    See [this thread|http://forums.oracle.com/forums/message.jspa?messageID=3430965#3430965] for an example.
    Depending on your data, you could do an Outer Join of the two tables that are only in Query 2 to the other tables.
    The WHERE clause would look something like this:
    WHERE     SUBCON.MEME_CK = MECD.MEME_CK
    AND        Right(MECD_MCTR_AIDC,2) not in ('31', '33')
    AND        MECD_MCTR_AIDC Not in ('PC36','J36')
    AND        SUBCON.MEME_CK = MEME.MEME_CK
    AND        SBAD_PHONE  " "
    AND        SBAD_PHONE  "0000000000"
    AND        CHAR_LENGTH(RTRIM(SBAD_PHONE)) < 11
    AND        (     DATEDIFF (mm, MEMBER_DOB, DATEADD(mm,  1,GETDATE())) < 25     -- Extra condition from Query 1
            OR  (                                                                    -- Extra conditions from Query 2
                       SUBCON.PCP_ID_NUMBER   = PRPR.PRPR_ID
              AND   SUBCON.PCP_ID_NUMBER   = PRAD.PRAD_ID
              AND   PRAD.PRAD_TYPE          = 'PRI'_
              AND   (CONVERT(CHAR(10),GETDATE(),101))  BETWEEN PRAD.PRAD_EFF_DT
                                              AND      PRAD.PRAD_TERM_DT
              AND   MEME.SBSB_CK           = SBAD.SBSB_CK
              AND   SBAD_TYPE               = 1
            )Since all the tables in the Outer Join are referenced in the conditions from Query 2, this has the effect of making that an Inner Join unless the extra conditions from Query 1 were met.
    iIn the SELECT claue, use a CASE expression for each column that occurs only in Query 2 that repeats all the extra conditions for Query 2:
    ,       CASE
              WHEN  SUBCON.PCP_ID_NUMBER   = PRPR.PRPR_ID
              AND   SUBCON.PCP_ID_NUMBER   = PRAD.PRAD_ID
              AND   PRAD.PRAD_TYPE          = 'PRI'_
              AND   (CONVERT(CHAR(10),GETDATE(),101))  BETWEEN PRAD.PRAD_EFF_DT
                                              AND      PRAD.PRAD_TERM_DT
              AND   MEME.SBSB_CK           = SBAD.SBSB_CK
              AND   SBAD_TYPE               = 1
              THEN  PRCF_MCTR_SPEC
           END     AS PRCF_MCTR_SPECThat column will be NULL if the extra conditions from Query 2 are not met.
    Instead of computing all those extra conditions over and over again, you may want to compute them once for all in a sub-query:
    SELECT  ...
    ,       CASE
              WHEN  SUBCON.PCP_ID_NUMBER   = PRPR.PRPR_ID
              AND   SUBCON.PCP_ID_NUMBER   = PRAD.PRAD_ID
              AND   PRAD.PRAD_TYPE          = 'PRI'_
              AND   (CONVERT(CHAR(10),GETDATE(),101))  BETWEEN PRAD.PRAD_EFF_DT
                                              AND      PRAD.PRAD_TERM_DT
              AND   MEME.SBSB_CK           = SBAD.SBSB_CK
              AND   SBAD_TYPE               = 1
              THEN  1
                                    ELSE  0
           END     AS query_2_extraThen, in the main querry, you can use use that column:
    WHERE     ...
    AND        (     DATEDIFF (mm, MEMBER_DOB, DATEADD(mm,  1,GETDATE())) < 25     -- Extra condition from Query 1
            OR     query_2_extra = 1                                              -- Extra conditions from Query 2
            )

  • Awr show this sql as highest cpu consuming sql .Is this sql need tunning?

    Hi,
    As awr reports showing this sql as the highest CPU consumer
    Please consider me newbie and help me to understand this.
    Thanking you ..
    SQL ordered by CPU Time            DB/Inst:  Snaps: 
    -> Resources reported for PL/SQL code includes the resources used by all SQL
       statements called by the code.
    -> % Total DB Time is the Elapsed Time of the SQL statement divided
       into the Total Database Time multiplied by 100
        CPU      Elapsed                  CPU per  % Total
      Time (s)   Time (s)  Executions     Exec (s) DB Time    SQL Id
         2,658      2,665            1     2658.18     5.7 5aawbyzqjk8by
    select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, ta
    s_site ts where trp.tsa_id = tti.tsa_id and tti.status = 1 and ts.site_id = trp
    .site_id and (tti.max_install != trp.pushed_rsn and ((tti.max_install = 0 and
    (trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1) or (tti.max_installComplete sql =>
    select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
    ts
    where
    trp.tsa_id = tti.tsa_id
    and tti.status = 1
    and ts.site_id = trp.site_id 
    and
    tti.max_install != trp.pushed_rsn
    and  (
           (tti.max_install = 0 and
               (trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1
           ) or 
           (tti.max_install > 0 and
               (trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :2
           ) or  
           (tti.max_install = trp.pushed_rsn and
           tti.max_install <> 0
    ) or
    (trp.pushed_time !=
    to_date(tti.created_date,'dd-MON-yyhh24:mi:ss') + (1/24/60) * ts.workahead_time
    ) and 
    to_date(sysdate,'dd-MON-yyhh24:mi:ss') + (1/24/60) * :3
      ) > trp.pushed_time
    )getting the explain plan for the above sql =>
    QL> SELECT plan_table_output FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('g6c8y31xr06vp',0,'ALL'));
    PLAN_TABLE_OUTPUT
    SQL_ID  g6c8y31xr06vp, child number 0
    select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
    ts  where trp.tsa_id = tti.tsa_id and tti.status = 1 and ts.site_id = trp.site_id  and
    (tti.max_install != trp.pushed_rsn and  ((tti.max_install = 0 and (trp.pushed_rsn -
    trp.curr_rsn) < ts.workahead_count * :1) or  (tti.max_install > 0 and (trp.pushed_rsn -
    trp.curr_rsn) < ts.workahead_count * :2) or   (tti.max_install = trp.pushed_rsn and
    tti.max_install <> 0 )  )) or (trp.pushed_time != (to_date(tti.created_date,'dd-MON-yy
    hh24:mi:ss') + (1/24/60) * ts.workahead_time) and  ((to_date(sysdate,'dd-MON-yy
    hh24:mi:ss') + (1/24/60) * :3) > trp.pushed_time))
    Plan hash value: 2862358316
    | Id  | Operation               | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT        |                      |       |       |   601K(100)|          |
    |   1 |  HASH UNIQUE            |                      |     4 |   216 |   601K (10)| 02:00:14 |
    |   2 |   CONCATENATION         |                      |       |       |            |          |
    |   3 |    NESTED LOOPS         |                      |   200M|    10G|   579K  (6)| 01:55:52 |
    |   4 |     MERGE JOIN CARTESIAN|                      |  2849 | 99715 |    12   (0)| 00:00:01 |
    |   5 |      TABLE ACCESS FULL  | TAS_SITE             |     7 |    70 |     3   (0)| 00:00:01 |
    |   6 |      BUFFER SORT        |                      |   407 | 10175 |     9   (0)| 00:00:01 |
    |*  7 |       TABLE ACCESS FULL | TAS_RECEIPTS_PROCESS |   407 | 10175 |     1   (0)| 00:00:01 |
    |*  8 |     TABLE ACCESS FULL   | TAS_TSA_INFO         | 70411 |  1306K|   203   (6)| 00:00:03 |
    |*  9 |    HASH JOIN            |                      |     2 |   108 |   203   (2)| 00:00:03 |
    |* 10 |     HASH JOIN           |                      |   407 | 14245 |     7  (15)| 00:00:01 |
    |  11 |      TABLE ACCESS FULL  | TAS_SITE             |     7 |    70 |     3   (0)| 00:00:01 |
    |  12 |      TABLE ACCESS FULL  | TAS_RECEIPTS_PROCESS |   407 | 10175 |     3   (0)| 00:00:01 |
    |* 13 |     TABLE ACCESS FULL   | TAS_TSA_INFO         | 21474 |   398K|   196   (2)| 00:00:03 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1
       5 - SEL$1_1 / TS@SEL$1
       7 - SEL$1_1 / TRP@SEL$1
       8 - SEL$1_1 / TTI@SEL$1
      11 - SEL$1_2 / TS@SEL$1_2
      12 - SEL$1_2 / TRP@SEL$1_2
      13 - SEL$1_2 / TTI@SEL$1_2
    Predicate Information (identified by operation id):
       7 - filter("TRP"."PUSHED_TIME"<TO_DATE(TO_CHAR(SYSDATE@!),'dd-MON-yy
                  hh24:mi:ss')+.000694444444444444444444444444444444444445*:3)
       8 - filter("TRP"."PUSHED_TIME"<>TO_DATE(INTERNAL_FUNCTION("TTI"."CREATED_DATE"),'dd-M
                  ON-yy hh24:mi:ss')+.000694444444444444444444444444444444444445*"TS"."WORKAHEAD_TIME")
       9 - access("TRP"."TSA_ID"="TTI"."TSA_ID")
           filter(("TTI"."MAX_INSTALL"<>"TRP"."PUSHED_RSN" AND (("TTI"."MAX_INSTALL"=0 AND
                  "TRP"."PUSHED_RSN"-"TRP"."CURR_RSN"<"TS"."WORKAHEAD_COUNT"*:1) OR
                  ("TTI"."MAX_INSTALL">0 AND "TRP"."PUSHED_RSN"-"TRP"."CURR_RSN"<"TS"."WORKAHEAD_COUNT"*:2
                  ) OR ("TTI"."MAX_INSTALL"="TRP"."PUSHED_RSN" AND "TTI"."MAX_INSTALL"<>0)) AND
                  (LNNVL("TRP"."PUSHED_TIME"<TO_DATE(TO_CHAR(SYSDATE@!),'dd-MON-yy
                  hh24:mi:ss')+.000694444444444444444444444444444444444445*:3) OR
                  LNNVL("TRP"."PUSHED_TIME"<>TO_DATE(INTERNAL_FUNCTION("TTI"."CREATED_DATE"),'dd-MON-yy
                  hh24:mi:ss')+.000694444444444444444444444444444444444445*"TS"."WORKAHEAD_TIME"))))
      10 - access("TS"."SITE_ID"="TRP"."SITE_ID")
      13 - filter("TTI"."STATUS"=1)
    Column Projection Information (identified by operation id):
       1 - "TRP"."SITE_ID"[NUMBER,22]
       2 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
           "TS"."WORKAHEAD_TIME"[NUMBER,22], "TRP"."TSA_ID"[NUMBER,22],
           "TRP"."SITE_ID"[NUMBER,22], "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22],
           "TRP"."PUSHED_TIME"[DATE,7], "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
           "TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
       3 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
           "TS"."WORKAHEAD_TIME"[NUMBER,22], "TRP"."TSA_ID"[NUMBER,22],
           "TRP"."SITE_ID"[NUMBER,22], "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22],
           "TRP"."PUSHED_TIME"[DATE,7], "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
           "TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
       4 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
           "TS"."WORKAHEAD_TIME"[NUMBER,22], "TRP"."TSA_ID"[NUMBER,22],
           "TRP"."SITE_ID"[NUMBER,22], "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22],
           "TRP"."PUSHED_TIME"[DATE,7]
       5 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
           "TS"."WORKAHEAD_TIME"[NUMBER,22]
       6 - (#keys=0) "TRP"."TSA_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
           "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7]
       7 - "TRP"."TSA_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
           "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7]
       8 - "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
           "TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
       9 - (#keys=1) "TRP"."TSA_ID"[NUMBER,22], "TTI"."TSA_ID"[NUMBER,22],
           "TS"."SITE_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
           "TS"."WORKAHEAD_TIME"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
           "TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7],
           "TRP"."CURR_RSN"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7], "TTI"."STATUS"[NUMBER,22],
           "TTI"."MAX_INSTALL"[NUMBER,22]
      10 - (#keys=1) "TS"."SITE_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
           "TS"."WORKAHEAD_TIME"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
           "TRP"."TSA_ID"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7], "TRP"."CURR_RSN"[NUMBER,22],
           "TRP"."PUSHED_RSN"[NUMBER,22]
      11 - "TS"."SITE_ID"[NUMBER,22], "TS"."WORKAHEAD_COUNT"[NUMBER,22],
           "TS"."WORKAHEAD_TIME"[NUMBER,22]
      12 - "TRP"."TSA_ID"[NUMBER,22], "TRP"."SITE_ID"[NUMBER,22],
           "TRP"."CURR_RSN"[NUMBER,22], "TRP"."PUSHED_RSN"[NUMBER,22], "TRP"."PUSHED_TIME"[DATE,7]
      13 - "TTI"."TSA_ID"[NUMBER,22], "TTI"."STATUS"[NUMBER,22],
           "TTI"."MAX_INSTALL"[NUMBER,22], "TTI"."CREATED_DATE"[DATE,7]
    105 rows selected.sizes of concerned objects=>
    OWNER           SEGMENT_NAME                   SEGMENT_TYPE         TABLESPACE_NAME      EXTENTS           BYTES_
    AZD_SCHM     TAS_TSA_INFO                   TABLE                TATSU_DATA_TS             22        7,340,032
    AZD_SCHM     TAS_TSA_INFO_PK                INDEX                TATSU_DATA_TS             17        2,097,152
    AZD_SCHM     TAS_RECEIPTS_PROCESS           TABLE                TATSU_DATA_TS              1           65,536
    AZD_SCHM     TAS_RECEIPTS_PROCESS_IDX       INDEX                TATSU_INDEX_TS             1           65,536
    AZD_SCHM     TAS_SITE                       TABLE                TATSU_DATA_TS              1           65,536
    AZD_SCHM     TAS_SITE_NAME_UNQ              INDEX                TATSU_INDEX_TS             1           65,536
    AZD_SCHM     TAS_SITE_PK                    INDEX                TATSU_DATA_TS              1           65,536
    --------------- ------------------------------ -------------------- -------------------- ------- ----------------Please suggest how to tune this above SQL
    Does above sql plan looks good
    Any comment and help is highely appreciated.
    Thanks & Regards,
    IVW

    ivw wrote:
    Complete sql =>
    Please suggest how to tune this above SQL
    Does above sql plan looks good
    Any comment and help is highely appreciated.Your SQL is probably incorrectly using the OR operator. In its present form it means this:
    select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
    ts
    where
    trp.tsa_id = tti.tsa_id
    and tti.status = 1
    and ts.site_id = trp.site_id 
    and
    tti.max_install != trp.pushed_rsn
    and  (
           (tti.max_install = 0 and
               (trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1
           ) or 
           (tti.max_install > 0 and
               (trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :2
           ) or  
           (tti.max_install = trp.pushed_rsn and
           tti.max_install <> 0
    union all
    select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
    ts
    where
    (trp.pushed_time !=
    to_date(tti.created_date,'dd-MON-yyhh24:mi:ss') + (1/24/60) * ts.workahead_time
    ) and 
    to_date(sysdate,'dd-MON-yyhh24:mi:ss') + (1/24/60) * :3
      ) > trp.pushed_time
    and not (above condition)So one of the two parts of the SQL are missing all the join predicates between the tables due to the OR operator at top level. The way the SQL is formatted, it might be meant to read like this:
    select distinct trp.site_id from tas_receipts_process trp , tas_tsa_info tti, tas_site
    ts
    where
    trp.tsa_id = tti.tsa_id
    and tti.status = 1
    and ts.site_id = trp.site_id 
    and
      (tti.max_install != trp.pushed_rsn
    and  (
           (tti.max_install = 0 and
               (trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :1
           ) or 
           (tti.max_install > 0 and
               (trp.pushed_rsn - trp.curr_rsn) < ts.workahead_count * :2
           ) or  
           (tti.max_install = trp.pushed_rsn and
           tti.max_install <> 0
    or   (trp.pushed_time != to_date(tti.created_date,'dd-MON-yyhh24:mi:ss') + (1/24/60) * ts.workahead_time
          and to_date(sysdate,'dd-MON-yyhh24:mi:ss') + (1/24/60) * :3 > trp.pushed_time
    )But you need to find out what exactly it is supposed to express from a logical point of view. Very likely the present form is simply incorrect. Depending on your data correcting the usage of the OR operator might even render the DISTINCT operator redundant which is probably at present used to remove the many duplicates generated by the missing join predicates.
    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/

  • For running utlrp.sql need users termination from the database?

    Hai All,
    My database jobs terminated in some time. So I want to run utlrp.sql for compiling all invalid objects. Is It needs users termination from the database? or login to restricted session? Please give a correct step for doing this activity..
    Please help?
    Shiju

    database? or login to restricted session? Please
    give a correct step for doing this activity..
    It is good , if you run utlrp.sql in restricted mode also set job_queue_processes =0 and check no dbms_job running package ( if package is valid then fine ). Problem only come when package/procedure are locked/in use by session. If invalid package are not used by any session then you can run utlrp.sql without restricted mode also. Well you know better you application.
    Since you not altering any dependencies, just want to compile , you can run without restricted mode.
    Virag

  • Conditional loop to update table / pl/sql  -------needed.

    I want to post my work order bill of material quantity from inventory : example below
    table stock
    id .... number
    part ... varchar2..(10)
    qty ... number
    table bom
    id.... number
    parent .... varchar2..(10)
    component .... varchar2..(10)
    qty .... number
    something like :
    update stock set stock.qty = stock.qty - ( bom.qty where bom.component = stock.part);
    end;
    example of data in bom table:
    1....a1000....b1000...12
    2....a2000....b2000...3
    3....a3000....b20001..6
    data in stock table:
    1...b1000...1000
    2...b2000...1200
    3...b3000....980
    4...b4000...1566
    5...b5000....456
    6...b6000....123
    -----------Any ideas/ Thanks-------
    .......................... BJ

    Thanks for the script . I had requested a script however I simple sql may also be fine for my needes in fact I may just create a PROCESS in the application area of my program anyway.
    Here is the error message I received when running the script you provided.
    ORA-06550: line 9, column 9: PLS-00103: Encountered the symbol "]" when expecting one of the following: in The symbol "in was inserted before "]" to continue. ORA-06550: line 9, column 21: PLS-00103: Encountered the symbol "IN" when expecting one of the following: * & - + / at mod remainder rem .. <an exponent (**)> || multiset year DAY_ ORA-06550: line 13, column 1: PLS-00103: Encountered the symbol "END"
    Thanks again
    BJ

  • "Join" SQL needed

    my sql is like this:
    SELECT DISTINCT ITEM_MASTER.BARCODE, SUBSTR(ITEM_MASTER.VENDOR_STYLE_DESC, 6, 5) Parcel_Barcode,
    FROM ITEM_MASTER
    now i need to join another ITEM_MASTER1 table where ITEM_MASTER1.BARCODE=Parcel_Barcode
    How do i do that?
    Thanks

    Well, at the first look, the error is caused by the last comma in the select list. Without this comma it should disappear:
    SELECT DISTINCT ITEM_MASTER.BARCODE, SUBSTR(ITEM_MASTER.VENDOR_STYLE_DESC, 6, 5) Parcel_Barcode
    FROM ITEM_MASTER, ITEM_MASTER_A1
    WHERE ITEM_MASTER.Parcel_Barcode=ITEM_MASTER_A1.BARCODEThe column parcel_barcode should however exist in the item_master table, otherwise, you should put in the where clause the substr expression instead of it (or inline the query).
    Best regards
    Maxim

  • New to PL/SQL needs help?

    I am new to PL/SQL and i want to write a procedure to display the fields returned by the select statement by the procedure to display on the Web Page.
    Here i have written a small procedure to display fields on the web page.
    Create or Replace procedure Try(id number) is
    Begin
    select ename,empno,job,sal from emp where empno=id;
    end Try;
    Can i call this procedure instead of writting the SQL Code in Java for displaying the ename,empno,job,sal.

    I am new to PL/SQL and i want to write a procedure to
    display the fields returned by the select statement
    by the procedure to display on the Web Page.
    Here i have written a small procedure to display
    fields on the web page.
    Create or Replace procedure Try(id number) is
    Begin
    select ename,empno,job,sal from emp where empno=id;
    end Try;
    Can i call this procedure instead of writting the SQL
    Code in Java for displaying the ename,empno,job,sal.Nice and helpful, guys.
    Presumably you have a Java procedure that will call this procedure and display on the webpage. So you need to return the values to the Java. There are many ways to do this - you could have 1 OUT parameter for each column, or return a record, or a refcursor.
    Ideally, you'll get a PL/SQL developer to handle that end, or go on a course yourself.

  • Executing catpatch.sql and catcpu.sql needed ???

    hello,
    I have installed oracle 9.2 and i upgraded to 9207 and then applied the Apr2007 CPU. After all these i created the database.
    My concern is do i need to run the catpatch.sql and catcpu.sql.
    TIA,
    Jj

    Because the database has been upgraded after running catpatch.sql only. Before this it was in 9.2.0.1 version.
    .. But that was not the original poster's point.
    - J..J asked if an oracle home was patched, THEN a new database created, if he had to run catcpu.sql and catpatch.sql.
    - viraq and rob schenk said no, the SQL's did not need to be run, since the DB did not exist before the patch.
    - J..J tested this by installing and upgrading the OracleHome to 9.2.0.7, then creating a new database. Curiously, the dba_registry showed old versions of the catalog. He had to run catcpu.sql/catpatch.sql after creating the new DB, even though the DB was created under the new 9207 code base. This conflicts with what viraq and rob said.
    I'm having this same issue with the current jan2009 CPU, and didn't realize this entire time that I was creating databases without running the catcpu/catpatch.sql's, since I was simply following the db install guide. I'm currently trying to track back how far this 'catcpu/catpatch' rule goes.. unless someone can correct my understanding on this.

  • Arraysize in glogin.sql need install suggestion.

    hello.
    My co is developing software to interface with Oracle. And we would really like to change the arraysize in the glogin.sql script to be about 6000 during the installation of our program. 6000 seems to make our software run faster anything larger shows marginal performance gains.
    What are the pro's/con's of doing this? (Assuming we change it to ~6000 if arraysize has not been set or set to something smaller in glogin.sql.)
    Would a prompt during our install step giving the admins the choice whether to change glogin.sql be reasonable? Or should we just print a suggestion during the install and in our manuals?
    thanks.

    It will increase sqlplus query efficiency, but will use more memory.
    BTW- The maximum you can set arraysize is 5000. So you cannot set it to 6000. Also any values more than 100 will not add significant change over when it is set to 100

  • Prob in using rank in pl/sql ,need logic same of rank function in any way

    I have a query as of the following <br>
    <br>
    SELECT sr_no,cod_acct_no,dat_arrears_due,amt_arrear_due<br>
    FROM ( select cod_acct_no,dat_arrears_due,sum(amt_arrears_due) <br>amt_arrear_due,rank() over (partition by cod_acct_no order by <br>dat_arrears_due asc) sr_no<br>
              from arrears_table <br>
              where amt_arrears_due > 0<br>
    and dat_arrears_due <= to_date('31/10/2006','dd/mm/yyyy')<br>
    and COD_ARREAR_TYPE = 'C'<br>
         group by cod_acct_no,dat_arrears_due<br>
         ) Z <br>
    WHERE z.sr_no <=5 <br>
    <br>
    I have to use this in a cursor in pl/sql but because i have rank analytic function <br>
    I am facing a compilation error ORA-06550: error <br>
    <br>
    Can you give me a logic which gives same output as of above <br>
    <br>
    Regards<br>
    vamsi krishna<br>
    <br>
    <br>

    [1]: (Error): ORA-06550: line 5, column 28: PLS-00103: Encountered the <br>symbol "(" when expecting one of the following: , from <br>
    <br>
    My oracle version is <br>
    Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production<br>
    PL/SQL Release 8.1.6.0.0 - Production<br>
    CORE 8.1.6.0.0 Production<br>
    TNS for 32-bit Windows: Version 8.1.6.0.0 - Production<br>
    NLSRTL Version 3.4.1.0.0 - Production<br>
    <br>I think it is comming for rank function it self <br>
    <br> will this version support analytic (rank) function's in pl/sql cursors<br>
    Regards<br>
    vamsi krishna<br>

Maybe you are looking for

  • All USB drives mount as read only for user

    I have searched a bunch and thee results I find seem to be irrelevant to my situation. Most relate to a single USB media that is a problem and won't read or write. On a new Arch install on a new computer (my third base system install). Running Gnome.

  • What is in the MacBook Air accessory kit? Is there a Magic Mouse?

    I would like to know what is in the accessory kit, so I don't have to buy any extra stuff.

  • Binding troubleshooting

    Hi! I've been struggling with a bit of binding code - I'm making tabs, and I'm trying to get the content to change when a different tab is selected. The tab headers change so far, but the tab content doesn't. When a tab header is clicked on, the tab

  • How to apply group settings of UDF and UserDefinedValues to all documents ?

    I have made many User Defined Fields, category group settings of UDF, and User Defined Values (Formatted search) in a marketing document. And I want to apply them to all of the marketing documents, that is Sales and Purchase documents,,, all the same

  • Move data between tables with INSERT-LOOP?

    Greetings I need to move all the contact information (contained in 5 fields- call it the address table) into the table (call it the main table) that contains all the other associated information. Tables are related via the "vendor_ID" key field. Ther