Many to many relationship in oracle

i have an employee table and i have a department table
i have to establish a many to many relationship between the two tables
how to do that

You may read about Intersection Tables
or here: About Intersection Tables

Similar Messages

  • Many to many relationships (Again)

    Hello,
    There was a posting on above subject.
    Re: Many to many relationships between Fact and Dimension
    They asked to look chapter 3 in the user's guide... <http://download.oracle.com/docs/pdf/B10996_01.pdf>. chapter 3 talks about defining Oracle Data Objects. I could find above subject in chapter 3 .
    Here is our situation We are using OWB 9.2.0.2.8. We are in a situation to build ETL from denormalized (relational tables) source to normalized target (relational tables). It is not a data warehouse situation. It could be a reverse of data warehouse. As given below
    Supplier >--------------------<Item
    becomes Supplier ------<supp_item.>--------------Item after many to many resolution, Where supp_item is interface table.
    We were able build Supplier and Item through seprate mapping. I could build supp_item through post mapping process. I look for alternate thought as well.
    We are using separate sequence number for Supplier , Item and supp_item. The sequences will be surrogate keys such as Supplier ( Suppseq(PK)), Item (Itemseq (PK)) and supp_item(suppitemseq (PK)) Here is the sample
    Supplier
    001|S001
    002|S002
    003|S003
    004|S004
    Item
    001|I001
    002|I002
    003|I003
    Supp_item (Suppseq|ItemSeq)
    001|002 --- S001 I002
    001003 -----S001 I003
    001|004 ----- S001 I 004
    002|002 ---- S 002 I002
    002|003 ---- S 002 I003
    003|001 --- S 003 I 003
    003|003 --- S 003 I 003
    Did any body face such situation? What is the best way to create a mapping (single map or multiple map with processflow sequence) for this situation?
    Let me know the steps exercised in OWB for this situation.
    I appreciate your help.
    Regards
    Ram

    Hi Ram,
    The easiest way to do this, would be to:
    - Load supplier in one mapping and generate the surrogate key.
    - Load item another (or the same) mapping and generate the surrogate key.
    - Load supplier_item in its own separate mapping, using a key lookup (or join) to (with) the supplier and item tables.
    Needless to say, you should create unique keys on the natural key of the supplier and item tables, to enable quick index-based lookups and make sure you get one unique value for every value of the natural key.
    Hope this helps,
    Mark.

  • Modeling a Many to Many relationship

    How can I modeling a Many to Many relationship between a fact table and a dimensión in Essbase?
    For example I have a economic zone dimension and a record in the fact is just related to one country... but a country is related to many economic zone...
    Is this posible?
    Thanks.

    Glenn kibbitzes (sp?) on my answers, so it's payback time. :)
    There are a couple of ways to approach this:
    1) Shared hierarchies: Create a master hierarchy that contains all of your regions/countries/states/provinces/parishes/principalities. Call this one Total. Create separate, nonconsolidating hierarchies like Atlantic, Pacific, etc., and use Essbase's shared members functionality to get those totals.
    2) Put two (or more) attribute dimensions against your Geography dimension and assign the base members (Mexico, Brazil, etc.) to attribute dimensions like Atlantic or Pacific. These would be one member attribute dimensions.
    3) Use a UDA to do much the same as #2, but with poorer reporting capabilities.
    Regards,
    Cameron Lackpour
    Edited by: CL on Jul 18, 2009 6:33 PM
    Owned by Glenn when he pointed out my mistake with approach #2. Oh, the humiliation. But now it's fixed. Never tangle with an Oracle Ace -- your ego will be handed to you, in a nicely wrapped box, with a pretty bow to make the pain go away.

  • Self referencing table many to many relationship

    I am in a bit of a logic pickle, and I was wondering if someone could help me out.
    I have a table in a database I am designing called document, it holds information on surprisingly on documents in our DMS.
    I want to create the notion that a document can have multiple related documents, and those documents can be the related documents for many documents.
    So it is a self referencing table, I have done these before so no big deal, but this time is a many to many relation, it wasnt before.
    Maybe something like:
    document
    docid (pk)
    related_doc
    docid (pk) (fk to document.docid)
    related_docid (pk) fk to document.docid)
    Does anyone have any experience with this or any advise I might find sueful?
    Thanks!

    A junction table can be used to resolve a many-to-many relationship as is in your example. There are two PK/FK relationships between document and related_document table. This will prevent denormalization of data.
    The other option could be to have just one table with two columns (parent_doc_id and child_doc_id) and have a PK constraint on both the columns - just like bill-of-materials.
    But I think the approach you have in your posting will work well.
    Shakti
    http://www.impact-sol.com
    Developers of Guggi Oracle - Tool for DBAs and Developers

  • From MS Access One-to-Many Form to Oracle Express

    Hello, hello,
    Firstly, I am new at Oracle and interested to really getting into out, however, I am a little ancy to get going. I'm looking for some sharp direction that could direct me to exactly what I need to do right now and then I can do further study, etc.
    I have a MS Access database with many tables, queries, etc. But I set up a fancy form whereby I could scroll to the name (let's say EMPLOYEE) and then I have about 10 different forms (a tabbed interface because there were so many) show up where I could input data about that employee specifically. Then when I scroll to the next person, all of the subforms would change accordingly.
    Thus, ultimately, what I would like to do using Oracle Express and APEX is to set up a page where I have a region which will pull a list of employees and act as a menu, then when someone select an employee (i.e., not only me) then all information, from numerous different tables pulls up and is visible, editable and can be added to. There could be a region for addresses, a region for links, for notes, for photos, for a list of articles, or whatever.
    I hope you track with what I am looking at. In Access I have numerous tables, then I create a monstrous one-many relationship thingamajiggy and ka-boom, things all fit together in a form, and subforms. All editable by me, but hardly available for anyone else. I know Oracle is the way to go, so...
    Can you assist me by explaining what I need to implement in Oracle? I am not clear on JOINs and what's the right one to use, how to adequately connect all of the dots, etc. Do I need to set up fancy queries, create SQL statements or what?
    Thanks.

    Thanks. I don't think my question is strictly APEX related.
    Rather, I am trying to determine how to create a "one-to-many" relationship (to use MS Access terminology) in Oracle Express. And then solve how to add data to them.
    I can create a view which links two tables together where I can add data, but I want to be able to be adding data to several tables all linked together from the same primary key. One row per person (or employee) won't handle this, particularly if you want to add more than one row of data about the person in a table.
    For example, if I had a restaurant with four employees (a cook, a waitress, a baker and a cleaner), my employees table would only have four rows. But now if I wanted to record the types of desserts the baker could make, that would take up more than one row. Therefore, from the baker, it would have to link to another table where I could input data about the different desserts. Typical one-to-many relationship. But the baker can also make different kinds of bread, thus another table with several rows. Perhaps the baker is so good, I may want to have yet another table for his different supremely delicious and famous pies (apple, pumpkin, pecan, etc.) which is now another table. The options are endless, but they all connect to the baker.
    As a result, someone could come to my application and ask what can the baker do, and it will pull up a table of desserts, a table of pies and a table of breads.
    Once I figure that out and can link many tables together using one primary key, then I presume I can easily move into the web application aspect. But for now, I am not quite there yet.
    If someone can at least direct me as to what this is called in Oracle and give me a little direction, then I will feel more confident in moving forward. Thanks again!

  • Portal Form for a Many to Many relationship

    I have 3 tables (well there are actually more but i'm glad when i can do the trick with 3 at the moment):
    T_JOURNAL (JOURNAL_ID, JOURNAL_NAME)
    T_CONTENTBROKER (CONTENTBROKER_ID, CONTENTBROKER_NAME)
    HT_JOURNAL_CONTENTBROKER (JOURNAL_ID, CONTENTBROKER_ID)
    The HT stants for 'help table'. T_JOURNAL and T_CONTENTBROKER have a many to many relationship. So one Journal can have many Broker and one Broker has many Journals.
    When doing a Form in Oracle Portal for adding a new Journal, i'd like to have a LoV with the Brokers. But an new entry would at least require 3 tables to update (T_JOURNAL, T_CONTENTBROKER and the help table HT_JOURNAL_CONTENTBROKER). How can this be solved? i'm not very good with pl/sql... so if there is only a solution with pl/sql i would be glad for the code...
    I also tried to create a view wich would show me the journal with all its broker but i kind of failed...
    any suggestions appreciated ;)
    - renato

    Thanks for the info. I tried that and it still doesn't pull the value. I have opened a TAR via metalink, but I'm not getting any
    satisfactory answers. I ran across an note - 137172.1 that has this snippet of information in it.
    Unfortunately, at this time (portal 3.0.7.6.2) , a non-table item cannot be
    referenced in a plsql event handler, only in client side JavaScript code. This
    is a known limitation and will be fixed in a future release.
    I don't know how to get the value from the client side JavaScript code to a pl/sql variable. Do you?
    I've been trying to get them to tell me if the 'known issue' has been addressed in 3.0.9.
    I'll keep at it. Thanks so much for your suggestion I appreciate it.
    Deb

  • Complex many to many relationships

    I am new to Oracle ADF and i have a question about associations.
    I have 3 business objects: User, Position and Country. A User can have different Positions for each Country. Therefore, i decided to create another BO, named UserPosition which has 4 attributes: Id, UserId, PositionId and CountryId.
    I wonder which is the best way to define associations for these objects.
    Should i define three "1 to *" associations between each BO's and UserPosition?
    Thanks.

    Usually if you have two tables with many-to-many relationship, you would have third table and its PK should be made of from 1st and 2nd tables. I think you are right. You need the 4th one with a new PK.

  • Many to Many Relationship using junction table..

    Hello im testing a many to many relation ship on j2ee and found this issue.
    Creating a relation ship table until now without succes to update the relationship table:
    code fragment as is:
    On application flow my session bean call the following method according with the specification i have no reason to call persist in my writer just on parent Object: Any clue on what is wrong ?
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void saveWriter (Book book , Writer writer){
    try {
    Book atBook = entityManager.merge(book);
    Writer atWriter = entityManager.merge(writer);
    book.getWriters().add(atWriter);
    entityManager.persist(atBook);
    entityManager.flush();
    }catch (Exception ex)
    ex.printStackTrace();
    <entity class="com.octech.biblio.domain.Book" name="book">
    <description></description>
    <table name="books" />
    <attributes>
    <id name="id">
    <generated-value strategy="IDENTITY"/>
    </id>
    <basic fetch="EAGER" name="bookName">
    <column insertable="true" length="128" name="bookname" table="" updatable="true"/>
    </basic>
    <many-to-one name="Library" fetch="LAZY" target-entity="com.octech.biblio.domain.Library">
    <join-table name="library_books">
    <join-column name="books_id"/>
    <inverse-join-column name="library_id"/>
    </join-table>
    <cascade/>
    </many-to-one>
    <many-to-many name="Writers" fetch="LAZY" target-entity="com.octech.biblio.domain.Writer">
    <join-table name="writers_books">
    <join-column name="books_id"/>
    <inverse-join-column name="writer_id"/>
    </join-table>
    <cascade/>
    </many-to-many>
    </attributes>
    </entity>
    <entity class="com.octech.biblio.domain.Writer" name="writer">
    <description></description>
    <table name="writers" />
    <attributes>
    <id name="id">
    <generated-value strategy="IDENTITY"/>
    </id>
    <basic fetch="EAGER" name="writerName">
    <column insertable="true" length="128" name="writer_name" table="" updatable="true"/>
    </basic>
    <many-to-many name="Books" fetch="LAZY" target-entity="com.octech.biblio.domain.Book">
    <join-table name="writers_books">
    <join-column name="writer_id"/>
    <inverse-join-column name="books_id"/>
    </join-table>
    <cascade/>
    </many-to-many>
    </attributes>
    </entity>

    sybrand_b wrote:
    The way you write it yes, but there is one minor detail.
    You can have a 0,1 or many relationship: one employee has zero, one or many phone numbers
    but you can not have the opposite, as it doesn't make sense.
    0, 1 or many phone numbers belong to 1 employee.
    It is customary to use 0,1 or m when the relationship is optional.
    Sybrand Bakker
    Senior Oracle DBAIs this correct now ?
    one to many : one employee has 0,1 or multiple phone numbers
    many to one : 1 or multiple phone numbers to one employee

  • Many-to-many relationship performance problem

    Hi:
    I have model that uses a bridge table to solve a many-to-many relationship. Here it is:
    dimension 1 -< fact table >-dimension 2-< bridge table >-additional data table
    Now, when I drive from the additional data table with a specific value and join to the bridge table and dimension 2, the performance is fine. But, as soon as I add the fact table to the query, the query never returns. I'm in a development environment, so my fact table has 220K records, and the bridge table has 200K records. The dimension 2 and additional data tables have hundreds of records. In other words, it's not much data. I have indexes and referential constraints on all relevant columns.
    Can anyone suggest what is happening to cause such a performance hit when I add the fact table to the query?
    Thanks for any suggestions!

    sybrand_b wrote:
    The way you write it yes, but there is one minor detail.
    You can have a 0,1 or many relationship: one employee has zero, one or many phone numbers
    but you can not have the opposite, as it doesn't make sense.
    0, 1 or many phone numbers belong to 1 employee.
    It is customary to use 0,1 or m when the relationship is optional.
    Sybrand Bakker
    Senior Oracle DBAIs this correct now ?
    one to many : one employee has 0,1 or multiple phone numbers
    many to one : 1 or multiple phone numbers to one employee

  • Many to many relationship in 11g

    How to define a Many-to-Many relationship with OBI 11g like bridge table in 10g? is there the way to design it?

    Hi ,
    Many to Many relationship for which bridge table was used is now disabled in 11g. This option is being replaced by the option of 'Look up table'.  There is offcourse way to define it. You need to create back end intermediate table which can interact between 2 dims or 2 facts. Best example you can find in the below link given of oracle.
    Working with Logical Tables, Joins, and Columns
    In this scenario , suppose we have 2 dim tables like Jobs, employees.
    1) 1 employees can fulfill multiple job
    2) 1 Job can be fulfilled by multiple employees.
    3) Intermediate table we could create here is assignment which is having both the information. In this employee id will be unique as primary key however for assignment column primary key is its composite key so that for 1 employee lot of rows of assignments could be assigned.
    Thanks,
    Amol
    (Please mark this answer, if you find helpful)

  • Newbie: one to many relationship SQL error

    Greetings all-
    This is probably a slam dunk for you JDO experts. I'm a JDO newbie, working
    with an existing schema in MySQL. I have a one to many relationship between
    two tables:
    Table "company":
    Fields:
    company_id: int(11) -- primary key
    name : varchar(64)
    division : varchar(64)
    Table "company_products"
    Fields:
    company_id: int(11) -- foreign key to table company
    product_name: varchar(64)
    product_description: varchar(64)
    So, I created the corresponding classes:
    public class Company {
    private int companyID;
    private String company_name;
    private String division;
    // Array of CompanyProduct
    private ArrayList companyProducts;
    // .. methods omitted
    public class CompanyProduct {
    private int companyID;
    private String productName;
    private String productDesc;
    // Methods omitted
    Then I created the "package.jdo" file:
    <?xml version="1.0"?>
    <jdo>
    <package name="com.packexpo.db">
    <class name="Company">
    <extension vendor-name="tt" key="table" value="company"/>
    <extension vendor-name="tt" key="pk-column" value="company_id"/>
    <extension vendor-name="tt" key="lock-column" value="none"/>
    <extension vendor-name="tt" key="class-column" value="none"/>
    <field name="companyID">
    <extension vendor-name="tt" key="data-column" value="company_id"/>
    </field>
    <field name="name">
    <extension vendor-name="tt" key="data-column" value="name"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    <field name="division">
    <extension vendor-name="tt" key="data-column" value="division"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    <field name="companyProducts">
    <collection element-type="com.packexpo.db.CompanyProduct"/>
    <extension vendor-name="tt" key="inverse" value="companyID"/>
    </field>
    </class>
    <class name="CompanyProduct">
    <extension vendor-name="tt" key="table" value="company_product"/>
    <extension vendor-name="tt" key="pk-column" value="company_id"/>
    <extension vendor-name="tt" key="lock-column" value="none"/>
    <extension vendor-name="tt" key="class-column" value="none"/>
    <field name="companyID">
    <extension vendor-name="tt" key="data-column" value="company_id"/>
    </field>
    <field name="productName">
    <extension vendor-name="tt" key="data-column" value="product_name"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    <field name="productDesc">
    <extension vendor-name="tt" key="data-column"
    value="product_description"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    </class>
    </package>
    </jdo>
    Enhancement works fine. I successfully query and retrive Company objects
    from the database, but as soon as I try to get the list of CompanyProducts,
    I get an SQL Error:
    javax.jdo.JDODataStoreException: [SQL=SELECT company.COMPANYPRODUCTSX FROM
    company WHERE company.company_id = 82061]
    E0610 Error in executeQuery()
    E0606 executeQuery() error --
    E0701 Error in getResult().
    E0708 Command results in error - 1054 Unknown column
    'company.COMPANYPRODUCTSX' in 'field list'
    NestedThrowables:
    com.solarmetric.kodo.impl.jdbc.sql.SQLExceptionWrapper: [SQL=SELECT
    company.COMPANYPRODUCTSX FROM company WHERE company.company_id = 82061]
    E0610 Error in executeQuery()
    E0606 executeQuery() error --
    E0701 Error in getResult().
    E0708 Command results in error - 1054 Unknown column
    'company.COMPANYPRODUCTSX' in 'field list'
    I know i have probably set up the package.jdo file incorrectly, but I'm at a
    loss for what I did wrong.
    Any suggestions?
    Thanks!
    -Mike

    Hi,
    915766 wrote:
    I need to write sql for below requirement:
    table structure is
    serial no LPN
    1 4
    2 4
    3 6
    4 6
    5 6
    6 3
    7 3
    8 3
    9 1
    I have to pick distinct 'LPN' like below:That sounds like a job for "GROUP BY lpn".
    (any serial no can be picked for the distinct LPN)It looks like you're displaying the lowest serial_no for each lpn. That's easy to do, using the aggregate MIN function.
    results needs to be as below:
    serial no LPN
    1 4
    3 6
    6 3
    9 1
    Please suggest with sql.Here's one way:
    SELECT    MIN (serial_no)   AS serial_no
    ,         lpn
    FROM      table_x
    GROUP BY  lpn
    ORDER BY  lpn     -- if wanted
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • One-to-many relationship: problem with several tables on the one side...

    Hello
    I'm having problems developing a database for a content management system. Apart from details, I've got one main table, that holds the tree structure of the content ("resources") and several other tables that contain data of a particular datatype ("documents", "images", etc.). Now, there's one-to-many relationship between "resources" table and all the datatype tables - that is, in the "resources" table there's "resource_id" column, being a foreign key referenced to the "id" columns in the datatype tables.
    The problem is that this design is deficient. I can't tell form the "resource_id" column from which datatype table to get the data. It seems to me that one-to-many relationship only works with two tables. If the data on the one side of the relationship is contained in several tables, problems arise.
    Anybody knows a solution? I would be obliged.
    Regards
    Havocado

    Hi;
    A simple way may be create a view on referenced tables:
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> drop table resources;
    Table dropped
    SQL> create table resources(id number, name varchar2(12));
    Table created
    SQL> insert into resources values(1,'Doc....');
    1 row inserted
    SQL> insert into resources values(2,'Img....');
    1 row inserted
    SQL> drop table documents;
    Table dropped
    SQL> create table documents(id number, resource_id number,type varchar2(12));
    Table created
    SQL> insert into documents values(1,1,'txt');
    1 row inserted
    SQL> drop table images;
    Table dropped
    SQL> create table images(id number, resource_id number,path varchar2(24));
    Table created
    SQL> insert into images values(1,2,'/data01/images/img01.jpg');
    1 row inserted
    SQL> create or replace view vw_resource_ref as
      2    select id, resource_id, type, null as path from documents
      3      union
      4     select id, resource_id, null as type, path from images;
    View created
    SQL> select * from resources r inner join vw_resource_ref rv on r.id = rv.resource_id;
            ID NAME                 ID RESOURCE_ID TYPE         PATH
             1 Doc....               1           1 txt         
             2 Img....               1           2              /data01/images/img01.jpg
    SQL> Regards....

  • One-to-many relationships problem

    Hi,
    I'm having some problems with one-to-many relationships.
    I've a two way relationship beetwen Person and Document.
    Person has a collection of Documents (1-n).
    Document has an instance for Person.
    In my database schema Document has a FK for person.
    The problem occurs when I'm trying to save the Person object
    with a collection of Documents.
    Oracle gives me the following message:
    ORA-00001: unique constraint (SMS.PK_PERSON) violated
    In my kodo.properties file I put:
    kodo.jdbc.ForeignKeyConstraints: true
    It seems that when the collection of Documents is persisted, kodo tries to
    save a new Person object for each Document.
    When I have just one instance of Document in my collection kodo persists
    it ok, but when I have move instances I get
    that problem.
    Can somebody help me?
    Thanks in advance,
    Joan Caffee

    You need to make sure each Document references the same Person object in
    the JVM. JDO persists your object model as-is. Each distinct JVM
    object becomes a distinct database record. You can't have multiple JVM
    objects in the same PersistenceManager representing the same database
    record.

  • Using data from one-to-many relationship

    Hi,
    i have an one-to-many relationship among two tables similar to the structure as in the below reference:-
    [One-to-many-reference|http://docs.oracle.com/cd/E23507_01/Platform.20073/RepositoryGuide/html/s1204repositoryexamplefonetomanymappi01.html]
    taking this as an example, i have the city's name with me. using this data in the addr_tbl in the 'address' item-descriptor, i need to get the value of the 'name' in the usr_tbl in the 'user' item descriptor. i will have the list of 'city' with me which i have to iterate and display the corresponding 'name'.
    will i be able to perform this in the jsp itself or does it have to be done in java? a sample code snippet or reference for doing this will be of much help.
    thank you.

    Thanks a lot, Sheik.
    if i have to do the reverse, ie for the 'name' in the usr_tbl of user item-descriptor i have to fetch the 'city' values in the addr_tbl, will it suffice if i do the following?
    <dsp:droplet name="/atg/dynamo/droplet/RQLQueryForEach">
    <dsp:param name="queryRQL" value="name=\"sirius\""/>
    <dsp:param name="repository"
    value="/com/MyRepository"/>
    <dsp:param name="itemDescriptor" value="user"/>
    <dsp:oparam name="output">
    <dsp:valueof param="element.address.city"/>
    </dsp:oparam>
    </dsp:droplet>

  • Modeling a many-to-many relationship in a dimension

    Hi, I'm using AWM and I need to create a book dimension which aggregates books about their authors.
    My table is: BRIDGE_TABLE_BOOKS(book_key, author_key)
    Its data are for example:
    Book - Author
    1 - 1
    1 - 2
    2 - 1
    3 - 2
    4 - 1
    4 - 2
    5 - 1
    because a book can be written by 1 or more authors.
    I'd like that AWM could aggregate them through authors as follows:
    1
    ->1
    ->2
    ->4
    ->5
    2
    ->1
    ->3
    ->4
    is it possibile in AWM?

    many-to-many relationships are always represented as fact tables in a dimensional model (Kimball likes the idea of the "bridge" table...but in my opinion a bridge table is nothing more than a 2 dimensional fact table). Doesn't matter whether you're using relational or OLAP, works the same either way.
    Simply create a cube dimensioned by book and author. Have a character or boolean measure with Y/N or true/false. Insert tuples where a given book was written by a given author. This is one area where relational is better - don't have to have a dummy measure, just make a "factless fact table" (you can do this in Oracle OLAP also...but it's gotten to the point where Oracle has tried to hide all the complexity of the OLAP language. Unfortunately, that hides a lot of power also...)
    What type of reports are you trying to get out?
    Thx,
    Scott

Maybe you are looking for