4 Copyright © 2004, Oracle. All rights reserved. Advanced Interface Methods.

Slides:



Advertisements
Similar presentations
18 Copyright © Oracle Corporation, All rights reserved. Transporting Data Between Databases.
Advertisements

Java Stored Procedures Introduction Benefits of Java Stored Procedures Deployment of Java Stored Procedures (in four steps). Prepared by: Prem Jayaraman.
5 Copyright © Oracle Corporation, All rights reserved. Using Data Dictionary and Dynamic Performance Views.
Copyright Ó Oracle Corporation, All rights reserved Sharing Objects and Code.
Advanced Package Concepts. 2 home back first prev next last What Will I Learn? Write packages that use the overloading feature Write packages that use.
Chapter 9: Advanced SQL and PL/SQL Topics Guide to Oracle 10g.
3 Copyright © 2004, Oracle. All rights reserved. Creating Packages.
1 Copyright © 2004, Oracle. All rights reserved. Creating Stored Procedures.
Creating Packages. 2 home back first prev next last What Will I Learn? Describe the reasons for using a package Describe the two components of a package:
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
4 Copyright © 2004, Oracle. All rights reserved. Creating a Basic Form Module.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
Copyright  Oracle Corporation, All rights reserved. 4 Creating Functions.
9 Copyright © Oracle Corporation, All rights reserved. Oracle Recovery Manager Overview and Configuration.
Introduction to PL/SQL Chapter 9. Objectives Explain the need for PL/SQL Explain the benefits of PL/SQL Identify the different types of PL/SQL blocks.
Advanced Databases Advanced PL/SQL Programming: Procedure, Function and Package.
24 Copyright © 2004, Oracle. All rights reserved. Using WebUtil to Interact with the Client.
Copyright  Oracle Corporation, All rights reserved. 3 Creating Procedures.
I Copyright © 2004, Oracle. All rights reserved. Introduction Copyright © 2004, Oracle. All rights reserved.
11 Copyright س Oracle Corporation, All rights reserved. ® Overview of PL/SQL.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 7 PL/SQL Packages.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9.
Lecture 8 Creating Stored Functions. Objectives  After completing this lesson, you should be able to do the following:  What is Function?  Types of.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Introduction to Oracle. Oracle History 1979 Oracle Release client/server relational database 1989 Oracle Oracle 8 (object relational) 1999.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
12 Copyright © 2004, Oracle. All rights reserved. Understanding and Influencing the PL/SQL Compiler.
8 Copyright © 2005, Oracle. All rights reserved. Managing Data.
What is a Package? A package is an Oracle object, which holds other objects within it. Objects commonly held within a package are procedures, functions,
3 Copyright © 2004, Oracle. All rights reserved. Controlling Access to the Oracle Listener.
Using Oracle-Supplied Packages. 2 home back first prev next last What Will I Learn? Describe two common uses for the DBMS_OUTPUT server-supplied package.
Chapter 9: Advanced SQL and PL/SQL Guide to Oracle 10g.
Dynamic SQL. 2 home back first prev next last What Will I Learn? Recall the stages through which all SQL statements pass Describe the reasons for using.
55 Creating Data Dictionary Views and Standard Packages.
Understand Windows Services Software Development Fundamentals LESSON 5.3.
30 Copyright © 2009, Oracle. All rights reserved. Using Oracle Business Intelligence Delivers.
Creating Procedures. PL/SQL Program Construct Tools Constructs Anonymous Block Application procedures or functions Application packages Application Triggers.
External Routines Oracle Database PL/SQL 10g Programming Chapter 12.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Copyright Ó Oracle Corporation, All rights reserved Debugging Triggers.
15 Copyright © 2004, Oracle. All rights reserved. Debugging Triggers.
10 Copyright © 2004, Oracle..All rights reserved. PL/SQL.
Creating Functions. Overview of Stored Functions A function is a named PL/SQL block that returns a value. A function is a named PL/SQL block that returns.
5 Copyright © 2004, Oracle. All rights reserved. PL/SQL Server Pages.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
What Are Subprograms? Subprograms are named PL/SQL blocks that can take parameters and be invoked. Subprograms allow decomposition of a program into logical.
17 Copyright © 2006, Oracle. All rights reserved. Information Publisher.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
E Copyright © 2006, Oracle. All rights reserved. Using SQL Developer.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
16 Copyright © 2004, Oracle. All rights reserved. Testing the Migrated Oracle Database.
4 Copyright © 2004, Oracle. All rights reserved. Managing the Oracle Instance.
9 Copyright © 2004, Oracle. All rights reserved. Getting Started with Oracle Migration Workbench.
Preface IIntroduction Course Objectives I-2 Oracle Complete Solution I-3 Course Agenda I-4 Tables Used in This Course I-5 The Order Entry Schema I-6 The.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
Slide 1 © 2016, Lera Technologies. All Rights Reserved. Oracle Data Integrator By Lera Technologies.
C Copyright © 2009, Oracle. All rights reserved. Using SQL Developer.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
Chapter 8 Dependencies, Privileges and Compilation Oracle11g:
Creating Stored Procedures and Functions
UNIT - V STORED PROCEDURE.
Introduction to PL/SQL
PL/SQL Scripting in Oracle:
Using JDeveloper.
Chapter 8 Advanced SQL.
MATERI PL/SQL Procedures Functions Packages Database Triggers
Prof. Arfaoui. COM390 Chapter 7
Presentation transcript:

