Index

( ) (parentheses)

controlling order of operations, 38

grouping for readability, 69, 252

& (ampersand)

in substitution variable names, 20, 22, 25

in variable names, 31

: (colon), in bind arguments, 260

-- (dashes), single-line comments, 29, 40

/ (slash), block terminator, 16, 264

:= (colon, equal sign), assignment operator, 37

‘ ‘ (single quotes), enclosing substitution variables, 25

/*...*/ (slash asterisk...), multiline comments, 29, 40

&& (double ampersand), in substitution variable names, 20, 24, 25

; (semicolon)

block terminator, 1617

SQL and PL/SQL statement terminator, 264265

variable terminator, 3637

A

ACCESSIBLE BY clause, xxviixxviii

Accessors

new for Oracle 12c, xxviixxviii

specifying, xxviixxviii

white lists, xxviixxviii

Actual parameters, 317318

AFTER triggers, 201204

ALL_DEPENDENCIES view, 376377

ALL_OBJECTS view, 374

ALL_USER_OBJECTS view, 314315

ALL_USER_SOURCE view, 314315

ALTER SYSTEM command, 411

ALTER TRIGGER command, 194

Ampersand (&)

in substitution variable names, 20, 22, 25

in variable names, 31

ANALYZE routine, 437

Anchored data types, 34

Anonymous blocks. See also Modular code; Named blocks.

definition, 5

description, 312

executing, 8

Application exception, profiling, 436437

Application processing tier, 3

Architecture. See also Blocks.

application processing tier, 3

client-server, 5

data management tier, 3

Oracle server, 24

overview, 25

presentation tier, 3

three-tier, 3

Arithmetic operators, 38

Arrays. See Associative arrays; Varrays.

Associative arrays

declaring, 227

EXTEND method, 233

LIMIT method, 238

vs. nested tables and varrays, 239240

NO_DATA_FOUND exception, 228229

of objects, populating with data, 392

populating, 227

referencing individual elements, 227228

syntax, 226

TRIM method, 233

upper bounds, specifying, 238239

Attributes (data), object types, 386

Autonomous transactions, triggers, 203204

AUTONOMOUS_TRANSACTION pragma, 204

B

BACKTRACE_DEPTH function, 424, 426427

BACKTRACE_LINE function, 424, 426427

BACKTRACE_UNIT function, 424, 426427

Batch processing. See Bulk SQL.

BEFORE triggers, 195201

BEGIN keyword, 7

BEQUEATH CURRENT_USER clause, xxxii

BEQUEATH DEFINER clause, xxxii

Bind arguments

in CREATE TABLE statements, 263264

definition, 260

passing run-time values to, 272

Binding, definition, 9

Binding collections with

CLOSE statements, 306309

EXECUTE IMMEDIATE statements, 299305

FETCH statements, 306309

OPEN-FOR statements, 306309

Blank lines, inserting in output, 242

Blocks

; (semicolon), block terminator, 16

anonymous, 5, 8

binding, 9

compilation errors, 78

creating subroutines, 5

declaration section, 6

definition, 5

displaying variable values. See DBMS_OUTPUT.PUT_LINE statements.

error types, 78

exception-handling section, 78

executable section, 67

executing, 89

named, 5, 89

nested, 5, 3941

runtime errors, 78

sections, 68

semantic checking, 9

sequences in, 4849

syntax checking, 89

terminating, 16, 264265

vs. transactions, 50, 5455

VALID vs. INVALID, 9

Books and publications

Database Object-Relational Developer’s Guide, 385

Oracle Forms Developer: The Complete Video Course, xxiii

Oracle PL/SQL by Example, Fifth Edition, xvii

Oracle SQL by Example, 414

Oracle Web Application Programming for PL/SQL Developers, xxiii

Boolean expressions, in WHILE loops, 101

BROKEN procedure, 410

Built-in exceptions, 126132

BULK COLLECT clause, 291299

BULK COLLECT INTO clause, xxix

BULK EXECUTE IMMEDIATE statements, 260

BULK FETCH statements, 260

Bulk SQL

BULK COLLECT clause, 291299

DELETE statements, in batches. See FORALL statements.

fetching results, 291299

INSERT statements, in batches. See FORALL statements.

limiting result sets, 292293

NO_DATA_FOUND exception, 292

UPDATE statements, in batches. See FORALL statements.

Bulk SQL, FORALL statements

description, 282285

error messages, displaying, 287288

exception handling, 285288

implicit loop counter, 283

INDICES OF option, 283, 288

looping, 283, 288290

SAVE EXCEPTIONS option, 285288

SQL%BULK_EXCEPTIONS attribute, 286287

VALUES OF option, 289290

C

Calling packages, 339341

CASE abbreviations. See COALESCE function; NULLIF function.

CASE expressions, 8084

Case sensitivity

formatting guide, 455

passwords, 10

PL/SQL, 29

variables, 29

CASE statements

Boolean results. See Searched CASE statements.

vs. CASE expressions, 8184

description, 7274

searched CASE statements, 7480

CHANGE procedure, 410, 412

CHAR data type, 35

Character types, 28

CLEAR_PLSQL_TRACE routine, 434436

Client-server architecture, 5

CLOSE statements

binding collections with, 306309

closing cursors, 271280

Closing

cursor variables, 349

cursors, 167168, 170

dynamic SQL cursors, 271280

explicit cursors, 162, 167168, 172173

files, 407

COALESCE function, 8789. See also NULLIF function.

Code generation, 9

COLLECT INTO statements, 260

Collection methods, 232235

Collections. See also Tables.

counting elements, 232235

defined on user-defined records, 255256

definition, 225

deleting elements, 233235

extending, 231

