How do I use count for this query?

How do I display all the addresses in a table that have more than one (or >1) account number? I wasn't sure how or if I should use count along with group by and having to get the expected results.

select address from tablename
group by address having count(1) > 1;

Similar Messages

  • How to write SQL hints for this query?

    The query is like:
    select * from foo, t
    where foo.name in
    (select name from bar
    where id in (
    select id from car
    where date < sysdate
    and foo.a = t.b;
    I want the innermostsubquery 'select id from car ...' to be executed first, and the subquery 'select name from bar ...' to be execute second, and the outermost query 'select * from foo,t ...' to be executed the last. How can I write the Oracle sql hints to force the order?
    Thanks.

    user553560
    You might be able to create a large set of hints to force the access path you want - but unless you really know what you are doing with hints, you may find that your solution is very unstable (it might be luck rather than correctness that let's it work to start with).
    The difficulty in this query is the double layer of IN subqueries, so if you can rewrite the query, you might try manually unnesting as follows:
    select
         t1.*. t.*
    from
              select     
                   distinct t2.name
              from     t2
              where     t2.id in (
                        select     t3.id
                             from     t3
                        where     t3.dated < sysdate
         )     v,
         t1,
         t
    where
         t1.name = v.name
    and     t1.a = t.bDepending on your indexing and statistics, you may find that a simple /*+ unnest */ hint in the first subquery will be sufficient to do this for your. Again depending on the statistics you may find that you have to put extra hints into the above to make Oracle use the join method and indexes you think appropriate.
    N.B. The first step (as others have noted) is to check that your statistics are good before you start manipulating the code or using hints.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

  • How to use case for this query.

    I have this table name Employee.
    columns..
    EmpId,
    EmpType,
    Joining date,
    Resigning date
    Now in EmpType either it can be 'P' OR 'C'
    so i want to check if the EmpTYpe is 'P' then joiningdate should not be null
    and if the EmpType is 'C' then Resigning date should not be null.
    Then only want those records from employee.
    Please help.

    978172 wrote:
    I have this table name Employee.
    columns..
    EmpId,
    EmpType,
    Joining date,
    Resigning date
    Now in EmpType either it can be 'P' OR 'C'
    so i want to check if the EmpTYpe is 'P' then joiningdate should not be null
    and if the EmpType is 'C' then Resigning date should not be null.
    Then only want those records from employee.
    Please help.
    -- EmpId, EmpType, Joining date, Resigning date
    select * from Employee
    where (EmpType = 'P' and JoiningDate IS NULL) OR (EmpType = 'C' and ResigningDate IS NULL);

  • How to solve the error "Ref Count for this object is greater then 0"

    Hi,
    I'm trying to add UDF at runtime to an already created UDT which is of No Object Type.
    my code is as follows:
    dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD
    oUserFieldsMD = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
    oUserFieldsMD.TableName = "@TI_ADDCODES"
    oUserFieldsMD.Name = codetoinsert
    oUserFieldsMD.Description = desctoinsert
      'Add the field to the table
       lRetCode = oUserFieldsMD.Add
       If lRetCode <> 0 Then
       ocompany.GetLastError(lErrCode, sErrMsg)
       MsgBox(sErrMsg)
        Else
        MsgBox("Field: '" & oUserFieldsMD.Name & "' was added successfuly to " & oUserFieldsMD.TableName & " Table")
        End If
    I got error msg as "Ref Count for this object is greater then 0" and error code is -1120
    how to rectify it?
    Thanks in advance!!!

    Hi,
    Have you searched the forum? You may check this first: error -1120 when adding UserTableMD.
    Thanks,
    Gordon

  • How can I use TopLink for querys that have two and more tables?

    I use TopLink today, and I can use one table to query, but how can I use TopLink for querys that have two and more tables?
    Thank you for see and answer this question.

    You can write a custom SQL query and map it to an object as needed. You can also use the Toplink query language "anyOf" or "get" commands to map two tables as long as you map them as one to one (get command) or one to many (anyOf command) in the toplink mapping workbench.
    Zev.
    check out oracle.toplink.expressions.Expression in the 10.1.3 API

  • Is there a way to create a plan guide for this query?

    How can i create a plan guide for this query,suppose i can't change the query text:
    USE AdventureWorks2008R2;
    GO
    SET NOCOUNT ON;
    GO
    -- query plan statement starts
    DECLARE @Group nvarchar(50), @Sales money;
    SET @Group = N'North America';
    SET @Sales = 2000000;
    SET NOCOUNT OFF;
    SELECT FirstName, LastName, SalesYTD
    FROM Sales.vSalesPerson
    WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;
    -- query plan statement ends
    AdventureWorks2008R2's parameterization option is simple, i want this type of query can reuse plan:
    DECLARE @Group nvarchar(50), @Sales money;
    SET @Group = N'Other Country';
    SET @Sales = 88;
    SET NOCOUNT OFF;
    SELECT FirstName, LastName, SalesYTD
    FROM Sales.vSalesPerson
    WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;
    I tried many times ,but it didn't work:
    declare @xml nvarchar(max) -- the plan i want to reuse
    set @xml = (select cast (query_plan as nvarchar(max)) 
    from sys.dm_exec_query_plan (0x060006001464570B405D92620200000001000000000000000000000000000000000000000000000000000000))
    -- create plan guide 
    exec sp_create_plan_guide 
    @name ='Test'
    ,@stmt=N'SELECT FirstName, LastName, SalesYTD
    FROM Sales.vSalesPerson
    WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;'
    ,@type =N'sql'
    ,@params =N'@Group nvarchar(50), @Sales money'
    ,@hints = @xml;
    Thanks.

    I guess you don't wanna fire these queries "adhoc" but prepared instead to reuse the plan:
    exec sp_executesql N'SELECT FirstName, LastName, SalesYTD FROM Sales.vSalesPerson WHERE TerritoryGroup = @Group and SalesYTD >= @Sales',
    N'@Group nvarchar(50), @Sales money', N'Other Country',88
    exec sp_executesql N'SELECT FirstName, LastName, SalesYTD FROM Sales.vSalesPerson WHERE TerritoryGroup = @Group and SalesYTD >= @Sales',
    N'@Group nvarchar(50), @Sales money', N'North America',2000000
    Bodo Michael Danitz - MCT, MCITP - free consultant - performance specialist - www.sql-server.de

  • Why doesn't SAP use SAPUI5 for this and that

    This is my personal opinion about this topic! Again and again I stumble about this and now I want to share some of my thoughts about this topic. I want to share this from a point of view, when I was not a SAP Employee - I worked at a SAP Partner company - because this best reflects the view from the outside.
    1. SAP "wants" us to use SAPUI5
    I don't think that "wants" is the right word - the right word is offers! In terms of: hey now even included in your license and open sourced (because you wanted it so). Look - we build sooo many Fiori apps with it - and put in some great enterprise features (right to left, accessibility, translation, ...) and it is responsive. So if you want to build Fiori-like "apps" - there you go - this is your technology to go! This is what I understood.
    I was very very very happy that it was build with open standards. But the main point for me another thing - (because I worked with Sybase Unwired Platform and SAP Mobile Platform) OMG an open data protocol!!! OData FTW! I could use ANY front-end technology and consume SAP data - the protocol is REST based - a dream came true. And so I did - yes I played around with Sencha Touch and OData, I used data.js and used it in a standard HTML5 application. We played around with an iOS application we already had and consumed the data. I feed the data into d3.js. I prototyped around with SAPUI5 and I have build apps with it. Brilliant, so I could choose whatever UI technology I wanted.
    I always had the feeling, that SAPUI5 was meant for B2E applications - and building many of that - and they should look and feel the same and I can theme the apps. I can use it when I want to make my applications SAP like - so that the user thinks the apps are all the same and everything fits nicely into the Fiori launchpad - great if you want to build partner apps. In my ex company we won a SAP Pinnacle Award - for a native iOS app, no SAPUI5 in sight - but we have received an award, so SAP did not "want us" to use SAPUI5 ;-)
    2. Is it the right UI technology for everything?
    At my ex-company I was dealing with mobile applications and web apps. I always knew that I get the best user experience when I write a real native application and if you want it to look like in a very specific way with awesome UI --> you would not do it with a write-once-run-everywhere HTML5 super-styled wrapped (phone gap/cordova) app - you would write the apps for the specific platform and it should feel like it was written for the platform. SAP offered us the SAP Fiori Client that I could enhance the user experience for the Fiori apps, but I was never told to use SAPUI5 it for everything.
    The same discussion goes on with: why was the new SAP website not build with SAPUI5, or the UX Explorer (eat your own dog food), or a useful internal app - why Angular, or the other way around why do we even use SAPUI5 and not Angular JS itself. Back to the past - SAP did never tell me to build a website with it, or to build something tiny and small with it (a widget) - or to enhance parts of a website with it - or to build something super-specific with it.
    And yes maybe the UI in a mobile app was not SAPUI5 but do you know if it uses Gateway with OData or the SAP Mobile Platform, was the API managed with Apigee, was HCI involved in getting the data from different sources, was it maybe wrapped with SAP Mobile Secure, did it maybe use a HANA backend or some of its features (predictions, text analytics, ...) - are some backend parts maybe hosted on HCP - who knows? So yeah, maybe other SAP technology was involved which you don't see, but in the end it made your life simpler.
    Instead of arguing around why this and that was used for this and that - can we save our energy and instead look at the result - which is all what counts - that it was the right UI technology with the right user interface which makes the user happy? I stated something like - does Google use AngularJS for everything? Nope. They offer us something great we can use. Right, maybe AngularJS is not as important for Google like SAPUI5 is for us. But we have something with which we can build our day-to-day business apps with and we do so.
    3. We missed great opportunity in not using SAPUI5 for this and that
    Let's think about how projects are going: you want something, you look at the costs, you choose most efficient option. Yes this could mean reusing an existing native application which was written long ago and you pimped it up. Or you had outsourced it to a company which wrote a similar app. Or you bought the source code. Or you have some cheap internal staff which could do it (students, trainee), or you could outsource it cheaply. Or all you have is people with experience in this and that technology. Or it must look in a very very specific way (because marketing says so) and you go native. Or it maybe should even differentiate itself and should look NOT like a Fiori app. And no - I don't think - this is my employees view - we are not for example an event app producer. We normally build business applications. And I don't think that we can write an app from scratch "just" for an event in a certain technology. Yes it would be nice if this and that would use SAPUI5, I think if it would be possible in terms of time and costs and UI wishes and hundreds of other factors we would do it with SAPUI5.
    Working at the partner SAP showed me over 50 Fiori apps, now hundreds of Fiori apps are released. SAP now showed that SAPUI5 is going big with S/4HANA. We have seen the Simple Finance solution. I was walking around at the CeBIT this year and I was impressed myself which cool apps and screens have been shown with SAPUI5. I used the SAPUI5 app on a Samsung Smart Watch myself. The SAP Web IDE itself is built with SAPUI5 in its heart. I don't need any other "proves" that SAPUI5 is great. I have seen great use cases for it, but I also know myself when I would use other stuff.
    4. My conclusion
    There is never every anything which can cover all different use cases. One-size-fits-all clothes also does not fit for everyone even if it says so. If someone creates something great don't judge it by the UI technology. Judge it by the experience and the value it creates. There are reasons why this and that was chosen. Use what fits your needs best with your requirements. Make the end user happy!

    Hey Denise,
    Thanks for pulling this discussion into SCN. Makes it much easier to discuss compared to Twitter. But I also have to apologize in the beginning that my answer now exceeds 140 characters by 50 times.
    Let me share my thoughts and personal opinion as well. I will try to look at it from a strategic point of view, as you – as the technical UI5 expert - have already covered the technical perspective.
    SAP recommends using SAPUI5 where it fits to customers’ requirements
    Let me begin with a clear statement from my perspective: It makes no sense that SAP takes customer decisions.
    Of course, customers expect SAP to help them with their strategies and decisions and of course we are helping. But at the end, the decisions have to be taken by the customer who needs to take the specific conditions of the company into account. The most important condition in the context of UX is the end user. But we shouldn't forget the business strategy as the most important influence factor. I’m not saying that technical decisions are completely unimportant, but I would like to point out that other things are more important for a company.
    As a result, it wouldn't make a lot of sense if SAP would just want every customer to use SAPUI5. To me, customers need recommendations leading to solutions that satisfy their needs and requirements.
    There is not that one UI technology that serves all needs
    This headline might be a challenging statement and I can already imagine reactions to it. But in fact I can confirm this sentence easily. You always have to combine different technologies. Some of them are from SAP others not. The selection and combination of these technologies is different from customer to customer because the requirements are different. There are still reasons to use Web Dynpro ABAP and I’m still recommending SAP NetWeaver Business Client, POWL (Power Lists), WDA Chips, FPM based on the given environment of the customer. And obviously there are also reasons for UI5.
    SAP already proves the usage of SAPUI5
    In general, I see two different use cases here: Developing custom applications vs. adopting applications from SAP.
    In the one case, customers want recommendations on development environments and UI technologies that consider their development requirements and existing conditions (e.g. existing skills, given implementations). SAPUI5 is a great UI technology and there are some special aspects that make the decision obviously easy. If I want to create simple business applications that can be connected with my SAP system easily, especially in combination under responsive conditions on multiple devices and targeted for casual and/or occasional users UI5 might be the right choice for many.  Exactly this pattern is what many customers are searching for these days. So, the recommendation for UI5 comes quite often.
    Whether or not SAP proves the usage of SAPUI5 in their own world is to me more connected to the use case where customers want to adopt SAP applications. And in deed, SAP is using SAPUI5. There are hundreds of SAP Fiori applications that have been built with SAPUI5 and there have been a lot of other applications developed using SAPUI5, too. And again, there is a huge need for applications for casual and/or occasional users, so that’s a big reason for SAP to create such applications.
    Websites vs. Business Applications
    This discussion was triggered by some statements in twitter, that SAP sites such as sap.com, SAP UX Explorer or the latest mobile conference app are not developed using UI5. Actually I see these to be websites but not business applications. I have never told a customer to build a website in UI5 and I would continue to do so.
    Maybe we need to discuss the difference between a website and a business application. I guess it is not easy to find a common understanding here, as the borderlines between several worlds have disappeared in the last years.
    Some years ago it was more or less easy to differ between:
    Native desktop applications running on a specific desktop OS
    Native mobile applications running on a specific mobile OS
    Browser-based applications running in specific browsers
    Websites, basically running on many browsers
    In the first three categories we saw business applications. 1 and 2 were selected especially when specific functions of the device and OS where needed to be accessed (for example the camera of the mobile device, the fast rendering capability of the desktop). 3 was also used for business applications but in most cases on desktop browsers.
    Today, one can develop browser-based applications that look like native applications and even can access the devices like native applications. Responsive design breaks the borderlines even more. Now, browser-based content can be rendered perfectly on a desktop browser as well as on a mobile phone and a user might even not be able to judge whether it was originally intended to be developed for the one or the other.
    So maybe there is no big difference anymore between websites and browser-based applications. But there is still a difference between browser-based applications and browser-based business applications, where additional requirements such as integration into business systems are drivers. Here I see SAPUI5 as a very cool UI technology.
    That’s just my 2 (personal) cents,
    JJ

  • How to include OSTC.rate in this query

    How to include OSTC.rate in this query,Im using it for crystal report.
    DECLARE @sVAT NVARCHAR(max) 
    DECLARE @sCess NVARCHAR(max) 
    DECLARE @sCST NVARCHAR(max) 
    DECLARE @nDocentry  INT 
    SET @sVAT='1'  SET @sCess='7' SET @sCST ='4'
    SELECT DocEntry
      ,DocDate,VehicleNo,Driver,NumAtCard
      ,Building,Block,Street,City,District,State,Country
      ,Series,DocNum
      ,BTinNo,BCstNo,BCeRegNo,BPanNo,BCeRange,BCeComRate,BCeDivision,BEccNo
      ,Type
      ,CardName,[Delivery Addr]
      ,ECCNo,CERange,CERegNo,CEDivis,CEComRate
      ,PAN,CST,STN
      ,[Deliver At]
      ,LineNum
      ,Dscription,HSNumber,Quantity,Rate,LineTotal,Discount,Vat [VAT],Cess [Cess],Total,GTotal
      ,TotalExpns
      ,MfgName
      ,MFGBuilding,MFGBlock,MFGStreet,MFGDistrict,MFGCity
      ,MCERegNo,MCERange,MCEDivis,MCEComRate,MPAN,MCST,MSTN
      ,SupName
      ,SUPBuilding,SUPBlock,SUPStreet,SUPDistrict,SUPCity
      ,SCERegNo,SCERange,SCEDivis,SCEComRate,SPAN,SCST,SSTN
      , (select substring((select upper(name)+',' from OUBR where isnull(U_SeriesGrp,'')<>'' order by Code FOR XML PATH ('')),1,LEN((select upper(name)+',' from OUBR order by Code FOR XML PATH ('')))-1))[Branches]
    FROM
    SELECT
      /*OBTN.DistNumber*/
      INV1.DocEntry
      ,OINV.DocDate,OINV.U_VehicleNo VehicleNo,OINV.U_Driver Driver,OINV.NumAtCard
      ,CAST(OLCT.Building AS VARCHAR(255))Building,OLCT.Block,OLCT.Street,OLCT.City,OLCT.County+' - '+OLCT.ZipCode[District],OCST.Name State,OCRY.Name Country
      , NNM1.SeriesName [Series], OINV.DocNum
      ,OLCT.TinNo [BTinNo],OLCT.CstNo [BCstNo],OLCT.CeRegNo [BCeRegNo],OLCT.PanNo [BPanNo],OLCT.CeRange [BCeRange]
      ,OLCT.CeComRate [BCeComRate],OLCT.CeDivision [BCeDivision],OLCT.EccNo [BEccNo]
      ,OBTN.U_InvType Type
      ,OINV.CardName,OINV.Address2[Delivery Addr]
      ,CE_CRD7.ECCNo,CE_CRD7.CERegNo,CE_CRD7.CERange,CE_CRD7.CEDivis,CE_CRD7.CEComRate
      ,CRD7.TaxId0[PAN],CRD7.TaxId1[CST],CRD7.TaxId11 [STN]
      ,OINV.U_Address [Deliver At]
      ,INV1.LineNum,INV1.ItemCode
      ,INV1.Dscription,OITM.SWW [HSNumber]
      ,INV1.Quantity,INV1.PriceBefDi Price,INV1.LineTotal,INV1.Price Rate,(INV1.PriceBefDi-INV1.Price)*INV1.Quantity Discount
      ,INV4.Vat
      ,INV4.Cess
      ,INV1.LineTotal+INV1.VatSum Total 
      ,OINV.DocTotal GTotal
      ,OINV.TotalExpns
      ,OBTN.U_MfgName MfgName
      ,convert(nvarchar(250),MFG_CRD1.Building) MFGBuilding,MFG_CRD1.Block MFGBlock,MFG_CRD1.Street MFGStreet,MFG_CRD1.City MFGCity,MFG_CRD1.ZipCode[MFGDistrict]
      ,OBTN.U_MCERegNo MCERegNo,OBTN.U_MCERange MCERange,OBTN.U_MCEDivis MCEDivis,OBTN.U_MCEComRate MCEComRate
      ,OBTN.U_MPAN MPAN,OBTN.U_MCST MCST,OBTN.U_MSTN MSTN
      ,OBTN.U_SupName SupName
      ,convert(nvarchar(250),SUP_CRD1.Building) SUPBuilding,SUP_CRD1.Block SUPBlock,SUP_CRD1.Street SUPStreet,SUP_CRD1.City SUPCity,SUP_CRD1.ZipCode[SUPDistrict]
      ,OBTN.U_SCERegNo SCERegNo,OBTN.U_SCERange SCERange,OBTN.U_SCEDivis SCEDivis,OBTN.U_SCEComRate SCEComRate
      ,OBTN.U_SPAN SPAN,OBTN.U_SCST SCST,OBTN.U_SSTN SSTN
    FROM
      OINV
      INNER JOIN INV1 ON OINV.DocEntry=INV1.DocEntry
      INNER JOIN OITM ON INV1.ItemCode=OITM.ItemCode
      INNER JOIN 
      select
      INV4.DocEntry,INV4.LineNum
      ,CASE WHEN INV4.staType IN (@sVAT,@sCST) THEN sum(INV4.TaxSum) ELSE 0 END Vat
      ,CASE WHEN INV4.staType=@sCess THEN sum(INV4.TaxSum) ELSE 0 END Cess
      from
      INV4
      where
      INV4.DocEntry={?DocKey@} and INV4.RelateType=1
      group by INV4.DocEntry,INV4.LineNum,INV4.staType
      )INV4 ON INV1.DocEntry=INV4.DocEntry AND INV1.LineNum=INV4.LineNum
      INNER JOIN OLCT ON INV1.LocCode=OLCT.Code
      INNER JOIN OCST ON OLCT.State=OCST.Code
      INNER JOIN OCRY ON OLCT.Country=OCRY.Code and OCST.Country=OCRY.Code
      INNER JOIN INV12 ON OINV.DocEntry=INV12.DocEntry
      INNER JOIN OITL ON INV1.BaseType=OITL.ApplyType AND INV1.BaseEntry=OITL.ApplyEntry AND INV1.BaseLine=OITL.ApplyLine
      INNER JOIN ITL1 ON OITL.LogEntry=ITL1.LogEntry
      INNER JOIN OBTN ON ITL1.MdAbsEntry=OBTN.AbsEntry and ITL1.SysNumber=OBTN.SysNumber and ITL1.ItemCode=OBTN.ItemCode
      LEFT JOIN OCRD MFG_OCRD ON MFG_OCRD.CardCode=OBTN.U_MfgCode
      LEFT JOIN CRD1 MFG_CRD1 ON MFG_OCRD.CardCode=MFG_CRD1.CardCode AND MFG_OCRD.BillToDef=MFG_CRD1.Address and MFG_CRD1.AdresType='B'
      LEFT JOIN OCRD SUP_OCRD ON SUP_OCRD.CardCode=OBTN.U_SupCode
      LEFT JOIN CRD1 SUP_CRD1 ON SUP_OCRD.CardCode=SUP_CRD1.CardCode AND SUP_OCRD.BillToDef=SUP_CRD1.Address and SUP_CRD1.AdresType='B'
      LEFT JOIN NNM1 ON OINV.Series=NNM1.Series
      LEFT JOIN CRD7 ON OINV.CardCode=CRD7.CardCode AND CRD7.Address='' AND CRD7.AddrType='S' --Tax Details
      LEFT JOIN CRD7 CE_CRD7 ON OINV.CardCode=CE_CRD7.CardCode AND OINV.ShipToCode=CE_CRD7.Address AND CE_CRD7.AddrType='S' -- Central Excise Details
      WHERE
      INV1.DocEntry={?DocKey@}
    )INVOICE
    GROUP BY
      DocEntry
      ,DocDate,VehicleNo,Driver,NumAtCard
      ,Building,Block,Street,City,District,State,Country
      ,Series,DocNum
      ,BTinNo,BCstNo,BCeRegNo,BPanNo,BCeRange,BCeComRate,BCeDivision,BEccNo
      ,Type
      ,CardName,[Delivery Addr]
      ,ECCNo,CERange,CERegNo,CEDivis,CEComRate
      ,PAN,CST,STN
      ,[Deliver At]
      ,LineNum
      ,Dscription,HSNumber,Quantity,Rate,LineTotal,Discount,Vat,Cess,Total,GTotal
      ,TotalExpns
      ,MfgName
      ,MFGBuilding,MFGBlock,MFGStreet,MFGDistrict,MFGCity
      ,MCERegNo,MCERange,MCEDivis,MCEComRate,MPAN,MCST,MSTN
      ,SupName
      ,SUPBuilding,SUPBlock,SUPStreet,SUPDistrict,SUPCity
      ,SCERegNo,SCERange,SCEDivis,SCEComRate,SPAN,SCST,SSTN

    You're double posting ( how to change join condition in this query ) , stop doing that, since you'll only be distracting and diverting by doing so.
    Take the time to read the SQL and PL/SQL FAQ @ https://forums.oracle.com/forums/ann.jspa?annID=1535, since you're not even mentioning a database version, while 9i {noformat} != {noformat} 10g {noformat} != {noformat}11g...
    Have your DBA trace/tkprof the query, and so on, if you cannot do that yourself.
    And then provide the feedback the volunteers, including Ace (Directors)' s need ( and you were very lucky, from that point of view, I think, from looking at both your posts ;) )

  • Any room for improvement for this query? Explain Plan attached.

    Is there any room for improvement for this query? Table stats are up-to-date. Any suggestions Query rewrite, addition of indexes,...etc ??
    select sum(CONF
                 when (cd.actl_qty - cd.total_alloc_qty - lsd.Q < 0) then
                  0
                 else
                  cd.actl_qty - cd.total_alloc_qty - lsd.Q
               end)
      from (select sum(reqd_qty) as Q, ITEM_ID as ITEM
              from SHIP_DTL SD
             where exists (select 1
                      from CONF_dtl
                     where CONF_nbr = '1'
                       and ITEM_id = SD.ITEM_id)
             group by ITEM_id) lsd,
           CONF_dtl cd
    where lsd.ITEM = cd.ITEM_id
       and cd.CONF_nbr = '1'Total number of rows in the tables involved
    select count(*) from CONF_DTL;
      COUNT(*)
       1785889
    select count(*) from shp_dtl;
      COUNT(*)
        286675
      Explain Plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 2325658044
    | Id  | Operation                           | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                    |                    |     1 |    39 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE                     |                    |     1 |    39 |            |          |
    |   2 |   VIEW                              |                    |     1 |    39 |     4  (25)| 00:00:01 |
    |   3 |    HASH GROUP BY                    |                    |     1 |   117 |     4  (25)| 00:00:01 |
    |   4 |     TABLE ACCESS BY INDEX ROWID     | SHIP_DTL           |     1 |    15 |     1   (0)| 00:00:01
    |   5 |      NESTED LOOPS                   |                    |     1 |   117 |     3   (0)| 00:00:01 |
    |   6 |       MERGE JOIN CARTESIAN          |                    |     1 |   102 |     2   (0)| 00:00:01 |
    |   7 |        TABLE ACCESS BY INDEX ROWID  | CONF_DTL           |     1 |    70 |     1   (0)| 00:00:01 |
    |*  8 |         INDEX RANGE SCAN            | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
    |   9 |        BUFFER SORT                  |                    |     1 |    32 |     1   (0)| 00:00:01 |
    |  10 |         SORT UNIQUE                 |                    |     1 |    32 |     1   (0)| 00:00:01 |
    |  11 |          TABLE ACCESS BY INDEX ROWID| CONF_DTL           |     1 |    32 |     1   (0)| 00:00:01 |
    |* 12 |           INDEX RANGE SCAN          | PK_CONF_DTL        |     1 |       |     1   (0)| 00:00:01 |
    |* 13 |       INDEX RANGE SCAN              | SHIP_DTL_IND_6 |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       8 - access("CD"."CONF_NBR"='1')
      12 - access("CONF_NBR"='1')
      13 - access("ITEM_ID"="SD"."ITEM_ID")
           filter("ITEM_ID"="CD"."ITEM_ID")

    Citizen_2 wrote:
    Is there any room for improvement for this query? Table stats are up-to-date. Any suggestions Query rewrite, addition of indexes,...etc ??You say that the table stats are up-to-date, but is the following assumption of the optimizer correct:
    select count(*)
    from CONF_dtl
    where CONF_nbr = '1';Does this query return a count of 1? I doubt that, but that's what Oracle estimates in the EXPLAIN PLAN output. Based on that assumption you get a cartesian join between the two CONF_DTL table instances, and the result - which is still expected to be one row at most - is then joined to the SHIP_DTL table using a NESTED LOOP.
    If above assumption is incorrect, the number of rows generated by the cartesian join can be tremendous rendering the NESTED LOOP operation quite inefficient.
    You can verify this by using the DBMS_XPLAN.DISPLAY_CURSOR function together with the GATHER_PLAN_STATISTICS hint, if you're already on 10g or later.
    For more information regarding the DISPLAY_CURSOR function, see e.g. here: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
    It will show you the actual cardinalities compared to the estimated cardinalities.
    If the estimate of the optimizer is incorrect, you should find out why. There still might be some issues with the statistics, since this is most obvious reason for incorrect estimates.
    Are your index statistics up-to-date?
    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/

  • Error: Ref count for this object is higher then 0

    Hello All,
    I am trying to create User Defined Tables in SAP through Coding but while running the code the error "Ref count for this object is higher then 0 " is showing .
    I have created a temporary table in which the Table Description are stored as follows :-
    Create Table Test_Table (TblCode Varchar(30),TblName Varchar(100),TblType int)
    From this table then using recordset i am getting the table details for creation :-
    oRecord.DoQuery("Select TblCode,TblName,TblType From Csv_UDT")
                While Not oRecord.EoF
                    Dim Table_Id As String = oRecord.Fields.Item("TblCode").Value
                    Dim Table_Name As String = oRecord.Fields.Item("TblName").Value
                    Dim Table_Type As integer = oRecord.Fields.Item("TblType").Value
                    Dim oUserTablesMD As SAPbobsCOM.UserTablesMD
                    oUserTablesMD = Class_OprTbl_Main.ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
                    '// set the table parameters
                    oUserTablesMD.TableName = Table_Id
                    oUserTablesMD.TableDescription = Table_Name
                    oUserTablesMD.TableType = Table_Type
                    lRetCode = oUserTablesMD.Add
                    If lRetCode <> 0 Then
                        If lRetCode = -1 Then
                        Else
                            Class_OprTbl_Main.ocompany.GetLastError(lRetCode, sErrMsg)
                            Class_OprTbl_Main.SBO_Application.MessageBox(sErrMsg + oUserTablesMD.TableName)
                        End If
                    End If
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
                    oUserTablesMD = Nothing
    But while running this code the error is coming .
    How to solve this error ........
    Thanks,
    Amit

    First of all, you are not meant to create temporary table in SAP database. SAP have never made an official announcement, but I think they would not be too happy if they saw it and may withdraw support. Just something to be aware of.
    Secondly, your error is very common and you would have found the solution by searching the forum. It is caused by having an open recordset while trying to use a metadata object.
    You will have to change how your code works. You can not use the UserFieldsMD or UserTablesMD object while you have an undisposed recordset object.
    -1120 - Ref count for this object is higher then 0
    Ref count for this object is higher then 0
    Error: Ref count for this object is higher then 0
    Meaning of Error Msg: "Ref count for this object is higher than 0"
    The solution is you must dispose of any recordset object before attempting to use the UserTablesMD object:
    System.Runtime.InteropServices.Marshal.ReleaseComObject(oRecordSet)
    oRecordSet= Nothing
    GC.Collect()
    GC.WaitForPendingFinalizers()

  • How to create custom folder for parameterized query

    Hi Gurus,
    I developed a query to generate report to " who is reporting to who in organization", when i am trying to create custom folder using this query but i am getting error like "The custom sql entered contains parameter and therefore invalid". Could you please help to parameterize the emp_key in query in Oracle Discoverer. Is there any way to pass the value using external procedure for this query.
    SELECT
    lpad(' ', 8 *(LEVEL -1)) || emp_last_name, emp_key, manager_id, emp_key, manager_key,
    mgr_last_name, mgr_first_name, empid,
    emp_last_name, emp_first_name, LEVEL FROM cmp_ppl1 START WITH emp_key = &emp_key
    CONNECT BY PRIOR emp_key = manager_key;
    Thanks & Regards
    Vikram

    I agree 100% that it's way easier to create a dataview or a custom folder - with no run time parameters being passed to the EUL - as is being done by Vikram.
    The only concern I would have is that I don't know if it would work - or at least ever come back in reasonable time - for Vikram and therefore the question about parameters (only Vikram can say).
    The reason I'm wondering is that I've created SQL similar to being shown (when used in an org chart report at a large client) and the start / connect by is used for going down the tree getting everyone on the way. And if it's not limited - that could be a huge undertaking - of records and/or time. Guess it depends on how many people work at the organization (and of course, levels).
    But otherwise, absolutely, I would try and bring back all logical records to the folder and then filter in Disco.
    Russ

  • I have two users with different music on each itunes and i can only use one library, how do i use both for one iTouch?

    i have two users with different music on each itunes and i can only use one library, how do i use both for one iTouch?

    Chris, I believe this link may have the information you're looking for. Welcome to discussions!
    http://docs.info.apple.com/article.html?artnum=300432

  • How can i use AME for the new OAF page.

    Dear all,
    I have developed a new OAF page and registered under Employee Self Service.
    How can i use AME for the approval process.
    Appreciate your ideas?
    zamora

    I will try to answer based on my experience of working with iProcurement and AME. It depends on how you want to make a call to AME , directly from OAF Page or from Workflow and your requirement. You didn't specify what you want to show the users on OAF Page and your business requirement.
    Before calling AME Engine from the OAF page or workflow, I guess you did already setup AME Transaction Type and it's Approval Groups, Conditions, Action Types and Rules. Do some testing from AME Business Analyst Test Workbench. Please note that, AME provides lot of PL/SQL API's that you have to call from your programs (java or workflow pl/sql)
    Let's look at the workflow and putting an OAF Page as notification.
    As Sameer said, you have kick-off workflow process from PR of CO and with in the workflow function, you make a call to AME Engine API's with the AME Transaction ID. This transactionId belongs to the AME Transsaction Type that you setup. Based on the rules setup, AME Engine generates list of approvers/approver and stores them AME Tables for that transactionId. Then, it sends a notification to the approver.
    In the workflow, where that notification is defined, in the message body you have to put an attribute(&XX_WF_FWK_RN) of type document/send. And this attribute will have the constant JSP:/OA_HTML/OA.jsp?OAFunc=XX_FUNC&paramId=-&DOCUMENT_ID-. This function is SSWA Jsp function that makes a web html call to your OAF Region.
    If your requirement is to just show the list of approvers on the OAF Page, you may have to call AME API diectly passing your AME TrasnactionId with other parameters. Then AME generates list of approvers and stores them in AME tables with each approver status. You can pickup those approvers using VO and show them on OAF Page.
    Hope this gives some idea.

  • How can i use RTFEditorKit for JTextField.

    hi all,
    how can i use RTFEditorKit for JTextField.
    thanks in advance
    daya

    Don't cross post. This is a Swing related question and you have already posted in the Swing forum:
    http://forum.java.sun.com/thread.jspa?threadID=619619&tstart=0

  • Table creation Error "Ref Count for this object is higher than 0"

    Hi All
    I have a problem in creation of table using SDK on a button event.  I have a procedure to create tables and fields. If I call this procedure on a menu Event than it works fine but If I call this procedure on a button event than It gives error "Ref count for this object is higher than 0" . I know this error occur When an object does not release after creating a table. but this error occur at when first table is created. My code it given below. plz see and give me your valuable suggestions.
      Dim oUserTablesMD As SAPbobsCOM.UserTablesMD
                Try
                    oUserTablesMD = B1Connections.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
                    oUserTablesMD.TableName = "AM_OBIN"
                    oUserTablesMD.TableDescription = "PutAway Table"
                    oUserTablesMD.TableType = BoUTBTableType.bott_Document
                    lRetCode = oUserTablesMD.Add
                    '// check for errors in the process
                    If lRetCode <> 0 Then
                        B1Connections.diCompany.GetLastError(lRetCode, sErrMsg)
                        MsgBox(sErrMsg)
                    Else
                        B1Connections.theAppl.StatusBar.SetText("Table: " & oUserTablesMD.TableName & " was added successfully", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success)
                    End If
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
                    oUserTablesMD = Nothing
                    GC.Collect()
                    oUserTablesMD = B1Connections.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
                    oUserTablesMD.TableName = "AM_BIN1"
                    oUserTablesMD.TableDescription = "PutAway Upper Grid"
                    oUserTablesMD.TableType = BoUTBTableType.bott_DocumentLines
                    lRetCode = oUserTablesMD.Add
                    '// check for errors in the process
                    If lRetCode <> 0 Then
                        If lRetCode = -1 Then
                        Else
                            B1Connections.diCompany.GetLastError(lRetCode, sErrMsg)
                            MsgBox(sErrMsg)
                        End If
                    Else
                        B1Connections.theAppl.StatusBar.SetText("Table: " & oUserTablesMD.TableName & " was added successfully", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success)
                    End If
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
                    oUserTablesMD = Nothing
                    GC.Collect()
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
    Thanks
    Regards
    Gorge

    Hi Gorge,
    The "Ref count error..." usually occurs in case of Meta Data objects not being properly cleared.  And yes, you have got the error in the right place, generally while creating tables / fields / UDOs.  For this, you just need to clear the Meta Data object (At times even DI objects like Record Set) once they are used.
    Eg: Release these objects in the below way in a Finally Block.
    System.Runtime.InteropServices.Marshal.ReleaseComObject(oRecordSet);
    Hope this helps.
    Regards,
    Satish

Maybe you are looking for

  • Can i install iCloud on a drive other than C:?

    I am installing i Cloud on a Windows 7  but do not have an option of putting it any where but C drive. How can i install it to another drive? I keeep my operating system on a small partition and install all my programs to a larger partition.

  • KP06 is not allowing to post monthly planning.

    Hi , I have done configuration for KP06 to upload data from excel sheet. Configuration done. 1) created planning profile in KP65. copy 1-101 to Z1-101 and maintained monthly 1 to 12 period, 2) Assigned Profile in layout Kp34. but planing data is not

  • Documentation of XSLT Transformation

    Hi all, Is there any documentation for the XSLT Transformation? Please. Thanks.

  • What to Study to become an Designer / Architect

    Hi, This post may have nothing to do with code, but I still wanted to ask you people because I know all of you have different experiences. I have finished my studies from a polytechnic college. Found a job and worked in the UK for some time. Now I ca

  • Reports Timeout Error

    I'm executing a report and I'm getting the following error, can anyone help me ? 500 Internal Server Error org.omg.CORBA.OBJ_ADAPTER: The delegate has not been set! minor code: 0 completed: No at com.inprise.vbroker.poa.BOAImpl.deactivate_obj (BOAImp