4 Copyright © 2004, Oracle. All rights reserved. Advanced Interface Methods

4-2 Copyright © 2004, Oracle. All rights reserved. Objectives After completing this lesson, you should be able to do the following: Execute external C programs from PL/SQL Execute Java programs from PL/SQL

4-3 Copyright © 2004, Oracle. All rights reserved. Calling External Procedures from PL/SQL With external procedures, you can make “callouts” and, optionally, “callbacks” through PL/SQL. PL/SQL subprogram DECLARE BEGIN EXCEPTION END; External procedure Java class method C routine

4-4 Copyright © 2004, Oracle. All rights reserved. Benefits of External Procedures External procedures integrate the strength and capability of different languages to give transparent access to these routines from within the database. Extensibility: Provides functionality in the database that is specific to a particular application, company, or technological area Reusability: Can be shared by all users on a database, as well as moved to other databases or computers, providing standard functionality with limited cost in development, maintenance, and deployment

4-5 Copyright © 2004, Oracle. All rights reserved. DECLARE BEGIN EXCEPTION END; PL/SQL subprogram Alias library External C Procedure Components Shared library or directory extproc process External procedure User process Listener process

4-6 Copyright © 2004, Oracle. All rights reserved. DECLARE BEGIN EXCEPTION END; PL/SQL subprogram 1 BEGIN myproc User process How PL/SQL Calls a C External Procedure Listener process External procedure extproc process Shared library Alias library

4-7 Copyright © 2004, Oracle. All rights reserved. The extproc Process The extproc process services the execution of external procedures for the duration of the session until the user logs off. Each session uses a different extproc process to execute external procedures. The listener must be configured to allow the server to be associated to the extproc process. The listener must be on the same machine as the server.

4-8 Copyright © 2004, Oracle. All rights reserved. The Listener Process listener.ora tnsnames.ora PL/SQL subprogram Alias library Listener process External procedure Shared library DECLARE BEGIN EXCEPTION END; extproc process

4-9 Copyright © 2004, Oracle. All rights reserved. Development Steps for External C Procedures 1.Create and compile the external procedure in 3GL. 2.Link the external procedure with the shared library at the operating system level. 3.Create an alias library schema object to map to the operating system’s shared library. 4.Grant execute privileges on the library. 5.Publish the external C procedure by creating the PL/SQL subprogram unit specification, which references the alias library. 6.Execute the PL/SQL subprogram that invokes the external procedure.

4-10 Copyright © 2004, Oracle. All rights reserved. 1.Varies for each operating system; consult documentation. 2.Use the CREATE LIBRARY statement to create an alias library object. 3.Grant the EXECUTE privilege on the alias library. Development Steps for External C Procedures CREATE OR REPLACE LIBRARY library_name IS|AS 'file_path'; GRANT EXECUTE ON library_name TO user|ROLE|PUBLIC;

4-11 Copyright © 2004, Oracle. All rights reserved.

4-12 Copyright © 2004, Oracle. All rights reserved. Development Steps for External C Procedures Publish the external procedure in PL/SQL through call specifications: The body of the subprogram contains the external routine registration. The external procedure runs on the same machine. Access is controlled through the alias library. Library External routine within the procedure

4-13 Copyright © 2004, Oracle. All rights reserved. The Call Specification Call specifications enable: Dispatching the appropriate C or Java target procedure Data type conversions Parameter mode mappings Automatic memory allocation and cleanup Purity constraints to be specified, where necessary, for packaged functions that are called from SQL Calling Java methods or C procedures from database triggers Location flexibility