multilevel, 240242

in nested records, 252253

NULL vs. empty, 232

of object types, 391394

records, 253256

testing for elements, 232235

upper bounds, specifying, 238239

variable-size arrays. See Varrays.

Collections, binding with

CLOSE statements, 306309

EXECUTE IMMEDIATE statements, 299305

FETCH statements, 306309

OPEN-FOR statements, 306309

Colon, equal sign (:=), assignment operator, 37

Colon (:), in bind arguments, 260

Columns

aliases, 175

invisible, xxxiiixxxiv

in a table, describing, 377378

Comments

formatting, 29, 456459

single-line vs. multiline, 29

COMMIT statements

description, 4952

placing, 188, 314

in triggers, 195

Companion Website, URL for, xviii

Comparing objects

map methods, 400401

order methods, 401404

overview, 399400

Comparison operators, 38

Compatibility, record types, 249250

Compilation errors, 78, 124126

Complex functions, creating, 328329

Complex nested cursors, 185187

Compound triggers

definition, 218

firing order, 219

resolving mutating table issues, 220223

restrictions, 219

structure, 218

Conditional control. See CASE statements; ELSIF statements; IF statements.

Connecting to a database

SQL Developer, 1011

SQL*Plus, 13

Connection name, SQL Developer, 10

Constructor methods, 395397

Contiguous numbers, generating, 48

CONTINUE statements, 111115

CONTINUE WHEN statements, 115118

COUNT method, 232235

Counting collection elements, 232235

CREATE reserved word, 192193

CREATE TABLE statements, 263264

CREATE TYPE statements, 229230

Creating

cursor variables, 345346, 349350

error messages, 149153

event triggers on PDBs, xxx

nested tables, 229230

object types, 386390

procedures, 312315

triggers, 192195, 197201

Creating functions

complex functions, 328329

stored functions, 322325

using a WITH clause, 329330

using the UDF pragma, 330331

Creating packages

information hiding, 335

package body, 335336, 337339

package specification, 335

package variables, 367368

private elements, 341344

Creating user-defined functions with a

WITH clause, xxxiv

UDF pragma, xxxivxxxv

CREDENTIAL clause, xxxxxxi

Currency conversion example, 334

CURRVAL pseudocolumn, 48

Cursor attributes, 170174. See also specific attributes.

Cursor FOR loops, 175177

Cursor loops

closing a cursor, 167168, 170

explicit cursors, 165168

fetching rows in a cursor, 166167

opening a cursor, 165166

Cursor variables

closing, 349

creating, 345346, 349350

vs. cursors, 346

definition, 345

explicit, 345

in packages, 347348, 350352

processing, 346347

query results, printing automatically, 348

rules for using, 353

sharing result sets, 348352

strong (restrictive), 345346

weak (nonrestrictive), 345346

Cursor-based records

compatibility, 249250

creating, 163165

defining a collection on, 253255

definition, 163

description, 244246

Cursors. See also Dynamic SQL cursors.

column aliases, 175

vs. cursor variables, 346

definition, 159

explicit, 160

expressions in a select list, 175

fetch status, getting, 170174

implicit, 160161

locking rows for update, 187189

most recently opened, 160

number of records fetched, getting, 170174

number of rows updated, getting, 161

open, detecting, 170174

parameterized, 183185

scope, 175

select list, 175

SQL, 160

tips for using, 175

types of, 159165

FOR UPDATE clause, 187189

FOR UPDATE OF clause, 189

updating tables in a database, 187190

WHERE CURRENT OF clause, 189190

Cursors, explicit

associating with SELECT statements, 162

closing, 162, 167168, 172173

cursor-based records, 163165

declaring, 162163, 172173

definition, 160

fetching rows in a cursor, 162, 166167, 170174

naming conventions, 162163

opening, 162, 165166, 172173

processing, 165168

record types, 163165

records, 163165

table-based records, 163

user-defined records, 168170

Cursors, nested

complex, 185187

looping through data, 177181, 185187

processing, 177181

D

Dashes (--), single-line comments, 29, 40

Data (attributes), object types, 386

Data dictionary, examining stored code

ALL_DEPENDENCIES view, 376377

ALL_OBJECTS view, 374

DBA_DEPENDENCIES view, 376377

DBA_OBJECTS view, 374

debugging, 376

dependencies, displaying, 376377

DESC command, 377378

describing columns in a table, 377378

displaying errors, 375376

identifying procedures, packages, and functions, 377378

modules with duplicate names. See Overloading.

overloading modules, 378382

retrieving specified line numbers, 374375

SHO ERR command, 376

USER_DEPENDENCIES view, 376377

USER_ERRORS view, 375376

USER_OBJECTS view, 374

Data dictionary queries

ALL_USER_OBJECTS view, 314315

ALL_USER_SOURCE view, 314315

DBA_USER_OBJECTS view, 314315

DBA_USER_SOURCE view, 314315

displaying source code, 314315

object information, 314315

procedure information, 314315

USER_OBJECTS view, 314315

USER_SOURCE view, 314315

Data management tier, 3

Data Manipulation Language (DML)

definition, 46

and transaction control, 5355

Data types

based on database objects. See Anchored data types.

common, summary of, 3536. See also specific types.

displaying maximum size, xxx

extended maximum size, xxx

for file handles, 407

new for Oracle 12c, xxx

passing to procedures, 318

Database Object-Relational Developer’s Guide, 385

Database triggers. See Triggers.

Databases

edition-based redefinition, 193

erasing changes. See ROLLBACK statements.

saving changes. See COMMIT statements.

setting a save point. See SAVEPOINT statements.

STUDENT schema, 461468

used in this book, 461468

DATE data type, 36

