SlideShare una empresa de Scribd logo
1 de 33
Advanced SQL and PL/SQL Topics
Overview of PL/SQL Stored Program
Units
• Program unit
– Self-contained group of program statements that
can be used within larger program

•
•
•
•

Anonymous PL/SQL programs
Stored PL/SQL program units
Server-side program units
Client-side program units

Guide to Oracle 10g

2
Types of Oracle 10g Stored Program
Units

Guide to Oracle 10g

3
Creating Stored Program Units
• Procedure
– Receive multiple input parameters
– Return multiple output values or return no output
values
– Perform action such as inserting, updating, or
deleting database records

• Function
– Receive multiple input parameters
– Always returns single output value
Guide to Oracle 10g

4
Stored Program Unit Procedures
• CREATE_PROCEDURE command
–
–
–
–

Header
Parameter declarations list
Program unit body
Exception section

Guide to Oracle 10g

5
Syntax to Create a Stored Program
Unit Procedure

Guide to Oracle 10g

6
Creating the Parameter Declarations
List
• Defines parameters
• Declares associated data types
• Parameter mode
– IN
– OUT
– IN OUT

Guide to Oracle 10g

7
Creating a Stored Procedure in
SQL*Plus

Guide to Oracle 10g

8
Debugging Stored Program Units in
SQL*Plus
• Similar to debugging any program
• Identify program line causing error
• SQL*Plus interpreter displays error warning
message
– Does not automatically display compile error
messages and line locations
– Writes all compile errors to system table
• Access using USER_ERRORS data dictionary view
• Execute SHOW ERRORS command
Guide to Oracle 10g

9
Calling a Stored Procedure
• Execute directly from SQL*Plus command line
• Create separate PL/SQL program that contains
– Command to call stored procedure
– Passes parameter values to procedure

• Calling stored procedure from SQL*Plus
command line:
EXECUTE procedure_name
(parameter1_value,
parameter2_value, ...);
Guide to Oracle 10g

10
Passing Parameters to a Procedure

•IN The value of the parameter is passed into the procedure when the
procedure is invoked. It is similar to read-only
•OUT Any value the parameter has when it is called is ignored. When the
procedure finishes, any value assigned to the parameter during its execution is
returned to the calling environment. It is similar to write-only IN OUT This
mode is a combination of both IN and OUT. The value of the parameter can be
passed into the procedure when the procedure is invoked. It is then
manipulated within the procedure and returned to the calling environment. It is
similar to read-write
Guide to Oracle 10g

11
Calling a Stored Procedure
(continued)
• Variables passed for each parameter
– Must be in same order as parameters appear in
parameter declarations list

• Calling stored procedure from separate PL/SQL
program
– Similar to calling stored procedure from SQL*Plus
command line
– Omit EXECUTE command
– update_enrollment_grade(MA100, 12, B);
Guide to Oracle 10g

12
Creating a Stored Program Unit
Function
• Use CREATE OR REPLACE FUNCTION
command
• function_return_value_datatype
– Defines data type that function returns

• return_value_variable
– Declares variable that represents function return
value

• RETURN command
Guide to Oracle 10g

13
Commands to Create a Stored
Program Unit Function

Guide to Oracle 10g

14
Calling a Function
• Syntax:
variable_name :=
function_name(parameter1, paramete
r2, ...);

• Variables passed for parameter values
– Must be in same order as parameters appear in
function declaration

Guide to Oracle 10g

15
Packages
• Code library containing related program units and
variables
• Stored in database
• Executes on database server
• Grant other users privilege to use package
– Any PL/SQL program can reference package
procedures and functions

• More functionality than PL/SQL libraries
• More convenient to use than PL/SQL libraries
Guide to Oracle 10g

16
The Package Specification
• Also called package header
• Declares public package objects, including:
–
–
–
–

Variables
Cursors
Procedures
Functions

• Made public
– Program units outside package can reference
package’s objects
Guide to Oracle 10g

17
The Package Specification (continued)
• Public variables
– Visible to many different PL/SQL programs
– Values remain in memory even after programs that
declare and reference them terminate
– Declare public variable in DECLARE section of
package
• Same syntax used to declare private variable

Guide to Oracle 10g

18
General Syntax for a Package
Specification

Guide to Oracle 10g

19
The Package Specification (continued)
• Declare variables and cursors in packages
– Same syntax used in other PL/SQL programs

• Declare procedure syntax:
PROCEDURE procedure_name
(parameter1 parameter1_data_type,
parameter2 parameter2_data_type, ...);

Guide to Oracle 10g

