Use * to reference all columns from a table : Object Column « Object Oriented « Oracle PL/SQL Tutorial

Home
Oracle PL/SQL Tutorial
1.Introduction
2.Query Select
3.Set
4.Insert Update Delete
5.Sequences
6.Table
7.Table Joins
8.View
9.Index
10.SQL Data Types
11.Character String Functions
12.Aggregate Functions
13.Date Timestamp Functions
14.Numerical Math Functions
15.Conversion Functions
16.Analytical Functions
17.Miscellaneous Functions
18.Regular Expressions Functions
19.Statistical Functions
20.Linear Regression Functions
21.PL SQL Data Types
22.PL SQL Statements
23.PL SQL Operators
24.PL SQL Programming
25.Cursor
26.Collections
27.Function Procedure Packages
28.Trigger
29.SQL PLUS Session Environment
30.System Tables Data Dictionary
31.System Packages
32.Object Oriented
33.XML
34.Large Objects
35.Transaction
36.User Privilege
Oracle PL/SQL Tutorial » Object Oriented » Object Column 
32.7.9.Use * to reference all columns from a table
SQL>
SQL>
SQL> CREATE TABLE DEPT (DEPTNO NUMBER(2),DNAME VARCHAR2(14),LOC VARCHAR2(13) );

Table created.

SQL>
SQL> INSERT INTO DEPT VALUES (10'ACCOUNTING', 'NEW YORK');

row created.

SQL> INSERT INTO DEPT VALUES (20'RESEARCH', 'DALLAS');

row created.

SQL> INSERT INTO DEPT VALUES (30'SALES', 'CHICAGO');

row created.

SQL> INSERT INTO DEPT VALUES (40'OPERATIONS', 'BOSTON');

row created.