DBA_DEPENDENCIES view, 376377

DBA_OBJECTS view, 374

DBA_USER_OBJECTS view, 314315

DBA_USER_SOURCE view, 314315

DBMS_HPROF package, 436437

DBMSHPTAB.sql script, 437

DBMS_JOB package, 410412

DBMS_OUTPUT.PUT_LINE statements, 1819, 21

DBMS_PROFILER package, 432433

DBMS_SQL package, 417418

DBMS_TRACE package, 433436

DBMS_UTILITY package, 419424

DBMS_XPLAN package, 414417

Debugging

new for Oracle 12c, xxxvii

stored code, 376

Declaration section, 6

DECLARE keyword, 6

Declaring

associative arrays, 227

explicit cursors, 162163, 172173

variables, 3639

varrays, 236238

exceptions, 137141

Definer rights (DR) subprogram, xxvixxvii

DELETE method

deleting collection elements, 233235

deleting varray elements, 239

DELETE statements. See also DML (Data Manipulation Language).

batch processing. See FORALL statements.

with BULK COLLECT clause, 295

Deleting

collection elements, 233235

statements, 295

varray elements, 239

Delimiters, 29

Dependencies, displaying, 376377

DESC command, 377378

Development environment. See PL/SQL Scripts; SQL Developer; SQL*Plus.

DIRECTORY objects, defining LIBRARY objects as, xxxxxxi

DISABLE option, 194

Disabling substitution variable verification, 23

Disconnecting from a database

SQL Developer, 1112

SQL*Plus, 13

Displaying

code dependencies, 376377

code errors, 375376

data type maximum size, xxx

data type size, xxx

error messages, 287288

errors, 375376

invalid procedures, 315

passwords, 13

procedures, 314315

source code, 314315

stored code dependencies, 376377

variable values. See DBMS_OUTPUT.PUT_LINE statements.

DML (Data Manipulation Language)

definition, 46

and transaction control, 5355

DML statements. See also DELETE statements; INSERT statements; UPDATE statements.

in blocks, 4749

as triggering events, 4749

Double ampersand (&&), in substitution variable names, 20, 24, 25

DR (definer rights) subprogram, xxvixxvii

Duplicate names. See Overloading.

DUP_VALUE_ON_INDEX exception, 129

Dynamic SELECT statements, 259

Dynamic SQL, optimizing, 260

Dynamic SQL cursors. See also Cursors.

closing, 271280

fetching from, 271280

opening, 271280

passing run-time values to bind arguments, 272

Dynamic SQL statements

CLOSE, 271280

example, 260

FETCH, 271280

multirow queries, 271280

OPEN-FOR, 271280

passing NULLS to, 265266

single-row queries, 261271

terminating, 264

Dynamic SQL statements, EXECUTE IMMEDIATE

avoiding ORA errors, 262271

binding collections, 299305

description, 260261

RETURNING INTO clause, 261262

USING clause, 261262

DYNAMIC_DEPTH function, 424426

E

EDITIONABLE property, xxxiv, 193

Edition-based redefinition, 193

ELSIF statements, 6367. See also IF statements.

Empty vs. NULL, 232

ENABLE option, 194

Encapsulation, 386

Erasing database changes. See ROLLBACK statements.

Error handling. See also Error messages.

compilation errors, 78, 124126

runtime errors, 78, 124126, 141147. See also Exception propagation; Exceptions.

Error isolation, SQL*Plus, 314

Error messages. See also Error handling.

creating, 149153

displaying, 287288

getting, 155158, 424, 428429

names, associating with numbers, 153155

references to line numbers and keywords, 126

Error numbers, getting, 155158, 424, 428429

Error reporting

DBMS_UTILITY package, 419424

UTL_CALL_STACK package, 424429

Error types, 78

ERROR_DEPTH function, 424, 428429

error_message parameter, 150

ERROR_MSG function, 424, 428429

ERROR_NUMBER function, 424, 428429

error_number parameter, 150

Errors, displaying, 375376

Event triggers, creating on PDBs, xxx

Exception handling. See also User-defined exceptions.

built-in, 126132

EXCEPTION keyword, 8

EXCEPTION_INIT pragma, 153155

file location not valid, 408

filename not valid, 408

FORALL statements, 285288

INTERNAL_ERROR, 408

invalid file handle, 408

invalid mode, 408

invalid operation, 408

INVALID_FILEHANDLE, 408

INVALID_MODE, 408

INVALID_OPERATION, 408

INVALID_PATH, 408

predefined, 128129. See also OTHERS exception; specific exceptions.

raising implicitly, 127

read error, 408

READ_ERROR, 408

re-raising, 146148

scope, 133137

unspecified PL/SQL error, 408

UTL_FILE, 408

write error, 408

WRITE_ERROR, 408

EXCEPTION keyword, 8

Exception propagation, 141147

Exception-handling section, 78

EXCEPTION_INIT pragma, 153155

Exceptions, raising

explicitly, 144145

implicitly, 127

re-raising, 147

user-defined, 138

Executable section, 67

EXECUTE IMMEDIATE statements

avoiding ORA errors, 262271

binding collections with, 299305

description, 260261

RETURNING INTO clause, 261262

USING clause, 261262

Executing blocks

overview, 89

SQL Developer, 1416

Executing queries

SQL Developer, 14

SQL*Plus, 15

Execution times

baseline, computing, 432433

for SQL and PL/SQL, separating, 436437

EXISTS method, 232235

EXIT statements, 9397

EXIT WHEN statements, 9798

Explain plan, generating, 414417

Explicit cursor variables, 345

Expressions

( ) (parentheses), controlling order of operations, 38

CASE expressions, 8084