20
The Package Specification (continued)
• Declare function syntax:
FUNCTION function_name
(parameter1 parameter1_data_type,
parameter2 parameter2_data_type, ...)
RETURN return_datatype;

Guide to Oracle 10g

21
The Package Body
• Contains commands to create program units that
package specification declares
• Must create specification before body
• Optional
• Variables declared at beginning of package body
– Private to package

• Each program unit in package specification must
be defined
Guide to Oracle 10g

22
General Syntax for a Package Body

Guide to Oracle 10g

23
The Package Body (continued)
•
•
•
•

Create package using SQL*Plus
Create package specification in SQL*Plus
Create package body in SQL*Plus
Reference package objects syntax:
– package_name.item_name

Guide to Oracle 10g

24
The Package Body (continued)
• Package exists in user schema
– Must grant permission to others
– GRANT EXECUTE ON package_name TO
username;

Guide to Oracle 10g

25
Database Triggers
• Program units
– Execute in response to database events of
inserting, updating, or deleting record

• Different from form triggers
• Useful for maintaining integrity constraints
• Similar to other program units
– But cannot accept parameters

Guide to Oracle 10g

26
Database Trigger Properties
• Trigger timing
– BEFORE
– AFTER

• Trigger statement
– INSERT
– UPDATE
– DELETE

Guide to Oracle 10g

27
Database Trigger Properties
(continued)
• Trigger level
– Statement-level
– Row-level

• Reference value of field in current record
– Both before and after triggering statement executes
• :OLD.fieldname
• :NEW.fieldname

Guide to Oracle 10g

28
Creating Database Triggers
• Database trigger header
• Trigger body

Guide to Oracle 10g

29
General Syntax to Create a Trigger in
SQL*Plus

Guide to Oracle 10g

30
Creating Database Triggers to Leave
an Audit Trail for the Northwoods
University ENROLLMENT Table
• Track when users insert, update, and delete table
records
• Create trigger that leaves audit trail
– Create one or more tables to store audit trail values

• Create database trigger in SQL*Plus
• Create database trigger in Forms Builder

Guide to Oracle 10g

31
Disabling and Dropping Triggers
• Drop trigger when not needed:
– DROP TRIGGER trigger_name;

• Disable trigger
– Trigger still exists in user’s database schema
– No longer fires when triggering event occurs
– Syntax:
• ALTER TRIGGER trigger_name [ENABLE
| DISABLE];
Guide to Oracle 10g

32
Viewing Information About Triggers
• USER_TRIGGERS data dictionary view
– Contains information about triggers

Guide to Oracle 10g

33

Más contenido relacionado

La actualidad más candente

R12 d49656 gc10-apps dba 11
R12 d49656 gc10-apps dba 11R12 d49656 gc10-apps dba 11
R12 d49656 gc10-apps dba 11zeesniper
 
