Thông tin tài liệu
routines can now call the JSP as if it were another PL/SQL module.
1.19.1 Example
Let's write a simple "Hello, World" JSP that will accept an argument:
package oreilly.plsquick.demos;
public class Hello {
public static String sayIt (String toWhom) {
return "Hello, " + toWhom + "!";
}
}
Saved in a file called Hello.java, we can load the source code directly into Oracle. Doing so will
automatically compile the code. A simple form of the loadjava command:
loadjava -user scott/tiger -oci8 oreilly/plsquick/
demos/Hello.java
The Hello.java file follows the Java file placement convention for packages and so exists in a
subdirectory named oreilly/plsquick/demos.
Now we can fire up our favorite SQL interpreter, connect as SCOTT/TIGER, and create the call spec
for the Hello.sayIt( ) method:
CREATE FUNCTION hello_there (to_whom IN VARCHAR2)
RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'oreilly.plsquick.demos.Hello.sayIt
(java.lang.String) return java.lang.String';
/
Now we can call our function very easily:
BEGIN
DBMS_OUTPUT.PUT_LINE(hello_there('world'));
END;
/
And we get:
Hello, world!
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
as the expected output.
1.19.2 Publishing Java to PL/SQL
To write a call spec, use the AS LANGUAGE JAVA clause in a CREATE statement. The syntax for
this clause is:
{ IS | AS } LANGUAGE JAVA
NAME 'method_fullname [ (type_fullname, ]
[ return type_fullname ]'
method_fullname is the package-qualified name of the Java class and method. It is case-sensitive and
uses dots to separate parts of the package full name. type_fullname is the package-qualified name of
the Java datatype.
Notice that a simple string, not an SQL name, follows the NAME keyword.
Type mapping follows most JDBC rules regarding the legal mapping of SQL types to Java types.
Oracle extensions exist for Oracle-specific datatypes.
Most datatype mappings are relatively straightforward, but passing Oracle8 objects of a user-defined
type is harder than one would think. Oracle provides a JPublisher tool that generates the Java required
to encapsulate an Oracle8 object and its corresponding REF. Refer to Oracle's JPublisher
documentation for guidelines on usage.
The AS LANGUAGE JAVA clause is the same whether you are using Java as a standalone JSP, the
implementation of a packaged program, or the body of an object type method. For example, here is
the complete syntax for creating JSPs as PL/SQL-callable functions or procedures:
CREATE [OR REPLACE]
{ PROCEDURE procedure_name [(param[, param] )]
| FUNCTION function_name [(param[, param] )]
RETURN sql_type
}
[AUTHID {DEFINER | CURRENT_USER}]
[PARALLEL_ENABLE]
[DETERMINISTIC]
{ IS | AS } LANGUAGE JAVA
NAME 'method_fullname [ (type_fullname, ]
[ return type_fullname ]'
When using Java as the implementation of a packaged procedure or function, Oracle allows you to
place the Java call spec in either the package specification (where the call spec substitutes for the
subprogram specification) or in the package body (where the call spec substitutes for the subprogram
body).
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Similarly, when using JSPs in object type methods, the Java call spec can substitute for either the
object type method specification or its body.
Note that Java functions typically map to PL/SQL functions, but Java functions declared void map to
PL/SQL procedures. Also, you will quickly learn that mistakes in mapping PL/SQL parameters to
Java parameters become evident only at runtime.
1.19.3 Data Dictionary
To learn what Java library units are available in your schema, look in the USER_OBJECTS data
dictionary view where the object_type is like `JAVA%'. If you see a Java class with INVALID status,
it has not yet been successfully resolved. Note that the names of the Java source library units need not
match the names of the classes they produce.
As of press time, there is no apparent way to discover which stored programs are implemented as
Java stored procedures. You can look in the USER_SOURCE view for named programs that contain
the source text `AS LANGUAGE JAVA', but that may not yield accurate results. The
USER_DEPENDENCIES view does not track the relationship between PL/SQL cover programs and
their underlying Java class.
Even if you have loaded the Java source code into the database, there is no supported way of
retrieving the source from the data dictionary.
Previous: 1.18 External
Procedures
Oracle PL/SQL Language
Pocket Reference
1.18 External Procedures
The Oracle Library
Navigation
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
By Steven Feuerstein & Bill Pribyl; ISBN 1-56592-335-9E
Second Edition, published September 1997.
(See the catalog page for this book.)
Search the text of Oracle PL/SQL Programming, 2nd Edition.
Index
Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | Y | Z
Table of Contents
Dedication
Foreword
Preface
Part I: Programming in PL/SQL
Chapter 1: Introduction to PL/SQL
Chapter 2: PL/SQL Language Fundamentals
Chapter 3: Effective Coding Style
Part II: PL/SQL Language Elements
Chapter 4: Variables and Program Data
Chapter 5: Conditional and Sequential Control
Chapter 6: Database Interaction and Cursors
Chapter 7: Loops
Chapter 8: Exception Handlers
Chapter 9: Records in PL/SQL
Chapter 10: PL/SQL Tables
Part III: Built-In Functions
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Chapter 11: Character Functions
Chapter 12: Date Functions
Chapter 13: Numeric, LOB, and Miscellaneous Functions
Chapter 14: Conversion Functions
Part IV: Modular Code
Chapter 15: Procedures and Functions
Chapter 16: Packages
Chapter 17: Calling PL/SQL Functions in SQL
Part V: New PL/SQL8 Features
Chapter 18: Object Types
Chapter 19: Nested Tables and VARRAYs
Chapter 20: Object Views
Chapter 21: External Procedures
Part VI: Making PL/SQL Programs Work
Chapter 22: Code Design Tips
Chapter 23: Managing Code in the Database
Chapter 24: Debugging PL/SQL
Chapter 25: Tuning PL/SQL Applications
Chapter 26: Tracing PL/SQL Execution
Part VII: Appendixes
Appendix A: What's on the Companion Disk?
Appendix B: Calling Stored Procedures from PL/SQL Version 1.1
Appendix C: Built-In Packages
The Oracle PL/SQL CD
Bookshelf Navigation
Copyright © 2000 O'Reilly & Associates. All Rights Reserved.
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Full Text Search
If you are having difficulty searching, or if you have not used this search utility before, please read
this.
The Oracle PL/SQL CD
Bookshelf Navigation
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | Y | Z
Index: Symbols and Numbers
\:= (assignment) operator
2.1. The PL/SQL Character Set
4.4.3. Default Values
9.5. Assigning Values to and from Records
(comment indicator) :
2.5.1. Single-Line Comment Syntax
> (label delimeters) :
5.2.1. The GOTO Statement
' (quotation mark)
2.3.1. Embedding Single Quotes Inside a String
11.1.10. The REPLACE function
; (semicolon) :
2.4. The Semicolon Delimiter
/* and */ (comment block delimiters) :
2.5.2. Multiline Comment Syntax
|| (concatenation) operator
4.3.3. Function Results with NULL Arguments
11.1.3. The CONCAT function
Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | Y | Z
The Oracle Library
Navigation
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | Y | Z
Index: A
ABS function : 13.1.1. The ABS function
absolute value :
13.1.1. The ABS function
abstract data types : (see
ADTs)
abstraction :
18.1.5.3. Abstraction
access
to compiled code, tuning :
25.2. Tuning Access to Compiled Code
to data, tuning :
25.3. Tuning Access to Your Data
data structure, encapsulating :
1.7.2. Synchronize Program and Data Structures
to SQL, minimizing :
25.3.1. Use Package Data to Minimize SQL Access
ACCESS table, tuning :
25.2.3. Tune ACCESS$ Table to Reduce First Execution Time of Code
actual parameters :
15.6.3. Actual and Formal Parameters
Ada programming language :
Preface
ADD_MONTHS function :
12.1.1. The ADD_MONTHS function
customizing :
12.2.1. Customizing the Behavior of ADD_MONTHS
adding collection elements :
19.4.3. Adding and Removing Elements
administration of Oracle databases :
About the Contents
administration, Oracle/AQ :
C.3.2. DBMS_AQADM (PL/SQL 8 Only)
ADTs (abstract datatypes)
(see also
object types)
18.1.4.2. Classification
building :
22.6. Construct Abstract Data Types (ADTs)
advanced queuing :
1.4.7.2. Oracle/AQ, the Advanced Queueing Facility
ADVISE_COMMIT procedure :
C.15.1. The ADVISE_COMMIT procedure
ADVISE_NOTHING procedure :
C.15.2. The ADVISE_NOTHING procedure
ADVISE_ROLLBACK procedure :
C.15.3. The ADVISE_ROLLBACK procedure
aggregate
assignment into rows :
10.6.3. Aggregate Assignment
operations
9.1.3.2. Aggregate operations
9.5.4. Aggregate Assignment
9.6.1.2. Records of the same type
of nested records :
9.7.3. Aggregate Assignments of Nested Records
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
values, combining with scalars : 17.8.2. Combining Scalar and Aggregate Values
aggregation :
18.1.4.3. Inheritance
alerts : (see
DBMS_ALERT package)
algorithms, tuning :
25.4. Tuning Your Algorithms
aliases
column
6.7. Column Aliases in Cursors
9.3.2. Setting the Record's Column Names
directory :
13.2.1. The BFILENAME function
for cursor variables :
6.12.6.3. Cursor variable aliases
alignment of code : (see
coding, layout of)
ALLOCATE_UNIQUE procedure :
C.7.1. The ALLOCATE_UNIQUE procedure
ALTER SESSION command :
26.1.1. Enabling Program Units for Tracing
ALTER TABLE statement :
20.6. Schema Evolution
ALTER_COMPILE procedure :
C.4.1. The ALTER_COMPILE procedure
ALTER_QUEUE procedure :
C.3.2.4. The ALTER_QUEUE procedure
ANALYZE statement :
25.1. Analyzing Program Performance
ANALYZE_OBJECT procedure :
C.4.2. The ANALYZE_OBJECT procedure
ANALYZE_SCHEMA procedure :
C.16.1. The ANALYZE_SCHEMA procedure
anchored datatypes
1.6.1. Anchored declarations
4.5. Anchored Declarations
anchoring to subtypes :
4.6.3. Emulating Constrained Subtypes
angle brackets (>) as label delimiters :
5.2.1. The GOTO Statement
anonymous blocks :
15.3. The Anonymous PL/SQL Block
labels for :
15.3.6. Block Labels
nested :
15.3.4. Nested Blocks
in Oracle Tools :
15.3.3. Anonymous Blocks in the Oracle Tools
APPEND procedure :
C.6.1. The APPEND procedure
applications, tuning :
25. Tuning PL/SQL Applications
access to compiled code :
25.2. Tuning Access to Compiled Code
access to data :
25.3. Tuning Access to Your Data
analyzing performance :
25.1. Analyzing Program Performance
optimizing algorithms :
25.4. Tuning Your Algorithms
AQ : (see
advanced queuing)
arguments, trapping invalid :
22.2.4.1. Trap invalid argument values
arrays
(see also
tables)
1.4.3.4. PL/SQL tables
building with tables :
10.9.4. Building Traditional Arrays with PL/SQL Tables
package for
(see also
PSG_array package)
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
10.9.4.3. Features of the array package
variable arrays :
1.4.7.3. Variable arrays and nested tables
objects for :
18.1.2. Some Simple Examples
variable-size : (see
VARRAYs)
ASCII function :
11.1.1. The ASCII function
assertion modules :
22.2.4. Use Assertion Modules to Validate Parameters and Assumptions
assigning objects :
18.4.1.2. Direct assignment
assignment (\:=) operator
2.1. The PL/SQL Character Set
4.4.3. Default Values
9.5. Assigning Values to and from Records
association operator for positional notation (=>) :
2.1. The PL/SQL Character Set
association, object :
18.1.4.3. Inheritance
atomics of PL/SQL language :
2.1. The PL/SQL Character Set
attributes, cursor
6.9. Cursor Attributes
6.12.2. Similarities to Static Cursors
attributes, object :
18.1.1. Terminology
collections as :
19.2.1.2. Collection as an attribute of an object type
dot notation for
18.3.4.1. Dots in data structures
18.3.4.3. Attribute or method?
object equality and :
18.3.6.2. Equality comparisons
authority, execute/run : (see
execute authority)
Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | Y | Z
The Oracle Library
Navigation
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
[...]... Object and a PL/SQL Container Package object privileges and : 18.3.7.2 DML DML statements : 1.4.4.2 Support for DDL and dynamic SQL and tables : 10.3 PL/SQL Tables and DML Statements "do nothing" statement : (see NULL statements) documentation with encrypted code : 23.7.3 Impact of Encrypting Code of parameters : 22.7.1 Document All Parameters and Their Functions of programming process : 24.2.6 Document... Collections data dictionary entries for : 19.8.2 Data Dictionary declaring as datatype : 19.2.2 Collections in PL/SQL index-by tables : (see index-by tables) nested tables : (see nested tables) passing arguments of : 19.8.3 Call by Reference or Call by Value PL/SQL- to-server integration example : 19.7 Example: PL/SQL- to-Server Integration privileges : 19.8.1 Privileges pseudo-functions : 19.5 Collection Pseudo-Functions... External Procedures DBMS_AQ package : C.3 Oracle AQ, the Advanced Queueing Facility DBMS_AQADM package : C.3.2 DBMS_AQADM (PL/SQL 8 Only) DBMS_DDL package : C.4 DBMS_DDL DBMS_DESCRIBE package pinning in SGA shared pool : 25.2.2.1 Candidates for pinning in the shared pool DBMS_JOB package C.5 DBMS_ JOB 1.4.5.3 Job scheduling with DBMS_ JOB DBMS_LOB package : C.6 DBMS_LOB (PL/SQL8 Only) DBMS_LOCK package : C.7... cross-referencing source code : 23.6.5 Cross-Referencing Source Code in databases : 23 Managing Code in the Database documenting : 24.2.6 Document and Back Up Your Efforts errors : (see errors; exceptions) finding strings in : 23.6.4 Displaying and Searching Source Code hints for effective 1.5 Advice for Oracle Programmers 3 Effective Coding Style 4.2.8.3 Drawbacks of implicit conversions 22 Code Design Tips... Functions without parameters PL/SQL, calling in SQL : 25.3.2 Call PL/SQL Functions in SQL to Reduce I/O records as parameters : 9.1.4 Guidelines for Using Records RETURN statement : 15.5.8 The RETURN Statement returned value of : 15.5.2 The RETURN Datatype returning objects : 18.1.2 Some Simple Examples returning tables from : 10.8.1.1 Referencing fields of record elements in PL/SQL tables shared : 23.1.2... static : 6.2.1 Types of Cursors Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark variables in : 6.4.2 PL/SQL Variables in a Cursor Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | Y | Z The Oracle Library Navigation Copyright (c) 2000 O'Reilly & Associates All rights reserved Please purchase PDF Split-Merge on www.verypdf.com... collections as : 19.2.2 Collections in PL/SQL comverting external procedures and : 21.4.1 Datatype Conversion constrained/unconstrained : 4.4.1 Constrained Declarations converting performance and : 25.4.7 Avoid Type Conversions When Possible converting between 4.2.8 Conversion Between Datatypes 14 Conversion Functions declaring in tables 10.4.1 Defining the Table TYPE 10.8.1 PL/SQL Tables of Records external... Conversion for LOB variables : 1.4.7.6 Large object support for LOBs : 4.2.7 LOB Datatypes object : (see object types) for overloaded modules : 15.8.4 Restrictions on Overloading PL/SQL Version 2.0 : B.2.1 No Server-Side PL/SQL Datatypes programmer-defined : (see subtypes) standardizing with %TYPE : 4.7.8 Use %TYPE to Standardize Nondatabase Declarations of stored functions parameters : 17.3 Requirements... Architecture of PL/SQL Code procedural, avoiding : 25.3.5 Avoid Procedural Code When Possible repetetive : (see redundancy) reusing : 1.7.1 Write as Little Code as Possible Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark shared, executing : 23.1 Executing Stored Code structuring of : 1.7.5 Structured Code and Other Best Practices style of : 1.7.4 Standardize Your PL/SQL Development... C.7 DBMS_LOCK DBMS_MAIL package : C.8 DBMS_MAIL DBMS_OUTPUT package C.9 DBMS_OUTPUT 10.9.3 Displaying a PL/SQL Table 26.5 Quick-and-Dirty Tracing pinning in SGA shared pool : 25.2.2.1 Candidates for pinning in the shared pool DBMS_PIPE package : C.10 DBMS_PIPE DBMS_ROWID package : C.11 DBMS_ROWID (PL/SQL8 Only) DBMS_SESSION package : C.12 DBMS_SESSION DBMS_SHARED_POOL package : 25.2.2 Pin Critical Code . Programming in PL/SQL
Chapter 1: Introduction to PL/SQL
Chapter 2: PL/SQL Language Fundamentals
Chapter 3: Effective Coding Style
Part II: PL/SQL Language Elements. dictionary.
Previous: 1.18 External
Procedures
Oracle PL/SQL Language
Pocket Reference
1.18 External Procedures
The Oracle Library
Navigation
Copyright
Ngày đăng: 26/01/2014, 15:20
Xem thêm: Tài liệu Oracle PL/SQL Language Pocket Reference- P3 doc