Return all duplicate record

hi how can i return all duplicate records, not just the records which is duplicate, can you check my query
select c_code,facility_name,npo_registration_no,AGR.CONTRACT_NO
,ssch.name subsidy,SSCH.SUB_PROGRAMME, organisation,opex_allocation
from sms_parties par
,sms_agreements agr
,SMS_SUBSIDY_SCHEMES_VW ssch
,sms_agreement_years ayea
,sms_agreement_status asta
,sms_fyea_open_vw fyea
where par.id = agr.par_id
and agr.id = ayea.id (+)
and agr.contract_no like '%2011%'
and ayea.asta_id = asta.id (+)
and agr.ssch_id = SSCH.SSCH_ID
and npo_registration_no in (
select npo_registration_no
from sms_parties
group by npo_registration_no
having count(*) > 1
order by 1
Edited by: user603350 on 2011/08/25 5:30 PM

select *
from (
  select c_code
        ,facility_name
        ,npo_registration_no
        ,AGR.CONTRACT_NO
        ,ssch.name subsidy
        ,SSCH.SUB_PROGRAMME
        ,organisation
        ,opex_allocation
        ,row_number() over ( partition by c_code
                                      ,facility_name
                                      ,npo_registration_no
                                      ,AGR.CONTRACT_NO
                                      ,ssch.name subsidy
                                      ,SSCH.SUB_PROGRAMME
                                      ,organisation
                                      ,opex_allocation
                             order by npo_registration_no) rn
        ,count(1) over ( partition by c_code
                                      ,facility_name
                                      ,npo_registration_no
                                      ,AGR.CONTRACT_NO
                                      ,ssch.name subsidy
                                      ,SSCH.SUB_PROGRAMME
                                      ,organisation
                                      ,opex_allocation) cn
  from   sms_parties par
        ,sms_agreements agr
        ,SMS_SUBSIDY_SCHEMES_VW ssch
        ,sms_agreement_years ayea
        ,sms_agreement_status asta
        ,sms_fyea_open_vw fyea
  where  par.id             = agr.par_id
  and    agr.id             = ayea.id (+)
  and    agr.contract_no    like '%2011%'
  and    ayea.asta_id       = asta.id (+)
  and    agr.ssch_id = SSCH.SSCH_ID
where rn != 1
and   cn > 1
order by 1or
select *
from (
  select c_code
        ,facility_name
        ,npo_registration_no
        ,AGR.CONTRACT_NO
        ,ssch.name subsidy
        ,SSCH.SUB_PROGRAMME
        ,organisation
        ,opex_allocation
        ,row_number() over ( partition by npo_registration_no
                             order by npo_registration_no) rn
        ,count(1) over ( partition by npo_registration_no) cn
  from   sms_parties par
        ,sms_agreements agr
        ,SMS_SUBSIDY_SCHEMES_VW ssch
        ,sms_agreement_years ayea
        ,sms_agreement_status asta
        ,sms_fyea_open_vw fyea
  where  par.id             = agr.par_id
  and    agr.id             = ayea.id (+)
  and    agr.contract_no    like '%2011%'
  and    ayea.asta_id       = asta.id (+)
  and    agr.ssch_id = SSCH.SSCH_ID
where rn != 1
and   cn > 1
order by 1Included both as I'm not sure about your logic, but you'll have to play around with the PARTITION BY window.
UNETSTED!

Similar Messages

  • Remove all duplicate records and load into temp table

    Hi
    I have a table contains data like this.
    Emp No Designation location
    1111 SE CA
    1111 DE CT
    3456 WE NJ
    4523 TY GH
    We found that there are two duplicate records for emp no: 1111. I want to delete all duplicate records (in this case two records for emp no:1111) and load into the temp table.
    Please advice me how to do it.

    Oh look, you can search the forums...
    http://forums.oracle.com/forums/search.jspa?threadID=&q=delete+duplicates&objID=f75&dateRange=all&userID=&numResults=30

  • How can I view all duplicate records

    Hello everyone,
    My question is very straight forward. How can I view all duplicate records?
    Thanks in advance,
    Sonya

    If you want to see duplicate records in a table and how many you have you can do something like this:
    Select all of the columns in the table and look for those having more than one row. If you're more concerned
    about duplicate keys than each column individual column being the same just select the key columns.
    select c1, c2, c3,..., count(*)
    from table
    group by c1, c2, c3...
    having count(*)>1
    order by c1, c2, c3...
    If you eventually want to get rid of the duplicates you can issue:
    delete from table t1
    where rowid not in
    (select max(rowid)
    from table t2
    where t1.c1 = t2.c1
    and t1.c2 = t2.c2...)
    Where c1, c2, c3... match your column list from the select statement above.
    HTH

  • Database adapter not returning all the records

    I've taken over a BPEL from a developer who left the organization and have been having an issue during our User Acceptance Testing. We are querying a table that will return the insurance enrollment information for employee's and their dependants. When an employee change plans, or adds people, the old plan is terminated and a new once is created. When this happens there will be two records on the database to show the old plan and the new plan.
    When we run the SQL thru JDEV or SQLDeveloper, the data comes out fine. When we run it through a BPEL Database Adapter we are only getting one of the rows returned.
    I have created a small tester BPEL that is easily modified and deployed to run the same query to try multiple configurations changes within the DBAdapter. What I have found is all the records are returned when the "Return single result set" box on the DBAdapter Wizard is unchecked. When it's checked then it only returns one record for the employees with an old and a new plan.
    Can someone explain what the "Return single result set" option does, and what the impact will be if it's unchecked?

    Hello,
    In same way i am using two parent-child(header-line) tables. they have one to many relationship.
    I want to generate XML which contains multiple line items under a child elements for header elements.
    I have tried it but i am getting only one line under that child item. i am using jdev10.0.3.3.0
    can u help me please.
    -regards
    satyendra

  • Contains return all the records when the query string matches the columns

    I used the multi_column_datastore preference and created an index on three columns (item_name, description,owner_part_number). Now if I do a search:
    select * from items where contains(description, 'description') > 0;It returns all the rows in items table, but not all the rows have "description" as a word. I guess Oracle text assumes the query intends to get all the rows as the query string matches one of the column names. My question is whether Oracle Text has any preference settings to alter this behavior?
    execute ctx_ddl.create_preference('item_multi_preference', 'MULTI_COLUMN_DATASTORE');
    execute ctx_ddl.set_attribute('item_multi_preference', 'columns', 'item_name, description,owner_part_number');
    create index item_text_index on items(description) indextype is ctxsys.context filter by owner parameters('LEXER ENG_LEXER WORDLIST ENG_WORDLIST STOPLIST CTXSYS.EMPTY_STOPLIST datastore item_multi_preference MEMORY 1024M');Thanks.
    Jun Gao

    It looks like a basic_section_group fixes the problem as well, as demonstrated below and I believe a basic_section_group may be more efficient than auto_section_group.
    SCOTT@orcl_11gR2> -- recreation of problem:
    SCOTT@orcl_11gR2> drop table items
      2  /
    Table dropped.
    SCOTT@orcl_11gR2> create table items (
      2       "ITEM_NAME"             varchar2(100 byte),
      3        "ITEM_NUMBER"              varchar2(100 byte),
      4        "DESCRIPTION"              varchar2(4000 byte),
      5        "OWNER" number
      6  )
      7  /
    Table created.
    SCOTT@orcl_11gR2> begin
      2    FOR Lcntr IN 1..100
      3    loop
      4         insert into items (item_name, item_number, description, owner)
      5         values (dbms_random.string('A', 10),
      6              dbms_random.string('A', 10),
      7              dbms_random.string('L', 8) || ' '
      8              || dbms_random.string('A', 4)
      9              || dbms_random.string('A', 5)  || ' '
    10              || dbms_random.string('A', 10),
    11              dbms_random.value(1,10) );
    12    end loop;
    13  end;
    14  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    FOR Lcntr IN 1..100
      3    loop
      4         insert into items (item_name, item_number, description, owner)
      5         values (dbms_random.string('A', 10),
      6              dbms_random.string('A', 10),
      7              dbms_random.string('L', 8) || ' '
      8              || dbms_random.string('A', 4) || '111'
      9              || dbms_random.string('A', 5)  || ' '
    10              || dbms_random.string('A', 10), 1234 );
    11    end loop;
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> exec ctx_ddl.drop_preference('ENG_WORDLIST');
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    ctx_ddl.create_preference('ENG_WORDLIST', 'BASIC_WORDLIST');
      3    ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_INDEX','TRUE');
      4    ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_MIN_LENGTH',1);
      5    ctx_ddl.set_attribute('ENG_WORDLIST','PREFIX_MAX_LENGTH',10);
      6    ctx_ddl.set_attribute('ENG_WORDLIST','SUBSTRING_INDEX','TRUE');
      7    ctx_ddl.set_attribute('ENG_WORDLIST','WILDCARD_MAXTERMS', 0);
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> execute ctx_ddl.drop_preference('ENG_LEXER');
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    CTX_DDL.CREATE_PREFERENCE ('ENG_LEXER', 'BASIC_LEXER');
      3    CTX_DDL.SET_ATTRIBUTE ('ENG_LEXER', 'PRINTJOINS', '@-_');
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> execute ctx_ddl.drop_preference('items_multi_preference');
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    ctx_ddl.create_preference('items_multi_preference', 'MULTI_COLUMN_DATASTORE');
      3    ctx_ddl.set_attribute('items_multi_preference', 'columns', 'item_name, description,item_number');
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> create index items_text_index
      2  on items(description)
      3  indextype is ctxsys.context
      4  parameters
      5    ('LEXER         ENG_LEXER
      6        WORDLIST   ENG_WORDLIST
      7        STOPLIST   CTXSYS.EMPTY_STOPLIST
      8        datastore  items_multi_preference
      9        MEMORY     1024M')
    10  /
    Index created.
    SCOTT@orcl_11gR2> create index owner_idx on items (owner)
      2  /
    Index created.
    SCOTT@orcl_11gR2> exec dbms_stats.gather_table_stats (user, 'ITEMS')
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> select count(*)
      2  from   items
      3  where  contains (description, 'description') > 0
      4  /
      COUNT(*)
           200
    1 row selected.
    SCOTT@orcl_11gR2> -- correction of problem:
    SCOTT@orcl_11gR2> exec ctx_ddl.drop_section_group ('items_sec')
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> begin
      2    ctx_ddl.create_section_group ('items_sec', 'basic_section_group');
      3    ctx_ddl.add_field_section ('items_sec', 'item_name', 'item_name', true);
      4    ctx_ddl.add_field_section ('items_sec', 'description', 'description', true);
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> drop index items_text_index
      2  /
    Index dropped.
    SCOTT@orcl_11gR2> create index items_text_index
      2  on items(description)
      3  indextype is ctxsys.context
      4  parameters
      5    ('LEXER         ENG_LEXER
      6        WORDLIST   ENG_WORDLIST
      7        STOPLIST   CTXSYS.EMPTY_STOPLIST
      8        datastore  items_multi_preference
      9        MEMORY     1024M
    10        section group items_sec')
    11  /
    Index created.
    SCOTT@orcl_11gR2> select count(*)
      2  from   items
      3  where  contains (description, 'description') > 0
      4  /
      COUNT(*)
             0
    1 row selected.

  • Help: SQL list all duplicate records

    Given table B with employer_id, ssn, period and employee_name, list all records with duplicate ssn for a given period and employer_id.
    I used:
    select employer_id, ssn, employee_name, count(ssn) from B
    group by employer_id, ssn
    where period='xxx' and count(ssn)>1
    got error:
    ORA-00933: SQL command not properly ended
    checked sometime and still can not figure it out, any help will be greatly appreciated.

    select employer_id, ssn, employee_name, count(ssn) from B
    where period='xxx'
    group by employer_id, ssn,employee_name having count(ssn)>1
    Regards
    Helio Dias
    http://heliodias.com

  • How to delete duplicate records in all tables of the database

    I would like to be able to delete all duplicate records in all the tables of the database. Many of the tables have LONG columns.
    Thanks.

    Hello
    To delete duplicates from an individual table you can use a construct like:
    DELETE FROM
        table_a del_tab
    WHERE
        del_tab.ROWID <> (SELECT
                                MAX(dups_tab.ROWID)
                          FROM
                                table_a dups_tab
                          WHERE
                                dups_tab.col1 = del_tab.col1
                          AND
                                dups_tab.col2 = del_tab.col2
                          )You can then apply this to any table you want. The only differences will be the columns that you join on in the sub query. If you want to look for duplicated data in the long columns themselves, I'm pretty sure you're going to need to do some PL/SQL coding or maybe convert them to blobs or something.
    HTH
    David

  • Help with Finding Duplicate records Query

    HI,
    I am trying to write a query that will find duplicate records/cases.
    This query will be used in a report.
    So, here are the requirements:
    I need to find duplicate cases/records based on the following fields:
    DOB, DOCKET, SENT_DATEI was able to do that with the following query. The query below is able to give me all duplicate records based on the Criteria above
    SELECT      DEF.BIRTH_DATE DOB,
               S.DOCKET DOCKET,
               S.SENT_VIO_DATE SENT_DATE, COUNT(*)
    FROM SENTENCES S,
                DEFENDANTS DEF
    WHERE      S.DEF_ID = DEF.DEF_ID
    AND       S.CASE_TYPE_CODE = 10
    GROUP BY  DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE
    HAVING COUNT(*) > 1;
    //I AM GOING TO CALL THIS QUERY 'X'Now, the information to be displayed on the report: defendants Name, DOB, District, Docket, Def Num, Sent Date, and PACTS Num if possible.
    The problem that I need help on is how to combine those queries together (what I mean is a sub query). the 'X' query returns multiple values. please have a look at the comments on the query below to see what I'm trying to achieve.
    here is the main query:
    SELECT      INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
    FROM      USSC_CASES.DEFENDANTS DEF,
            USSC_CASES.SENTENCES S,
            LOOKUP.DISTRICTS DIST
    WHERE      DEF.DEF_ID = S.DEF_ID
    AND      S.DIST_ID = DIST.USSC_DISTRICT_ID
    AND     S.CASE_TYPE_CODE = 10
    AND     S.USSC_ID IS NOT NULL
    AND // what i'm trying to do is: DOB, DOCKET, SENT_DATE IN ('X' QUERY), is this possible ??
    ORDER BY DEFENDANT_NAME; thanks in advance.
    I am using Oracle 11g, and sql developer.
    if my approach doesn't work, is there a better approach ?
    Edited by: Rooney on Jul 11, 2012 3:50 PM

    If I got it right, you want to join table USSC_CASES.DEFENDANTS to duplicate rows in USSC_CASES. If so:
    SELECT  INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
      FROM  USSC_CASES.DEFENDANTS DEF,
             SELECT  *
               FROM  (
                      SELECT  S.*,
                              COUNT(*) OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE) CNT
                        FROM  USSC_CASES.SENTENCES S
               WHERE CNT > 1
            ) S,
            LOOKUP.DISTRICTS DIST
      WHERE DEF.DEF_ID = S.DEF_ID
       AND  S.DIST_ID = DIST.USSC_DISTRICT_ID
       AND  S.CASE_TYPE_CODE = 10
       AND  S.USSC_ID IS NOT NULL
      ORDER BY DEFENDANT_NAME;If you want to exclude duplicates from the query and do not care which row out of duplicate rows to choose:
    SELECT  INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
      FROM  USSC_CASES.DEFENDANTS DEF,
             SELECT  *
               FROM  (
                      SELECT  S.*,
                              ROW_NUMBER() OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE ORDER BY 1) RN
                        FROM  USSC_CASES.SENTENCES S
               WHERE RN = 1
            ) S,
            LOOKUP.DISTRICTS DIST
      WHERE DEF.DEF_ID = S.DEF_ID
       AND  S.DIST_ID = DIST.USSC_DISTRICT_ID
       AND  S.CASE_TYPE_CODE = 10
       AND  S.USSC_ID IS NOT NULL
      ORDER BY DEFENDANT_NAME;SY.

  • Remove Duplicate record

    Dear All,
    I have oracle 10g R2 On windows.
    I have table structure like below...
    ASSIGNED_TO
    USER_ZONE
    CREATED
    MASTER_FOLIO_NUMBER
    NAME
    A_B_BROKER_CODE
    INTERACTION_ID
    INTERACTION_CREATED
    INTERACTION_STATE
    USER_TEAM_BRANCH
    A4_IN_CALL_TYPE
    A5_IN_CALL_SUBTYPE
    DNT_AGING_IN_DAYS
    DNT_PENDING_WITH
    DNT_ESCALATION_STAGE_2
    DT_UPDATEI use sql loader to load the data from .csv file to oracle table and have assign the value to dt_update sysdate. Everytime i execute the sql loader control file dt_update set as sysdate.
    Sometimes problem occures while inserting data through sql loader and half row get insert. after solving the problem again i execute sql loader and hence these duplicate records get inserted.
    Now I want to remove all the duplicate records for those dt_update is same.
    Please help me to solve the problem
    Regards,
    Chanchal Wankhade.

    Galbarad wrote:
    Hi
    I think you have two ways
    first - if it is first import in your table - you can delete all record from table and run import yet one time
    second - you can delete all duplicate records and not running import
    try this script
    <pre>
    delete from YOUR_TABLE
    where rowid in (select min(rowid)
    from YOUR_TABLE
    group by ASSIGNED_TO,
    USER_ZONE,
    CREATED,
    MASTER_FOLIO_NUMBER,
    NAME,
    A_B_BROKER_CODE,
    INTERACTION_ID,
    INTERACTION_CREATED,
    INTERACTION_STATE,
    USER_TEAM_BRANCH,
    A4_IN_CALL_TYPE,
    A5_IN_CALL_SUBTYPE,
    DNT_AGING_IN_DAYS,
    DNT_PENDING_WITH,
    DNT_ESCALATION_STAGE_2,
    DT_UPDATE)
    </pre>Have you ever tried that script for deleting duplicates? I think not. If you did you'd find it deleted non-duplicates too. You'd also find that it only deletes the first duplicate where there are duplicates.
    XXXX> CREATE TABLE dt_test_dup
      2  AS
      3  SELECT
      4      mod(rownum,3) id
      5  FROM
      6      dual
      7  CONNECT BY
      8      level <= 9
      9  UNION ALL
    10  SELECT
    11      rownum + 3 id
    12  FROM
    13      dual
    14  CONNECT BY
    15      level <= 3
    16  /
    Table created.
    Elapsed: 00:00:00.10
    XXXX> select * from dt_test_dup;
            ID
             1
             2
             0
             1
             2
             0
             1
             2
             0
             4
             5
             6
    12 rows selected.
    Elapsed: 00:00:00.18
    XXXX> delete
      2  from
      3      dt_test_dup
      4  where
      5      rowid IN ( SELECT
      6                    MIN(rowid)
      7                 FROM
      8                     dt_test_dup
      9                 GROUP BY
    10                     id
    11                )
    12  /
    6 rows deleted.
    Elapsed: 00:00:00.51
    XXXX> select * from dt_test_dup;
            ID
             1
             2
             0
             1
             2
             0
    6 rows selected.
    Elapsed: 00:00:00.00

  • Identify Duplicate Records

    Post Author: chrise
    CA Forum: Crystal Reports
    I know that Crystal has the ability to identify all distinct records, thereby, getting rid of all duplicate records. However, I need to do the exact opposite and so far have been unsuccessful. Can anyone aid me in creating a report to identify only duplicate records in Crystal?
    Thanks.

    Post Author: SKodidine
    CA Forum: Crystal Reports
    Check out this KBase article.
    Retrieving duplicate records

  • Query returning too many records

    Hello,
    Below is my query. My intention is to return only the records that fail the test, but it is returning all the records that failed the test and also those that passed the Test. See below
    select pod.pur po_pfx, pod.purch po#, pod.poline line#,pod.waid,
         pod.st, pod.color,pod.po_det,
              (case when pod.po_det is null then 'color can not be Null'
         else case when trim(pod.po_det) = ''then 'color can not be Null'
                   else case when (pod.po_det) is null or trim(pod.po_det) = ''
                   and pod.pur='K'then 'Color is no good'
                        end end end) error_message     
    from s.detail pod, s.ste s
    where po_ind = '0' and po_status='0'     
    and pod.unit_id = s.unit_id
    and pod.id = s.id
    and s.type_ind ='0'

    SELECT *
    FROM (SELECT pod.pur po_pfx, pod.purch po#, pod.poline line#,pod.waid,
                 pod.st, pod.color,pod.po_det,
                 CASE WHEN TRIM(pod.po_det)IS NULL THEN 'color can not be Null'
                      WHEN pod.pur='K' THEN 'Color is no good'
                      ELSE NULL END error_message
          FROM s.detail pod, s.ste s
          WHERE po_ind = '0' and
                po_status='0' and
                pod.unit_id = s.unit_id and
                pod.id = s.id and s.type_ind ='0')
    WHERE error_message IS NOT NULLor possibly
    SELECT pod.pur po_pfx, pod.purch po#, pod.poline line#,pod.waid,
           pod.st, pod.color,pod.po_det,
           (CASE WHEN TRIM(pod.po_det)IS NULL THEN 'color can not be Null'
                 WHEN pod.pur='K' THEN 'Color is no good'
                 ELSE NULL END) error_message
    FROM s.detail pod, s.ste s
    WHERE po_ind = '0' and
          po_status='0' and
          pod.unit_id = s.unit_id and
          pod.id = s.id and s.type_ind ='0' and
          (TRIM(pod.po_det) IS NULL OR
           pod.pur = 'K')Not sure which would be more performant.
    TTFN
    John

  • How can I view duplicate records in a table?

    Hello everyone,
    My question is very straight forward. How can I view all duplicate records?
    Thanks in advance,
    Sonya

    Easy enough,
    select t1.n1,t1.c1,count(*) as "TOTAL_DUPS" from tableA t1 having count(*) > 1 group by t1.n1,t1.c1 order by count(*) desc
    Tyler

  • Duplicate records returned by db adapter

    Hi,
    We have a DB Adapter design as following.
    From a J2EE application, an invoking procedure at the adapter is triggered. This invokes the DB adapter which inturn invokes the implemetned procedure which
    returns a VARRAY.
    J2EE application is deployed on the AS 10g Protal side.
    The implemented procedure further invokes a legacy procedure which returns a Refcursor.Inside this implemetned procedure, the cursor is fetched into a
    Recortype and each element of the record type is added to an Object (of type MPLUS_MPLUS_BankGurDet_OAI_V1). Then each of this object is added to a VARRAY and this VARRAY is returned to the invoking procedure.
    The problem we face is that, in the returned the varray, there is always a duplicate of the last recored. That is if we have , say 5 records, then when we manipulate the VARRAY, there will 6 recored and the sixth record will be a duplicate of the 5th one.
    Why is this happening. I have attached the code I used and log file. This is happening for all cases where VARRAY is returned. I have attached only one set
    here.The log file attached clearly show the duplicate records.
    -- All these is defined at the Legacy system
    -- Following is a object definition used by the implemented procedure to return a collection of objects.
    TYPE MPLUS_MPLUS_BankGurDet_OAI_V1 IS OBJECT (
    AG_CODE VARCHAR2(1000),
    AMT_NO NUMBER,
    BANK VARCHAR2(1000),
    VAL_FROM DATE,
    VAL_TO DATE,
    GUAR_NO VARCHAR2(1000)
    -- Following is the defintion of Varray returned by the implemented procedure.
    TYPE MPLUS_MPLUS_BankGurDet_OAI_Arr IS VARRAY(1000) OF MPLUS_MPLUS_BankGurDet_OAI_V1;
    -- This is the implemented procedure called by adapter. This returns a Varray of the above object.(MPLUS_MPLUS_BankGurDet_OAI_V1).
    PACKAGE Mplus AS
    TYPE MY_TYPE IS REF CURSOR;
    PROCEDURE imp_bankGurDet_OAI_V1(
    i_CUSTOMER_CODE IN LONG,
    i_CURRENT_DATE IN DATE,
    o_RESULT OUT MPLUS_MPLUS_BankGurDet_OAI_Arr
    END Mplus ;
    PACKAGE BODY Mplus AS
    PROCEDURE imp_bankGurDet_OAI_V1(
    i_CUSTOMER_CODE IN LONG,
    i_CURRENT_DATE IN DATE,
    o_RESULT OUT MPLUS_MPLUS_BankGurDet_OAI_Arr
    AS
    Type BANK IS RECORD(agencyname VARCHAR2(1000),Amout NUMBER,BankName VARCHAR2(1000),validfrom date , validto date,guarenteeno varchar2(1000));
    RECS MY_TYPE; -- Ref cursor
    BANKDETAILS_REC BANK ;
    BANKDETAILS_OBJ MPLUS_MPLUS_BANKGURDET_OAI_V1;
    i Number;
    dummy number;
    BEGIN
    WF_MP_ADVT.SP_ADV_AGE_BANK_GRTY(i_CUSTOMER_CODE,i_CURRENT_DATE,RECS);
    dummy:= 0;
    BANKDETAILS_OBJ:=new MPLUS_MPLUS_BankGurDet_OAI_V1('',0,'',sysdate,sysdate,'');
    o_RESULT:=MPLUS_MPLUS_BankGurDet_OAI_Arr();
    i:=1;
    LOOP
    fetch RECS INTO BANKDETAILS_REC;
    BANKDETAILS_OBJ.AG_CODE:=BANKDETAILS_REC.agencyname;
    BANKDETAILS_OBJ.AMT_NO:=BANKDETAILS_REC.Amout;
    BANKDETAILS_OBJ.BANK:=BANKDETAILS_REC.BankName;
    BANKDETAILS_OBJ.VAL_FROM:=to_date(BANKDETAILS_REC.validfrom,'dd-mon-yyyy');
    BANKDETAILS_OBJ.VAL_TO:=to_date(BANKDETAILS_REC.validto,'dd-mon-yyyy');
    BANKDETAILS_OBJ.GUAR_NO:=BANKDETAILS_REC.guarenteeno;
    o_RESULT.EXTEND;
    o_RESULT(i):=BANKDETAILS_OBJ;
    i:=i+1;
    EXIT WHEN RECS%NOTFOUND;
    END LOOP;
    END imp_bankGurDet_OAI_V1;
    END Mplus ;
    -- The following is a legacy procedure which return a refcursor which is iterated by the implemented procedure to create object and then this object is added to VARRAY in the.
    PACKAGE WF_MP_ADVT AS
    PROCEDURE SP_ADV_AGE_BANK_GRTY(
              Customer_Code      IN     CHAR,
    curdate in date,
              RESULT          OUT     Record_Type);
    END;
    PACKAGE BODY WF_MP_ADVT AS
    PROCEDURE SP_ADV_AGE_BANK_GRTY(
              Customer_Code      IN     CHAR,
    curdate in date,
              RESULT          OUT     Record_Type) IS
    BEGIN
    -- OPEN RESULT FOR SELECT AG_CODE,AMT_NO,BANK,to_char(VAL_FROM,'dd-mm-yyyy'),to_char(VAL_TO,'dd-mm-yyyy'),GUAR_NO FROM WF_MP_ADVT_BANKGAR WHERE AG_CODE=CUSTOMER_CODE;
    --OPEN RESULT FOR SELECT * FROM WF_MP_ADVT_BANKGAR WHERE AG_CODE=CUSTOMER_CODE;
    OPEN RESULT FOR SELECT AG_CODE,AMT_NO,BANK,to_char(VAL_FROM,'dd-mon-yyyy'),to_char(VAL_TO,'dd-mon-yyyy'),GUAR_NO FROM WF_MP_ADVT_BANKGAR WHERE AG_CODE=CUSTOMER_CODE;
    -- null;
    END SP_ADV_AGE_BANK_GRTY;
    END;
    The log file is as following
    Mplus.bankGurDet:OAI/V1,OAI/V1,false,1
    CUSTOMER_CODE: 1
    CURRENT_DATE: Fri Oct 29 00:00:00 GMT+05:30 2004
    Tue Nov 02 14:55:10 GMT+05:30 2004: InMessageTransformer: got a message for processing.
    Mplus.bankGurDet:OAI/V1,OAI/V1,false,1
    CUSTOMER_CODE: 1
    CURRENT_DATE: Fri Oct 29 00:00:00 GMT+05:30 2004
    Tue Nov 02 14:55:11 GMT+05:30 2004: Inbound Transform Engine: beginning to transform message.
    Tue Nov 02 14:55:11 GMT+05:30 2004: MessageTransformer: Successfully created destination message object with necessary header information but no attribute objects yet.
    Tue Nov 02 14:55:11 GMT+05:30 2004: InMessageTransformer: got a message for processing.
    Mplus.bankGurDet:OAI/V1,OAI/V1,false,1
    CUSTOMER_CODE: 1
    CURRENT_DATE: Fri Oct 29 00:00:00 GMT+05:30 2004
    Tue Nov 02 14:56:14 GMT+05:30 2004: db_bridge_writer_1 wrote the message to the database successfully.
    Tue Nov 02 14:56:14 GMT+05:30 2004: Agent: sending reply message.
    Mplus.bankGurDet:OAI/V1,OAI/V1,true,2
    RESULT[0]
    AG_CODE: 1
    AMT_NO: 200000.0
    BANK: STATE BANK OF INDIA
    VAL_FROM: 0004-04-01
    VAL_TO: 0005-03-31
    GUAR_NO: SBI01
    RESULT[1]
    AG_CODE: 1
    AMT_NO: 200000.0
    BANK: HDFC BANK
    VAL_FROM: 0004-04-01
    VAL_TO: 0005-03-31
    GUAR_NO: SBI01
    RESULT[2]
    AG_CODE: 1
    AMT_NO: 200000.0
    BANK: HDFC BANK
    VAL_FROM: 0004-04-01
    VAL_TO: 0005-03-31
    GUAR_NO: SBI01

    Vinod,
    As far as I can see the problem with duplicating the last record is a result of the EXIT condition in the loop in procedure 'imp_bankGurDet_OAI_V1'. Your loop looks as follows:
    LOOP
    FETCH recs INTO bankdetails_rec;
    bankdetails_obj.ag_code := bankdetails_rec.agencyname;
    bankdetails_obj.amt_no := bankdetails_rec.amout;
    bankdetails_obj.bank := bankdetails_rec.bankname;
    bankdetails_obj.val_from := TO_DATE(bankdetails_rec.validfrom,'DD-MON-YYYY');
    bankdetails_obj.val_to := TO_DATE(bankdetails_rec.validto,'DD-MON-YYYY');
    bankdetails_obj.guar_no := bankdetails_rec.guarenteeno;
    o_result.EXTEND;
    o_result(i):= bankdetails_obj;
    i:=i+1;
    EXIT WHEN recs%NOTFOUND;
    END LOOP;
    The problem is that checking for recs%NOTFOUND at the end of the loop results in going through the loop one more time even though you can't fetch another row from the recs cursor. The solution is to put the EXIT condition right after the FETCH statement. You now exit the loop if you can't fetch another row without assigning the last fetched record to bankdetails_obj again:
    LOOP
    FETCH recs INTO bankdetails_rec;
    EXIT WHEN recs%NOTFOUND;
    bankdetails_obj.ag_code := bankdetails_rec.agencyname;
    bankdetails_obj.amt_no := bankdetails_rec.amout;
    bankdetails_obj.bank := bankdetails_rec.bankname;
    bankdetails_obj.val_from := TO_DATE(bankdetails_rec.validfrom,'DD-MON-YYYY');
    bankdetails_obj.val_to := TO_DATE(bankdetails_rec.validto,'DD-MON-YYYY');
    bankdetails_obj.guar_no := bankdetails_rec.guarenteeno;
    o_result.EXTEND;
    o_result(i):= bankdetails_obj;
    i:=i+1;
    END LOOP;
    CLOSE recs;
    You also might want to consider to close the ref cursor after exiting the loop... 'too many open cursors' is not a good exception to get. ;-)
    Hope this is helpful.
    Thanks,
    Markus

  • Using Rownum and ROwid returns duplicate records

    Hi All,
    We have implemented pagination as below using rowid and rownum
    SELECT
    id
    FROM
    emp
    WHERE
    ROWID IN
    SELECT RID FROM (SELECT
    ROWID RID,
    ROWNUM RNUM
    FROM
    SELECT ID FROM emp
    WHERE
    ((T_ID IN (200005,200229,200230,200249,200250,200049))) AND
    (dte >= sysdate-90) AND
    (LOWER(DESC) = LOWER ('A') AND
    LOWER(NVL(FLAG,'0')) != LOWER ('3') AND
    LOWER(MODDE) like LOWER ('%210%')) ORDER BY dte ASC ))
    WHERE ROWNUM < 11) WHERE RNUM>= 1)) ORDER BY dte emp.ASC
    But, we face that - the query inserts duplicate records in consecutive pages. For Eg:
    1.if a,b,c,d,e - is returned for first iteration, then for the next iteration - f,g,h,a,y is returned.
    Is it because that the Order by clause doesnt have a Unique key column.
    Please help. or suggest how to efficietly implement pagination without performance hit

    try distinct since you are using only one column it will eliminate any duplicates.
    SELECT distinct id
      FROM emp
    WHERE (ROWID IN ( SELECT RID
                         FROM (SELECT ROWID RID,ROWNUM RNUM
                                 FROM (SELECT ID
                                         FROM emp
                                        WHERE ((T_ID IN (200005,200229,200230,200249,200250,200049)))
                                          AND (dte >= sysdate-90)
                                          AND (LOWER(DESC) = LOWER ('A')
                                          AND LOWER(NVL(FLAG,'0')) != LOWER ('3')
                                          AND LOWER(MODDE) like LOWER ('%210%'))
                                       ORDER BY dte ASC ))
                                WHERE ROWNUM < 11) 
                        WHERE RNUM>= 1))
    ORDER BY dte emp.ASC

  • Search query returning ALL records

    DW CS3 - MS Access - ASP/VBScript
    I have a search form for records to display on the same page with keywords highlighted.  The search is returning ALL records and highlighting keywords throughout rather than returning specific records with the searched word.  What am I missing?  I'm sure it's something terribly simple.....
              <input name="search" type="text" id="search" value="<%= Request.QueryString("search") %>" />
              SELECT item, item, item, item
              FROM tbl_name
              WHERE item OR item OR item LIKE %MMColParam%
              ORDER BY sql_orderby, Date DESC
              Name: MMColParam
              Type: Text
              Value: Request.Querystring("search")
              Default Value: %

    I was using the word "item" as an example for multiple columns without actually naming them - they are not the same.  I should've used this example:
    SELECT shoes, socks, hats, gloves
    FROM tbl_apparel
    WHERE shoes OR socks OR hats LIKE %MMColParam%
    ORDER BY sql_orderby, Date DESC
    In the past, I had four duplicate query parameters for four columns which worked fine.  But since I only have one search term, I thought I could eliminate three of the duplicate parameters and use just one with the OR statement.
    In the past, you questioned me on this.  You stated, "You only have one search term and so all of the parameters have the same value, but DW still wants to creates 4 parameters. If you were coding this by hand you wouldn't do it that way, but DW's one-size-fits-all code generates four seperate parms. It's nothing to worry about."

Maybe you are looking for