ADVANCED FEATURES

21
ADVANCED FEATURES Of PL/SQL

description

ADVANCED FEATURES. Of PL/SQL. * PROCEDURAL LANGUAGE FEATURE * OBJECT ORIENTED FEATURES * EXCEPTION HANDLING * INCREASED SECUTIRY * PACKAGES. PROGRAMMING FEATURES. * PROCEDURES and FUNCTIONS * BLOCK FEATURES * DEBUGGING IS FRUSTRATION * REUSABILITY * INBUILT PACKAGES. - PowerPoint PPT Presentation

Transcript of ADVANCED FEATURES

Page 1: ADVANCED FEATURES

ADVANCED FEATURESOf

PL/SQL

Page 2: ADVANCED FEATURES

* PROCEDURAL LANGUAGE FEATURE

* OBJECT ORIENTED FEATURES

* EXCEPTION HANDLING

* INCREASED SECUTIRY

* PACKAGES

Page 3: ADVANCED FEATURES

PROGRAMMING FEATURES

* PROCEDURES and FUNCTIONS* BLOCK FEATURES* DEBUGGING IS FRUSTRATION* REUSABILITY* INBUILT PACKAGES

Page 4: ADVANCED FEATURES

PROCEDURES AND FUNCTIONS

Page 5: ADVANCED FEATURES

BLOCK FEATURES

Page 6: ADVANCED FEATURES

DEBUGGING

- Suspending Executionbreakpoint: unconditional and conditional

- Stepping through the codeSTEP IN, STEP OVER, STEP OUT, RUN TO CURSOR

- Monitoring valuesWATCH window

- Monitoring Execution FlowCALL STACK window

This is done using Sql Program Debugger Window, oneof the modules of PL/SQL and needs installation

Page 7: ADVANCED FEATURES

REUSABILITY

BEST EXAMPLES ARE INBUILT PACKAGES

Page 8: ADVANCED FEATURES

USER FRIENDLY

- Search keys in PL/SQL codes

- Print to the screen

- Read or Write from PL/SQL

- Use SQL from PL/SQL

- Execute Operating System Commands

Page 9: ADVANCED FEATURES

INBUILT PACKAGES

e.g Banking Package package banking isprocedure new_acct(name IN VARCHAR);procedure acct_dep(acno IN NUMBER, amount IN NUMBER);procedure acc_wdr(acno IN NUMBER, amount IN NUMBER);procedure acc_bal(acno IN NUMBER, bal OUT NUMBER);function acc_drwn(acno IN NUMBER) RETURN BOOLEAN;end banking;

Page 10: ADVANCED FEATURES

OBJECT ORIENTED

* Data Centric* Encapsulation* Function Overloading* DOES NOT SUPPORT INHERITENCE

Page 11: ADVANCED FEATURES

WE CAN PROTECT OUR SOURCE CODE

wrap iname=myscript.sql

oname=xxxx.plb

CALL REMOTE PROCEDURES

Page 12: ADVANCED FEATURES

SECURITY

? LOGS OF FILE and CODE e.g. We can keep log of last modification of any code

with the following code.

SELECT OBJECT_NAME, TO_CHAR(CREATED, 'DD-Mon-RR HH24:MI')

CREATE_TIME,TO_CHAR(LAST_DDL_TIME, 'DD-Mon-RR HH24:MI')

MOD_TIME, STATUS

FROM USER_OBJECTS WHERE LAST_DDL_TIME > '&CHECK_FROM_DATE';

Page 13: ADVANCED FEATURES

? KEEP HISTORY

e.g code

CREATE TABLE SOURCE_HIST

AS

SELECT SYSDATE CHANGE_DATE, USER_SOURCE.*

FROM USER_SOURCE

WHERE 1=2;

Page 14: ADVANCED FEATURES

CREATE OR REPLACE TRIGGER change_hist

AFTER CREATE ON SCOTT.SCHEMA

DECLARE

BEGIN

if DICTIONARY_OBJ_TYPE in ('PROCEDURE', 'FUNCTION',

'PACKAGE', 'PACKAGE BODY', 'TYPE')

then INSERT INTO SOURCE_HIST

SELECT sysdate, user_source.* FROM USER_SOURCE

WHERE TYPE = DICTIONARY_OBJ_TYPE

AND NAME = DICTIONARY_OBJ_NAME;

end if;

EXCEPTION

WHEN OTHERS THEN raise_application_error(-20000, SQLERRM);

END;

Page 15: ADVANCED FEATURES

EXCEPTION HANDLING

TYPICAL BODY OF AN PL/SQL PROGRAM

DECLARE …..BEGIN

…..EXCEPTION

…..END;

Page 16: ADVANCED FEATURES

OTHERS

* INTERPORATBILITY and INTERPRETABILITY

•JAVA INSIDE PL/SQL

• MAILS from DATABASE

Page 17: ADVANCED FEATURES

JAVA

Page 18: ADVANCED FEATURES

Step 1 Identify the Java functionality you want to use in your application. See if the existing Java class libraries have any predefined Java classes containing methods that have that functionality.  Step 2 Create a specific Java class that includes a method based on this functionality.  Step 3 Compile the Java class, test it, and load it into the database.

Page 19: ADVANCED FEATURES

 

Step 4 Build a PL/SQL wrapper program that will call theJava stored procedure you've loaded.  Step 5 Grant the privileges required for the PL/SQL wrapperprogram and the Java stored procedure it references.  Step 6 Call the PL/SQL program.

Page 20: ADVANCED FEATURES

Build a Custom Java Class  Why can't you just call File.delete directly inside the PL/SQL wrapper? There are two reasons:  A Java method is, in almost every case (except for static and class methods), executed for a specific object instantiated from the class. You cannot instantiate a Java object from within PL/SQL and then invoke the method on that object.

Page 21: ADVANCED FEATURES

Datatypes in Java and PL/SQL do not map directly to each other. For example, you can't pass a Java Boolean datatype directly to a PL/SQL Boolean datatype.

Therefore, you need to build your own class that will :- - Instantiate an object from the File class  - Invoke the delete method on that object

– Return a value that PL/SQL can interpret