<1>create type t_dept as object(deptno number,dname varchar2(20),loc varchar2(20));
<2>
-- create table
create table emp
(empno number(4) not null,
ename varchar2(10),
job varchar2(9),
mgr number(4),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2),
dept t_dept
)tablespace users
pctfree 10
initrans 1
maxtrans 255
storage
(initial 64k
next 1m
minextents 1
maxextents unlimited
);-- create/recreate primary, unique and foreign key constraints
alter table emp
add constraint pk_emp primary key (empno)
using index
tablespace users
pctfree 10
initrans 2
maxtrans 255
storage
(initial 64k
next 1m
minextents 1
maxextents unlimited
);<3>
declare
t scott.dept%rowtype;
begin
for rec in (select empno, deptno from emp) loop
select * into t from scott.dept where deptno = rec.deptno;
update emp a set a.dept = t_dept(t.deptno, t.dname, t.loc);
end loop;
end;
select * from emp;
<4>
empno ename job mgr hiredate sal comm deptno dept.deptno dept.dname dept.loc
1 7369 smith clerk 7902 12/17/1980 800.00 20 10 accounting new york
2 7499 allen salesman 7698 2/20/1981 1600.00 300.00 30 10 accounting new york
3 7521 ward salesman 7698 2/22/1981 1250.00 500.00 30 10 accounting new york
4 7566 jones manager 7839 4/2/1981 2975.00 20 10 accounting new york
5 7654 martin salesman 7698 9/28/1981 1250.00 1400.00 30 10 accounting new york
6 7698 blake manager 7839 5/1/1981 2850.00 30 10 accounting new york
7 7782 clark manager 7839 6/9/1981 2450.00 10 10 accounting new york
8 7788 scott analyst 7566 4/19/1987 3000.00 20 10 accounting new york
9 7839 king president 11/17/1981 5000.00 10 10 accounting new york
10 7844 turner salesman 7698 9/8/1981 1500.00 1.00 30 10 accounting new york
11 7876 adams clerk 7788 5/23/1987 1100.00 20 10 accounting new york
12 7900 james clerk 7698 12/3/1981 950.00 30 10 accounting new york
13 7902 ford analyst 7566 12/3/1981 3000.00 20 10 accounting new york
14 7934 miller clerk 7782 1/23/1982 1300.00 10 10 accounting new york
oracle自定義型別
1 定義乙個型別 sql create or replace type propertyvalue as object number value number,string value varchar2 2000 date value date,member function getnumberva...
oracle 自定義型別
而如果沒有這句話 index by binary integer 那就得要顯示對初始化,且每插入乙個元素到numbers型別的table中時,都需要先extend.示例 沒加 index by binary integer 時 declare type my number arr is table ...
oracle 自定義型別
例1 批量 查詢部門號為 10 號的並把它們列印出來 declare type emp table type is table of my emp rowtype index by binary integer v emp table emp table type begin select bulk...