SlideShare ist ein Scribd-Unternehmen logo
1 von 26
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
2
3
4
User
process
How PL/SQL Calls a C External Procedure
5
6
7
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-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

Weitere ähnliche Inhalte

Was ist angesagt?

11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilarrehaniltifat
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Developmentrehaniltifat
 
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...rehaniltifat
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statmentsrehaniltifat
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Proceduresrehaniltifat
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadatarehaniltifat
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
Oracle sql & plsql
Oracle sql & plsqlOracle sql & plsql
Oracle sql & plsqlSid Xing
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptionsrehaniltifat
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Salman Memon
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals INick Buytaert
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQLKailash N
 

Was ist angesagt? (20)

11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar11 Understanding and Influencing the PL/SQL Compilar
11 Understanding and Influencing the PL/SQL Compilar
 
07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
 
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Procedures
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
 
plsql Lec11
plsql Lec11 plsql Lec11
plsql Lec11
 
plsql Les07
plsql Les07 plsql Les07
plsql Les07
 
plsql Les08
plsql Les08 plsql Les08
plsql Les08
 
plsql Les09
 plsql Les09 plsql Les09
plsql Les09
 
PL/SQL 3 DML
PL/SQL 3 DMLPL/SQL 3 DML
PL/SQL 3 DML
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Oracle sql & plsql
Oracle sql & plsqlOracle sql & plsql
Oracle sql & plsql
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptions
 
Pl sql chapter 1
Pl sql chapter 1Pl sql chapter 1
Pl sql chapter 1
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
Plsql guide 2
Plsql guide 2Plsql guide 2
Plsql guide 2
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
 

Andere mochten auch

SOA for PL/SQL Developer (OPP 2010)
SOA for PL/SQL Developer (OPP 2010)SOA for PL/SQL Developer (OPP 2010)
SOA for PL/SQL Developer (OPP 2010)Lucas Jellema
 
Pattern driven Enterprise Architecture
Pattern driven Enterprise ArchitecturePattern driven Enterprise Architecture
Pattern driven Enterprise ArchitectureWSO2
 
Advanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceAdvanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceZohar Elkayam
 
ICTA Technology Meetup 06 - Enterprise Application Design Patterns
ICTA Technology Meetup 06 - Enterprise Application Design PatternsICTA Technology Meetup 06 - Enterprise Application Design Patterns
ICTA Technology Meetup 06 - Enterprise Application Design PatternsCrishantha Nanayakkara
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSmohdoracle
 
Role of integration in Digital Transformation
Role of integration in Digital TransformationRole of integration in Digital Transformation
Role of integration in Digital TransformationWSO2
 
Lidando com o Caos: Testando Código PLSQL em um Projeto Critico
Lidando com o Caos: Testando Código PLSQL em um Projeto CriticoLidando com o Caos: Testando Código PLSQL em um Projeto Critico
Lidando com o Caos: Testando Código PLSQL em um Projeto CriticoRafael Ponte
 

Andere mochten auch (7)

SOA for PL/SQL Developer (OPP 2010)
SOA for PL/SQL Developer (OPP 2010)SOA for PL/SQL Developer (OPP 2010)
SOA for PL/SQL Developer (OPP 2010)
 
Pattern driven Enterprise Architecture
Pattern driven Enterprise ArchitecturePattern driven Enterprise Architecture
Pattern driven Enterprise Architecture
 
Advanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better PerformanceAdvanced PLSQL Optimizing for Better Performance
Advanced PLSQL Optimizing for Better Performance
 
ICTA Technology Meetup 06 - Enterprise Application Design Patterns
ICTA Technology Meetup 06 - Enterprise Application Design PatternsICTA Technology Meetup 06 - Enterprise Application Design Patterns
ICTA Technology Meetup 06 - Enterprise Application Design Patterns
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
 
Role of integration in Digital Transformation
Role of integration in Digital TransformationRole of integration in Digital Transformation
Role of integration in Digital Transformation
 
Lidando com o Caos: Testando Código PLSQL em um Projeto Critico
Lidando com o Caos: Testando Código PLSQL em um Projeto CriticoLidando com o Caos: Testando Código PLSQL em um Projeto Critico
Lidando com o Caos: Testando Código PLSQL em um Projeto Critico
 

Ähnlich wie Plsql les04