SQL>
SQL>
SQL> CREATE TABLE EMP (EMPNO NUMBER(4NOT NULL,
  2                    ENAME VARCHAR2(10),
  3                    JOB VARCHAR2(9),
  4                    MGR NUMBER(4),
  5                    HIREDATE DATE,
  6                    SAL NUMBER(72),
  7                    COMM NUMBER(72),
  8                    DEPTNO NUMBER(2));

Table created.

SQL>
SQL> INSERT INTO EMP VALUES (7369'SMITH', 'CLERK',    7902, TO_DATE('17-DEC-1980', 'DD-MON-YYYY'), 800, NULL, 20);

row created.

SQL> INSERT INTO EMP VALUES (7499'ALLEN', 'SALESMAN', 7698, TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 160030030);

row created.

SQL> INSERT INTO EMP VALUES (7521'WARD',  'SALESMAN', 7698, TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 125050030);

row created.

SQL> INSERT INTO EMP VALUES (7566'JONES', 'MANAGER',  7839, TO_DATE('2-APR-1981',  'DD-MON-YYYY'), 2975, NULL, 20);

row created.

SQL> INSERT INTO EMP VALUES (7654'MARTIN', 'SALESMAN', 7698,TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250140030);

row created.

SQL> INSERT INTO EMP VALUES (7698'BLAKE', 'MANAGER', 7839,TO_DATE('1-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30);

row created.

SQL> INSERT INTO EMP VALUES (7782'CLARK', 'MANAGER', 7839,TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);

row created.

SQL> INSERT INTO EMP VALUES (7788'SCOTT', 'ANALYST', 7566,TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);

row created.

SQL> INSERT INTO EMP VALUES (7839'KING', 'PRESIDENT', NULL,TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);

row created.

SQL> INSERT INTO EMP VALUES (7844'TURNER', 'SALESMAN', 7698,TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500030);

row created.

SQL> INSERT INTO EMP VALUES (7876'ADAMS', 'CLERK', 7788,TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);

row created.

SQL> INSERT INTO EMP VALUES (7900'JAMES', 'CLERK', 7698,TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 950, NULL, 30);

row created.

SQL> INSERT INTO EMP VALUES (7902'FORD', 'ANALYST', 7566,TO_DATE('3-DEC-1981', 'DD-MON-YYYY'), 3000, NULL, 20);

row created.

SQL> INSERT INTO EMP VALUES (7934'MILLER', 'CLERK', 7782,TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);

row created.

SQL>
SQL> create or replace type emp_type
  2    as object
  3    (empno       number(4),
  4     ename       varchar2(10),
  5     job         varchar2(9),
  6     mgr         number(4),
  7     hiredate    date,
  8     sal         number(72),
  9     comm        number(72)
 10    );
 11  /

Type created.

SQL>
SQL> create or replace type emp_tab_type
  2    as table of emp_type
  3  /

Type created.

SQL> create table dept_and_emp
  2    (deptno number(2primary key,
  3     dname     varchar2(14),
  4     loc       varchar2(13),
  5     emps      emp_tab_type
  6    )
  7    nested table emps store as emps_nt;

Table created.

SQL>
SQL> alter table emps_nt add constraint emps_empno_unique
  2               unique(empno)
  3  /

Table altered.



SQL>
SQL> insert into dept_and_emp
  2    select dept.*,
  3       CASTmultisetselect empno, ename, job, mgr, hiredate, sal, comm
  4                         from emp
  5                         where emp.deptno = dept.deptno AS emp_tab_type )
  6      from dept
  7  /

rows created.

SQL>
SQL> select d.deptno, d.dname, emp.*
  2    from dept_and_emp D, table(d.empsemp
  3  /

    DEPTNO DNAME               EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM
---------- -------------- ---------- ---------- --------- ---------- --------- ---------- ----------
        10 ACCOUNTING           7782 CLARK      MANAGER         7839 09-JUN-81       2450
        10 ACCOUNTING           7839 KING       PRESIDENT            17-NOV-81       5000
        10 ACCOUNTING           7934 MILLER     CLERK           7782 23-JAN-82       1300
        20 RESEARCH             7369 SMITH      CLERK           7902 17-DEC-80        800
        20 RESEARCH             7566 JONES      MANAGER         7839 02-APR-81       2975
        20 RESEARCH             7788 SCOTT      ANALYST         7566 09-DEC-82       3000
        20 RESEARCH             7876 ADAMS      CLERK           7788 12-JAN-83       1100
        20 RESEARCH             7902 FORD       ANALYST         7566 03-DEC-81       3000
        30 SALES                7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300
        30 SALES                7521 WARD       SALESMAN        7698 22-FEB-81       1250        500
        30 SALES                7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400

    DEPTNO DNAME               EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM
---------- -------------- ---------- ---------- --------- ---------- --------- ---------- ----------
        30 SALES                7698 BLAKE      MANAGER         7839 01-MAY-81       2850
        30 SALES                7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0
        30 SALES                7900 JAMES      CLERK           7698 03-DEC-81        950

14 rows selected.

SQL>
SQL> drop table dept cascade constraint;

Table dropped.

SQL> drop table emp;

Table dropped.

SQL> drop table dept_and_emp;

Table dropped.

SQL> drop type emp_tab_type;

Type dropped.

SQL> drop type emp_type;

Type dropped.

SQL>
SQL>
32.7.Object Column
32.7.1.Using Object Types to Define Column Objects and Object Tables
32.7.2.You can use an object type to define an entire table, and the table is known as an object table.
32.7.3.The Object Type Column Objects
32.7.4.Loading the 'row object' Table
32.7.5.SELECT with a WHERE Clause
32.7.6.UPDATE Data in a Table of Row Objects
32.7.7.Using UPDATE with TYPEed Columns
32.7.8.Query a table with user-defined column type
32.7.9.Use * to reference all columns from a table
32.7.10.Use 'table of custom type' as table column type
32.7.11.Nested varray and table collection column
32.7.12.Create type and use it as table column
32.7.13.Nested type Column
32.7.14.Create a new type and add it to a table
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.