没有合适的资源?快使用搜索试试~ 我知道了~
首页Oracle Database 11g: 深入学习SQL与实战示例
"Oracle Database 11g 开发指南"
Oracle Database 11g 是一个企业级的关系型数据库管理系统,由甲骨文公司(Oracle Corporation)开发。它提供了强大的数据存储、管理和处理能力,广泛应用于各种规模的企业和组织。SQL(Structured Query Language),即结构化查询语言,是访问和操作数据库的标准语言,包括数据检索、插入、更新和删除等操作。
在《Oracle Database 11g SQL》这本书中,读者将深入学习如何掌握SQL,书中的内容涵盖了从基础概念到高级特性的全面指导。通过实例和实践案例,读者可以了解如何有效地利用SQL与Oracle Database 11g进行交互,提升数据库管理技能。书中提到,所有示例脚本和程序都可以在线获取,为读者提供了进一步学习和实践的资源。
Oracle Database 11g 的主要特性包括:
1. 高可用性:Oracle提供了高可用性解决方案,如Real Application Clusters (RAC) 和Automatic Storage Management (ASM),确保即使在硬件故障或网络问题下,数据库也能持续运行。
2. 性能优化:通过Database Resource Manager,可以更好地管理数据库资源,确保关键业务优先得到执行。此外,SQL优化器能够智能选择最佳执行计划,提高查询性能。
3. 数据安全:Oracle提供了全面的安全特性,包括用户权限管理、数据加密、审计和访问控制,以保护敏感信息不被未经授权的访问。
4. 复杂的数据管理:支持多种数据类型,包括BLOB(Binary Large Object)和CLOB(Character Large Object),可处理各种结构化和非结构化数据。
5. 数据仓库和分析:Oracle Data Mining和OLAP(Online Analytical Processing)工具允许用户进行大数据分析和挖掘,以支持决策制定。
6. 故障恢复和备份:Oracle Recovery Manager (RMAN) 提供了自动化的备份和恢复功能,确保数据的完整性和一致性。
7. 管理工具:Oracle Enterprise Manager 提供了一个全面的图形界面,用于监控、配置和管理Oracle数据库。
8. 支持标准:Oracle Database 11g 遵循SQL标准,并且兼容其他数据库系统的迁移。
通过阅读《Oracle Database 11g SQL》,开发者和数据库管理员不仅可以掌握SQL语言,还能了解到如何在Oracle环境中充分利用这些特性,提高工作效率和数据库的性能。书中深入浅出的讲解和丰富的实例,对于想要在Oracle Database 11g上进行开发和管理的人员来说是一份宝贵的资源。
![](https://csdnimg.cn/release/download_crawler_static/6331883/bg10.jpg)
xiv
Oracle Database 11g SQL
Using Default Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Merging Rows Using MERGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Database Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Committing and Rolling Back a Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Starting and Ending a Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Savepoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
ACID Transaction Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Concurrent Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Transaction Locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Transaction Isolation Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
A SERIALIZABLE Transaction Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Query Flashbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Granting the Privilege for Using Flashbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Time Query Flashbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
System Change Number Query Flashbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
9 Users, Privileges, and Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Creating a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Changing a User’s Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Deleting a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
System Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Granting System Privileges to a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Checking System Privileges Granted to a User . . . . . . . . . . . . . . . . . . . . . . . . . 280
Making Use of System Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Revoking System Privileges from a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Object Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Granting Object Privileges to a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Checking Object Privileges Made . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Checking Object Privileges Received . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Making Use of Object Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Public Synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Revoking Object Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Creating Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Granting Privileges to Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Granting Roles to a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Checking Roles Granted to a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Checking System Privileges Granted to a Role . . . . . . . . . . . . . . . . . . . . . . . . . 291
Checking Object Privileges Granted to a Role . . . . . . . . . . . . . . . . . . . . . . . . . 292
Making Use of Privileges Granted to a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Default Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Revoking a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Revoking Privileges from a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Dropping a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Auditing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Privileges Required to Perform Auditing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Auditing Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
![](https://csdnimg.cn/release/download_crawler_static/6331883/bg11.jpg)
Contents
xv
Audit Trail Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
10 Creating Tables, Sequences, Indexes, and Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Getting Information on Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Getting Information on Columns in Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Altering a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Renaming a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Adding a Comment to a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Truncating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Dropping a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Creating a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Retrieving Information on Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Using a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Populating a Primary Key Using a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Modifying a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Dropping a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Creating a B-tree Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Creating a Function-Based Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Retrieving Information on Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Retrieving Information on the Indexes on a Column . . . . . . . . . . . . . . . . . . . . . 323
Modifying an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Dropping an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Creating a Bitmap Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Creating and Using a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Modifying a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Dropping a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Flashback Data Archives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
11 Introducing PL/SQL Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Block Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
Variables and Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Conditional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Simple Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
WHILE Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
FOR Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Step 1: Declare the Variables to Store the Column Values . . . . . . . . . . . . . . . . . 346
Step 2: Declare the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Step 3: Open the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Step 4: Fetch the Rows from the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Step 5: Close the Cursor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Complete Example: product_cursor.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
![](https://csdnimg.cn/release/download_crawler_static/6331883/bg12.jpg)
xvi
Oracle Database 11g SQL
Cursors and FOR Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
OPEN-FOR Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
Unconstrained Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
ZERO_DIVIDE Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
DUP_VAL_ON_INDEX Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
INVALID_NUMBER Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
OTHERS Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Creating a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Calling a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
Getting Information on Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Dropping a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Viewing Errors in a Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Creating a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Calling a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Getting Information on Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Dropping a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Creating a Package Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Creating a Package Body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Calling Functions and Procedures in a Package . . . . . . . . . . . . . . . . . . . . . . . . 367
Getting Information on Functions and Procedures in a Package . . . . . . . . . . . . 368
Dropping a Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
When a Trigger Fires . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Set Up for the Example Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Creating a Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Firing a Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Getting Information on Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Disabling and Enabling a Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Dropping a Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
New Oracle Database 11g PL/SQL Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
SIMPLE_INTEGER Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Sequences in PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
PL/SQL Native Machine Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
12 Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Introducing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Creating Object Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Using DESCRIBE to Get Information on Object Types . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Using Object Types in Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Column Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Object Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Object Identifiers and Object References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Comparing Object Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Using Objects in PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
The get_products() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
The display_product() Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
![](https://csdnimg.cn/release/download_crawler_static/6331883/bg13.jpg)
Contents
xvii
The insert_product() Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
The update_product_price() Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
The get_product() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
The update_product() Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
The get_product_ref() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
The delete_product() Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
The product_lifecycle() Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
The product_lifecycle2() Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
Type Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Using a Subtype Object in Place of a Supertype Object . . . . . . . . . . . . . . . . . . . . . . . . 405
SQL Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
PL/SQL Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
NOT SUBSTITUTABLE Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Other Useful Object Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
IS OF() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
TREAT() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
SYS_TYPEID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
NOT INSTANTIABLE Object Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
User-Defined Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Overriding Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
Generalized Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
13 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Introducing Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Creating Collection Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Creating a Varray Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Creating a Nested Table Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Using a Collection Type to Define a Column in a Table . . . . . . . . . . . . . . . . . . . . . . . . 430
Using a Varray Type to Define a Column in a Table . . . . . . . . . . . . . . . . . . . . . . 430
Using a Nested Table Type to Define a Column in a Table . . . . . . . . . . . . . . . . . 430
Getting Information on Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Getting Information on a Varray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Getting Information on a Nested Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
Populating a Collection with Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Populating a Varray with Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Populating a Nested Table with Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Retrieving Elements from Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
Retrieving Elements from a Varray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
Retrieving Elements from a Nested Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Using TABLE() to Treat a Collection as a Series of Rows . . . . . . . . . . . . . . . . . . . . . . . . 436
Using TABLE() with a Varray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Using TABLE() with a Nested Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Modifying Elements of Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Modifying Elements of a Varray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Modifying Elements of a Nested Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Using a Map Method to Compare the Contents of Nested Tables . . . . . . . . . . . . . . . . . 440
Using CAST() to Convert Collections from One Type to Another . . . . . . . . . . . . . . . . . . 443
Using CAST() to Convert a Varray to a Nested Table . . . . . . . . . . . . . . . . . . . . . 443
Using CAST() to Convert a Nested Table to a Varray . . . . . . . . . . . . . . . . . . . . . 443
![](https://csdnimg.cn/release/download_crawler_static/6331883/bg14.jpg)
xviii
Oracle Database 11g SQL
Using Collections in PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
Manipulating a Varray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
Manipulating a Nested Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
PL/SQL Collection Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Multilevel Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Oracle Database 10g Enhancements to Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Changing the Size of an Element Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Increasing the Number of Elements in a Varray . . . . . . . . . . . . . . . . . . . . . . . . . 463
Using Varrays in Temporary Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Using a Different Tablespace for a Nested Table’s Storage Table . . . . . . . . . . . . 463
ANSI Support for Nested Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
14 Large Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
Introducing Large Objects (LOBs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
The Example Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Large Object Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Creating Tables Containing Large Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Using Large Objects in SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Using CLOBs and BLOBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Using BFILEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
Using Large Objects in PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
APPEND() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
CLOSE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
COMPARE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
COPY() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
CREATETEMPORARY() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
ERASE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
FILECLOSE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
FILECLOSEALL() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
FILEEXISTS() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
FILEGETNAME() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
FILEISOPEN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
FILEOPEN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
FREETEMPORARY() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
GETCHUNKSIZE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
GET_STORAGE_LIMIT() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
GETLENGTH() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
INSTR() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
ISOPEN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
ISTEMPORARY() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
LOADFROMFILE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
LOADBLOBFROMFILE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
LOADCLOBFROMFILE() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
OPEN() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
READ() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
SUBSTR() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
TRIM() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
剩余689页未读,继续阅读
137 浏览量
289 浏览量
140 浏览量
187 浏览量
135 浏览量
2011-08-08 上传
2010-06-15 上传
2012-03-31 上传
![](https://profile-avatar.csdnimg.cn/eaabd969f82e4e69acacffaa5c999f06_u012273123.jpg!1)
swartz_king
- 粉丝: 0
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- UABE 2.1d 64bit:Unity资源包编辑与提取工具
- RH64成功编译ffmpeg0.7版本,解决JNI编译难题
- HexBuilder工具:合并十六进制文件并转换为二进制
- 傻瓜式EXCEL财务记账系统教程
- React开发的Traekunst.dk项目概述
- 子域名检测大师:高效采集与暴力枚举解决方案
- Laravel网格查询抽象实现详解
- CKplayer:小巧跨平台网页视频播放器
- SpringBoot实现秒杀功能的简单示例教程
- LabView在WEB开发中的应用:用户事件记录温度报警
- Qt框架下QCamera实现摄像头调用与图像显示
- Mac环境下Sublime Text插件的安装教程
- EFT2.22.1R4中文正式版V3.1发布:绝地反击
- 基于Java技术的网上拍卖商城系统设计与实现
- 42巴黎C++课程完全指南与学习心得
- myBase V7.0.0 Pro Beta-20:升级至HTML格式与丰富插件支持
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)