(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0
(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0
(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0BIOVIA
 
Oracle-L11 using Oracle flashback technology-Mazenet solution
Oracle-L11 using  Oracle flashback technology-Mazenet solutionOracle-L11 using  Oracle flashback technology-Mazenet solution
Oracle-L11 using Oracle flashback technology-Mazenet solutionMazenetsolution
 
Nov. 4, 2011 o reilly webcast-hbase- lars george
Nov. 4, 2011 o reilly webcast-hbase- lars georgeNov. 4, 2011 o reilly webcast-hbase- lars george
Nov. 4, 2011 o reilly webcast-hbase- lars georgeO'Reilly Media
 
Oracle flashback
Oracle flashbackOracle flashback
Oracle flashbackCambodia
 
Less17 flashback tb3
Less17 flashback tb3Less17 flashback tb3
Less17 flashback tb3Imran Ali
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
Case_Study_-_Advanced_Oracle_PLSQL
Case_Study_-_Advanced_Oracle_PLSQLCase_Study_-_Advanced_Oracle_PLSQL
Case_Study_-_Advanced_Oracle_PLSQLZiemowit Jankowski
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbmsjain.pralabh
 
Hovitaga OpenSQL Editor - Comparison with SE16 and SAP query
Hovitaga OpenSQL Editor - Comparison with SE16 and SAP queryHovitaga OpenSQL Editor - Comparison with SE16 and SAP query
Hovitaga OpenSQL Editor - Comparison with SE16 and SAP queryHovitaga Kft.
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, proceduresVaibhav Kathuria
 
Improving the Performance of PL/SQL function calls from SQL
Improving the Performance of PL/SQL function calls from SQLImproving the Performance of PL/SQL function calls from SQL
Improving the Performance of PL/SQL function calls from SQLGuatemala User Group
 
R12 d49656 gc10-apps dba 06
R12 d49656 gc10-apps dba 06R12 d49656 gc10-apps dba 06
R12 d49656 gc10-apps dba 06zeesniper
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadatarehaniltifat
 
Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.Alexey Furmanov
 
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
 

La actualidad más candente (20)

R12 d49656 gc10-apps dba 11
R12 d49656 gc10-apps dba 11R12 d49656 gc10-apps dba 11
R12 d49656 gc10-apps dba 11
 
(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0
(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0
(ATS6-DEV01) What’s new for Protocol and Component Developers in AEP 9.0
 
Oracle-L11 using Oracle flashback technology-Mazenet solution
Oracle-L11 using  Oracle flashback technology-Mazenet solutionOracle-L11 using  Oracle flashback technology-Mazenet solution
Oracle-L11 using Oracle flashback technology-Mazenet solution
 
Nov. 4, 2011 o reilly webcast-hbase- lars george
Nov. 4, 2011 o reilly webcast-hbase- lars georgeNov. 4, 2011 o reilly webcast-hbase- lars george
Nov. 4, 2011 o reilly webcast-hbase- lars george
 
Oracle flashback
Oracle flashbackOracle flashback
Oracle flashback
 
Less17 flashback tb3
Less17 flashback tb3Less17 flashback tb3
Less17 flashback tb3
 
Jsp project module
Jsp project moduleJsp project module
Jsp project module
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Case_Study_-_Advanced_Oracle_PLSQL
Case_Study_-_Advanced_Oracle_PLSQLCase_Study_-_Advanced_Oracle_PLSQL
Case_Study_-_Advanced_Oracle_PLSQL
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Hovitaga OpenSQL Editor - Comparison with SE16 and SAP query
Hovitaga OpenSQL Editor - Comparison with SE16 and SAP queryHovitaga OpenSQL Editor - Comparison with SE16 and SAP query
Hovitaga OpenSQL Editor - Comparison with SE16 and SAP query
 
plsql les03
 plsql les03 plsql les03
plsql les03
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
 
Improving the Performance of PL/SQL function calls from SQL
Improving the Performance of PL/SQL function calls from SQLImproving the Performance of PL/SQL function calls from SQL
Improving the Performance of PL/SQL function calls from SQL
 
Plsql
PlsqlPlsql
Plsql
 
R12 d49656 gc10-apps dba 06
R12 d49656 gc10-apps dba 06R12 d49656 gc10-apps dba 06
R12 d49656 gc10-apps dba 06
 
08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata08 Dynamic SQL and Metadata
08 Dynamic SQL and Metadata
 
Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.
 
plsql les02
 plsql les02 plsql les02
plsql les02
 
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
 

Similar a Store programs

Oracle applications r12.2, ebr, online patching means lot of work for devel...
Oracle applications r12.2, ebr, online patching   means lot of work for devel...Oracle applications r12.2, ebr, online patching   means lot of work for devel...
Oracle applications r12.2, ebr, online patching means lot of work for devel...Ajith Narayanan
 
Db Triggers05ch
Db Triggers05chDb Triggers05ch
Db Triggers05chtheo_10
 
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
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
 
ebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdfebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdfElboulmaniMohamed
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management Systemsweetysweety8
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013Andrejs Vorobjovs
 
MOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMonica Li
 
MOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMonica Li
 
0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorialKlausePaulino
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14Syed Asrarali
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesAlfredo Abate
 

Similar a Store programs (20)

Oracle applications r12.2, ebr, online patching means lot of work for devel...
Oracle applications r12.2, ebr, online patching   means lot of work for devel...Oracle applications r12.2, ebr, online patching   means lot of work for devel...
Oracle applications r12.2, ebr, online patching means lot of work for devel...
 
Db Triggers05ch
Db Triggers05chDb Triggers05ch
Db Triggers05ch
 
Plsql guide 2
Plsql guide 2Plsql guide 2
Plsql guide 2
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
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
 
Plsql les04
Plsql les04Plsql les04
Plsql les04
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
ebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdfebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdf
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
Exploring plsql new features best practices september 2013
Exploring plsql new features best practices   september 2013Exploring plsql new features best practices   september 2013
Exploring plsql new features best practices september 2013
 
MOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical Examples
 
MOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your Data
 
0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial
 
Intro to tsql
Intro to tsqlIntro to tsql
Intro to tsql
 
Intro to tsql unit 14
Intro to tsql   unit 14Intro to tsql   unit 14
Intro to tsql unit 14
 
COUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_FeaturesCOUG_AAbate_Oracle_Database_12c_New_Features
COUG_AAbate_Oracle_Database_12c_New_Features
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
ow.ppt
ow.pptow.ppt
ow.ppt
 
Ow
OwOw
Ow
 

Más de Hitesh Kumar Markam (19)

Concepts of Distributed Computing & Cloud Computing
Concepts of Distributed Computing & Cloud Computing Concepts of Distributed Computing & Cloud Computing
Concepts of Distributed Computing & Cloud Computing
 
Data guard
Data guardData guard
Data guard
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
Resize sga
Resize sgaResize sga
Resize sga
 
Rman offline backup
Rman offline backupRman offline backup
Rman offline backup
 
Oracle shutdown
Oracle shutdownOracle shutdown
Oracle shutdown
 
Log miner in oracle.ppt
Log miner in oracle.pptLog miner in oracle.ppt
Log miner in oracle.ppt
 
Dba in 2 days unit no 9
Dba in 2 days unit no 9Dba in 2 days unit no 9
Dba in 2 days unit no 9
 
5 backuprecoveryw imp
5 backuprecoveryw imp5 backuprecoveryw imp
5 backuprecoveryw imp
 
Rmanpres
RmanpresRmanpres
Rmanpres
 
Pl sql
Pl sqlPl sql
Pl sql
 
Oracle archi ppt
Oracle archi pptOracle archi ppt
Oracle archi ppt
 
Lecture2 oracle ppt
Lecture2 oracle pptLecture2 oracle ppt
Lecture2 oracle ppt
 
Dbms objective and subjective notes
Dbms objective and subjective notesDbms objective and subjective notes
Dbms objective and subjective notes
 
Dba in 2 days
Dba in 2 daysDba in 2 days
Dba in 2 days
 
Creating database
Creating databaseCreating database
Creating database
 
1 plsql introduction1
1 plsql introduction11 plsql introduction1
1 plsql introduction1
 
javascript code for mysql database connection
javascript code for mysql database connectionjavascript code for mysql database connection
javascript code for mysql database connection
 
Advanced Planning And Optimization
Advanced Planning And OptimizationAdvanced Planning And Optimization
Advanced Planning And Optimization
 

Último

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Último (20)

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 

Store programs

  • 1. Advanced SQL and PL/SQL Topics
  • 2. Overview of PL/SQL Stored Program Units • Program unit – Self-contained group of program statements that can be used within larger program • • • • Anonymous PL/SQL programs Stored PL/SQL program units Server-side program units Client-side program units Guide to Oracle 10g 2
  • 3. Types of Oracle 10g Stored Program Units Guide to Oracle 10g 3
  • 4. Creating Stored Program Units • Procedure – Receive multiple input parameters – Return multiple output values or return no output values – Perform action such as inserting, updating, or deleting database records • Function – Receive multiple input parameters – Always returns single output value Guide to Oracle 10g 4
  • 5. Stored Program Unit Procedures • CREATE_PROCEDURE command – – – – Header Parameter declarations list Program unit body Exception section Guide to Oracle 10g 5
  • 6. Syntax to Create a Stored Program Unit Procedure Guide to Oracle 10g 6
  • 7. Creating the Parameter Declarations List • Defines parameters • Declares associated data types • Parameter mode – IN – OUT – IN OUT Guide to Oracle 10g 7
  • 8. Creating a Stored Procedure in SQL*Plus Guide to Oracle 10g 8
  • 9. Debugging Stored Program Units in SQL*Plus • Similar to debugging any program • Identify program line causing error • SQL*Plus interpreter displays error warning message – Does not automatically display compile error messages and line locations – Writes all compile errors to system table • Access using USER_ERRORS data dictionary view • Execute SHOW ERRORS command Guide to Oracle 10g 9
  • 10. Calling a Stored Procedure • Execute directly from SQL*Plus command line • Create separate PL/SQL program that contains – Command to call stored procedure – Passes parameter values to procedure • Calling stored procedure from SQL*Plus command line: EXECUTE procedure_name (parameter1_value, parameter2_value, ...); Guide to Oracle 10g 10
  • 11. Passing Parameters to a Procedure •IN The value of the parameter is passed into the procedure when the procedure is invoked. It is similar to read-only •OUT Any value the parameter has when it is called is ignored. When the procedure finishes, any value assigned to the parameter during its execution is returned to the calling environment. It is similar to write-only IN OUT This mode is a combination of both IN and OUT. The value of the parameter can be passed into the procedure when the procedure is invoked. It is then manipulated within the procedure and returned to the calling environment. It is similar to read-write Guide to Oracle 10g 11
  • 12. Calling a Stored Procedure (continued) • Variables passed for each parameter – Must be in same order as parameters appear in parameter declarations list • Calling stored procedure from separate PL/SQL program – Similar to calling stored procedure from SQL*Plus command line – Omit EXECUTE command – update_enrollment_grade(MA100, 12, B); Guide to Oracle 10g 12
  • 13. Creating a Stored Program Unit Function • Use CREATE OR REPLACE FUNCTION command • function_return_value_datatype – Defines data type that function returns • return_value_variable – Declares variable that represents function return value • RETURN command Guide to Oracle 10g 13
  • 14. Commands to Create a Stored Program Unit Function Guide to Oracle 10g 14
  • 15. Calling a Function • Syntax: variable_name := function_name(parameter1, paramete r2, ...); • Variables passed for parameter values – Must be in same order as parameters appear in function declaration Guide to Oracle 10g 15
  • 16. Packages • Code library containing related program units and variables • Stored in database • Executes on database server • Grant other users privilege to use package – Any PL/SQL program can reference package procedures and functions • More functionality than PL/SQL libraries • More convenient to use than PL/SQL libraries Guide to Oracle 10g 16
  • 17. The Package Specification • Also called package header • Declares public package objects, including: – – – – Variables Cursors Procedures Functions • Made public – Program units outside package can reference package’s objects Guide to Oracle 10g 17
  • 18. The Package Specification (continued) • Public variables – Visible to many different PL/SQL programs – Values remain in memory even after programs that declare and reference them terminate – Declare public variable in DECLARE section of package • Same syntax used to declare private variable Guide to Oracle 10g 18
  • 19. General Syntax for a Package Specification Guide to Oracle 10g 19
  • 20. The Package Specification (continued) • Declare variables and cursors in packages – Same syntax used in other PL/SQL programs • Declare procedure syntax: PROCEDURE procedure_name (parameter1 parameter1_data_type, parameter2 parameter2_data_type, ...); Guide to Oracle 10g 20
  • 21. The Package Specification (continued) • Declare function syntax: FUNCTION function_name (parameter1 parameter1_data_type, parameter2 parameter2_data_type, ...) RETURN return_datatype; Guide to Oracle 10g 21
  • 22. The Package Body • Contains commands to create program units that package specification declares • Must create specification before body • Optional • Variables declared at beginning of package body – Private to package • Each program unit in package specification must be defined Guide to Oracle 10g 22
  • 23. General Syntax for a Package Body Guide to Oracle 10g 23
  • 24. The Package Body (continued) • • • • Create package using SQL*Plus Create package specification in SQL*Plus Create package body in SQL*Plus Reference package objects syntax: – package_name.item_name Guide to Oracle 10g 24
  • 25. The Package Body (continued) • Package exists in user schema – Must grant permission to others – GRANT EXECUTE ON package_name TO username; Guide to Oracle 10g 25
  • 26. Database Triggers • Program units – Execute in response to database events of inserting, updating, or deleting record • Different from form triggers • Useful for maintaining integrity constraints • Similar to other program units – But cannot accept parameters Guide to Oracle 10g 26
  • 27. Database Trigger Properties • Trigger timing – BEFORE – AFTER • Trigger statement – INSERT – UPDATE – DELETE Guide to Oracle 10g 27
  • 28. Database Trigger Properties (continued) • Trigger level – Statement-level – Row-level • Reference value of field in current record – Both before and after triggering statement executes • :OLD.fieldname • :NEW.fieldname Guide to Oracle 10g 28
  • 29. Creating Database Triggers • Database trigger header • Trigger body Guide to Oracle 10g 29
  • 30. General Syntax to Create a Trigger in SQL*Plus Guide to Oracle 10g 30
  • 31. Creating Database Triggers to Leave an Audit Trail for the Northwoods University ENROLLMENT Table • Track when users insert, update, and delete table records • Create trigger that leaves audit trail – Create one or more tables to store audit trail values • Create database trigger in SQL*Plus • Create database trigger in Forms Builder Guide to Oracle 10g 31
  • 32. Disabling and Dropping Triggers • Drop trigger when not needed: – DROP TRIGGER trigger_name; • Disable trigger – Trigger still exists in user’s database schema – No longer fires when triggering event occurs – Syntax: • ALTER TRIGGER trigger_name [ENABLE | DISABLE]; Guide to Oracle 10g 32
  • 33. Viewing Information About Triggers • USER_TRIGGERS data dictionary view – Contains information about triggers Guide to Oracle 10g 33