databaseoracle-databasenested-tableodb

Oracle ODB - nested tables


i have problem with creating new nested object in table. Problem is in last line. The Rest is going good. Error: "PACJENT: Invalid identifier", when i put there NULL it is work, but i need put there new PACJENT. Can u help me ?

PLACÓWKA

CREATE TYPE placowka_typ AS OBJECT (nazwa VARCHAR2(50), adres VARCHAR(250));
CREATE TABLE placowka_table OF placowka_typ;
INSERT INTO placowka_table VALUES (placowka_typ ('xxx', 'xxx'));

LEKARZ

CREATE TYPE lekarz_typ AS OBJECT (imie VARCHAR2(50), nazwisko VARCHAR(50),specjalizacja VARCHAR(150));
CREATE TABLE lekarz_table OF lekarz_typ;
INSERT INTO lekarz_table VALUES (lekarz_typ ('xxx','xxx', 'xxx')); 

PACJENT

CREATE TYPE pacjent_typ AS OBJECT (imie VARCHAR2(30),nazwisko VARCHAR(50), adres VARCHAR(250), data_zlecenia DATE, data_urodzenia DATE, pesel NUMBER(11));
CREATE TABLE pacjent_table OF pacjent_typ;
INSERT INTO pacjent_table VALUES (pacjent_typ ('xxx','xxx','xxx','2012-01-11','1997-11-24',xxx)); 

BADANIE

CREATE TYPE badanie_typ AS OBJECT (id_badania VARCHAR(10),nazwa_badania VARCHAR2(75), data_badania DATE, lekarz lekarz_typ, pacjent pacjent_typ, placowka REF placowka_typ);
CREATE TABLE badanie_table OF badanie_typ;
ALTER TABLE Badanie_table ADD SCOPE FOR(placowka) IS Placowka_table;
INSERT INTO badanie_table VALUES (badanie_typ ('xxx','xxx', '2014-03-13',NULL,NULL,NULL));
UPDATE Badanie_table b SET b.PLACOWKA = (SELECT REF(p) FROM Placowka_table p WHERE p.NAZWA = 'xxx%');
SELECT b.Nazwa_badania, DEREF (b.placowka) FROM BADANIE_TABLE b;
SELECT b.Nazwa_badania, b.placowka.nazwa FROM BADANIE_TABLE b;
DELETE FROM LEKARZ_TABLE WHERE IMIE = 'xxx';
DELETE FROM PACJENT_TABLE WHERE IMIE = 'xxx';
DELETE FROM BADANIE_TABLE WHERE ID_BADANIA = 'xxxx';
INSERT INTO badanie_table VALUES (badanie_typ ('xxx','xxx', '2014-03-13',LEKARZ('xxx','xxx','xxx'), pacjent('xxx','xxx','xxx','2014-03-13','1997-11-24',xxx),NULL));

Error:

Error at Command Line : 1 Column : 141
Error report -
SQL Error: ORA-00904: "PACJENT": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Solution

  • You don't have a type (or any other object) called pacjent, you just have a field with that name within another object type.

    You seem to be wanting to insert an instance of the pacjent_typ object. You have the same issue with your lekarz reference:

    INSERT INTO badanie_table VALUES (
      badanie_typ ('xxx','xxx', date '2014-03-13',
        lekarz_typ('xxx','xxx','xxx'),
        pacjent_typ('xxx','xxx','xxx',date '2014-03-13',date '1997-11-24',999),
        NULL
      )
    );
    

    As you have object tables for those types it might make more sense for those two fields in badanie_typ to also be REFs, rather than independent objects, as you've done for placowka:

    CREATE TYPE badanie_typ AS OBJECT (id_badania VARCHAR(10), nazwa_badania VARCHAR2(75), data_badania DATE,
      lekarz REF lekarz_typ, pacjent REF pacjent_typ, placowka REF placowka_typ);
    /
    CREATE TABLE badanie_table OF badanie_typ;
    ALTER TABLE Badanie_table ADD SCOPE FOR(lekarz) IS lekarz_table;
    ALTER TABLE Badanie_table ADD SCOPE FOR(pacjent) IS pacjent_table;
    ALTER TABLE Badanie_table ADD SCOPE FOR(placowka) IS placowka_table;
    
    INSERT INTO badanie_table VALUES (badanie_typ ('xxx','xxx', date '2014-03-13',
      (SELECT REF(l) FROM lekarz_table l WHERE l.imie = 'xxx'),
      (SELECT REF(p) FROM pacjent_table p WHERE p.imie = 'xxx'),
      (SELECT REF(p) FROM Placowka_table p WHERE p.nazwa = 'xxx')
    ));