comparing. See COALESCE function; NULLIF function.

in a cursor select lists, 175

operands, 38

operators, 3839. See also specific operators.

EXTEND method, 231, 232235

Extending collections, 232235

Extending packages

with additional procedures, 353366

final_grade function, 355366

manage_grades package specification, 354356

median_grade function, 362365

F

FCLOSE function, 407

FCLOSE_ALL procedure, 407

FETCH command, 166167

FETCH FIRST clause, xxviiixxix

FETCH statements, 271280, 306309

Fetch status, getting, 170174

Fetching records

from dynamic SQL cursors, 271280

results in bulk SQL, 291299

rows in a cursor, 166167

FFLUSH procedure, 407

File handle invalid, exception, 408

File location not valid exception, 408

Filename not valid, exception, 408

Files, accessing within PL/SQL, 406410

FILE_TYPE data type, 407

Firing order, compound triggers, 219

Firing triggers, 192, 194

FIRST method, 233235

Flushing the data buffer, 407

FLUSH_PROFILER routine, 433

FOLLOWS option, 194

FOPEN function, 407

FOR loops. See Numeric FOR loops.

FOR reserved word, 104

FOR UPDATE clause, 187189

FOR UPDATE OF clause, 189

FORALL statements

description, 282285

error messages, displaying, 287288

exception handling, 285288

implicit loop counter, 283

improving performance, 260

INDICES OF option, 283, 288

looping, 283, 288290

SAVE EXCEPTIONS option, 285288

SQL%BULK_EXCEPTIONS attribute, 286287

VALUES OF option, 289290

Formal parameters, 317318

FORMAT_CALL_STACK function, 419421

FORMAT_ERROR_BACKTRACE function, 419, 421422

FORMAT_ERROR_STACK function, 419, 422424

Formatting guide

case sensitivity, 455

comments, 456459

naming conventions, 456457

white space, 455456

Formatting guide, for readability by humans

dynamic SQL statements, 275

EXCEPTION_INIT pragma, 155

formatting IF statements, 6667

formatting SELECT statements, 275

grouping with parentheses, 69, 252

inserting blank lines, 242

inserting blank spaces, 275

labels on nested blocks, 3940

labels on nested loops, 120

WORK keyword, 5152

%FOUND attribute, 170174

Functions. See also Modular code.

collections of. See Packages.

final_grade function, 355366

identifying, 377378

invoking in SQL statements, 327328

IR (invoker rights), xxvixxvii

median_grade function, 362365

optimizing execution, 329331

vs. procedures, 322

syntax, 322327

user-defined. See User-defined functions.

uses for, 325327

Functions, creating

complex functions, 328329

stored functions, 322325

using a WITH clause, 329330

using the UDF pragma, 330331

G

GET_LINE procedure, 407

GET_NEXT_RESULT procedure, xxxixxxii

GET_PLSQL_TRACE_LEVEL routine, 434436

Getting records. See Fetching records.

Grouping transactions, 49

H

Help, Oracle online, 193

Hierarchical Profiler, 436437

I

Identifiers, 29, 3334. See also Variables.

IF statements. See also ELSIF statements.

description, 58

formatting for readability, 6667

inner, 67

logical operators, 6870

nested, 6770

outer, 67

IF-THEN statements

description, 5860

inner IF, 67

IF-THEN-ELSE statements

description, 6063

outer IF, 6063

Implicit cursors, 160161

Implicit statement results, xxxixxxii

Implicit statement results, generating, 417418

IN option, 105107

IN OUT parameter, 316317

IN parameter, 315319

Index-by tables. See Associative arrays.

INDICES OF option, 283, 288

Infinite loops

definition, 93

simple, 95

WHILE, 100

Information hiding, 335

INHERIT ANY PRIVILEGES clause, xxxiixxxiii

INHERIT PRIVILEGES clause, xxxiixxxiii

Initializing

nested tables, 230232

object attributes, 389390

packages, 367368

Initializing variables

with an assignment operator, 3639

with CASE expressions, 8384

to a null value, 32

with SELECT INTO statements, 4447, 8384

Inner IF statements, 67

INSERT statements. See also DML (Data Manipulation Language).

batch processing. See FORALL statements.

with BULK COLLECT clause, 295

Instantiating packages, 366

INSTEAD OF triggers, 206211

INTERNAL_ERROR exception, 408

Interpreted mode code generation, 9

INTERVAL parameter, 411

INTERVAL procedure, 410

Invalid

file handle exception, 408

mode exception, 408

operation exception, 408

procedures, 315

INVALID blocks vs. VALID, 9

INVALID_FILEHANDLE exception, 408

INVALID_MODE exception, 408

INVALID_OPERATION exception, 408

INVALID_PATH exception, 408

Invisible columns, xxxiiixxxiv

IR (invoker rights) unit

creating views, xxxii

new for Oracle 12c, xxvixxvii, xxxiixxxiii

permissions, xxxiixxxiii

%ISOPEN attribute, 170174

IS_OPEN function, 407

Iterative control. See CONTINUE statements; Loops.

J

JOB parameter, 411

Job queue

changing items in the queue, 410

changing job intervals, 410

DBMS_JOB package, 410412

disabling jobs, 410, 412

examining, 412

flagging jobs as broken, 412

forcing a job to run, 410, 412

job numbers, assigning, 411

removing jobs from, 410, 412

scheduling the next run date, 410

submitting jobs, 410, 411412

K

keep_errors parameter, 150

L

Labels on

nested blocks, 3940

nested loops, 120

Language components

anchored data types, 34

character types, 28

comments, 29

delimiters, 29

identifiers, 29, 3334. See also Variables.

lexical units, 2829

