Function Issues - Query

Hi Guys,
The below is just a query. Given are two codes for a function, when I executed the first it was giving erronous result and was taking about 2 minutes to give out that error but when I made the changes in second and executed it worked perfectly fine and that too withing 2 secs.
Code 1:
CREATE OR REPLACE FUNCTION BUSOBJ.pos_countrycode_lookup (
   record_locator      VARCHAR2,
   pnr_creation_date   VARCHAR2
   RETURN VARCHAR2
IS
   pnr_id                  NUMBER;
   city_code               VARCHAR2 (10 BYTE);
   country_code            VARCHAR2 (10 BYTE);
   record_loc              VARCHAR2 (10 BYTE);
   pnr_create_dt           DATE;
   org_booking_city        VARCHAR2 (10 BYTE);
   org_booking_agent       VARCHAR2 (10 BYTE);
   org_booking_city_code   VARCHAR2 (10 BYTE);
   rec_iso_country_code    VARCHAR2 (10 BYTE);
   gds_country_code        VARCHAR2 (10 BYTE);
   is_country_code         VARCHAR2 (10 BYTE);
BEGIN
   BEGIN
      SELECT   ph.pnr_id_pk, ph.record_locator, ph.pnr_creation_date_time,
               ph.original_booking_city, ph.original_booking_agent,
               ph.original_booking_city_code, pd.rec_loc_iso_country_code,
               pd.gds_location_country_iso, ph.iso_country_code
          INTO pnr_id, record_loc, pnr_create_dt,
               org_booking_city, org_booking_agent,
               org_booking_city_code, rec_iso_country_code,
               gds_country_code, is_country_code
          FROM pnr_hdr ph, pos_details pd
         WHERE ph.record_locator = record_locator
           AND TRUNC (ph.pnr_creation_date_time) = pnr_creation_date
           AND ph.pnr_id_pk = pd.pnr_id_fk
           AND ph.delete_flag IS NULL
           AND ROWNUM = 1
      GROUP BY ph.pnr_id_pk,
               ph.record_locator,
               ph.pnr_creation_date_time,
               ph.original_booking_city,
               ph.original_booking_agent,
               ph.original_booking_city_code,
               pd.rec_loc_iso_country_code,
               pd.gds_location_country_iso,
               ph.iso_country_code;
   END;Code 2:
CREATE OR REPLACE FUNCTION BUSOBJ.pos_countrycode_lookup (
   record_locator      VARCHAR2,
   pnr_creation_date   VARCHAR2
   RETURN VARCHAR2
IS
   pnr_id                  NUMBER;
   city_code               VARCHAR2 (10 BYTE);
   country_code            VARCHAR2 (10 BYTE);
   record_loc              VARCHAR2 (10 BYTE);
   pnr_create_dt           DATE;
   org_booking_city        VARCHAR2 (10 BYTE);
   org_booking_agent       VARCHAR2 (10 BYTE);
   org_booking_city_code   VARCHAR2 (10 BYTE);
   rec_iso_country_code    VARCHAR2 (10 BYTE);
   gds_country_code        VARCHAR2 (10 BYTE);
   is_country_code         VARCHAR2 (10 BYTE);
   pnr_locator             VARCHAR2 (10 BYTE);
   pnr_date                VARCHAR2 (20 BYTE);
BEGIN
   pnr_locator := record_locator;
   pnr_date := pnr_creation_date;
   BEGIN
      SELECT   ph.pnr_id_pk, ph.record_locator, ph.pnr_creation_date_time,
               ph.original_booking_city, ph.original_booking_agent,
               ph.original_booking_city_code, pd.rec_loc_iso_country_code,
               pd.gds_location_country_iso, ph.iso_country_code
          INTO pnr_id, record_loc, pnr_create_dt,
               org_booking_city, org_booking_agent,
               org_booking_city_code, rec_iso_country_code,
               gds_country_code, is_country_code
          FROM pnr_hdr ph, pos_details pd
         WHERE ph.record_locator = pnr_locator
           AND TRUNC (ph.pnr_creation_date_time) = pnr_date
           AND ph.pnr_id_pk = pd.pnr_id_fk
           AND ph.delete_flag IS NULL
           AND ROWNUM = 1
      GROUP BY ph.pnr_id_pk,
               ph.record_locator,
               ph.pnr_creation_date_time,
               ph.original_booking_city,
               ph.original_booking_agent,
               ph.original_booking_city_code,
               pd.rec_loc_iso_country_code,
               pd.gds_location_country_iso,
               ph.iso_country_code;
   END;Please can you gurus suggest what mistake I was making in the first piece of code.
Cheers,
Shaz
Edited by: BluShadow on 20-Feb-2012 16:07
Added {noformat}{noformat} tags for readability.  Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

First statement
WHERE ph.record_locator                      = record_locator
AND TRUNC (ph.pnr_creation_date_time) = pnr_creation_datedifferent from second statement
WHERE ph.record_locator                     = pnr_locator
AND TRUNC (ph.pnr_creation_date_time) = pnr_dateAlso , you have other issues where you are potentially disabling an index by
using
TRUNC (ph.pnr_creation_date_time)  and the fact that you have and ROWNUM=1 in your statements is a possible cause for concern. in 99% of cases this means your query is not restrictive enough.
It needs investigation.
Also , its possible that your second ran query ran quickly because your first query had already retrieved a lot of the data into the required blocks, thus only requiring a logical read where the first query would have required physical reads.
You would need to do an explain plan on the queries to see if this is the case

Similar Messages

  • Function returning query takes more time to run in Apex4.0

    Hi All,
    I created a report using function returning query. The function returns query based the parameters which returns dynamic columns. When I run the query in sql developer the query generates and returns the result in 3mins. But in apex it takes maximum of 35mins to return.
    The query will return around 10000 rows.
    Is it a performance issue in the query or in Apex?can anyone please help
    Regards
    Raj

    RajEndiran wrote:
    Hi Roel,
    Thanks much for your suggestion. I run in TOAD and got the result as
    Row 1 of 500 fetched so far in 3.31 minutes which means it queried for 500 records alone ? is that not the actual time taken to run the fulll query?That reflects the time to return the first 500 records...
    Please suggest.With all the best will in the world, if I was your user and I had to wait 3 minutes for the page to refresh, I'd steadily lose the will to live!
    As this is primarily an SQL tuning question, have a look at this message in the FAQ thread in the {forum:id=75} forum:
    {message:id=9360003}
    That should give you some pointers on the right approach.

  • When using TODATE function MDX query is not correctly generated

    Essbase 9.3.1.2 and OBIEE 10.1.3.4.1.
    When using TODATE function MDX query is not correctly generated.
    This leads to unexpected values not only on cumulative columns in report (generated with TODATE), but also other columns (calculated with AGO function or directly read from cube) have incorrect values.
    The problem occurs when you filter on a column that is not in the select list. If you filter on just one level of dimension, results are fine. You can filter on multiple dimensions as long as you filter on just one level of each dimension.
    If you filter on two or more levels of one dimension, than results are not correct. In some cases results for TODATE column are all zeros, in some cases it is a random value returned by Essbase (same random value for all rows of that column), and in some cases BI Server returns an error:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. Essbase Error: Network error [10054]: Cannot Send Data (HY000).
    Here is generated MDX code:
    With
    set [Grupe proizvoda2] as '{[Grupe proizvoda].[N4]}'
    set [Grupe proizvoda4] as 'Generate([Grupe proizvoda2], Descendants([Grupe proizvoda].currentmember, [Grupe proizvoda].Generations(4), leaves))'
    set [Segmentacija2] as '{[Segmentacija].[RETAIL]}'
    set [Segmentacija4] as 'Filter(Generate({[Segmentacija2]}, Descendants([Segmentacija].currentmember, [Segmentacija].Generations(4),SELF), ALL), ([Segmentacija].CurrentMember IS [Segmentacija].[AFFLUENT]))'
    set [Vrijeme3] as '{[Vrijeme].[MJESEC_4_2009]}'
    member [Segmentacija].[SegmentacijaCustomGroup]as 'Sum([Segmentacija4])', SOLVE_ORDER = AGGREGATION_SOLVEORDER
    member [Accounts].[MS1] as '(ParallelPeriod([Vrijeme].[Gen3,Vrijeme],2,[Vrijeme].currentmember), [Accounts].[Trosak kapitala])'
    member [Accounts].[MS2] as '(ParallelPeriod([Vrijeme].[Gen3,Vrijeme],1,[Vrijeme].currentmember), [Accounts].[Trosak kapitala])'
    member [Accounts].[MS3] as 'AGGREGATE({PeriodsToDate([Vrijeme].[Gen2,Vrijeme],[Vrijeme].currentmember)}, [Accounts].[Trosak kapitala])'
    select
    { [Accounts].[Trosak kapitala],
    [Accounts].[MS1],
    [Accounts].[MS2],
    [Accounts].[MS3]
    } on columns,
    NON EMPTY {crossjoin ({[Grupe proizvoda4]},{[Vrijeme3]})} properties ANCESTOR_NAMES, GEN_NUMBER on rows
    from [NISE.NISE]
    where ([Segmentacija].[SegmentacijaCustomGroup])
    If you remove part with TODATE function, the results are fine. If you leave TODATE function, OBIEE returns an error mentioned above. If you manually modify variable SOLVE_ORDER and set value to, for example, 100 instead of AGGREGATION_SOLVEORDER, results are OK.
    In all cases when this variable was modified in generated MDX, and query manually executed on Essabse, results were OK. This variable seems to be the possible problem.

    Hi,
    Version is
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE    10.2.0.5.0      Production
    TNS for 64-bit Windows: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    Sorry, in my last post i forgot to mention that i already created a function based index but still it is not using because, there is a UNIQUE constraint on that column.
    Thanks

  • Function issue of Cross-Reference

    Hi,
    thanks for your attention on this topic.
    there is function issue of Cross-Reference.
    when click the Cross-Reference after re-installed the software (adobe Framemaker 7.10), the function is not working. please kindly check the screenshots below:
    Error message below:
    Please help to check this issue.
    software: Adobe Framemaker 7.10
    System: windows xp sp3
    thanks in advance for your support .
    Message was edited by: Lu Steven

    Fire the error log off to the e-mail address indicated in the error message and then contact Adobe Support.

  • How to create user function in Data Functions in Query Designer?

    Could someone tell me how to create user function in Data Functions in Query Designer?
    I mean function like "NDIV0" in Data Functions.
    SAP BW 3.x.
    Query Designer (SAP BW 3.x)

    Hi check the following URL, it gives how to add in Formulas in formula Builder, not in DataFunctions.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f095592f-42f7-2a10-6ab1-c836a559b48f
    Thanks
    Reddy

  • How to create search function (af:query) using method in java

    hi All..:)
    i got problem with search custom (af:query), how to create search function/ af:query using method in java class?
    anyone help me....
    thx
    agungdmt

    Hi,
    download the ADF Faces component demo sources from here: http://www.oracle.com/technetwork/testcontent/adf-faces-rc-demo-083799.html It also has an example for creating a custom af:query model
    Frank

  • How send parameter in prerender() function for query

    Sir I use requestbean for sending data to next page
    Because want use this parameter in query
    I get data as per this parameter
    But when I call next page not pass parameter value to next page and query use blank parameter
    I write code in prerender()
    See my code
    public void prerender() {
    try {
    getSessionBean1().getTripRowSet().setObject( 1, parameter1..getValue());
    tripDataProvider.refresh();
    } catch (Exception e) {
    error("Cannot switch to person " + “no record “);
    log("Cannot switch to person " + “no record , e);
    Please give me idea how I send my parameter in prerender() function for query
    Thank’s
    aamir

    sir i try SessionBean but same as result
    sir you see my full problem
    I use studio creator
    I create two page first for sending data to other page such as user login page
    I add property in SessionBean, RequestBean and bind to data with my user name textfield
    and in next page I bind to data with other textfield
    after this I try to use this textfield use in
    public void prerender() {  
    try {
    getSessionBean1().getChartofaccRowSet().setObject(1, textfield1.getValue());
    chartofaccDataProvider.refresh();
    } catch (Exception e) {
    error("Cannot switch to person " + �noooo�t);
    log("Cannot switch to person " + �noooo�, e);
    In this line I use that textfiled that bind to data form login page
    getSessionBean1().getChartofaccRowSet().setObject(1, textfield1.getValue());
    but sir this public void prerender() {   function t not get textfield1 value in this function textfield give me null value
    but when page complete run then show value in textfield
    it mean this public void prerender() { function run befor  SessionBean, RequestBean and not get SessionBean, RequestBean value
    please give me idea how I pass value in public void prerender() { function form other page and I use this value in query
    such as example
    getSessionBean1().getChartofaccRowSet().setObject(1, textfield1.getValue());
    this is my sessionbean query
    SELECT ALL FNET.CHARTOFACC.PARENT,
    FNET.CHARTOFACC.CHILD,
    FNET.CHARTOFACC.ACCID,
    FNET.CHARTOFACC.TITLE,
    FNET.CHARTOFACC.CAMPID,
    FNET.CHARTOFACC.ACTIVE,
    FNET.CHARTOFACC.FSTATUS,
    FNET.CHARTOFACC.COMHEADID,
    FNET.CHARTOFACC.FIX_VARIABLE,
    FNET.CHARTOFACC.VARI_PER
    FROM FNET.CHARTOFACC
    WHERE FNET.CHARTOFACC.CAMPID = ?
    please give me idea
    thank�s
    aamir
    SELECT ALL FNET.CHARTOFACC.PARENT,
    FNET.CHARTOFACC.CHILD,
    FNET.CHARTOFACC.ACCID,
    FNET.CHARTOFACC.TITLE,
    FNET.CHARTOFACC.CAMPID,
    FNET.CHARTOFACC.ACTIVE,
    FNET.CHARTOFACC.FSTATUS,
    FNET.CHARTOFACC.COMHEADID,
    FNET.CHARTOFACC.FIX_VARIABLE,
    FNET.CHARTOFACC.VARI_PER
    FROM FNET.CHARTOFACC
    WHERE FNET.CHARTOFACC.CAMPID = ?

  • Workflow notification with link and Form open functionality issue

    Hi All,
    In GLBATCH workflow, Request Approval from Approver message we need a new link 'View Journal' avaliable. Once user click on it GLXJEENT form should be opened with GLXIQJRN function (with query only mode, that mean no New Jouranl or batch option)
    We could able to do this. Created a attribute of form type and assigned below vlaues with defulat as constant
    GLXIQJRN:AUTOQUERY_LEVEL=BATCH AUTOQUERY_COORDINATION=INITIAL AUTOQUERY_CRITERIA=&BATCH_ID
    The problem here is, it is not auto populating the batch name in that query form
    I tried lot of ways, but no use.
    Can anyone please help me in this. We need auto population of batch name in the Batch Name field.

    Try by defining the message attribute holding the link to the framework region. Then, once the notification has been created (sent) call WF_NOTIFICATIONS.SetAttrText to set the value of the region in that attribute value.
    Regards,
    Alejandro

  • Select function issue

    Hello;
    I am trying to write a little nav using a select menue. This page is a dynamic page, you can only get to it when there is an URL.ID, if there is not one, it kicks you back to the page that spawns the details page. I have it locked down pretty well with the url.ID, I added the select nav on the detail page so people won't have to go back to the main page for the list of records in that part of the db, and they won't have to cycle through number 1-12 to find a record they want to pull up.I have 2 queries running this. I will comment it out and mainly focus on the select function.
    This is the MAIN query, this one runs the page and outputs the info for the details of the records I am bring up. This works fine from the main page link using url.id
    <cfquery name="GetRecordevent" datasource="#APPLICATION.dataSource#">
    SELECT events.display AS ViewField1, events.title AS ViewField2, events.eventDate AS ViewField3, events.eventTime AS ViewField4, events.location AS ViewField5, events.contact AS ViewField6, events.phone AS ViewField7, events.fax AS ViewField8, events.email AS ViewField9, events.URL AS ViewField10, events.sponsor AS ViewField11, events.Body AS htmlList, events.ID AS ID
    FROM events
    WHERE events.ID =<cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer">
    </cfquery>
    now this is the tag that locks down the detail page:
    <cfif (isDefined ("URL.ID")) OR (isDefined ("value.id"))>
    they get the info on this page
    <cfelse>
    <cflocation url="index.cfm" addtoken="no">
    </cfif>
    this is the select function and query that populates it with the titles of records and the id
    <CFQUERY name="cata" datasource="#APPLICATION.dataSource#" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
    SELECT events.title AS ViewField2, events.ID AS ID
    FROM events
    </CFQUERY>
    <cfform Name="eventnav" method="post" Action="detail.cfm?value=#ID#">
         <select name="ID" size="1" class="selectstyle" onChange="eventnav.submit();">
         <option value=""> --Select an Event-- </option>
             <CFOUTPUT query= "cata">
             <option value="#ID#">#ViewField2#</option>
             </CFOUTPUT>
         </select>
    </cfform>
    now my query is not recognizing the value.id in the url from the select function action part of the form. I tried adding a AND statement and changed it to an OR statement, neither one works. What do I need to do to either change the select function to match a url.id or add to my main query that the select function needs to pull a record?I'm a little confused, my lockdown works as it is with teh OR in it. But my main query is not liking what I am doing.Can anyone help me figure out how to make this work properly?Thank you.Codemonger

    CFmonger wrote:
    <cfform Name="eventnav" method="post" Action="detail.cfm?value=#ID#">
    method="post" means that the data will be submitted as post data in the request which will populate the FORM structure which is different from the URL structure that comes from get data in a request.
    The fastest way to fix this would be to change the method parameter to "get" in your cfform tag.
    There are also frameworks out there that blend the form and url scopes together so that you do not have to worry about which the data came from.  Fusebox is one such framework.  But doing something like that would be a lot of re-engineering if you have a lot of existing code.
    Otherwise you could work your logic to look for the ID value in either the URL or the FORM scopes.
    P.S. the ?value=#ID# I just noticed in the action parameter will be populated with the current ID on the page, not the new ID selected by the user from the select control.  So this form is going to submit both POST and GET data with ID values, but those values will be distinct and often different.

  • Functional Issues w/ IOS7

    Depending on how this discussion board works, I will attempt to update functional issues with this operating system.
    9/21/13: Alarm:  Setting the alarm is rather akward, the numbers are too rigid, fine, and small.  I feel the numbers being larger would be more user friendly.
    9/21/13 Calendar:  Previous version was superior in certain ways.  Shading out a part of the day which you typically don't use (ex:  1am-5:30am) would be great.  I feel lost in this update, it does not feel refined.  Please allow me to send an appointment through imessage already as well!

    Tell Apple.
    http://www.apple.com/feedback/iphone.html

  • Forum for functional issue

    Hi All!
    Is there any forum related to functional issues in SD and MM.Please do forward me the names if there are any.
    Regards
    Pavan

    Check these
    http://www.sapfans.com/
    http://www.erpfans.com/
    http://www.sap.com/community/default.epx?logonStatusCheck=0 (Login required)
    Regards,
    Vikas Madaan

  • SGD 4.5 Desktop Functionality Issue

    I've come across an odd functionality issue on SGD 4.5. When I start "My Desktop" everything works fine. However if I start a new Full JDS Desktop session on another server, the JDS session doesn't appear to load correctly. New windows automatically open in the upper left corner and can't be moved. If I close both JDS Desktop sessions and open the other system first, then "My Desktop" session doesn't open windows properly. Has anyone come across this? It's not to big of deal right now, but it might become more of an issue when more users start using our SGD instance.
    Adam

    @JRoesler :
    The script for installing the users during installation when the users are not created is included some version before the 4.50.907
    The SGD version here is only 1 minor version before the latest release.
    @aspenhedge:
    If I look into the rpm (for Linux install) I don't see a check for a valid shell. It does however try to 'su' into those accounts. I might be wrong in this one.
    Can you manually use 'su ttaserv' and 'su ttasys' without any problem? Do these users have a valid home-dir for example.
    - Remold

  • Issues using SUM Function in query

    I have pasted two queries Query1 (calculating counts for total_ships and ships_released) and Query2 (calculating the two same counts and then calculating SUM for total_shipments and I am having problem in this)
    Query 1:
    select  b.loc , b.week, b.vvalue2, b.Total_ships, nvl(a.up_date,'None') as datee , nvl( a.ships_rel_total,0) as Total_released
    from (
          SELECT l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD') as up_date ,  count(distinct s.ship_id ) as ships_rel_total
          FROM ship s, loct l,
             ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by l.loc , sr1.vvalue1, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD')
          ) A,
    ( SELECT distinct l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , count(s.ship_id ) as Total_Ships
          FROM ship s, loct l,
              ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by c.loc , c.week , c.vvalue2  ) B
    where a.loc (+) = b.loc
    and a.vvalue2  (+) = b.vvalue2
    order by b.loc, b.week , b.vvalue2,a.up_date; Query 1 Output:
    *OUTPUT*
    LOC         WEEK          VALUE2        TOTAL_SHIPS       DATEE         TOtAL_SHIPS_RELEASED
    AA          111              BB              12                  10-05-12            2
    AA          111              BB              12                  11-05-12            4
    AA          111              CC              2                    14-05-12            1Then I added sum function for total_ships and its not giving me result what I need :(
    Query 2:
    select  b.loc , b.week, b.vvalue2, b.sum_ships, nvl(a.up_date,'None') as datee , nvl( a.ships_rel_total,0) as Total_released
    from (
          SELECT l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD') as up_date ,  count(distinct s.ship_id ) as ships_rel_total
          FROM ship s, loct l,
             ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by l.loc , sr1.vvalue1, sr.vvalue2 , to_char(ss.udate, 'YYYY-MM-DD')
    ) A,
    ( Select  c.loc, c.week , c.vvalue2 ,  sum(c.total_ships) sum_ships 
    from
        ( SELECT distinct l.loc  , sr1.vvalue1 as Week, sr.vvalue2 , count(s.ship_id ) as Total_Ships
          FROM ship s, loct l,
              ship_num sr1,  ship_num sr, ship_stat ss, ship_stat ss1
          WHERE ......
          Group by l.loc , sr1.vvalue1 , sr.vvalue2  ) C
    Group by c.loc , c.week , c.vvalue2  ) B
    where a.loc (+) = b.loc
    and a.vvalue2  (+) = b.vvalue2
    order by b.loc, b.week , b.vvalue2,a.up_date;  my query is giving me this :(
    Query 2 Output:
    LOC         WEEK          VALUE2        *SUM_SHIPS*       DATEE         TOtAL_SHIPS_RELEASED
    AA          111                BB              26                 10-05-12            2
    AA          111                BB              26                 11-05-12            4
    AA          111                CC              26                 14-05-12            1
    But I need a result like this:
    LOC         WEEK          VALUE2        SUM_SHIPS       DATEE         TOtAL_SHIPS_RELEASED
    AA          111                BB              14              10-05-12            2
    AA          111                BB              14              11-05-12            4
    AA          111                CC              14              14-05-12            1

    Hi,
    It sounds like you have a Fan Trap , where a one-to-many relationship is causing some items to be counted many times.
    The usual solution is to compute the aggregates before doing the one-to-many join. Analytic functions may make this simpler.
    Sorry, I can't show you exactly how to do it without the exact data.
    Post CREATE TABLE and INSERT statements for all tables involved, and also post the results you want from that data (if different from what you've already posted).
    Explain, using specific examples, how you get those results from that data.
    Simplify the problem as much as possible. If the problem only concerns the total_ships column, then only post the data needed to compute total_ships. This includes all the columns involved in the joins and GROUP BY clauses.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Function issue:  inconsistent datatypes?

    Hi all.
    I'm having an issue with a function that converts coordinates to a spatial data type.
    My database version is:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Here's my package that I'm using
    create or replace package make_geometry
    as
                function get_geometry_from_coords (p_coords in clob  )
              return sdo_geometry;
    end;
    create or replace package body make_geometry
    as
              function get_geometry_from_coords (p_coords in clob)
              return sdo_geometry
              is
                 v_geometry sdo_geometry;
              begin
                 --with t as (select p_coords coords from dual)
              select MDSYS.SDO_GEOMETRY(2003,8307,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1)
                                  ,cast(multiset(
                                      select ordset
                                     from (
                                            select regexp_substr( regexp_replace(
                                                                                replace(p_coords,chr(10))
                                                                                 ,' {1,}',',')
                                                                  ,'[^,]+',1,level)  ordset
                                                  ,rownum rn
                                              from dual
                                                               connect by level <= length(regexp_replace(regexp_replace(
                                                                                                   replace(p_coords,chr(10))
                                                                                                   ,' {1,}',','),'[^,]+')) + 1
                                            where mod(rn,3) <> 0
                        ) as sdo_ordinate_array))
                  into v_geometry
                  from dual;
                  return v_geometry;
              end;
    end;
    /basically, it takes a list of coordinates, in the following format:
    with t as (select '130.88214073599997,-12.377589935499998,0 130.88189276799997,-12.378437734999997,0 130.88164895999998,-12.379271400499997,0 ' coords from dual)replaces the spaces with commas and splits the resultant string by comma, then removes the third coordinate in each set (sets delimited by spaces in above example) and converts the result to sdo_geometry type.
    This logic is not where my problem is occurring
    If I run the query found in the package separately, it works fine:
    SQL> with t as (select '130.88214073599997,-12.377589935499998,0 130.88189276799997,-12.378437734999997,0 130.88164895999998,
    -12.379271400499997,0 ' coords from dual)
      2            select MDSYS.SDO_GEOMETRY(2003,8307,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1)
      3                                ,cast(multiset(
      4                                    select ordset
      5                                   from (
      6                                          select regexp_substr( regexp_replace(
      7                                                                              replace(coords,chr(10))
      8                                                                               ,' {1,}',',')
      9                                                                ,'[^,]+',1,level)  ordset
    10                                                ,rownum rn
    11                                            from t
    12                                                             connect by level <= length(regexp_replace(regexp_replace(
    13                                                                                                 replace(coords,chr(10))
    14                                                                                                 ,' {1,}',','),'[^,]+')) +
    1
    15                                                               )
    16                                          where mod(rn,3) <> 0
    17                      ) as sdo_ordinate_array))
    18                from dual;
    MDSYS.SDO_GEOMETRY(2003,8307,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),CAST(MULTISET(SELECTORDSETFROM(SELECTREGEXP_SUBSTR(REGE
    XP_REPL
    SDO_GEOMETRY(2003, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(130.882141, -12.37759, 130.881893, -12.378
    438, 13
    0.881649, -12.379271, NULL))but if I call the function:
    SQL> with t as (select '130.88214073599997,-12.377589935499998,0 130.88189276799997,-12.378
    -12.379271400499997,0 ' coords from dual)
      2  select make_geometry.get_geometry_from_coords(coords)
      3    from t;
    select make_geometry.get_geometry_from_coords(coords)
    ERROR at line 2:
    ORA-00932: inconsistent datatypes: expected NUMBER got CLOB
    ORA-06512: at "HR.MAKE_GEOMETRY", line 13If I change the package to expect varchar2 the above example coordinate list works fine, but obviously that doesn't work when the coordinate list exceeds 4000 characters.
    any thoughts?

    not sure that is the problem:
    SQL> create table foo (mr_clob clob);
    Table created.
    SQL>
    SQL> insert into foo values ('testing'||chr(10)||'testing');
    1 row created.
    SQL>
    SQL> select replace(mr_clob,chr(10),'blah') from foo;
    REPLACE(MR_CLOB,CHR(10),'BLAH')
    testingblahtesting
    1 row selected.

  • Filter function issue

    Hi ,
    I am trying to calculate the count by using filter function like this for two different condition
    FILTER(count(distinct "trade"."issue") USING ("block"."path_id" = 10))
    FILTER(count(distinct "trade"."issue") USING ("block"."path_id" = 20))
    but is giving the same result as count(distinct "trade"."issue") . So , the filter condition is not getting applied, while in database , i am getting the different result . Please suggest .

    Hi,
    Check if "trade" and "block" are joined and the content level settings are done appropriately. Verify by creating an analysis for "issue" and "path_id" and make sure that query picks up both tables. Resolve any issues that you see here.
    Thanks,
    Rajesh Gurram

Maybe you are looking for