Search code examples
mysqlsqloracle-databaseviewobject-oriented-database

Duplicate Column name When Inserting Data In Object Views


I Have created an Object view from Existing Relational Table When I am trying To Insert data into the Table using view I am Getting Error. Although I am able to insert data into the Students TABLE in relational way

ORA-00957: duplicate column name

My Procedure is following

CREATE TABLE Students
(
 StudID        NUMBER(6)
 CONSTRAINT Students_StudID_PK PRIMARY KEY,
 Sname         VARCHAR2(15),
 Street        VARCHAR2(20),
 CityName      VARCHAR2(20),
 StateName     VARCHAR2(20),
 PinCode       NUMBER(6)
)

This is my relational Table Upon Which I am Creating An Object View

CREATE TYPE MyAddress
AS OBJECT
(
Street        VARCHAR2(20),
CityName      VARCHAR2(20),
StateName     VARCHAR2(20),
PinCode       NUMBER(6)
)

Another One as

CREATE TYPE MyStudent
AS OBJECT
(
  Sname       VARCHAR2(15),
  Saddress    MYAddress
)

Now Object View is Successfully created Using

CREATE OR REPLACE  VIEW StudentOv
(
   StudID,
   StudDEF
)
 AS
  SELECT StudID, MYStudent
      (
         StudID,
         MyAddress
                  (
                    Street,
                    CityName,
                    StateName,
                    PinCode
                  )
      )
FROM Students

And when I am Trying to Insert Data into the View I Got the Error Any Help Will be Appreciated. Thanks In Advance

INSERT INTO StudentOV
VALUES(1204,
    MYSTUDENT('RAMESH',
            MyAddress(
                     'SHYAMA NAGAR',
                      'SECUNDERABAD',
                       'ANDHRA PRADESH',
                        500601
                       )
                )
      )

Solution

  • While creating view, you selected studIdtwice.

    Try this... To create view.

    CREATE OR REPLACE VIEW StudentOv
    (
    StudId,
    StudDEF
    )
    AS
    SELECT StudId, MYStudent
        (
        StudName,
        MyAddress
              (
              Street,
              CityName,
              StateName,
              PinCode
              )
         )
    FROM Students;
    

    Then, try to insert the data into the view.