literals, 29

reserved words, 29, 3233

variables, 2932, 3639. See also Identifiers; Substitution variables.

LAST method, 233235

Lexical units, 2829

LIBRARY objects, defining as DIRECTORY objects, xxxxxxi

LIMIT method, 238, 292293

Limiting result sets, bulk SQL, 292293

Line terminators, inserting, 408

Literals

definition, 29

in expressions, 38

LOB data type, 36

Locking rows for update, 187189

Logical operators, 39, 6870

LOGIN_DENIED exception, 128

LONG data type, 36

LONG RAW data type, 36

Loop labels, 120122

LOOP reserved word, 92

Looping

FORALL statements, 283, 288290

INDICES OF option, 283, 288

VALUES OF option, 289290

Loops, nested, 118120. See also Nested cursors.

Loops, numeric FOR

description, 104105

IN option, 105107

premature termination, 108109

REVERSE option, 107108

Loops, simple

description, 9293

EXIT statements, 9397

EXIT WHEN statements, 9798

infinite, 93, 95

inner loops, 119

RETURN statements, 96

terminating, 9398

Loops, WHILE

Boolean expressions as test conditions, 101

description, 98101

infinite, 100

outer loops, 119

premature termination, 101103

M

Map methods, 400401

MAX_STRING_SIZE parameter

displaying data type size, xxx

Member methods, 398

Methods (functions and procedures), 386

Modes

code generation, 9

invalid, exception, 408

procedure parameters, 317318

Modular code

anonymous blocks, 312

benefits of, 312

block structure, 312

definition, 311

types of, 312. See also specific types.

Multilevel collections, 240242

Multirow queries, 271280

Mutating table errors, 214

Mutating tables

definition, 214

resolving issues, 215223

N

Named blocks, 5, 89. See also Anonymous blocks.

Named notation, procedure parameters, 318319

Naming conventions

explicit cursors, 162163

formatting guide, 456457

variables, 2930

Native code, 9

Native dynamic SQL. See Dynamic SQL.

Native mode code generation, 9

Nested

blocks, 5, 3941

collections in object types, 393

cursors, 177181

IF statements, 6770

loops, 118120

records, 250253

varrays, 240242

Nested cursors

complex, 185187

looping through data, 177181, 185187

processing, 177181

Nested tables

vs. associative arrays and varrays, 239240

creating, 229230

initializing, 230232

LIMIT method, 238

populating with the BULK COLLECT clause, 292

upper bounds, specifying, 238239

New features, summary of, xxvxxvi. See also specific features.

:NEW pseudorecords, 196199

NEW_LINE function, 408

NEXT DATE procedure, 410

NEXT method, 233235

NEXT_DATE parameter, 411

NEXTVAL pseudocolumn, 48

NO_DATA_FOUND exception, 128

associative arrays, 228229

bulk SQL, 292

NONEDITIONABLE property, xxxiv, 193

Nonrestrictive (weak) cursor variables, 345346

NO_PARSE parameter, 411

Not null, constraining variables to, 32

%NOTFOUND attribute, 170174

Null condition, IF-THEN-ELSE statements, 6163

Null values

assigning to expressions in NULLIF functions, 8687

variables, 32

NULL vs. empty, 232

NULLIF function, 8487. See also COALESCE function.

NULLS, passing to dynamic SQL statements, 265266

NUMBER data type, 35

Numeric FOR loops

in cursors, 175177

description, 104105

IN option, 105107

premature termination, 108109

REVERSE option, 107108

NVACHAR2 data type, xxx

O

Object attributes, initializing, 389390

Object instances. See Objects.

Object specification, 388

Object type methods

comparing objects, 399404

constructor, 395397

definition, 395

functions and procedures, 386

member, 398

parameter, 395

SELF parameter, 395, 397, 398, 401

static, 398399

Object types

attributes (data), 386

with collections, 391394

components of, 386

creating, 386390

encapsulation, 386

methods (functions and procedures), 386

nesting collections in, 393

Objects

associative arrays, populating with data, 392

comparing, 399404

getting information about, 314315

initial value, 389

schema, editionable vs. noneditionable, xxxiv

:OLD pseudorecords, 196199

Open cursors, testing for, 170174

Open files

testing for, 407

writing to, 408

OPEN-FOR statements

binding collections with, 306309

opening cursors, 271280

Opening

dynamic SQL cursors, 271280

explicit cursors, 162, 165166, 172173

files, 407

Operands

definition, 38

in expressions, 38

Operation invalid, exception, 408

Operators

definition, 38

in expressions, 38

precedence, 39

Optimization levels

examples of, 439444

performance optimizer, 438

PLSQL_OPTIMIZE_LEVEL parameter, 438

summary of, 438

Optimizing

dynamic SQL, 260

function execution, 329331

Optimizing PL/SQL, tuning tools

ANALYZE routine, 437

CLEAR_PLSQL_TRACE routine, 434436

computing execution time baseline, 432433

DBMS_HPROF package, 436437

DBMSHPTAB.sql script, 437

DBMS_PROFILER package, 432433

DBMS_TRACE package, 433436

FLUSH_PROFILER routine, 433

GET_PLSQL_TRACE_LEVEL routine, 434436

Hierarchical Profiler, 436437

PAUSE_PROFILER routine, 433

Profiler API, 432433

profiling execution of applications, 436437

PROFLOAD.sql script, 432433

PROFTAB.sql script, 432433

RESUME_PROFILER routine, 433

separating execution times for SQL and PL/SQL, 436437

SET_PLSQL_TRACE routine, 434436

START_PROFILER routine, 432433

START_PROFILING routine, 437

STOP_PROFILER routine, 432433

