<div id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New',courier,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New',monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px">------------------------抽象数据类型---------<span style="color: #008000">--
方法
replace type address (
属性
属性
final; -- final表示该类型可以有子类型
address说明这个类型继承至address类型replace type detailAddress address (
属性 第3个成员empInfo
empInfo (
(2),--性别,--年龄增加数据,只能用构造方法empInfo (,,28,detailAddress(,,));
empInfo (,26,,));
empInfo (,,29,));
查询* empInfo;
* empInfo eSex = ;
* empInfo e e.eAddress.city = ; --如果查询条件包含属性必须用表的别名
empInfo e e.eAddress = detailAddress(,) e.eName = ;
empInfo e e.eAddress.city = e.eName = ;
删除empInfo e e.eAddress.city = ;
属性建立索引idxemp empInfo(eAddress.city);
删除empInfo;
type address force; --强制删除抽象类型replace type person (
(2),--性别--年龄final;replace type student person (
stuInfo student;
stuInfo pk_stuInfo (stuId);
stuInfo (,1001);
方法stuInfo (student(,1002));
stuInfo (student(,1003));
查询,当普通表用* stuInfo stuId = 1002;
删除都用普通的sql语句即可stuInfo pAge = 29 pName = ;
stuInfo stuId = 1001;
;(表别名)函数用来返回对象的OID,也就是对象标识符,对象表也有rowid(s) stuInfo s;
rowid,(s) OIDS stuInfo s;
stuscore (
student,--stu这一列的值必须出现在stuInfo表中,且stu这一列存的对象的OID而不是对象本身score --分数
错误的做法:insert stuscore ( (s) stuInfo stuId = 1001,90)
stuscore (s),90 stuInfo s stuId = 1001;stuInfo s; --插入3行数据stuInfo s stuId = 1003;
* stuscore;
(列名)函数可以把OID还原为对象,主键列显示有问题(s.stu),score stuscore s s.stu.stuId = 1001;
修改,以下2个都可以stuscore score=100 stu = ( (s) stuInfo s stuId = 1001);stuscore s score = 99 s.stu.stuId = 1001;删除,以下3个都可以stuscore stu = ( (s) stuInfo s stuId = 1001);
stuscore s s.stu.stuId = 1001;
stuscore stuId = 1001;
aaa
);type aaaa
replace view_stu aaaa oid(a)
* aaa;
* view_stu;
方法-----------get_pro varchar2,--函数,后面接,而不是;
get_city varchar2,
set_pro(pro varchar2),--过程set_city(cy varchar2)replace type body ADDRESS--后面不能加
--后面不能加beginget_pro varchar2
province;get_pro;get_city varchar2
city;;set_pro(pro varchar2)set_city(cy varchar2);;函数和过程,);
stuInfo;
stuInfo (
,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px"> addr address
);stuInfo (1,addr);
););stuInfo (2,addr);
* stuInfo;
删除类型type address force;方法 结束-----------replace type arrType varray(10) number(4);
replace type scoreType (
scorereplace type arrscoreType varray(10) scoreType;
score arrscoreType --可变数组,最多10个成员函数stuInfo (1,arrscoreType(
scoreType(sql',50),scoreType(,80),scoreType(,90)));stuInfo (2,60),85),95),scoreType(,60)));
stuInfo (3,70),93)));
* stuInfo; --查询结果是集合
查询出可变数组里的数据呢?思路是:用table函数把集合转化为表,然后再从这个表查询数据* ( s.score stuInfo s s.stuId = 2);
函数里面只能是一个可变数组s.stuId,t.* stuInfo s,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px"> ( score stuInfo stuId = s.stuId) t
s.stuId = 2;stuInfo score = arrscoreType(
stuId = 1;删除,按主键删除scoreType force;type arrscoreType force;stuInfo;
replace type scoreType (
scorereplace type nestTable scoreType;
,monospace; direction: ltr; border-top-style: none; color: black; font-size: 10pt; border-left-style: none; overflow: visible; padding-top: 0px"> score nestTable --其实存的是引用,实际数据存在abc表中score store abc;score store abc意思是:stuInfo这个表中的score这一列是嵌套表类型,嵌套表实际是存在abc这个表中查询,思路:把嵌套表先查出来,然后把嵌套表和stuInfo进行联合查询* ( ss.score stuInfo ss stuId = 3);
( ss.score stuInfo ss stuId = s.stuId) t
s.stuId = 3;( ss.score stuInfo ss stuId=3) t
t.score = 80 t.subName = sql';( ss.score stuInfo ss stuId = 3) t
t.subname=sql';