简体   繁体   中英

Storing an object into a SQL database in Oracle

Simply trying to find the correct syntax/method to enter create SQL objects and store them inside an oracle database. (school project so it's got to be possible)

CREATE OR REPLACE TYPE Person AS OBJECT 
(id NUMBER,
 fname VARCHAR(255), 
 lname VARCHAR(255)) NOT FINAL 

CREATE OR REPLACE TYPE customer UNDER Person (

  num_purchases NUMBER,
  email VARCHAR(255)
);

CREATE TABLE Customers (
 id NUMBER,
 cust customer
);

INSERT INTO Customers(id, cust)
VALUES (1, customer(1, "John", "Doe", 44, "doezer@gmail.com"));

Returns the error ORA-00984: column not allowed here

I can't seem to find any way to declare a specific order for putting the values inside of the customer object other than the order that they were declared in. Thank you!

Seems you are inserting columns not literal values. replace your double quotes to single quotes .

INSERT INTO Customers(id, cust)
VALUES (1, customer(1, 'John', 'Doe', 44, 'doezer@gmail.com'));

SELECT ID, TREAT(cust AS Person).id, TREAT(cust AS Person).fname FROM Customers;

See dbfiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM