Loading a Table with a VARRAY in It: INSERT VALUEs with Constants

Oracle's VARRAYs behave like classes in object-oriented programming.

Classes are instantiated into objects using constructors.

SQL>
SQL> CREATE OR REPLACE TYPE mem_type IS VARRAY(10of VARCHAR2(15)
  2  /

Type created.

SQL>
SQL> CREATE TABLE club (Name VARCHAR2(10),
  2  Address VARCHAR2(20),
  3  City VARCHAR2(20),
  4  Phone VARCHAR2(8),
  5  Members mem_type)
  6  /

Table created.

SQL>
SQL> INSERT INTO club VALUES ('AL','111 First St.','Mobile',
  2  '222-2222', mem_type('Brenda','Richard'));

row created.

SQL>
SQL> INSERT INTO club VALUES ('FL','222 Second St.','Orlando',
  2  '333-3333', mem_type('Gen','John','Steph','JJ'));

row created.

SQL>
SQL> SELECT *
  2  FROM club;

NAME       ADDRESS                                            CITY                 PHONE
---------- -------------------------------------------------- -------------------- --------
MEMBERS
-------------------------------------------------------------------------------------------
AL         111 First St.                                      Mobile               222-2222
MEM_TYPE('Brenda', 'Richard')

FL         222 Second St.                                     Orlando              333-3333
MEM_TYPE('Gen', 'John', 'Steph', 'JJ')


SQL>
SQL>
SQL>
SQL> drop table club;

Table dropped.

SQL> drop type mem_type;

Type dropped.

SQL>
SQL>


文章出自:http://www.java2s.com/Tutorial/Oracle/0520__Collections/LoadingaTablewithaVARRAYinItINSERTVALUEswithConstants.htm

posted @ 2012-02-15 09:40  月亮的影子  阅读(183)  评论(0编辑  收藏  举报