4-14 Copyright © 2004, Oracle. All rights reserved. The Call Specification Identify the external body within a PL/SQL program to publish the external C procedure. The external body contains the external C procedure information. CREATE OR REPLACE FUNCTION function_name (parameter_list) RETURN datatype regularbody | externalbody END; IS|AS LANGUAGE C LIBRARY libname [NAME C_function_name] [CALLING STANDARD C | PASCAL] [WITH CONTEXT] [PARAMETERS (param_1, [param_n]);

4-15 Copyright © 2004, Oracle. All rights reserved. The parameter list: The parameter list element: parameter_list_element [, parameter_list_element ] { formal_parameter_name [indicator] | RETURN INDICATOR | CONTEXT } [BY REFERENCE] [external_datatype] The Call Specification

4-16 Copyright © 2004, Oracle. All rights reserved. Publishing an External C Routine Example Publish a C function called c_tax from a PL/SQL function. The C prototype: CREATE FUNCTION tax_amt ( x BINARY_INTEGER) RETURN BINARY_INTEGER AS LANGUAGE C LIBRARY c_utility NAME "c_tax"; / int c_tax (int x_val);

4-17 Copyright © 2004, Oracle. All rights reserved. Executing the External Procedure 1.Create and compile the external procedure in 3GL. 2.Link the external procedure with the shared library at the operating system level. 3.Create an alias library schema object to map to the operating system’s shared library. 4.Grant execute privileges on the library. 5.Publish the external C procedure by creating the PL/SQL subprogram unit specification, which references the alias library. 6.Execute the PL/SQL subprogram that invokes the external procedure.

4-18 Copyright © 2004, Oracle. All rights reserved. Overview of Java The Oracle database can store Java classes and Java source, which: Are stored in the database as procedures, functions, or triggers Run inside the database Manipulate data

4-19 Copyright © 2004, Oracle. All rights reserved. How PL/SQL Calls a Java Class Method libunits Java class /home/java/bin/Agent.class 1 3 Java Virtual Machine 2 CREATE JAVA 4

4-20 Copyright © 2004, Oracle. All rights reserved. Development Steps for Java Class Methods 1.Upload the Java file. 2.Publish the Java class method by creating the PL/SQL subprogram unit specification that references the Java class methods. 3.Execute the PL/SQL subprogram that invokes the Java class method. Publish Execute

4-21 Copyright © 2004, Oracle. All rights reserved. Loading Java Class Methods 1.Upload the Java file. –At the operating system, use the loadjava command-line utility to load either the Java class file or the Java source file. To load the Java class file, use: To load the Java source file, use: –If you load the Java source file, you do not need to load the Java class file. >loadjava –user oe/oe Factorial.class >loadjava –user oe/oe Factorial.java

4-22 Copyright © 2004, Oracle. All rights reserved. Publishing a Java Class Method 2.Publish the Java class method by creating the PL/SQL subprogram unit specification that references the Java class methods. –Identify the external body within a PL/SQL program to publish the Java class method. –The external body contains the name of the Java class method. {IS | AS} LANGUAGE JAVA NAME 'method_fullname (java_type_fullname [, java_type_fullname]...) [return java_type_fullname]'; CREATE OR REPLACE { PROCEDURE procedure_name [(parameter_list)] | FUNCTION function_name [(parameter_list]...)] RETURN datatype} regularbody | externalbody END;

4-23 Copyright © 2004, Oracle. All rights reserved. Publishing a Java Class Method Example: Java method definition: CREATE OR REPLACE FUNCTION plstojavafac_fun (N NUMBER) RETURN NUMBER AS LANGUAGE JAVA NAME 'Factorial.calcFactorial (int) return int'; public class Factorial { public static int calcFactorial (int n) { if (n == 1) return 1; else return n * calcFactorial (n - 1) ; }

4-24 Copyright © 2004, Oracle. All rights reserved. Executing the Java Routine 1.Upload the Java file. 2.Publish the Java class method by creating the PL/SQL subprogram unit specification that references the Java class methods. 3.Execute the PL/SQL subprogram that invokes the Java class method.

4-25 Copyright © 2004, Oracle. All rights reserved. Creating Packages for Java Class Methods CREATE OR REPLACE PACKAGE BODY Demo_pack AS PROCEDURE plsToJ_InSpec_proc (x BINARY_INTEGER, y VARCHAR2, z DATE) IS LANGUAGE JAVA NAME 'pkg1.class4.J_InSpec_meth (int, java.lang.String, java.sql.Date)'; CREATE OR REPLACE PACKAGE Demo_pack AUTHID DEFINER AS PROCEDURE plsToJ_InSpec_proc (x BINARY_INTEGER, y VARCHAR2, z DATE) END;

4-26 Copyright © 2004, Oracle. All rights reserved. Summary In this lesson, you should have learned how to: Use external C routines and call them from your PL/SQL programs Use Java methods and call them from your PL/SQL programs

4-27 Copyright © 2004, Oracle. All rights reserved. Practice Overview This practice covers the following topics: Writing programs to interact with C routines Writing programs to interact with Java code

4-28 Copyright © 2004, Oracle. All rights reserved.

4-29 Copyright © 2004, Oracle. All rights reserved.

4-30 Copyright © 2004, Oracle. All rights reserved.