STOP_PROFILING routine, 437

Trace API, 433436

TRACE_ALL_CALLS constant, 434436

TRACE_ALL_EXCEPTIONS constant, 434436

TRACE_ALL_SQL constant, 434436

TRACE_ENABLED_CALLS constant, 434436

TRACE_ENABLED_EXCEPTION constant, 434436

TRACE_ENABLED_SQL constant, 434436

TRACE_PAUSE constant, 434436

TRACE_RESUME constant, 434436

TRACE_STOP constant, 434436

TRACETAB.sql script, 433436

tracing order of execution, 433436

ORA errors, avoiding, 262271

Oracle Forms Developer: The Complete Video Course, xxiii

Oracle online help, 193

Oracle PL/SQL by Example, Fifth Edition, xvii

Oracle sequences. See Sequences.

Oracle server, 24

Oracle SQL by Example, 414

Oracle SQL Developer. See SQL Developer.

Oracle Web Application Programming for PL/SQL Developers, xxiii

Oracle-supplied packages

accessing files within PL/SQL, 406410

DBMS_JOB, 410412

DBMS_SQL, 417418

DBMS_XPLAN, 414417

explain plan, generating, 414417

implicit statement results, generating, 417418

scheduling jobs, 410413

text file capabilities, 406410

UTL_FILE, 406410

Oracle-supplied packages, error reporting

DBMS_UTILITY package, 419424

UTL_CALL_STACK package, 424429

Order methods, 401404

Order of execution, tracing, 433436

OTHERS exception, 131, 155156. See also SQLCODE function; SQLERRM function.

OUT parameter, 315319

Outer IF statements, 67

Overloading

construction methods, 397

modules, 378382

P

Packages. See also Modular code.

benefits of, 334

currency conversion example, 334

definition, 333

granting roles to, xxixxxx

identifying, 377378

initialization, 367368

instantiation, 366

manage_grades package specification, 354356

referencing packaged elements, 336337. See also Cursor variables.

serialization, 368371

stored, calling, 339341

supplied by Oracle. See Oracle-supplied packages.

Packages, creating

information hiding, 335

package body, 335336, 337339

package specification, 335

package variables, 367368

private elements, 341344

Packages, extending

with additional procedures, 353366

final_grade function, 355366

manage_grades package specification, 354356

median_grade function, 362365

Parameterized cursors, 183185

Parameters, passing to procedures

actual parameters, 317318

data types, 318

default values, 318319

formal parameters, 317318

modes, 317318

named notation, 318319

OUT parameter, 315319

IN OUT parameter, 316317

IN parameter, 315319

positional notation, 318319

Parentheses ( )

controlling order of operations, 38

grouping for readability, 69, 252

Parse trees, 8

Passing

data types to procedures, 318

NULLS to dynamic SQL statements, 265266

run-time values to bind arguments, 272

Passing parameters to procedures

actual parameters, 317318

data types, 318

default values, 318319

formal parameters, 317318

modes, 317318

named notation, 318319

OUT parameter, 315319

IN OUT parameter, 316317

IN parameter, 315319

positional notation, 318319

Passwords

SQL Developer, case sensitivity, 10

SQL*Plus, displaying, 13

PAUSE_PROFILER routine, 433

P-code, 9

PDBs (pluggable databases), xxx

Performance. See Optimizing.

Performance optimizer, 438. See also Optimizing PL/SQL.

PL/SQL Scripts, 1416

PL/SQL statements, 44. See also SQL statements; specific statements.

PLSQL_CODE_TYPE parameter, 9

PLSQL_DEBUG parameter, xxxvii

$$PLSQL_LINE directive, xxxvixxxvii

PL/SQL-only data types, xxvixxvii

PLSQL_OPTIMIZE_LEVEL parameter, 438

$$PLSQL_UNIT directive, xxxvixxxvii

$$PLSQL_UNIT_OWNER directive, xxxvixxxvii

$$PLSQL_UNIT_TYPE directive, xxxvixxxvii

Populating associative arrays, 227

Positional notation, procedure parameters, 318319

PRAGMA INLINE statement, 445

Pragmas, definition, 153

PRECEDES option, 194

Predefined exceptions, 128129

Predefined inquiry directives, new for Oracle 12c, xxxvixxxvii

Presentation tier, 3

Primary key values, generating. See Sequences.

Printing query results automatically, 348

PRIOR method, 233235

Privileges for creating views, 207

Procedures. See also Modular code.

collections of. See Packages.

creating, 312315

vs. functions, 322

getting information about, 314315

identifying, 377378

invalid, recompiling, 315

Procedures, displaying

data dictionary queries, 314315

invalid, recompiling, 315

invalid vs. valid, 315

red X, 315

with SQL Developer, 315

Procedures, passing parameters

actual parameters, 317318

data types, 318

default values, 318319

formal parameters, 317318

modes, 317318

named notation, 318319

OUT parameter, 315319

IN OUT parameter, 316317

IN parameter, 315319

positional notation, 318319

Profiler API, 432433

PROFLOAD.sql script, 432433

PROFTAB.sql script, 432433

PROGRAM_ERROR exception, 128

PUT procedure, 408

PUTF procedure, 408

PUT_LINE procedure, 408

Q

Queries. See SQL queries.

Query results

printing automatically, 348

sharing. See Cursor variables.

R

RAISE statements

in conjunction with IF statements, 140

raising exceptions explicitly, 144145

raising user-defined exceptions, 138

re-raising exceptions, 147

RAISE_APPLICATION_ERROR procedure, 149153

Raising exceptions

explicitly, 144145

implicitly, 127

re-raising exceptions, 147

user-defined, 138

RAW data type, xxx, 36

