Testing for unique records in a compound Primary Key table

I have a table with 2 fields being primary keys. I want to write a sql script to check if there are duplicates.
Here is what I have but not sure if this is working right. I have table with millions of records.
SELECT COUNT(CASE WHEN A.AUNQ >1  THEN 1 ELSE NULL END)
FROM
SELECT (List_Cd + Account_Key) PK_ListAcc, COUNT(List_Cd) AUNQ
FROM RAW_AML_LISTEDACCNTS_JUN GROUP BY List_Cd, Account_Key HAVING (COUNT(List_Cd) >1))
 A;
Can someone help?
thanks

Yes, I agree. I am doing data profiling and testing all these tables. I am expecting that the results show me zero, however, if there were any problems with the settings, then I should get something. I think that the subquery is needed because if I used
what you suggested above I will get the following:
List_CD    Account_Key
1                    a
2                    b
3                    c
3                    C
1                    a
1                    a
the results will be:
List_CD    Account_Key    CountOFAccount_Key
1                    a                       
3
3                    C                       
2
I now need to count that query results to get the total which should be 2
do you agree? I am just trying to confirm that the sql script I listed will give me this result correctly.

Similar Messages

  • Problem With Compound Primary Key

    Hello Experts,
      i am facing some probelm with copound primarykey.
      the Probelm is
    i have data base table which has compound primary key  for that one i have created the entity bean(CMP) and primary key of type compound.using this i am able to insert record into databse but for updation i am using
    <b>findbyPrimarykey()</b> method ,for that methos i am passing
    primary key object with compound key values.
    when i am executing this methos it is throwing <b>nosuchobject exception.</b>
    what might be the problem
    any help will be appriciated
    thanks in advance
    With Regds
    Naidu

    Hi,
    Is ur compound primarykey class is something like this?
    public class PrimaryKey implements java.io.Serializable {
          public String id = "";
          public int no = 0;
          //a default constructor is required:
          public PrimaryKey() { }
          // optional constructor fo clients:
          public PrimaryKey(String id, int no) {
               this.id = smsId;
               this.no = no;
          public String toString() {
               return id + "" + no;
         public boolean equals(Object obj) {
              if (obj == null || !(obj instanceof PrimaryKey))
                      return false;
                   else if ((((PrimaryKey)obj).no == no) && (((PrimaryKey)obj).id.equals(id)))
                      return true;
                   else
                      return false;     
          public int hashCode() {
                return id.hashCode() + no ;

  • CMP entity bean with compound primary key

    I'm trying to use a compound primary key in a CMP entity bean. I've created the custom primary key class okay, and I have the prim-key-class set in ejb-jar.xml. My client app gets the home reference okay, but when it tries to find an entity, I get the exception "SQLException: Incorrect syntax near '/'."
    I think I'm having trouble deploying this in OC4J. Is there a sample orion-ejb-jar.xml deployment for a custom, compound primary key somewhere?
    Many thanks for any help.
    Ernie

    Never mind. I solved my problem. Thanks.

  • Creating an unique index instaed of using primary key index

    Hi ,
    I heard in a debate sometimes it's better to create a unique index on a column and using it instaed of using primary key index in oracle.I couldn't understand what the reason propely.
    Can anyone please help me in thsi topic if it is a valid one .
    Thanks in advance

    Hi,
    They are exactly NOT identical.
    1. Unique key can have NULL values where primary keys can't.
    2. Primary key is fundamentally those keys which do not change. I mean updating a primary key is not a good idea.
    SQL> drop table test;
    Table dropped.
    SQL> create table test ( a number(2));
    Table created.
    SQL> ed
    Wrote file afiedt.buf
      1* create unique index test_idx on test(a)
    SQL> /
    Index created.
    SQL> ed
    Wrote file afiedt.buf
      1* insert into test values(NULL)
    SQL> /
    1 row created.
    SQL> drop table test;
    Table dropped.
    SQL>
    SQL> create table test ( a number(2) primary key);
    Table created.
    SQL> insert into test values(NULL);
    insert into test values(NULL)
    ERROR at line 1:
    ORA-01400: cannot insert NULL into ("HR"."TEST"."A")
    SQL>Cheers,
    Edited by: Avinash Tripathi on Nov 24, 2009 11:17 AM

  • Creating Compound Primary Key in EJB

    Hi there,
    I'm creating a CMP EJB and am trying to use the Compund Primary Key option but I get the following error trace:
    [EXCEPTION]
    com.sap.engine.services.ejb.exceptions.BaseTransactionRolledbackLocalException: Exception in method com.nexeninc.seismic.ejb.SeisSetLocalHomeImpl0.create(java.lang.String,java.lang.String).
         at com.nexeninc.seismic.ejb.SeisSetLocalHomeImpl0.create(SeisSetLocalHomeImpl0.java:363)
         at com.nexeninc.seismic.ejb.SeismicServicesBean.registerDataSet(SeismicServicesBean.java:253)
         at com.nexeninc.seismic.ejb.SeismicServicesLocalLocalObjectImpl0.registerDataSet(SeismicServicesLocalLocalObjectImpl0.java:775)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sap.engine.services.webservices.runtime.EJBImplementationContainer.invokeMethod(EJBImplementationContainer.java:126)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:157)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:79)
         at com.sap.engine.services.webservices.runtime.servlet.ServletDispatcherImpl.doPost(ServletDispatcherImpl.java:92)
         at SoapServlet.doPost(SoapServlet.java:51)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: com.sap.engine.services.applocking.exception.SAPAppLockingIllegalArgumentException: Inconsistency in number of primary keys
         at com.sap.engine.services.applocking.TableLockingImpl.getArgument(TableLockingImpl.java:388)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:129)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:139)
         at com.sap.engine.services.ejb.entity.pm.lock.TableLockingSystem.write(TableLockingSystem.java:82)
         at com.sap.engine.services.ejb.entity.pm.UpdatablePersistent.create(UpdatablePersistent.java:242)
         at com.nexeninc.seismic.ejb.SeisSetBean0Persistent.create(SeisSetBean0Persistent.java:703)
         at com.nexeninc.seismic.ejb.SeisSetBean0PM.ejbCreate(SeisSetBean0PM.java:370)
         at com.nexeninc.seismic.ejb.SeisSetLocalHomeImpl0.create(SeisSetLocalHomeImpl0.java:334)
         ... 27 more
    com.sap.engine.services.applocking.exception.SAPAppLockingIllegalArgumentException: Inconsistency in number of primary keys
         at com.sap.engine.services.applocking.TableLockingImpl.getArgument(TableLockingImpl.java:388)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:129)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:139)
         at com.sap.engine.services.ejb.entity.pm.lock.TableLockingSystem.write(TableLockingSystem.java:82)
         at com.sap.engine.services.ejb.entity.pm.UpdatablePersistent.create(UpdatablePersistent.java:242)
         at com.nexeninc.seismic.ejb.SeisSetBean0Persistent.create(SeisSetBean0Persistent.java:703)
         at com.nexeninc.seismic.ejb.SeisSetBean0PM.ejbCreate(SeisSetBean0PM.java:370)
         at com.nexeninc.seismic.ejb.SeisSetLocalHomeImpl0.create(SeisSetLocalHomeImpl0.java:334)
         at com.nexeninc.seismic.ejb.SeismicServicesBean.registerDataSet(SeismicServicesBean.java:253)
         at com.nexeninc.seismic.ejb.SeismicServicesLocalLocalObjectImpl0.registerDataSet(SeismicServicesLocalLocalObjectImpl0.java:775)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sap.engine.services.webservices.runtime.EJBImplementationContainer.invokeMethod(EJBImplementationContainer.java:126)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:157)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:79)
         at com.sap.engine.services.webservices.runtime.servlet.ServletDispatcherImpl.doPost(ServletDispatcherImpl.java:92)
         at SoapServlet.doPost(SoapServlet.java:51)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    My compund primary key class has two attributes and those are the only ones in my table.
    Please note that I'm on SP 16. I'll post the details of the compound primary key class, ejbCreate method in the next post.

    Here is the code I'm using.
    Session Bean code:
    SeisSetLocal seisSet = seisSetHome.create("10002", "SEIS_ACQTN_SURVEY");
    Entity Bean code:
    public SeisSetPK ejbCreate(String seisSetId, String seisSetType)
              throws CreateException {
              setSeisSetId(seisSetId);
              setSeisSetType(seisSetType);
              SeisSetPK seisSetPK = new SeisSetPK();
              return seisSetPK;
    SeisSetPK class code:
    package com.nexeninc.seismic.ejb;
    import java.io.Serializable;
    public class SeisSetPK implements Serializable {
         private static final boolean DEBUG = false;
         public String seisSetId;
         public String seisSetType;
         public boolean equals(Object another) {
              if (another instanceof SeisSetPK) {
                   SeisSetPK that = (SeisSetPK) another;
                   if (!this.seisSetId.equals(that.seisSetId)) {
                        return false;
                   if (!this.seisSetType.equals(that.seisSetType)) {
                        return false;
                   return true;
              return false;
         public int hashCode() {
              int result = 0;          
              result += seisSetId.hashCode();
              result += seisSetType.hashCode();
              return result;

  • Key value does not currently exist in the primary key table error

    Im testing out a form and creating a new insert once all the fields are filled in it wont allow me to move on and comes up with this error message;
    key value does not currently exist in the primary key table
    Is this becuase the form contains foriegn keys which reference different tables which fields are not dispalyed on this form?
    If so how to I link the other forms together so that when i create a new record in this form it will automaticaly create the primary key entry in the other form to allow the insert of the referenced foreign key in this form?
    does this make sense?

    It seems that it has the table in which you'r inserting is a foreign key table.
    Take the emp& dept table example in the schema scott/tiger.
    Say we have deptno 10, 20, 30, 40 in the dept table.
    We make a form for emp table and insert into this form.
    Now, we'r bound to insert deptno 10, 20, 30, 40 into this emp form. This form will not allow us to insert deptno 50 as it doesn't exist in the primary key column in dept table.
    Obviously if a department doesn't exist in the company, it doesn't make sense to assign the employees to that department.
    So for this purpose, we need to add a department in the dept table then we can insert values in the emp table for that department.
    For this purpose, I suggest to make a button on the mp form and invoke the dept form and add a new department to it and then insert into emp table.
    The same scenario can be applied in your case.

  • Let me know the standary primary key tables in standard table??

    let me know the standary primary key tables in standard table??

    Hi,
    You can go and check the primary keys of a table in SE11 by entering the table name and pressing display.
    You will get to see that there will be some fields with a tick mark in the primary key column.The fields which have such tick marks are the primary keys of that table.
    As far as I know there is nothing called primary key tables.All tables have some fields as primary keys based upon which a record is uniquely defined in that table.
    Hope it was useful.
    Thanks,
    Sandeep.

  • How to pass values for compound primary keys for updating the record in db.

    i have a entity bean in my ejb with two primary keys to it...eg. roleid,rolename...
    when iam retriving the record i use only one primary key ...so again to modify and update he same record which i retrived is a pbm..
    i cannot set the values for the compoundpk,,,
    but i can do the update for the bean with single primary key..
    i need to know how to pass the values/parameters for the coumpound primary key in my update method...
    thanx in advance...
    Arjun.G

    I istantiated a object for the pk class and assign the values for the primary key fields...
    Arjun.G

  • How to show multiple values for Unique records in Report

    Here's my question/problem:
    I've joined two tables, one table (TBL1) contains an object id (OBJ_ID) that repeats and the other table (TBL2) contains a date (DT), object type id (OBJ_TYP_ID), and object type description (OBJ_TYP_DES). The tables are joined by an inventory id (INV_ID).
    The OBJ_ID repeats and has a Date value for each record. I want to report an unique OBJ_ID and show each Date for a particular OBJ_ID in multiple Columns.
    An example of the current resultset looks like this:
    OBJ_ID OBJ_TYP_ID OBJ_TYP_DES DATE
    1 1 TYPE1 4/1/2009
    2 1 TYPE1 4/1/2009
    3 1 TYPE1 4/10/2009
    1 2 TYPE2 5/3/2009
    3 1 TYPE1 3/30/2005
    4 1 TYPE1 4/1/2009
    5 1 TYPE1 4/1/2009
    5 2 TYPE2 5/1/2009
    1 1 TYPE1 4/3/2007
    1 1 TYPE1 3/30/2005
    I want to express the resultset like this:
    OBJ_ID OBJ_TYP_ID OBJ_TYPE_DES DATE1 DATE2 DATE3
    1 1 TYPE1 4/1/2009 4/3/2007 3/30/2005
    1 2 TYPE2 5/3/2009
    2 1 TYPE1 4/1/2009
    3 1 TYPE1 4/10/2009 3/30/2005
    4 1 TYPE1 4/1/2009
    5 1 TYPE1 4/1/2009
    5 2 TYPE2 5/1/2009
    What technique is best to use to do this? I know I could create another table and populate the rows/columns by reading data from this query, but is there a better way?

    Hi,
    cclemmons wrote:
    I want to express the resultset like this:
    OBJ_ID OBJ_TYP_ID OBJ_TYPE_DES DATE1 DATE2 DATE3
    1 1 TYPE1 4/1/2009 4/3/2007 3/30/2005
    1 2 TYPE2 5/3/2009
    2 1 TYPE1 4/1/2009
    3 1 TYPE1 4/10/2009 3/30/2005
    4 1 TYPE1 4/1/2009
    5 1 TYPE1 4/1/2009
    5 2 TYPE2 5/1/2009
    What technique is best to use to do this? I know I could create another table and populate the rows/columns by reading data from this query, but is there a better way?Absolutely! You seem to have an instictive feeling that creating a separate table just for a query is inefficient. You instinct is 100% correct. Maybe in Oracle 7 there was a reason to do that, but today you can query results of other queries as if they were tables, so temporary tables like you describe are very rarely necessary, let alone convenient.
    What you want to do is pivot the date columns. Here's one way
    WITH     original_query     AS
         SELECT  obj_id
         ,     obj_typ_id
         ,     obj_typ_des
         ,     dt          -- date is not a good column name
         FROM     ...          -- the rest of your original query goes here
    ,     got_rnum     AS
         SELECT     oq.*
         ,     ROW_NUMBER () OVER ( PARTITION BY  obj_id
                                   ,                    obj_typ_id
                             ,             obj_typ_des
                             ORDER BY        dt     DESC
                           )         AS rnum
         FROM    original_query        oq
    SELECT       obj_id
    ,       obj_typ_id
    ,       obj_typ_des
    ,       MAX (CASE WHEN rnum = 1 THEN dt END)     AS dt1
    ,       MAX (CASE WHEN rnum = 2 THEN dt END)     AS dt2
    ,       MAX (CASE WHEN rnum = 3 THEN dt END)     AS dt3
    ,       MAX (CASE WHEN rnum = 4 THEN dt END)     AS dt4
    ,       MAX (CASE WHEN rnum = 5 THEN dt END)     AS dt5
    FROM       got_rnum
    GROUP BY  obj_id
    ,       obj_typ_id
    ,       obj_typ_des
    ;As you can see, this adds two layers of queries on top of your original query. One of those layers is probably not needed; depending on what you're doing in your original main query, you can probably compute rnum there, and omit the got_rnum sub-query.
    Also, depending on the relationship of obj_id, obj_typ_id and obj_typ_des, some of what I posted above may not be needed but including it won't really hurt.
    If you want to know more about this technique, search for "pivot" or "rows to columns". A <tt>SELECT ... PIVOT ...</tt> keyword was introduced in Oracle 11, but most of what you'll find when you search for "pivot" doesn't assume you have Oracle 11 (nor does the query above require Oracle 11).
    This assumes you know an upper limit (5 in the example above) of dts that can appear in any line of output.
    See [this thread|http://forums.oracle.com/forums/thread.jspa?messageID=3527823&#3527823] for a discussion of some alternatives.

  • Problem with update of BLOB field in a table with compound primary key

    Hi,
    I've been developing an application in Application Express 3.1.2.00.02 that includes processing of BLOB data in one of the tables (ZPRAVA). Unfortunately, I've come across a strange behaviour when I tried to update value in a BLOB field for an existing record via a DML form process. Insert of a new record including the BLOB value is OK (the binary file uploads upon submiting the form without any problems). I haven't changed the DML process in any way. The form update process used to work perfectly before I'd included the BLOB field. Since than, I keep on getting this error when trying to update the BLOB field:
    ORA-20505: Error in DML: p_rowid=3, p_alt_rowid=ID, p_rowid2=CZ000001, p_alt_rowid2=PR_ID. ORA-01008: not all variables bound
    Unable to process row of table ZPRAVA.
    OK
    Some time ago, I've already created another application where I used similar form that operated on a BLOB field without problems. The only, but maybe very important, difference between both the cases is that the first sucessfull one is based on a table with a standard one-column primary key whereas the second (problematic one) uses a table with compound (composite) two-column PK (two varchar2 fields: ID, PR_ID).
    In both cases, I've followed this tutorial: [http://www.oracle.com/technology/obe/apex/apex31nf/apex31blob.htm]).
    Can anybody confirm my suspicion that Automatic Row Processing (DML) can be used for updating BLOB fields within tables with only single-column primary keys?
    Thanks in advance.
    Zdenek

    Is there a chance that the bug will be included in the next patch?No, this fix will be in the next full version, 3.2.
    Scott

  • JDeveloper 10g Creating a new record with trigger sequence primary key

    Hi there, I'm sorry to post this incredibly simple question and I'm sure that someone must have answered this on this forum before but the searching of this site is incredible slow and painful and after 30 mins I can't find help.
    I am using a struts Data Action to create a new record in the database and then being forwarded to an edit page where I can enter the new details. Then when the details are entered I am clicking an update button and returning to a browse screen where I can either commit the change to the database or rollback. Sounds pretty simple but I am really struggling with trying to get the trigger of the number sequence to work properly.
    Ideally I would like to click the create new record button and then the primary key/triggered sequence number is already displayed on the empty form...
    ... but if this is too tricky or not possible then I would like the user to either not enter any value in the key field (which currently causes error - JBO-27014: Attribute PoNo in PO_SYS_MODULE.PoSystemView1 is required) OR the user enters a number and the trigger overwrites this number with the next in the sequence.
    I can enter a new record if I look in the manager console and see the next number in the sequence and then create the record using this number and then click commit twice, as the first time I get the error: JBO-25019: Entity row of key oracle.jbo.Key[154 ] not found in PoSystem. Or if I enter a value 5 times greater than the next in the sequence I have to click the commit button 5 extra times to get the sequence to match the input.
    I hope that this lengthy explanation fills you in on my problem, there must be a simple solution to this and I will be VERY grateful to anyone who can help me.
    Many thanks
    Ben Sayers (clearly a newbie)

    Hi,
    ADF Business Components handles this for you - unless yo prefer doing this manually. In the Entity Object, set the PK attribute's type to DBSequence. Then create a database sequence and use a database trigger to add the sequence value on insert
    Frank

  • Key in View  for two primary keys tables

    Hi
    I have some view joining LIKP and LIPS:
    LIKP -   Primary Key MANDT, VBELN
    LIPS -   Primary Key MANDT, VBELN, POSR
    The Key for the LIKP-LIPS View is:
    MANDT      LIKP
    VBELN       LIKP
    MANDT_I    LIPS
    VBELN_I    LIPS
    POSNR_I   LIPS
    So, for that Key, if i need to acces a specify LIPS detail record , must i fill all the keys in the where  (filling VBELN twice) like this:
    WHERE VBELN =  vbvalue AND VBELN_I =  vbvalue AND POSNR_I = posvalue ?
    How must i make the Select for acces this View using its Key ?
    Regards
    Frank

    Hi
    Just as I said:
    SELECT SINGLE * FROM Z<VIEW> WHERE VBELN = <VBELN>
                                                                AND POSNR_I = <POSNR>.
    Anyway it's should be better you correct the view deleting the field MANDT_I, VBELN_I, if you can't, I believe the select above works fine.
    VIEW FIELDS:
    View Field Table Field Key
    MANDT LIKP MANDT Yes
    VBELN LIKP VBELN Yes
    <b>MANDT_I LIPS MANDT Yes <----- WRONG
    VBELN_I LIPS VBELN Yes      <----- WRONG</b>
    POSNR_I LIPS POSNR Yes
    ERNAM LIKP ERNAM
    ERDAT LIKP ERDAT
    VKORG LIKP VKORG
    PSTYV_I LIPS PSTYV
    MATNR_I LIPS MATNR
    WERKS_I LIPS WERKS
    LGORT_I LIPS LGORT
    By this defintion the field MANDT and VBELN are only twice, but it doesn't mean the record is double in the VIEW.
    So it you have the delivery 100 with 3 items in the client 200, in the view you'll see:
    Record 1: MANDT   = 200
                   VBELN    = 0000000100
                   MANDT_I = 200
                   VBELN_I  = 0000000100
                   POSNR_I = 000010
    Record 2: MANDT   = 200
                   VBELN    = 0000000100
                   MANDT_I = 200
                   VBELN_I  = 0000000100
                   POSNR_I = 000020
    Record 3: MANDT   = 200
                   VBELN    = 0000000100
                   MANDT_I = 200
                   VBELN_I  = 0000000100
                   POSNR_I = 000030
    Max

  • Delete records on basis of primary key.

    HI all,
    I need an ODI code so that i Should delete the record from target table on the basis of primay key with the reference of I$ table.
    for example ..
    T is target table & I$T is IKm table.
    T has primary key P and I$t is also primay key.
    So catually the code should be
    delete from T where T.P <> I$.P
    I wnat to insert the ODI code in IKM .
    I had tried something like but it doesnt work
    delete from <%=snpRef.getTable("L","TARG_NAME","A")%>
    where     <%=snpRef.getColList("", "[COL_NAME]\t <> :[COL_NAME]", "\nand\t", "", "(UK)")%>
    Please sussgest.
    Edited by: neeraj_singh on Dec 1, 2008 12:01 AM

    Hi,
    Use:
    delete from <%=snpRef.getTable("L","TARG_NAME","A")%>
    where <%=snpRef.getColList("(", "COL_NAME", ",", ") in ", "(UK)")%>
    (select <%=snpRef.getColList("", "COL_NAME", ",", "", "(UK)")%> from <%=snpRef.getTable("L", "INT_NAME", "A")%>)
    That code will give what you need...
    Cezar Santos

  • Insert record and return the primary key

    Okay, I need to insert a record into a MSSQL database and return the primary key of that record. Im using the following code which is obviously wrong as I'm getting either 'NULL' or 'com.microsoft.jdbc.base.BaseResultSet@1d520c4' returned depending on the ways I've tried. The primary key is an int value called clientID which is incremented by one each time a new record is added.
    // set the prepared statement
                String sql="INSERT INTO Client(username, country, clientIP, browser, os) VALUES(?,?,?,?,?)";
                PreparedStatement pstmt = conn.prepareStatement(sql);
                pstmt.setString(1, inUserName);
                pstmt.setString(2, inCountry);
                pstmt.setString(3, inClientIP);
                pstmt.setString(4, inBrowser);
                pstmt.setString(5, inOS);
                // Insert the row
                pstmt.executeUpdate();
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT SCOPE_IDENTITY()");
                System.out.println("Result "+rs);The primary key value is needed so that it can be used as a foregin key in another table. Am I going about this the correct way? Any help, pointers or code fixing would be appreciated.....

    Yes. I tried this way but I only ever get the answer
    of 0 when i print our the result! Not really sure
    whats happening.That's because you don't print a ResultSet like that. In order to get the key out, you have to do this:
    int key = 0;
    while (rs.next())
        key = rs.getInt(1);What were you thinking with your code?
    You might want to do this in a transaction. If the INSERT fails, you'll want to roll back.
    The "select @@identity" is correct for M$ Access, SQL Server, and Sybase. I believe it's also correct for MySQL, but I'm not 100% certain of that.
    %

  • Updation of table records having 5-6 primary key columns.

    I have a table structure having 12 primary composite keys.I have created report + form on this table.My requirement is to update the table by using form items fields.I am taking help of url option on report attribute page of application to fetch data on form page when we click on edit link of report page.Now i am having two problems which are as follows:-
    (i)I am unable to update data as requirement is to update 5 to 6 primary fields along with other non primary keys.I tried to create Pl/SQL process which will run update query but this process is not updating values.Is there any way that i could fetch data direct from database table in query rather then taking item values.Is there any other workaround?
    (ii)One of the primary key column contains records which have ' , ' in them .For ex:- cluth,bearing.So when i get navigated to edit page i am only getting text displayed as clutch i.e. text before ',' is getting displayed in text field while comma and the text after this is not getting displayed in text field of form page.
    Any solutions will be very helpful.
    Thanks
    Abhi

    Hello Abhi,
    >> I am unable to update data as requirement is to update 5 to 6 primary fields along with other non primary keys
    APEX wizards support a composite PK with up to 2 segments only. For every other scenario, you’ll have to manually create your DML code.
    If you have control over your data model, I would listen very carefully to Andre advices. Using a single segment PK is the best practice way. If you can’t add PK to your table, it seems that you’ll have to write your own DML code. The Object Browser option of creating a Package with methods on database table(s) can be a great help.
    >> … I am taking help of url option … One of the primary key column contains records which have ' , ' in them …
    Using the f?p notation, to pass a comma in an item value, you should enclose the characters with backslashes. For example,
    \cluth,bearing\In your case, it should be the item/column notation.
    http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/concept.htm#BCEDJBEH
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

Maybe you are looking for