Less04 instance
Less04 instanceLess04 instance
Less04 instanceImran Ali
 
Java Library for High Speed Streaming Data
Java Library for High Speed Streaming Data Java Library for High Speed Streaming Data
Java Library for High Speed Streaming Data Oracle Developers
 
The Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheThe Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheSteven Feuerstein
 
D17316 gc20 l05_phys_sql
D17316 gc20 l05_phys_sqlD17316 gc20 l05_phys_sql
D17316 gc20 l05_phys_sqlMoeen_uddin
 
Interactive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and ArchitectureInteractive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and ArchitectureJavaDayUA
 
JShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java PlatformJShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java PlatformJavaDayUA
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiUnmesh Baile
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiUnmesh Baile
 
Setting up Oracle WorkFlow.ppt
Setting up Oracle WorkFlow.pptSetting up Oracle WorkFlow.ppt
Setting up Oracle WorkFlow.pptrockysheddy
 
Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)XPERT INFOTECH
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Simon Ritter
 
Less 01 introduction
Less 01   introductionLess 01   introduction
Less 01 introductionAbu Nema
 
Oracle Cloud DBaaS
Oracle Cloud DBaaSOracle Cloud DBaaS
Oracle Cloud DBaaSArush Jain
 

Ähnlich wie Plsql les04 (20)

Store programs
Store programsStore programs
Store programs
 
15362590.ppt
15362590.ppt15362590.ppt
15362590.ppt
 
Les01
Les01Les01
Les01
 
Less04 instance
Less04 instanceLess04 instance
Less04 instance
 
Les 20 dup_db
Les 20 dup_dbLes 20 dup_db
Les 20 dup_db
 
Java Library for High Speed Streaming Data
Java Library for High Speed Streaming Data Java Library for High Speed Streaming Data
Java Library for High Speed Streaming Data
 
The Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result CacheThe Amazing and Elegant PL/SQL Function Result Cache
The Amazing and Elegant PL/SQL Function Result Cache
 
D17316 gc20 l05_phys_sql
D17316 gc20 l05_phys_sqlD17316 gc20 l05_phys_sql
D17316 gc20 l05_phys_sql
 
Interactive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and ArchitectureInteractive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and Architecture
 
JShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java PlatformJShell: An Interactive Shell for the Java Platform
JShell: An Interactive Shell for the Java Platform
 
13 java in oracle
13 java in oracle13 java in oracle
13 java in oracle
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbai
 
Corporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbaiCorporate-informatica-training-in-mumbai
Corporate-informatica-training-in-mumbai
 
Setting up Oracle WorkFlow.ppt
Setting up Oracle WorkFlow.pptSetting up Oracle WorkFlow.ppt
Setting up Oracle WorkFlow.ppt
 
Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)
 
ODTUG Webinar AWR Warehouse
ODTUG Webinar AWR WarehouseODTUG Webinar AWR Warehouse
ODTUG Webinar AWR Warehouse
 
Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8Improved Developer Productivity In JDK8
Improved Developer Productivity In JDK8
 
Less 01 introduction
Less 01   introductionLess 01   introduction
Less 01 introduction
 
Oracle Cloud DBaaS
Oracle Cloud DBaaSOracle Cloud DBaaS
Oracle Cloud DBaaS
 
Bn 1018 demo pl sql
Bn 1018 demo  pl sqlBn 1018 demo  pl sql
Bn 1018 demo pl sql
 

Kürzlich hochgeladen

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Kürzlich hochgeladen (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Plsql les04

  • 1. Copyright © 2004, Oracle. All rights reserved. Advanced Interface Methods
  • 2. 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
  • 3. 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-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
  • 5. 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
  • 6. 4-6 Copyright © 2004, Oracle. All rights reserved. DECLARE BEGIN EXCEPTION END; PL/SQL subprogram 1 BEGIN myproc 2 3 4 User process How PL/SQL Calls a C External Procedure 5 6 7 Listener process External procedure extproc process Shared library Alias library
  • 7. 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.
  • 8. 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
  • 9. 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.
  • 10. 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;
  • 11. 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
  • 12. 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
  • 13. 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]);
  • 14. 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
  • 15. 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);
  • 16. 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.
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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
  • 21. 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;
  • 22. 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) ; } }
  • 23. 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.
  • 24. 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;
  • 25. 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
  • 26. 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