Read error, exception, 408

Readability (by humans)

dynamic SQL statements, 275

EXCEPTION_INIT pragma, 155

formatting IF statements, 6667

formatting SELECT statements, 275

grouping with parentheses, 69, 252

inserting blank lines, 242

inserting blank spaces, 275

labels on nested blocks, 3940

labels on nested loops, 120

WORK keyword, 5152

READ_ERROR exception, 408

Reading

records from a database. See Fetching records.

text from an open file, 407

Record types

compatibility, 249250

cursor based, 244246, 249250, 253255

explicit cursors, 163165

table based, 244246, 249250

user defined, 246250, 255256

Records

collections of, 253256

compatibility, 248250

cursor-based, 163165

enclosing, 250

explicit cursors, 163165

nested, 250253

reading. See Fetching records.

table-based, 163165

testing values of, 244

user-defined, 168170

Red X on displayed procedures, 315

REF CURSOR data type, 345346. See also Cursor variables.

REMOVE procedure, 410, 412

REPLACE reserved word, 192193

Re-raising exceptions, 146148

Reserved words, 29, 3233

Restricted mode, turning on/off, 411

Restrictive (strong) cursor variables, 345346

Result sets, sharing. See Cursor variables.

Result-caching, IR (invoker rights) functions, xxvixxvii

RESUME_PROFILER routine, 433

RETURN statements, 96

RETURNING clause, with BULK COLLECT clause, 295

RETURNING INTO clause, 261262

RETURN_RESULT procedure, xxxixxxii

REVERSE option, 107108

Roles, granting to PL/SQL packages and standalone subprograms, xxixxxx

ROLLBACK statements, 4951, 52, 195

%ROWCOUNT attribute, 170174

Row-level triggers, 194, 205206

Rows, locking for update, 187189

%ROWTYPE attribute, 163165, 244246

RUN procedure, 410, 412

Runtime errors. See also Error handling; Exceptions.

vs. compilation errors, 124126

in a declaration section, 142143. See also Exception propagation.

definition, 78

error handling, 141147

in an exception-handling section, 143144. See also Exception propagation.

S

SAVE EXCEPTIONS option, 285288

SAVEPOINT statements

breaking down large PL/SQL statements, 44

setting a save point, 4951, 5253

in triggers, 195

Saving database changes. See COMMIT statements.

Scheduling jobs, 410413

Scope

cursors, 175

exceptions, 133137

labels, 3941

nested blocks, 3941

variables, 39

Searched CASE statements

vs. CASE statements, 7680

description, 7480

Sections of blocks, 68

SELECT INTO statements, 4447

Select list, cursors, 175

SELECT statements

dynamic, 259. See also Dynamic SQL.

formatting for readability, 275

returning no rows, 47

returning too many rows, 47

static, 259

SELF parameter, 395, 397, 398, 401

Semantic checking, 9

Semicolon (;)

block terminator, 1617

dynamic SQL statement terminator, 264265

variable terminator, 3637

Sequences

accessing, 48

in blocks, 4849

of contiguous numbers, 48

definition, 47

drawing numbers from, 48

incrementing, 48

uses for, 47

Serialized packages, 368371

SERIALLY_REUSABLE pragma, 368371

SET_PLSQL_TRACE routine, 434436

Setting a save point. See SAVEPOINT statements.

SHO ERR command, 376

SID, default, 10

Simple loops

description, 9293

EXIT statements, 9397

EXIT WHEN statements, 9798

infinite, 95

inner loops, 119

RETURN statements, 96

terminating, 9398

Single quotes (‘ ‘), enclosing substitution variables, 25

Single-row queries, 261271

Slash (/), block terminator, 16, 264

Slash asterisk... (/*...*/), multiline comments, 29, 40

Source code, displaying, 314315

SQL cursors, 160

SQL Developer

connecting to a database, 1011

connection name, 10

default SID, 10

definition, 9

disabling substitution variable verification, 23

disconnecting from a database, 1112

displaying procedures, 315

executing a block, 1416

executing a query, 14

getting started with, 1011

launching, 10

password, 10

substitution variables, 1925

user input at runtime. See Substitution variables.

user name, 10

SQL queries

implicit statement results, xxxixxxii

multirow, 271280

new for Oracle 12c, xxxixxxii

single-row, 261271

SQL statements. See also PL/SQL statements.

; (semicolon), statement terminator, 15

vs. PL/SQL, 14

SQL%BULK_EXCEPTIONS attribute, 286287

SQLCODE function, 155158. See also OTHERS exception; SQLERRM function.

SQLERRM function, 155158. See also OTHERS exception; SQLCODE function.

SQL*Plus

/ (slash), block terminator, 16

; (semicolon), block terminator, 1617

accessing, 11, 13

connecting to a database, 13

definition, 9

disabling substitution variable verification, 23

disconnecting from a database, 13

error isolation, 314

executing a query, 15

getting started with, 1113

password, 13

substitution variables, 1925

sqlplus command, 13

START_PROFILER routine, 432433

START_PROFILING routine, 437

Statement-level triggers, 194, 205206

Statements. See PL/SQL statements.

Static methods, 398399

Static SELECT statements, 259

STOP_PROFILER routine, 432433

STOP_PROFILING routine, 437

Stored code, examining

ALL_DEPENDENCIES view, 376377

ALL_OBJECTS view, 374

with the data dictionary, 374378

DBA_DEPENDENCIES view, 376377

DBA_OBJECTS view, 374

debugging, 376

dependencies, displaying, 376377

DESC command, 377378

describing columns in a table, 377378

displaying errors, 375376

identifying procedures, packages, and functions, 377378

overloading modules, 378382

retrieving specified line numbers, 374375

