How to add column in existing table ,this column is nothing but each rows here is object of other table
Can anyone explain to m开发者_StackOverflow社区e how to add a column in an existing table where the datatype for this column is object?
Also tell me how to insert and retrieve the data.
Thanks
Setup:
CREATE TABLE table1 (col1 varchar2(10));
CREATE OR REPLACE TYPE mytype authid definer AS OBJECT
(
thing1 varchar2(10),
thing2 date
);
Answer:
ALTER TABLE table1 ADD col2 mytype;
INSERT INTO table1 VALUES ('a', mytype('A',sysdate));
SELECT col1, t.col2.thing1, t.col2.thing2 FROM table1 t;
ALTER TABLE mytable ADD COLUMN (mynewcol NUMBER);
INSERT INTO mytable (col1, col2, col3, ...) VALUES (1, 'blah', SysDate, ...)
SELECT *
FROM mytable;
精彩评论