《Oracle PL/SQL开发指南》学习笔记25——对象类型(Object Types)(章节回顾、测试)

什么?数据库也有面向对象的概念?

没错,面向对象编程可以修复函数、过程和包的部分缺陷。

对象基础知识(Object Basics)

Review Section
This section has described the following points about the basics of using objects.
1. Oracle Database 12c qualifies object types as persistent objects or transient objects, and further qualifies persistent objects as stand-alone objects or embedded objects. You deploy stand-alone objects in tables, embedded objects in other object types, and transient objects in PL/SQL blocks.
2. Only persistent object types have unique object identifiers.
3. Object types share the same name space as tables, views, synonyms, functions, procedures, and packages. Only database triggers have a separate name space.
4. You declare an object type like a package with prototype functions and procedures, but object types have three specialized functions—CONSTRUCTOR, MAP, and ORDER.
5. Object type CONSTRUCTOR functions may have parameters, but they must use both the name and data type of the object type’s attributes, and they return an instance of the object type.
6. You can create instances of an object type when you append the INSTANTIABLE clause.
7. You can create a type dependent of an object type when you append the NOT FINAL clause to it; otherwise, you can't create type dependents or subtypes.
8. The current instance is known by the case-insensitive SELF keyword, which is equivalent to case-sensitive this in Java.
9. Object types can contain only MEMBER (instance) and STATIC functions and procedures.
10. You can white list object types with Oracle Database 12c's new ACCESSIBLE BY clause.
11. You implement an object type with an object body, and an object body can contain only MEMBER and STATIC functions and procedures.
12. You should implement getters to retrieve attribute values and setters to set and/or modify attribute values.
13. You can use either a MAP function or an ORDER function for object instance equality comparisons, but the ORDER function is the preferred and most OOPL-like solution.

 

实现对象主体(Implementing Object Type Collections)

Review Section
This section has described the following points about the basics of implementing object type collections:
1. You can create an array of any object type, provided you define it as a SQL varray or table collection first and then as an attribute of an object type.
2. You can instantiate a varray or table collection as an attribute of an object type inside a CONSTRUCTOR function.
3. You can instantiate a varray or table collection as an attribute of an object type inside a STATIC function that returns the collection type.
4. The index value of a collection inside an object type must be a different integer value than the index of a range FOR loop.

 

测验(Mastery Check)


The mastery check is a series of true-or-false and multiple-choice questions that let you confirm
how well you understand the material in the chapter. You may check Appendix I for answers to
these questions.

True or False:
1. Object types are instantiable by default.
True. Object types are instantiable by default. You must provide the optional NOT to negate the default.
2. The this keyword references an instance of an object type inside an object body.
False. Oracle object bodies use SELF to reference the current instance of an object type.
3. You can have a MAP function and an ORDER function in the same object type.
False. Oracle only allows you to implement a MAP function or an ORDER function in the same object type. The ORDER function is the more OOPL-like one, and the preferred solution.


4. CONSTRUCTOR functions require the name and data type to be the same as the attributes of the object type.
True. Oracle CONSTRUCTOR functions require the name and data type to be the same as the attributes of the object type.
5. Getters always should be implemented as MEMBER procedures.
False. Getters always should be implemented as MEMBER functions.
6. Setters always should be implemented as MEMBER procedures.
True. Setters always should be implemented as MEMBER procedures.
9. The UNDER clause designates a superclass.
False. The UNDER clause designates a subclass, subtype, or type dependent.
10. The OVERRIDING clause lets a subtype override a STATIC function or procedure.
False. The OVERRIDING clause lets a subtype override a MEMBER function.


Multiple Choice:
11. Which of the following are keywords in object types? (Multiple answers possible)
A. The MAP keyword
B. The OVERRIDE keyword
C. The OVERRIDING keyword
D. The NONSTATIC keyword
E. The MEMBER keyword
A and E are correct. An object type may have one MAP function, and all instance-level functions and procedures are MEMBER methods.
12. Which of the following are valid types of functions in object types? (Multiple answers possible)
A. An ORDER function
B. An OVERRIDE function
C. A MEMBER function
D. An UNDER function
E. A STATIC function
A, C, and E are correct. The ORDER, MEMBER, and STATIC functions are supported.
13. Which of the following are valid types of procedures in object types? (Multiple answers possible)
A. An ORDER procedure
B. A MAP procedure

C. An UNDER procedure
D. A MEMBER procedure
E. A STATIC procedure
D and E are correct. The MEMBER and STATIC procedures are possible.
14. Which of the following require an instance of the object type? (Multiple answers possible)
A. A STATIC function
B. A STATIC procedure
C. A CONSTRUCTOR function
D. A MEMBER function
E. A MEMBER procedure
D and E are correct. The STATIC functions and procedures don’t require an instance of
the object type. All MEMBER functions and procedures are instance methods.
15. Which of the following can be a function return type (or normalized table with a surrogate key for its single-column primary key)? (Multiple answers possible)
A. A VARCHAR2 data type
B. A NUMBER data type
C. A varray or table collection data type
D. A RECORD data type
E. An OBJECT data type
A, B, C, and E are correct. All scalar and composite data types can be return values from
object type functions and procedures except the PL/SQL-only RECORD data type.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值