SHO ERR command, 376

USER_DEPENDENCIES view, 376377

USER_ERRORS view, 375376

USER_OBJECTS view, 374

Stored functions, creating, 322325

Stored packages, calling, 339341

Stored queries. See Views.

String operators, 39

Strong (restrictive) cursor variables, 345346

STUDENT database schema, 461468

SUBMIT procedure, 410

Submitting jobs, 410, 411412. See also Job queue.

Subprogram inlining, 445453

Subprograms, granting roles to, xxixxxx

Substitution variables. See also Variables.

‘ ‘ (single quotes), enclosing in, 25

& (ampersand), name prefix, 20, 22, 25

&& (double ampersand), name prefix, 20, 24, 25

disabling, 25

disabling verification, 23

name prefix character, changing, 25

overview, 1925

Syntax checking, 89

Syntax errors. See Compilation errors.

T

Table-based records

compatibility, 249250

creating, 163165

definition, 163

description, 244246

Tables

mutating, 213223

PL/SQL, 226. See also Associative arrays; Nested tables.

Tables, nested

vs. associative arrays and varrays, 239240

creating, 229230

initializing, 230232

LIMIT method, 238

upper bounds, specifying, 238239

Text file capabilities, 406410

Three-tier architecture, 3

TOO_MANY_ROWS exception, 128

Trace API, 433436

TRACE_ALL_CALLS constant, 434436

TRACE_ALL_EXCEPTIONS constant, 434436

TRACE_ALL_SQL constant, 434436

TRACE_ENABLED_CALLS constant, 434436

TRACE_ENABLED_EXCEPTION constant, 434436

TRACE_ENABLED_SQL constant, 434436

TRACE_PAUSE constant, 434436

TRACE_RESUME constant, 434436

TRACE_STOP constant, 434436

TRACETAB.sql script, 433436

Tracing order of execution, 433436

Transaction control

and DML, 5355

erasing changes. See ROLLBACK statements.

saving changes. See COMMIT statements.

setting a save point. See SAVEPOINT statements.

Transactional control statements, from triggers, 195

Transactions

vs. blocks, 50, 5455

breaking down large statements, 44

definition, 43

grouping, 49

Triggering events, 192

Triggers. See also Modular code.

AFTER, 201204

autonomous transactions, 203204

BEFORE, 195201

compound, 217223

creating, 192195, 197201

defined on views, 206211

definition, 192

in dropped tables, 195

enabling/disabling, 194

event, xxx

firing, 192

firing order, specifying, 194

INSTEAD OF clause, 206211

issuing transactional control statements, 195

mutating table errors, 214223

:NEW pseudorecords, 196199

:OLD pseudorecords, 196199

restrictions, 195

row-level, 194, 205206

statement-level, 194, 205206

types of, 205211

uses for, 195

TRIM method, 233235

Tuning PL/SQL. See Optimizing PL/SQL, tuning tools.

TYPE statements, 247248

U

UDF pragma

creating functions, 330331

creating user-defined functions, xxxivxxxv

Undoing database changes. See ROLLBACK statements.

Unique numbers, generating, 4749

UPDATE statements. See also DML (Data Manipulation Language).

batch processing. See FORALL statements.

with BULK COLLECT clause, 295

Updating tables in a database, 187190. See also UPDATE statements.

User name, SQL Developer, 10

User-defined exceptions

declaring, 137

description, 137141

raising explicitly, 138139

unhandled, 145

User-defined functions

creating with a UDF pragma, xxxivxxxv

creating with a WITH clause, xxxiv

running under SQL, xxxivxxxv

User-defined records

compatibility, 249250

defining a collection on, 255256

description, 168170, 246249

USER_DEPENDENCIES view, 376377

USER_ERRORS view, 375376

USER_OBJECTS view, 314315, 374

USER_SOURCE view, 314315

USING clause, 261262

UTL_CALL_STACK package, 424429

UTL_FILE package, 406410

V

VALID blocks vs. INVALID, 9

VALUE_ERROR exception, 129

VALUES OF option, 289290

VARCHAR2 data type, xxx, 35

Variables. See also Identifiers; Substitution variables.

; (semicolon), variable terminator, 3637

case sensitivity, 29

constraining to not null, 32

declaring, 3639

displaying values. See DBMS_OUTPUT.PUT_LINE statements.

in expressions, 38

with identical names, 121122

naming conventions, 2930

null values, 32

overview, 2932

scope, 39

visibility, 40

Variables, initializing

with an assignment operator, 3639

with CASE expressions, 8384

to a null value, 32

with SELECT INTO statements, 4447, 8384

Varrays

declaring, 236238

definition, 235236

nested, 240242

vs. nested tables and associative arrays, 239240

upper bounds, setting, 238239

View queries, 208. See also SELECT statements.

Views, creating

BEQUEATH CURRENT_USER clause, xxxii

BEQUEATH DEFINER clause, xxxii

as an IR (invoker rights) unit, xxxii

new for Oracle 12c, xxxii

privileges for, 207

Views, triggers defined on, 206211

Visibility of variables, 40

W

Weak (nonrestrictive) cursor variables, 345346

Website, companion to this book. See Companion Website.

WHAT parameter, 411

WHERE CURRENT OF clause, 189190

WHILE loops

Boolean expressions as test conditions, 101

description, 98101

infinite, 100

outer loops, 119

premature termination, 101103

WHILE reserved word, 99

White space, formatting guide, 455456

WITH clause

creating functions, 329330

creating user-defined functions, xxxiv

WORK keyword, for readability, 5152

Write error, exception, 408

WRITE_ERROR exception, 408

Z

ZERO_DIVIDE exception, 128

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset