SQL Statement for Composite Primary key

Hi,
I need a SQL statement for finding the Distinct values for combination of 2 Columns( Composite Primary key). I dont want to use Data Dictionary views.
Table A
c1 c2
1 1
1 2
2 3
Now for the above table combination of c1 and c2 is unique.
Please advice.
Cheers
Ramkannan.A

This?
PRAZY@solarc> with tableA as
  2  (select 1 col1,2 col2 from dual
  3  union all
  4  select 1,1 from dual
  5  union all
  6  select 1,2 from dual
  7  union all
  8  select 2,3 from dual
  9  union all
10  select 1,2 from dual
11  union all
12  select 2,3 from dual
13  )
14  select distinct col1, col2 from TableA
15  /
      COL1       COL2
         2          3
         1          2
         1          1Regards,
Prazy

Similar Messages

  • Lov values not refreshing for composite primary key

    Hi All,
    I have LOV, which works fine on model project but not in view layer project.
    i have lov with three columns queried from database view dealer_code, scheme_code, scheme_desc
    dealer_code and scheme_code are composite keys
    d001 sch001
    d001 sch002
    d002 sch003
    when i select d002 , i can get the value in bean,
    but when i select d001 and i am getting the scheme sch001,
    if i choose after selecting sch001 to sch002, i am still getting sch001
    the value is not changing when i select composite values from lov.
    any solution ?
    thanks
    Gopinath

    hi Luka, try to install demo sample applications to see
    report pages and forms for insert(as create) and updates(save)
    into tables
    regards,
    gordan,
    http://gordanmilojevic.blogspot.com/

  • Doubt in composite primary key

    hi, i need ans for the following question.
    1. what is composite primary key
    2.in what situation it is used?
    3.advantages and dis advantages of the composite primary key.
    4.example for composite primary key.
    please give me ans for this,pleaseeeeeeeeeeeee

    1) A primary key that consists of more than one column
    2) When you like natural keys more than surrogate keys (search the forum for numerous discussions on this subject)
    3) Advantage: By duplicating key information in your fact tables, you may have enough information in the key values to prevent accessing the real table
    Disadvantage: Your key values become part of other tables, preventing updates of key values (and natural key values can and will eventually almost always change, warning: this is an opinion)
    4) tables order and order_items. Order has a order_no as a primary key, order_items's primary key is (order_no,sequence_no)
    Regards,
    Rob.

  • How to specify  tablespace for a primary key inde in create table statement

    How to specify the tablespace for a primary key index in a create table statement?
    Does the following statement is right?
    CREATE TABLE 'GPS'||TO_CHAR(SYSDATE+1,'YYYYMMDD')
                ("ID" NUMBER(10,0) NOT NULL ENABLE,
                "IP_ADDRESS" VARCHAR2(32 BYTE),
                "EQUIPMENT_ID" VARCHAR2(32 BYTE),
                "PACKET_DT" DATE,
                "PACKET" VARCHAR2(255 BYTE),
                "PACKET_FORMAT" VARCHAR2(32 BYTE),
                "SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP,
                 CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") TABLESPACE "INDEX_DATA"
                 TABLESPACE "SBM_DATA";   Thank you
    Edited by: qkc on 09-Nov-2009 13:42

    As orafad indicated, you'll have to use the USING INDEX clause from the documentation, i.e.
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE TABLE GPS
      2              ("ID" NUMBER(10,0) NOT NULL ENABLE,
      3              "IP_ADDRESS" VARCHAR2(32 BYTE),
      4              "EQUIPMENT_ID" VARCHAR2(32 BYTE),
      5              "PACKET_DT" DATE,
      6              "PACKET" VARCHAR2(255 BYTE),
      7              "PACKET_FORMAT" VARCHAR2(32 BYTE),
      8              "SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP,
      9               CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") USING INDEX TABLESP
    ACE "USERS"
    10               )
    11*              TABLESPACE "USERS"
    SQL> /
    Table created.Justin

  • How to define Composite primary key for a Table

    Hi ,
    I am basically more into Java Programming , with little bit knowledge on Oracle as DataBase .so please excuse for my silly doubts .
    Can anybody please tell me how to define a Composite Primary Key on a Table .
    Thanks in advance .
    Edited by: user672373773 on Sep 25, 2009 8:54 AM

    Here is an example right out of the Oracle documentation and the syntax for adding PK since you mention adding a composite PK.
    Example creating composite index
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_indexing.htm#sthref594
    Syntax for adding a PK (composite or not)
    alter table oooooooo.tttttttt
    add constraint tttttttt_PK
    primary key (sample_column2,
    sample_column1)
    using index
    tablespace IDXSPC
    pctfree 05
    initrans 04
    maxtrans 08
    storage (initial 16k
    next 16k
    maxextents 32
    pctincrease 0);
    -- dictionary management with restricted storage, change as desired.
    HTH -- Mark D Powell --

  • Creation of CMP bean for a Composite Primary key????

    Hi
    i am having a composite primary keys in one of my table in the database.
    I am trying to create a new entity bean for this table but i don't know how to create one in case when there is a composite primary key for a table.
    Can anybody let me know is it possible to do it.
    what is the procedure to be followed for the creation of the Entity bean in case of a composite primary key.
    I am using MySql as the database .Creating CMP type of Entity bean.
    Any help in this regard will be greatly useful to me as this is very urgent.
    Thanks & Regards
    Vikram K

    Hi Nikola,
    There are several problems with your CMP bean.
    1. Fields of a Primary Key Class must be a subset of CMP fields, so yes, they must be either a primitive or a Serializable type.
    2. Sun Application Server does not support Primary Key fields of an arbitrary Serializable type (i.e. those that will be stored
    as BLOB in the database), but only primitives, Java wrappers, String, and Date/Time types.
    Do you try to use stubs instead of relationships or for some other reason?
    If it's the former - look at the CMR fields.
    If it's the latter, I suggest to store these fields as regular CMP fields and use some other value as the PK. If you prefer that
    the CMP container generates the PK values, use the Unknown
    PrimaryKey feature.
    Regards,
    -marina

  • Composite Primary Key question

    I have a new question regarding composite primary keys on another table I have created.
    I have the following table with the following definition:
    CREATE TABLE "APSOM"."CPULIST"
    ( "CPU_ID" VARCHAR2(10 BYTE),
    "SERVER_ID" VARCHAR2(10 BYTE),
    "CREATED_DATETIME" TIMESTAMP (6),
    "UPDATED_DATETIME" TIMESTAMP (6)
    with the following composite PK definition:
    ALTER TABLE "APSOM"."CPULIST" ADD CONSTRAINT "CPULIST_PK" PRIMARY KEY ("CPU_ID", "SERVER_ID")
    Then, I inserted data in the following way:
    insert into CPULIST
    values ('CPU1', 'P1', SYSDATE, SYSDATE);
    with following CPU ID values from 'CPU1' to 'CPU16' for SERVER ID value 'P1' also inserted as well.
    Now, I am trying to insert values for SERVER ID value 'P2'
    insert into CPULIST
    values ('CPU1', 'P2', SYSDATE, SYSDATE);
    and I am getting the following error message:
    Error starting at line 1 in command:
    insert into CPULIST
    values ('CPU1', 'P2', SYSDATE, SYSDATE)
    Error report:
    SQL Error: ORA-00001: unique constraint (APSOM.XPKCPULIST) violated
    00001. 00000 - "unique constraint (%s.%s) violated"
    *Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
    For Trusted Oracle configured in DBMS MAC mode, you may see
    this message if a duplicate entry exists at a different level.
    *Action: Either remove the unique restriction or do not insert the key.
    Using the following SQL command:
    select column_name from all_cons_columns
    where constraint_name = 'CPULIST_PK'
    and owner = 'APSOM';
    I get the following records
    1. CPU_ID
    2. SERVER_ID
    This error does not make sense to me. Any help would be appreciated.
    Thanks,
    Patrick Quinn
    Operations
    Turning Point Global Solutions

    So, if there is a hidden unique constraint XPKCPULIST that cannot be pulled the all_cons_column table and I drop the XPXCPULIST constraint with the following SQL:
    alter table CPULIST drop constraint XPKCPULIST;
    Error starting at line 1 in command:
    alter table CPULIST drop constraint XPKCPULIST
    Error report:
    SQL Error: ORA-02443: Cannot drop constraint - nonexistent constraint
    02443. 00000 - "Cannot drop constraint - nonexistent constraint"
    *Cause:    alter table drop constraint <constraint_name>
    *Action:   make sure you supply correct constraint name.
    What can I do to get past this so I can perform the following insert and receive this error message??
    insert into CPULIST
    values ('CPU1', 'P2', SYSTIMESTAMP, SYSTIMESTAMP);
    Error starting at line 1 in command:
    insert into CPULIST
    values ('CPU1', 'P2', SYSTIMESTAMP, SYSTIMESTAMP)
    Error report:
    SQL Error: ORA-00001: unique constraint (APSOM.XPKCPULIST) violated
    00001. 00000 - "unique constraint (%s.%s) violated"
    *Cause:    An UPDATE or INSERT statement attempted to insert a duplicate key.
    For Trusted Oracle configured in DBMS MAC mode, you may see
    this message if a duplicate entry exists at a different level.
    *Action:   Either remove the unique restriction or do not insert the key.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Master Detail Forms with 2 composite primary keys - Is there a workaround?

    Hello All,
    I have been searching for a workaround to the maximum 2 part primary key restriction on the multi-row updates, and master-detail forms, and am hoping that someone can help me. I am using HTMLDB v2.0.0.00.49 with IE 6 against a 9.2 DB.
    I successfully implemented the workaround of Fred Stoopendaal's (see Updata PK on HTML DB ) and it works fine for single page multi-record updateable forms, but alas I haven't been able to extend it to master detail forms (I think it is something to do with Oracle not allowing the "returning" clause on views).
    Here is what I tried:
    two tables, one with a 2 part composite primary key, which is the master table, and a detail table with 3 part composite primary key -
    --------- BEGIN SQL ---------
    create table master_table
    ( master_col1 number
    , master_col2 number
    , master_col3 varchar2(30)
    , constraint master_pk primary key (master_col1,master_col2));
    create table detail_table
    (detail_col1 number
    ,detail_col2 number
    ,detail_col3 number
    ,detail_col4 varchar2(30)
    , constraint detail_pk primary key(detail_col1,detail_col2,detail_col3)
    , constraint master_detail_fk foreign key (detail_col1,detail_col2) references master_table(master_col1,master_col2));
    create or replace view v_master_table as
    select rowid mata_rowid,mata.*
    from master_table mata;
    create or replace view v_detail_table as
    select rowid deta_rowid,
    (select rowid from master_table mata where mata.master_col1 = deta.detail_col1 and mata.master_col2 = deta.detail_col2) deta_mata_rowid
    , deta.*
    from detail_table deta;
    create or replace trigger mata_ins_upd_trg
    instead of insert or update on v_master_table
    referencing new as new old as old
    for each row
    begin
    if inserting then
    insert into master_table (master_col1, master_col2, master_col3)
    values (:new.master_col1, :new.master_col2, :new.master_col3);
    end if;
    if updating then
    update master_table
    set master_col1 = :new.master_col1,
    master_col2 = :new.master_col2,
    master_col3 = :new.master_col3
    where rowid = :old.mata_rowid;
    end if;
    end;
    create or replace trigger deta_ins_upd_trg
    instead of insert or update on v_detail_table
    referencing new as new old as old
    for each row
    begin
    if inserting then
    insert into detail_table ( detail_col1, detail_col2, detail_col3, detail_col4)
    values (:new.detail_col1, :new.detail_col2, :new.detail_col3, :new.detail_col4);
    end if;
    if updating then
    update detail_table
    set detail_col1 = :new.detail_col1,
    detail_col2 = :new.detail_col2,
    detail_col3 = :new.detail_col3,
    detail_col4 = :new.detail_col4
    where rowid = :old.deta_rowid;
    end if;
    end;
    --------- END SQL ---------
    Then I created a master-detail form in Apex on the two views, using the mata_rowid and deta_rowid as primary keys, and mata_rowid=deta_mata_rowid as the link. I realise that using a function to fetch the master rowid within the detail view query is costly, but it was my intention to modify the record fetch queries to use the real FK columns once things were up and running.
    It seems to generate the pages ok, and I can insert/update master table records, but as soon as I modify records in the detail table things go a bit haywire. I can't find any documentation on how the inbuilt MRU/MRD logic works, so can't figure out the issue.
    Can anyone out there tell me what the problem is with the logic above, or if they have come up with a neat solution to this annoying limitation. I know that many will say that I should modify the data model to use surrogate primary keys, but many of the uses for HTMLDB are new interfaces for old schemas, so a workaround that doesn't involve wholesale data model changes would be preferable.
    Thanks in advance,
    Mike Cretan

    Hi, this is likely not the most elegant way...but perhaps the simplest -- and I didn't have much time to play.
    I used Wizard to create two separate Master Detail forms, each with a separate detail table. Thus I ended up with four pages:
    Page "A" - "Selector" page for Master (Report), with Edit link driving to Detail-1
    Page "B" - Editable Master/Detail-1 page (HTML / Report)
    Page "C" - "Selector" page for Master (Report), with Edit link driving to Detail-2
    Page "D" - Editable Master/Detail-2 page (HTML / Report)
    Then I selected the primary key column TWICE on the Report on Page A. Modified the second instance of this column to navigate to Page D (passing primary key) exactly the way the original instance of this column navigates to Page B. Then I deleted Page C.
    Since you can have only one Tabular Entry form per page, this seemed the best way to drive two separate detail tables from a common interface.

  • Composite Primary Key

    Hi,
    I have few tables which had primary key on one column A, I made it composite primary key by adding one more column B at 2nd position. I made this change in all the tables. When I ran few SQLs to check the performance I found that explain plan shows full table scan on few tables which was not showing eariler (before composite PK). The SQL has outer join between these tables on column A (1st position in composite PK index). Is there anything I need to look into?
    I'm using Oracle 10.2.0.5.0.
    Thanks

    Onkar Talekar wrote:
    I guess you are talking about the same table in this thread: [url:https://forums.oracle.com/forums/thread.jspa?threadID=2372871&start=0&tstart=0]Primary Key modification
    Yes. thats right.
    If it is the same post, could you post current structure of the table plus what is recommended in the FAQ to post for performance issues?
    Have you replaced your primary key from PARENT_ID to a composite primary key (PARENT_ID, PT_TIME)?
    What was the reason for that?
    Did you have any need to insert the same key (PARENT_ID) with different PT_TIME?
    What is the benefit you expected creating this index?
    What did you mean with "contention" that is happening on this primary key/index? Someone using the same primary key?
    How is the PARENT_ID generated?
    At a first look I did not see the need of replacing your primary key, as Tubby advised in your previous post. Adding a column to solve contention added additional trouble to you on performance side.
    Regards.
    Al.

  • Composite Primary key & Primary key questions

    Background:
    1.5 TB data warehouse. All tables use at least a 3 column composite Primary key. Most use 3. col1||col2||col3 to achieve uniqueness.
    col1= very low cardinality. 99% of the values are '0'
    col2 = high cardinality. (SSN's, loaded monthly)
    col3 = low cardinality. (monthly sequence number used for partitioning)
    From what I've read, the first column used in a composite primary key also receives its own index. If that is correct, then the primary key being used is losing its effectiveness by putting a very low cardinality column as the first column of the Primary key. By moving col2 to the first position of the composite key, I would be obtaining an index on SSN which would be much more useful. (Please correct me if I'm wrong) Or since the index would be so large anyway, the CBO would just do full table scans which is what I'm trying to get away from.
    This Primary key is used to ensure uniqueness during loads. Other than that, it really has no purpose and is never queried by the user. (WHERE col1||col2||col3 = xxxxxxxxx)
    As a DBA, I see this massive tablespace for holding the primary keys now reaching in excess of 157 GB and it seems like such a waste of space. The problem I'm running across is how to ensure uniqueness during the loads w/o having to store the unique values. (the 157 GB) If I drop the PK's, then create unique indexes just for the loads, then the unique index would be generated against the entire table, which would take forever.
    If you create a local index (what I want in the end) it still has to create the index for all previous partitions (250+ partitions). You can't create a specific 'local' index on a partition. You create a local index on the table and when a new partition is added, the index is then added as well. That's what I want to do with some of my fields like SSN but for loading purposes, this isn't going to help me.
    I need a way to ensure uniqueness during a monthly load of a new partition (col1||col2||col3) but w/o having to store these values for eternity. Right now it's the primary key, so it has to be stored. I hope I'm making sense here. Any ideas?

    I think you need some clarification about the index supporting the primary key.
    The primary key is unique - the database will enforce this for you.
    All of the columns in the primary key are in the index that enforces the key (not just the first column).
    Usually this index is a unique index, but you can have a non-unique index supporting a primary key.
    I'm a little confused with some of your other statements
    how to ensure uniqueness during the loads w/o having to store the unique valuesIf you don't store the value how do you know it is unique?
    Did you mean that you don't want to store the key values in both the table and the index?
    You may want to consider making col3 (the partition key) the leading column of the index, so you can create a local (instead of global) PK index.
    I wouldn't worry too much about col1 (the column full of mostly zeros) - numbers are stored variable length. A NUMBER(38) that holds a zero takes no more space than a NUMBER(1) that holds a zero.

  • Maximum number of column in Composite Primary Key

    Hi
    I have read that composite primary key can contain maximum of 32 columns (Oracle 9i).
    However I am able to create a primary key on 33 columns. It fails to create primary key on 34 columns. Below are the queries.
    DROP TABLE XYZ;
    CREATE TABLE XYZ
    ( N1 NUMBER
    ,N2 NUMBER
    ,N3 NUMBER
    ,N4 NUMBER
    ,N5 NUMBER
    ,N6 NUMBER
    ,N7 NUMBER
    ,N8 NUMBER
    ,N9 NUMBER
    ,N10 NUMBER
    ,N11 NUMBER
    ,N12 NUMBER
    ,N13 NUMBER
    ,N14 NUMBER
    ,N15 NUMBER
    ,N16 NUMBER
    ,N17 NUMBER
    ,N18 NUMBER
    ,N19 NUMBER
    ,N20 NUMBER
    ,N21 NUMBER
    ,N22 NUMBER
    ,N23 NUMBER
    ,N24 NUMBER
    ,N25 NUMBER
    ,N26 NUMBER
    ,N27 NUMBER
    ,N28 NUMBER
    ,N29 NUMBER
    ,N30 NUMBER
    ,N31 NUMBER
    ,N32 NUMBER
    ,N33 NUMBER
    ,N34 NUMBER
    ,N35 NUMBER
    ,N36 NUMBER
    ,N37 NUMBER
    ,N38 NUMBER
    ,N39 NUMBER
    ,N40 NUMBER
    ,N41 NUMBER
    ,N42 NUMBER
    ,N43 NUMBER
    ,N44 NUMBER
    ,N45 NUMBER
    ,N46 NUMBER
    ,N47 NUMBER
    ,N48 NUMBER
    ,N49 NUMBER
    ,N50 NUMBER
    ALTER TABLE XYZ ADD CONSTRAINT XYZ_PK PRIMARY KEY
    ( N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14
    ,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26
    ,N27,N28,N29,N30,N31,N32,N33,N34);
    ALTER TABLE XYZ ADD CONSTRAINT XYZ_PK PRIMARY KEY
    ( N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14
    ,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26
    ,N27,N28,N29,N30,N31,N32,N33);
    Can someone let me know the lmit of maximum no. of columns in Primary Key?
    Regards
    Arun

    SQL> select * from v$version;
    BANNER                                                                         
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production                     
    PL/SQL Release 9.2.0.1.0 - Production                                          
    CORE     9.2.0.1.0     Production                                                      
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production                         
    NLSRTL Version 9.2.0.1.0 - Production                                          
    SQL> ALTER TABLE XYZ ADD CONSTRAINT XYZ_PK PRIMARY KEY
      2  ( N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14
      3  ,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26
      4  ,N27,N28,N29,N30,N31,N32,N33);
    Table altered.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Is this good approach for generating Primary Keys ?

    Hi,
    All our EJBs are state less Session Beans.
    We have created a state less Session(name SequenceEJB) for getting Primary Key.
    Thre is a method,
    int getSequenceNumber(String tableName,String fieldName) in SequenceEJB. And the following query is used in the above said method.
    SELECT MAX("+fieldName+") ID FROM "+tableName
    Each EJB will lookup SequenceEJB, and call the above said method for getting sequence number.
    Is this approach sclable ?
    Can we proceed by this approach ?
    Thanks in advance
    Srinivas

    As long as you are in EJB, synchronization won't help you because it is not permitted by the EJB spec.
    If you can go with JDBC 3.0 / Java 1.4, the statement interface supportes generated keys. See http://java.sun.com/j2se/1.4/docs/api/java/sql/Statement.html.
    If you cannot go with JDBC 3.0 / Java 1.4, you can implement the key-generation db-specific (e.g. using oracle sequences for oracle tables, and whatever exists for DB2, SQL Server etc.) That of course requires special support for all databases, but at least you can run your app with different databases.
    Or you can try to do it the following way, using a separate table for the keys.
    ResultSet rs = statement.executeQuery("select id from mySequences");
    oldId = rs.getInt(1);
    newId = oldId + 1
    int updatedRows = statement.executeQuery("update mySequences set id = newId where id = oldId");
    if(updatedRows == 1) {
      // succesful
    } else {
      // not sucessful, somebody else has already retrieve this id; do something like Thread.sleep() and retry
    }This way, the database does the actual synchronization between the processes (each process sees the same data in the tables), and you implement the retry logic.

  • Update enrolled table which has 6 composite primary key

    Hi Everyone,
    I am trying to update a grade column in table called enrolled which has 6 composite primary key column including SID, TERMYEAR, FACCODE, DEPCODE, COURSENO, SECNO and 2 extra column including GRADE, IDD all of them are of type VARCHAR2 as describe below:
    To update this table I used the command below:
    UPDATE enrolled
    SET grade = :COURSE_BLOCK.GRADE_TEXT
    WHERE IID = :GLOBAL.logUserid
    AND SID = :COURSE_BLOCK.SID_TEXT
    AND FACCODE = :COURSE_BLOCK.FACULTY_TEXT
    AND DEPCODE = :COURSE_BLOCK.DEPARTMENT_TEXT
    AND COURSENO = :COURSE_BLOCK.COURSE_TEXT
    AND SECNO = :COURSE_BLOCK.SECTION_TEXT;
    Note: the :GLOBAL.logUserid is a global variable that I assigned the user id when the user log on to the application.
    When I run the application and fill out the form in order to update the table this doesn't update the table and if I use SQL*PLUS as well with the values that I use for the form to update the table I get message: o rows updated
    Can Someone help please?

    Here is the solution.
    The problem:
    The problem was that the enrolled table was designed in a way that a student can enrolled in the lecture(LEC type column) and Laboratory(LAB type column). When a student is given a grade, it is given a grade for the course 100 (eg: 03-60-100) this course has a lecture and lab. this course belong to the faculty code 03(science) department 60 (computer Science) so when a student register to a course, will register to a lecture and a lab but he will receive a grade for the course 100 lec in this case Oracle couldn't update the table because there was two column with course 100 for that particular student Id
    The solution:
    There are many solution I believe but my quickest solution is when a student register to the course by default is given a grade 'I' means Incomplete then when the instructor add the grade, he can just update a grade from incomplete to the final grade (eg A) now the code will be to get only the course 100 that has grade and discard that doesn't have grade this means that I need only to make sure that the WHERE Clause grade is not null shown below.
    UPDATE enrolled
    SET grade = BLOCK_NAME.FIELD_NAME
    WHERE grade IS NOY NULL
    AND IID = BLOCK_NAME.FIELD
    AND faccode = BLOCK_NAME.FIELD
    AND depcode = BLOCK_NAME.FIELD
    AND courseno= BLOCK_NAME.FIELD_NAME
    NAD secno = BLOCK_NAME.FIELD_NAME
    AND SID = BLOCK_NAME.FIELD_NAME

  • Does composite primary key in BMP really work?

    Here's a issue. I have a bean called CalendarEvent which uses name, startTime and endTime in composite fashion for primary key. I have a primary key class defined as well. Now I have a ejbFindByUser method which takes in a name and creates a collection of primary key class objects. THis happens properly. But when the client invokes findByUser it gets a collection of SIMILAR items. Its like only the last primary key object that was added into the collection by ejbFindByUser was translated by the server and the corresponding entity bean returned to the client.
    Please help, this thing is killing me!!!

    Thanks a ton for your response. However I am afraid I didn't fully understand what you were trying to say.
    1) Don't use persisted data for your primary key (and
    certainly not composite keys). This is an old skool
    thing to do, and will end up hurting you later.I don't understand this comment. My database table needs a composite key for uniqueness. So I created my own PK class with those fields as members. The hash code returned by the PK class uses all these member variables to determine the hash code and I believe it will is unique. Also the equals method compares all these member variables. I didn't understand your line about using persisted data for primary key.
    >
    2) Ok, either your ejbFindByXXX() method is not
    returning distinct primary key objects, or your
    ejbLoad() method isn't working. If you can properly
    retrieve an entity via the findByPrimaryKey method,
    then I'd say you should re-examine what your
    ejbFindByXX method is returning to the container.This is my understanding. When the client invokes findByPrimaryKey, the container invokes ejbFindByPrimaryKey with the provided key on ALL the ejb objects of that class. Only one of these EJB objects must be returning the same PK it took as an argument for ejbFindByPrimaryKey. The container must then return that EJB object back to the client. This is what happens in my code as per the logging statements i have in my ejbFindByPrimaryKey method. The argument is a PK object say pk1. I return an object pk2 and i ascertain that pk1 and pk2 have the same hash code and pk1.equals(pk2) returns true. well i guess it wld be easier to just return the argument but i didn't see a problem with this. Now the logging statements in ejbFindByPrimaryKey don't show any problem, they return the same primary key they get.
    But this is what bothers me. I have two records inthe database. The container seems to call my ejbFindByPrimaryKey only once. Shouldn't it be checking twice on each of the ejbs corresponding to each of the records? And ultimately, it returns the wrong ejb back to the client.
    I have no idea about this and would DEEPLY appreciate your help.
    Thanks in anticipation,
    Balan
    >

  • Reconciling composite primary key tables in 9.0.1.4 DB app connector

    Hi
    I am trying to get the reconciliation in the 9.0.1.4 db app connector to work on a view that has a composite primary key (one user_id field and one group_id field)
    There are no examples on how to do this and my "trial-and-error" efforts have not been fruitful this far. Anyone that has any experience of how to solve this problem?
    Best regards
    /Martin

    Hi Martin, our customer is also very sensitive to changes in his HR system, it is a custom oracle development. He provide us a read only view every day with all changes on their identities. We have developed a custom pl/sql proccess to fill a custom local table with the right information . Then we use this table locally with dbtable connector but with some custom addons.
    So i believe that using a second table and keep in synch it is the best approach.
    We have detect some problem with 9.0.1.4 DB app connector, it is using internally only one db connection for all its operations, in a huge load condition its can produce errors and race condition problems. We have a custom connector now and it is using connection pool from application server so we will have not this problem.
    I believe that oracle should release source for their connectors, i am very sure that partners and customers can improve it.

Maybe you are looking for