SQL count(*) return a wrong result

Hi all, i've got 2 table F_1 and F_2. I also have a view VW based on the previous table that create the join clause.
If i execute
select * from
F_1   F_1,
VW VW,
F_2 F2
where
F_1.SEQ_LINE = VW.LINEA
AND
TO_NUMBER(VW.TESTA) = TO_NUMBER(F_2.SEQ_LINE)
i obtain 506 rows (the correct result). If i execute
select count(*) from
F_1   F_1,
VW VW,
F_2 F2
where
F_1.SEQ_LINE = VW.LINEA
AND
TO_NUMBER(VW.TESTA) = TO_NUMBER(F_2.SEQ_LINE)
the result is 0. Any idea?
Thanks, DecaXD

Hi all, TO_NUMBER was a copy paste error.
The table (dummy data) is
CREATE TABLE "F1"
(     "C1" VARCHAR2(5),
     "SEQ_LINE" NUMBER(8,0)
-- Records of F1
INSERT INTO "F1" VALUES ('aaa', '1');
INSERT INTO "F1" VALUES ('bbb', '4');
INSERT INTO "F1" VALUES ('ccc', '6');
CREATE TABLE "D2"
(     "C1" VARCHAR2(5),
     "SEQ_LINE" NUMBER(8,0)
-- Records of F2
INSERT INTO "F2" VALUES ('aaa1', '2');
INSERT INTO "F2" VALUES ('aaa2', '3');
INSERT INTO "F2" VALUES ('bbb1', '5');
INSERT INTO "F2" VALUES ('ccc1', '7');
The view is
select F2.SEQ_LINE LINEA ,max(F1.SEQ_LINE) TESTA from F1,F2
where F2.SEQ_LINE > F1.SEQ_LINE
group by F2.SEQ_LINE
ORDER BY 1,2

Similar Messages

  • SQL Expression returning too many results

    I am trying to display the value of a field in one table as a caption in the report header. This  caption is above a u2018descriptionu2019 field in the details section. When I run my report, I get  the description field displaying 832 times; which is the number of rows found in my caption table. Here is the structure of the two tables:
    Table 1: Code, Description
    Table 2: Table, Name, Field Name, Caption
    Here are the SQL Expressions that I have tried:
    (SELECT Caption FROM Table2
        WHERE Table2.FieldName='Description'
              AND Table2.TableName='Code')
    (SELECT DISTINCT Caption FROM Table2
        WHERE Table2.FieldName='Description'
              AND Table2.TableName='Code')
    And
    (SELECT TOP 1 Caption FROM Table2
        WHERE Table2.FieldName='Description'
              AND Table2.TableName='Code')
    If I run these directly in my Db, I get correct results. If in Crystal, incorrect results. I have tried the following suppress on the Details: Table1.Code= previous (Table1.Code) which works UNLESS I have any summaries. Once I include a summary, my total ALWAYS factors in the suppressed, duplicate records.
    I have now moved to try using parameters and a sub report for each caption; however my existing reports have sub reports that also need caption changes and I am not aware of a way to add a subreport to a subreport
    Any ideas?

    can you use select distinct on all the queries,
    crystal tends to duplicate
    create a group for your distinct value
    place the records in the group header and it will return the first unique value it hits.

  • Simple Query with subquery returns the 'wrong' result

    DB version: 11.2
    We created about 27 schemas in the last 4 days. The below query confirms that.
    SQL > select username, created from dba_users where created > sysdate-4;
    USERNAME                       CREATED
    MANHSMPTOM_DEV_01              12 Jul 2012 11:55:16
    PRSM01_OAT_IAU                 13 Jul 2012 01:51:03
    F_SW                           11 Jul 2012 17:52:42
    FUN_CDD_HK_SIT                 09 Jul 2012 15:33:57
    CEMSCOMPTOM_UAT_01             12 Jul 2012 11:43:45
    STORM02_OAT_IAU                13 Jul 2012 02:06:29
    27 rows selected.  -------------> Truncated outputFrom DBA_TS_QUOTAS.max_bytes column , we can determine the space quota allocated for a user/schema
    SQL > desc dba_ts_quotas
    Name                                      Null?    Type
    TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
    USERNAME                                  NOT NULL VARCHAR2(30)
    BYTES                                              NUMBER
    MAX_BYTES                                          NUMBER
    BLOCKS                                             NUMBER
    MAX_BLOCKS                                         NUMBER
    DROPPED                                            VARCHAR2(3)So, I wanted to see the allocated space for the users created in the last 4 days. The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !
    select username, tablespace_name, max_bytes/1024/1024 quotaInMB
    from dba_ts_quotas
    where username in (select username from dba_users where created > sysdate-4);Any idea why ? I know it is not a bug with oracle. Its just I haven't been eating fish lately.

    Hi,
    J.Kiechle wrote:
    So, I wanted to see the allocated space for the users created in the last 4 days.DBA_TS_QUOTAS doesn't give the allocated space but rather the maximum allowed for a given user.
    J.Kiechle wrote:
    The below query should return only 27 records because the subquery returns only 27 records. Instead it returned 66 records !What if your user John has Quotas on 3 tablespace TBS1, TBS2 and TBS3 ?
    You cannot expect the outer query to only retrieve at most 27 rows just because the inner query returns 27 rows.
    For allocated space by tablespace for recently created users, you'd better query dba_segments. something like :select owner, tablespace_name, trunc(sum(bytes)/1024/1024) alloc_mb
    from dba_segments
    where owner in (select username from dba_users where created > sysdate - 4)
    group by owner, tablespace_name
    order by owner, tablespace_name;

  • 2 queries should return the same result (but they dont...)

    hello
    i have a following query:
    select col1,extract(year from datum) yr, COUNT(*)
    from tableA@dblink where
    DATUM between '1-jan-1985' and '31-dec-2012'
    and col2 > 100 and col2 not in ('999999')
    and TRIM(TO_CHAR(col1)) in ('0','1')
    group by col1,extract(year from DATUM);the above query returns the count: 143 982 for year 1991
    however when i put the filter directly into this year the query returns a different number: 143 917
    select col1,extract(year from datum) yr, COUNT(*)
    from tableA@dblink  where
    DATUM between '1-jan-1991' and '31-dec-1991'
    and col2 > 100 and col2 not in ('999999')
    and TRIM(TO_CHAR(col1)) in ('0','1')
    group by col1,extract(year from DATUM);please can you help me understand why is this happening and why these 2 counts are different?
    id appreciate any tips
    thanks very much
    rgds

    UserMB wrote:
    please can you help me understand why is this happening and why these 2 counts are different?
    id appreciate any tipsThis is tricky. All others of cause are right. You must compare date columns with date values.
    If you don't explicitly compare as a date value, then it might happen that a string comparison is made.
    And if that happens both of your counts would return a wrong result. For example all dates that start with
    '4' are not counted. Like '4-jan-1991'. The string '4-jan-1991' is greater then the string '31-dec-1991'. Therefore it would not be included in the count.
    I don't think this happened. But the danger is there.
    However I have a problem seeing, what the difference between your two counts can be.
    The two important parts are the date between filter and the group by condition.
    DATUM between '1-jan-1985' and '31-dec-2012'
    DATUM between '1-jan-1991' and '31-dec-1991'
    group by col1,extract(year from DATUM);The second option returns less results than the first option. Some rows must be missing because of this different filter condition.
    If this would be a text comparison then there shouldn't be a difference. Only if it is a date comparison then this could be explained.
    Here is an example:
    Dates like 31-dec-1991 17:53:14 are included in the first count+group, but not included in the second count.
    Why? Because the string '31-dec-1991' is converted into a date. This date is 31-dec-1991 00:00:00 (midnight). Everything from this day, that is not exactly on midnight is greater than this value and therefore not included in your second query.
    So as others already pointed out you need to either truncate the date or to compare it a little differently.
    select col1,extract(year from datum) yr, COUNT(*)
    from tableA@dblink 
    where DATUM >= to_date('01-01-1991','dd-mm-yyyy')
    and  DATUM < to_date('01-01-1992','dd-mm-yyyy')
    and col2 > 100 and col2 not in ('999999')
    and TRIM(TO_CHAR(col1)) in ('0','1')
    group by col1,extract(year from DATUM);This should give the same result as your first query.
    Note that I changed the month from a month name to a number. This makes it independent from national language settings. E.g. DEZ = German, DEC = American
    Edited by: Sven W. on Oct 9, 2012 2:04 PM

  • SQL History - returning wrong statement if history is sorted

    I have searched the forum and not seen anything on this, but I have been getting the wrong SQL statement returned when I select Append/Replace.
    I have statements going back to 12-Jan-06 (using 804 since 13-Jan-06, 796 since 12-Jan-06 and 715 last year), so I don't know if I have hit the aging limit or not (I think I counted 221 entries).
    It seems to me that it works out the cursor position and then returns that statement number from the history - independently of resorting the history.
    For example, if I sort from oldest to newest (based on timestamp) and then select the bottom statement (displays as newest) and Replace, I get the oldest statement in the worksheet. If I select the top statement (displays as oldest) and Replace, I get the newest statement in the worksheet.
    This is further complicated by the fact that sorting on the Timestamp is doing an alpha-numeric sort, rather than a date sort. When sorting from oldest to newest, the bottom three timestamps are (in "oldest to newest" order) are:
    1/23/06 10:58 AM
    1/23/06 9:21 AM
    1/23/06 9:31 AM
    If I then remove the sorting, the statement returned is the correct one.

    It was great to get the fix for the SQL History returning the right statement if sorted (we got it in v1184).
    However v1215 still does a text sort on the TimeStamp column rather than a date sort, so 2PM comes before 9AM, etc.
    Also, where is the format for the TimeStamp column coming from? As someone who doesn't live in the US and thinks that days should come before months in date formats (ie DD-Mon-YYYY), I am frustrated by yet another product that uses MM/DD/YY, despite my best efforts at telling it otherwise.

  • [HELP] AGO function return wrong result

    Hi, i try to implement ago function in OBIEE, but the result is not as expected. Please help me to configure Time Dimension to get this work.
    My case:
    - I have a time dimension with this configuration:
    [http://i264.photobucket.com/albums/ii176/necrombi/NEO/1-1.png]
    Time Hierarchy: Total > Year > Quarter > Month > Day
    Year:
    Primary key: Calendar_year_cal_year_code
    Chronological key: Does not define
    Quarter:
    Primary key: Calendar_quarter_description
    Chronological key: Does not define
    Month:
    Primary key: Calendar_month_description
    Chronological key: Calendar_month_description
    Day:
    Primary key: Dimension_key
    Chronological key: Day_day_code
    My ago function: AGO(expression, mywh.D_qn_thoigianDim."month", 1)
    I do not understand why i get this wrong results:
    [http://i264.photobucket.com/albums/ii176/necrombi/NEO/2.png]
    Does anyone know how to solve this?
    Edited by: 864451 on Jun 8, 2011 5:11 AM

    Hi, thanks for your reply.
    I implemented Time dimension with your recommend, and have time dimension like this:
    Time Hierarchy: Total > Year > Quarter > Month > Day
    Year:
    Primary key: Calendar_year_start_date
    Chronological key: Calendar_year_start_date
    Quarter:
    Primary key: Calendar_quarter_start_date
    Chronological key: Calendar_quarter_start_date
    Month:
    Primary key: Calendar_month_start_date
    Chronological key: Calendar_month_start_date
    Day:
    Primary key: Day
    Chronological key: Dimension_key
    And Ago function works fine with month level: AGO(expression, mywh.D_qn_thoigianDim."month", n)
    But return sum result of 12 month with: AGO(expression, mywh.D_qn_thoigianDim."year", 1)
    In my case, i just use AGO(expression, mywh.D_qn_thoigianDim."month", 12) to get year ago value. But i still don't understand clearly about OBIEE Time Serries functions.
    Thanks,
    Dung Nguyen

  • Please Help Urgent:Fast Search returning wrong result sets

    Hi All,
    We are facing below issue with fast search.
    Currently in My project  when  we are searching  for a phrase it is returning wrong result sets.
    For example if we search for “Endura”, It is returning documents related to
    Endura  as well as Centura.
    But the expected results are only Endura documents.
    When we look in to the documents we didn’t find the search term (“Endura” ) either inside document content or in its meta data.
    In order to resolve the issue we tried the below steps
    1-     
    We manually edited and saved the document, to ensure the appropriate Guid association to metadata.
    2-     
    Index reset
    3-     
    Full crawl
    But no luck  so far.
    Please help.Thanks in advance.
    Regards
    Subrat

    Subrat,
    This may be related to spellchecking or may be synonym. Spellcheck is based on indexed terms.
    The best test would be to run the queries from qrserver (13280) and then look at the spellcheck query transformations. If spellchecking is not doing it, then you must have a synonym setup .Check your keyword/synonyms from the SharePoint side. 

  • Simple query with like return wrong result

    Hi,
    I run simple query with like.
    If I use parameter I get wrong results.
    If I use query without parameter results are ok.
    My script:
    ALTER SESSION SET NLS_SORT=BINARY_CI;
    ALTER SESSION SET NLS_COMP=LINGUISTIC;
    -- drop table abcd;
    create table abcd (col1 varchar2(10));
    INSERT INTO ABCD VALUES ('122222');
    insert into abcd values ('111222');
    SELECT * FROM ABCD WHERE COL1 LIKE :1; -- wrong result with value 12%
    COL1
    122222
    *111222*
    select * from abcd where col1 like '12%'; -- result ok
    COL1
    122222
    I use Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    and query run in Oracle SQL Developer 3.1.07.

    Hi,
    welcome to the forum.
    When you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    You should specify exactly how you run your code.
    If I run this statement in SQL Plus:SQL> ALTER SESSION SET NLS_SORT=BINARY_CI;
    Session altered.
    SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC;
    Session altered.
    SQL>
    SQL> -- drop table abcd;
    SQL> create table abcd (col1 varchar2(10));
    Table created.
    SQL>
    SQL> INSERT INTO ABCD VALUES ('122222');
    1 row created.
    SQL> insert into abcd values ('111222');
    1 row created.
    SQL>
    SQL> SELECT * FROM ABCD WHERE COL1 LIKE :1;
    SP2-0552: Bind variable "1" not declared.
    SQL>
    I got this error. So I wonder how you set value 12%
    Please specify exactly how you run your test as we cannot reproduce your problem.
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SQL Server 2012 Time(7) DataType values Comparison giving wrong result. Please help

    We have a Table with StartTime and EndTime columns in Time(7) datatype, so we want to count the rows for each hour from 6 AM to 5 AM. If a record in table is as StartTime= 7 PM to EndTime = 5 AM (a shift of an employee) then the result is wrong beacause
    being time(7) datatype the EndTime(5AM)< StartTime(7PM) in 24 hours format so following query gives wrong results.
    select
    * from EmpSchedule
    where (StartTime>='19:00:00.0000000'
    OR EndTime>='19:00:00.0000000')
    Please help me out. Thanks

    DECLARE @clockIns TABLE (employeeID INT, startDateTime DATETIME, endDateTime DATETIME)
    INSERT INTO @clockIns (employeeID, startDateTime, endDateTime)
    VALUES
    (1, '2014-07-01 19:01:00.000', '2014-07-02 04:27:00.000'),
    (2, '2014-07-01 18:01:00.000', '2014-07-02 05:27:00.000'),
    (3, '2014-07-01 19:01:00.000', '2014-07-02 05:27:00.000'),
    (4, '2014-07-01 18:01:00.000', '2014-07-02 04:27:00.000')
    SELECT *
    FROM @clockIns
    WHERE datepart(HOUR,startDateTime) BETWEEN 19 AND 23
    OR datepart(HOUR,startDateTime) BETWEEN 0 AND 4
    OR datepart(HOUR,endDateTime) BETWEEN 19 AND 23
    OR datepart(HOUR,endDateTime) BETWEEN 0 AND 4
    Try this out.

  • MDX IIF returning wrong results

    Dear All,
    We are using MDX formulas with IIF statements.
    We have found that if there is no figure on the first test of the MDX then no figure is returned.
    Example MDX and data
    IIF([CATEGORY] = [BUDGET],[599003BU],IIF([CATEGORY] = [ESTIMATE],[599003ES],IIF([CATEGORY] = [FORECAST],[599003FC],[599003AC])))
                        300     599003     599003BU     599003ES     599003FC     599003AC
                        Sales     Sales growth in %     Sales growth in %     Sales growth in %     Sales growth in %     Sales growth in %
    ACTUAL     2008.JAN     Actual     JAN 2008     278,124.09               24.24     24.24     24.24
    ACTUAL     2008.DEC     Actual     DEC 2008     3,713,534.23     4.99     12.33     4.99     4.99     4.99
    In line 1 there is no data in 599003BU hence there is no data on the destination account.  In line 2 there is data on 599003BU and hence data on the destination account.
    We are using SAP BPC 5.1 on SQL Server 2005 SP3.
    Any suggestions would be appreciated.
    Regards,
    Mark

    Akim,
    Thanks for your input.  Your statement did not process as described.  I have to put "[]" round the dimension and account id's.
    What I have found is the following.  If the process comes accross an empty value it stops working at that point.
    I started with this statement.  CASE [CATEGORY] WHEN [BUDGET] THEN [599003BU] WHEN [ACTUAL] THEN [599003AC] WHEN [ESTIMATE] THEN [599003ES] WHEN [FORECAST] THEN [599003ES] ELSE [599003AC] END
    Where the MDX formula for 599003BU returns null.  Then no value is put into 599003 even if there are values in the other accounts and the category is not BUDGET.
    I have reordered the statement so that Budget is tested last I get figures for ACTUAL, ESTIMATE, and FORECAST.
    CASE [CATEGORY] WHEN [ACTUAL] THEN [599003AC] WHEN [ESTIMATE] THEN [599003ES] WHEN [FORECAST] THEN [599003ES] WHEN [BUDGET] THEN [599003BU] ELSE [599003AC] END
    This now returns more consistant results, though they are not 100% correct.
    I am going to open a message on this issue.
    Regards,
    Mark

  • Query returning wrong results - Help required.

    Hi All,
    I am having a query in which I have 10 records, 5 with stop time 1 and 5 with stop time 2.
    I have a scenario in which, I need to calculate the maximum,minimum for the records
    with stop time 1 and 2.
    What I did is, I selected all the 10 records using for loop. Within the loop
    I am trying to find the maximum and minimum. It is giving me wrong results.
    Please help me. My code is follows
    declare
         v_p1_min_stop_tm     number;
         v_p1_max_stop_tm     number;
         v_p2_min_stop_tm     number;
         v_p2_max_stop_tm     number;
    begin
         for i in(
              select
                   stop_tm
              from
                   sample_stop
              where
                   map_nbr = 16645 and
                   stop_dt = '05-sep-08'
         )loop
              if i.stop_tm = 1 then
                   select
                        min(i.stop_tm),
                        max(i.stop_tm)
                   into
                        v_p1_min_stop_tm,
                        v_p1_max_stop_tm
                   from
                        dual;
              elsif i.stop_tm = 2 then
                   select
                        min(i.stop_tm),
                        max(i.stop_tm)
                   into
                        v_p2_min_stop_tm,
                        v_p2_max_stop_tm
                   from
                        dual;
              end if;
         end loop;
         dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
         dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
         dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
         dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
    end;
    My o/p is :
    Minimum P1 stop time : 523
    Maximum P1 stop time : 523
    Minimum P2 stop time : 719
    Maximum P2 stop time : 719
    Here how can I make the data as two sets, one set with stop time 1 and
    other with stop time 2.
    Regards
    Raghu

    If the data type of stop_tm is varchar then try following
    declare
         v_p1_min_stop_tm number;
         v_p1_max_stop_tm number;
         v_p2_min_stop_tm number;
         v_p2_max_stop_tm number;
    begin
         for i in(select  stop_tm  from  sample_stop
              where
                   map_nbr = 16645 and
                   stop_dt = '05-sep-08'
              )loop
         if i.stop_tm = 1 then
              select min(to_number(i.stop_tm)), max(to_number(i.stop_tm))
                   into v_p1_min_stop_tm,v_p1_max_stop_tm
              from
                   dual;
         elsif i.stop_tm = 2 then
              select
                   min(to_number(i.stop_tm)),     max(to_number(i.stop_tm))
                   into
                   v_p2_min_stop_tm,v_p2_max_stop_tm
              from
                   dual;
         end if;
    end loop;
    dbms_output.put_line('minimum p1 stop time : '|| v_p1_min_stop_tm);
    dbms_output.put_line('maximum p1 stop time : '|| v_p1_max_stop_tm);
    dbms_output.put_line('minimum p2 stop time : '|| v_p2_min_stop_tm);
    dbms_output.put_line('maximum p2 stop time : '|| v_p2_max_stop_tm);
    end;
    / Regards
    Singh

  • WebService returning wrong result

    Hi All,
    I am trying to write a webservice but somehow getting wrong result. Not sure where i am going wrong. I am seeing following in logs -
    Request envelop -
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <Multiply xmlns="http://tempuri.org/">
    <A xsi:type="xsd:float" xmlns="">40.0</A>
    <B xsi:type="xsd:float" xmlns="">20.0</B>
    </Multiply>
    </soapenv:Body>
    </soapenv:Envelope>
    Response -
    <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><MultiplyResponse xmlns="http://tempuri.org/"><MultiplyResult>0</MultiplyResult></MultiplyResponse></soap:Body></soap:Envelope>
    This is a webservice available online url - http://samples.gotdotnet.com/quickstart/aspplus/samples/services/MathService/VB/MathService.asmx?op=Multiply
    Please HELP!!! Thanks in advance.
    -Tarun

    send this and write the results...
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <SOAP-ENV:Body>
              <m:Multiply xmlns:m="http://tempuri.org/">
                   <m:A>3.14159E0</m:A>
                   <m:B>3.14159E0</m:B>
              </m:Multiply>
         </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

  • TABLE(CAST()) function not returning the correct results in few scenarios.

    I am using TABLE(CAST()) operation in PL/SQL and it is returning me no data.
    Here is what I have done:
    1.     Created Record type
    CREATE OR REPLACE TYPE target_rec AS OBJECT
    target__id          NUMBER(10),
    target_entity_id NUMBER(10),
    dd           CHAR(3),
    fd           CHAR(3),
    code      NUMBER(10),
    target_pct      NUMBER,
    template_nm VARCHAR2(50),
    p_symbol      VARCHAR2(10),
    pm_init          VARCHAR2(3),
    target_name     VARCHAR2(20),
    targe_type     VARCHAR2(30),
    target_caption     VARCHAR2(30),
    sort_order      NUMBER (4)
    2.     Created Table type
    CREATE OR REPLACE TYPE target_arr AS TABLE OF target_rec
    3.     Created Stored procedure which accepts parameter of type target_arr and runs the Table(Cast()) function on it.
         Following is the simplified form of my procedure.
         PROCEDURE get_target_weights
         p_in_template_target IN target_arr,
         p_out_count          OUT NUMBER,
         IS
         BEGIN
              SELECT count(*) into p_out_count
         FROM TABLE(CAST(p_in_template_target AS                     target_arr)) arr;
         END;
    I am calling get_target_weights from my java code and passing p_in_template_target with 10140 records.
    Scenario 1: If target_pct in the last record is 0, p_out_count returned from the procedure is 0.
    Scenario 2: If target_pct in the last record is any other value(say 0.01), p_out_count returned from the procedure is 10140.
    Please help me understand why the Table(Cast()) is not returning the correct results in Scenario 1. Also adding or deleting any record from the test data returns the correct results (i.e. if keep target_pct in the last record as 0 but add or delete any record).
    Let me know how can I attach the test data I am using to help you debugging as I don’t see any Attach file button on Post Message screen on the forum.

    I am not able to reproduce this problem with a small data set. I can only reproduce with the data having 10140 records.
    I am not sure if this is the memory issue as adding a new record also solves the problem.
    This should not be the error because of wrong way of filling the records in java as for testing purpose I just saved the records which I am sending from java in a table. I updated the stored procedure as well to read the data from the table and then perform TABLE(CAST()) operation. I am still getting 0 as the output for scenario 1 mentioned in my last mail.
    Here is what I have updated:
    1.     Created the table target_table
    CREATE Table target_table
    target_id          NUMBER(10),
    target_entity_id NUMBER(10),
    dd           CHAR(3),
    fd           CHAR(3),
    code      NUMBER(10),
    target_pct      NUMBER,
    template_nm VARCHAR2(50),
    p_symbol      VARCHAR2(10),
    pm_init          VARCHAR2(3),
    target_name     VARCHAR2(20),
    target_type     VARCHAR2(30),
    target_caption     VARCHAR2(30),
    sort_order      NUMBER (4)
    2.     Inserted data into the table : The script has around 10140 rows. Pls let me know how can I send it to you
    3.     Updated procedure to read data from table and stored into variable of type target_arr. Run Table(cast()) operation on target_arr and get the count
    PROCEDURE test_target_weights
    IS
         v_target_rec target_table%ROWTYPE;
         CURSOR wt_cursor IS
         Select * from target_table;
         v_count NUMBER := 1;
         v_target_arr cws_target_arr:= target_arr ();
         v_target_arr_rec target_rec;
         v_rec_count NUMBER;
         BEGIN
         OPEN wt_cursor;
         loop
              fetch wt_cursor into v_target_rec; -- fetch data from table into local           record.
              exit when wt_cursor%notfound;
              --move data into target_arr
              v_target_arr_rec :=                     cws_curr_pair_entity_wt_rec(v_target_rec target_id,v_target_rec. target_entity_id,
                        v_target_rec.dd,v_target_rec.fd,v_target_rec.code,v_target_rec.target_pct,
         v_target_rec.template_nm,v_target_rec.p_symbol,v_target_rec.pm_init,v_target_rec.template_name,
         v_target_rec.template_type,v_target_rec.template_caption,v_target_rec.sort_order);
              v_target_arr.extend();
              v_target_arr(v_count) := v_target_arr_rec;
              v_count := v_count + 1;
         end loop;
         close wt_cursor;
         -- run table cast on target_arr
         SELECT count(*) into v_rec_count
         FROM TABLE(CAST(v_target_arr AS target_arr)) arr;
         DBMS_OUTPUT.enable;
         DBMS_OUTPUT.PUT_LINE('p_out_count ' || v_rec_count);
         DBMS_OUTPUT.PUT_LINE('v_count ' || v_count);
    END;
    Output is
    p_out_count 0
    v_count 10140
    Expected output
    p_out_count 10140
    v_count 10140

  • Wrong results after upgrading 10g database to 11.2.0.2.6

    Hi,
    Do anyone know, why the following query results are different?
    Not Working query:
    sql1:
    select col1 from tab1
    where col1 = (select '123' from dual)
    Working query:
    sql2:
    select col1 from tab1
    where col1 = '123';
    Both the sql1 and sql2 are returning same reseults in 10g database , but not in 11g.

    Pl post OS details along with sample outputs and explain plans from the the sql1 statement from the two databases. These MOS Docs may help also
    Things to Consider Before Upgrading to 11.2.0.2 to Avoid Poor Performance or Wrong Results [ID 1320966.1]
    Wrong Results on 11.2.0.2 with Function-Based Index and OR Expansion [ID 1264550.1]
    Wrong Results/No Rows for Sql Involving Functions in 11.2.0.2. [ID 1380679.1]
    HTH
    Srini

  • Wrong results for context search on empty element tags

    I'm using Oracle DBMS 11.1 and 11.2 and created a context index on an XML column (section group: PATH_SECTION_GROUP).
    When entering a query like
    SELECT count(*) FROM my_table t WHERE contains (t.co_xml,'hasPath(/tag1/tag2)') > 0
    I get wrong results if tag2 is an empty element tag (<tag2/>) that appears somewhere within the
    XML instance, but NOT directly under tag1.
    E.g., the following XML instance is found (but shouldn't!):
    <a>
    <tag1>bla<tag3>bla</tag3></tag1>
    <tag4>bla<tag2/></tag4>
    </a>
    This seems to happen only for empty element tags. Is this a known bug and does anybody know a workaround?
    Thanks in advance for your help!
    Roman

    I am unable to reproduce the problem. Can you provide a copy and paste of an actual run, including create table, insert data, create index, and select, as I have done below?
    SCOTT@orcl_11g> select * from v$version
      2  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE     11.1.0.6.0     Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    SCOTT@orcl_11g> create table my_table
      2    (co_xml     xmltype)
      3  /
    Table created.
    SCOTT@orcl_11g> insert into my_table values (
      2  xmltype ('<?xml version="1.0"?>
      3  <tag5>
      4    <tag1>bla<tag3>bla</tag3></tag1>
      5    <tag4>bla<tag2/></tag4>
      6  </tag5>'))
      7  /
    1 row created.
    SCOTT@orcl_11g> create index my_idx
      2  on my_table (co_xml)
      3  indextype is ctxsys.context
      4  parameters ('section group ctxsys.path_section_group')
      5  /
    Index created.
    SCOTT@orcl_11g> SELECT count(*)
      2  FROM   my_table t
      3  WHERE  contains (t.co_xml, 'hasPath (//tag1/tag2)') > 0
      4  /
      COUNT(*)
             0
    SCOTT@orcl_11g> SELECT count(*)
      2  FROM   my_table t
      3  WHERE  contains (t.co_xml, 'hasPath (//tag1/tag3)') > 0
      4  /
      COUNT(*)
             1
    SCOTT@orcl_11g>

Maybe you are looking for