SlideShare a Scribd company logo
PL/SQL –
Procedure/Functions
Le funzioni in PL/SQL sono sottoprogrammi con un valore di
ritorno. Le procedure sono sottoprogrammi senza valori di
ritorno.
Procedure
PROCEDURE name [ ( parameter [, parameter ... ] ) ]
IS
[declaration statements]
BEGIN
executable statements−
[ EXCEPTION
exception handler statements]
END [ name ];
Le procedure vengono invocate per nome passando eventualmente dei
parametri:
apply_discount( new_company_id, 0.15 );
Funzioni
FUNCTION name [ ( parameter [, parameter ... ] ) ]
RETURN return_datatype
IS
[ declaration statements ]
BEGIN
executable statements
[ EXCEPTION
exception handler statements ]
END [ name ];
A differenza delle procedure c’è il tipo di ritorno.
Le funzioni ritornano un valore quindi vengono richiamate così:
sales_for_1995 := tot_sales (1504, 'C');
Esempio di funzione
FUNCTION company_type (type_code_in IN VARCHAR2)
RETURN VARCHAR2
IS
return_value VARCHAR2 (25) := NULL;
BEGIN
IF type_code_in = 'S'
THEN
return_value := 'SUBSIDIARY';
ELSIF type_code_in = 'P'
THEN
return_value := 'PARTNER';
END IF;
RETURN return_value;
END;
Parametri IN e OUT
I parametri IN sono passati per valore in parametri OUT per riferimento.
PROCEDURE combine_and_format_names
(first_name_inout IN OUT VARCHAR2, last_name_inout IN OUT VARCHAR2,
full_name_out OUT VARCHAR2,name_format_in IN VARCHAR2 := 'LAST,
FIRST')
IS
BEGIN
/* Upper case the first and last names. */−
first_name_inout := UPPER (first_name_inout);
last_name_inout := UPPER (last_name_inout);
/* Combine the names as directed by the name format string. */
IF name_format_in = 'LAST, FIRST'
THEN
full_name_out := last_name_inout || ', ' ||
first_name_inout;
ELSIFname_format_in = 'FIRST LAST'
THEN
full_name_out := first_name_inout || ' ' || last_name_inout;
END IF;
END;
Esempio: Giorni mese
CREATE OR REPLACE FUNCTION “UTENTE"."F_GET_GIORNIMESE"
(
pIntIDF_MESE T_RAPPORTINI.IDF_MESE%TYPE,
pStrANNO T_RAPPORTINI.ANNO%TYPE
)
return INTEGER
as
V_GIORNI_MESE INTEGER;
BEGIN
IF pIntIDF_MESE = 11 OR pIntIDF_MESE = 4 OR pIntIDF_MESE = 6 OR pIntIDF_MESE = 9 THEN
V_GIORNI_MESE := 30;
ELSIF pIntIDF_MESE = 2 THEN
IF MOD(TO_NUMBER(pStrANNO), 4) = 0 THEN
V_GIORNI_MESE := 29;
ELSE
V_GIORNI_MESE := 28;
END IF;
ELSE
V_GIORNI_MESE := 31;
END IF;
RETURN V_GIORNI_MESE;
END F_GET_GIORNIMESE;
Esempio: Giorni mese
CREATE OR REPLACE FUNCTION “UTENTE"."F_GET_GIORNIMESE"
(
pIntIDF_MESE T_RAPPORTINI.IDF_MESE%TYPE,
pStrANNO T_RAPPORTINI.ANNO%TYPE
)
return INTEGER
as
V_GIORNI_MESE INTEGER;
BEGIN
IF pIntIDF_MESE = 11 OR pIntIDF_MESE = 4 OR pIntIDF_MESE = 6 OR pIntIDF_MESE = 9 THEN
V_GIORNI_MESE := 30;
ELSIF pIntIDF_MESE = 2 THEN
IF MOD(TO_NUMBER(pStrANNO), 4) = 0 THEN
V_GIORNI_MESE := 29;
ELSE
V_GIORNI_MESE := 28;
END IF;
ELSE
V_GIORNI_MESE := 31;
END IF;
RETURN V_GIORNI_MESE;
END F_GET_GIORNIMESE;

More Related Content

PPT
PL/SQL
PPTX
Function and types
PPTX
Procedure n functions
DOCX
PL/SQL Code for Sample Projects
PPT
PLSQL Cursors
DOCX
Functions oracle (pl/sql)
PPTX
PPTX
Oracle: Control Structures
PL/SQL
Function and types
Procedure n functions
PL/SQL Code for Sample Projects
PLSQL Cursors
Functions oracle (pl/sql)
Oracle: Control Structures

What's hot (13)

PPTX
Unit 3(rdbms)
PDF
Oracle 11g PL/SQL notes
PPTX
Scalar expressions and control structures in perl
PPT
Oracle PLSQL Step By Step Guide
PPTX
PL/SQL Fundamentals I
DOCX
Authentication Functions
PPTX
A green solution to solve a race condition problem
PPTX
Subroutines in perl
PDF
Cursors
PPTX
C function presentation
PPTX
PPTX
User defined functions in C
PPT
Php Reusing Code And Writing Functions
Unit 3(rdbms)
Oracle 11g PL/SQL notes
Scalar expressions and control structures in perl
Oracle PLSQL Step By Step Guide
PL/SQL Fundamentals I
Authentication Functions
A green solution to solve a race condition problem
Subroutines in perl
Cursors
C function presentation
User defined functions in C
Php Reusing Code And Writing Functions
Ad

Similar to Oracle PL sql 3 (20)

PPTX
Procedure and Functions in pl/sql
PPTX
Plsql coding conventions
PPT
05 Creating Stored Procedures
PPT
PPTX
PL_SQL_1.pptx fvbxcfbhxdfgh .
PPTX
Functions
PPT
PL/SQL Introduction and Concepts
PPT
PPTX
9. DBMS Experiment Laboratory PresentationPPT
PPTX
Pl/SQL Procedure,Function & Packages - sub programs
PPTX
Function in PL/SQL
PPT
Pl sql guide
PDF
Lecture Notes Unit5 chapter17 Stored procedures and functions
PPT
SQL- Introduction to PL/SQL
PDF
SQL Procedures & Functions
PPT
PPT
PDF
Function Procedure Trigger Partition.pdf
PPTX
pl/sql Procedure
PPTX
Lecture 3.2_Subprogrammm - Function.pptx
Procedure and Functions in pl/sql
Plsql coding conventions
05 Creating Stored Procedures
PL_SQL_1.pptx fvbxcfbhxdfgh .
Functions
PL/SQL Introduction and Concepts
9. DBMS Experiment Laboratory PresentationPPT
Pl/SQL Procedure,Function & Packages - sub programs
Function in PL/SQL
Pl sql guide
Lecture Notes Unit5 chapter17 Stored procedures and functions
SQL- Introduction to PL/SQL
SQL Procedures & Functions
Function Procedure Trigger Partition.pdf
pl/sql Procedure
Lecture 3.2_Subprogrammm - Function.pptx
Ad

More from Sergio Ronchi (20)

PPT
Java lezione 19
PPT
Java lezione 18
PPT
Java lezione 17
PPT
Java lezione 16
PPT
Java lezione 15
PPT
Java lezione 14
PPT
Java lezione 13
PPT
Java lezione 12
PPT
Java lezione 11
PPT
Java lezione 10
PPT
Java lezione 9
PPT
Java lezione 8
PPT
Java lezione 7
PPT
Java lezione 6
PPT
Java lezione 5
PPT
Java lezione 4
PPT
Java lezione 3
PPT
Java lezione 2
PPT
Java introduzione
PPT
Java Lezione 1
Java lezione 19
Java lezione 18
Java lezione 17
Java lezione 16
Java lezione 15
Java lezione 14
Java lezione 13
Java lezione 12
Java lezione 11
Java lezione 10
Java lezione 9
Java lezione 8
Java lezione 7
Java lezione 6
Java lezione 5
Java lezione 4
Java lezione 3
Java lezione 2
Java introduzione
Java Lezione 1

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
AI in Product Development-omnex systems
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Introduction to Artificial Intelligence
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Essential Infomation Tech presentation.pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
medical staffing services at VALiNTRY
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Softaken Excel to vCard Converter Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
AI in Product Development-omnex systems
Upgrade and Innovation Strategies for SAP ERP Customers
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms I-SECS-1021-03
How to Migrate SBCGlobal Email to Yahoo Easily
Introduction to Artificial Intelligence
Which alternative to Crystal Reports is best for small or large businesses.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms II-SECS-1021-03
Essential Infomation Tech presentation.pptx
ai tools demonstartion for schools and inter college
medical staffing services at VALiNTRY
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...

Oracle PL sql 3

  • 1. PL/SQL – Procedure/Functions Le funzioni in PL/SQL sono sottoprogrammi con un valore di ritorno. Le procedure sono sottoprogrammi senza valori di ritorno.
  • 2. Procedure PROCEDURE name [ ( parameter [, parameter ... ] ) ] IS [declaration statements] BEGIN executable statements− [ EXCEPTION exception handler statements] END [ name ]; Le procedure vengono invocate per nome passando eventualmente dei parametri: apply_discount( new_company_id, 0.15 );
  • 3. Funzioni FUNCTION name [ ( parameter [, parameter ... ] ) ] RETURN return_datatype IS [ declaration statements ] BEGIN executable statements [ EXCEPTION exception handler statements ] END [ name ]; A differenza delle procedure c’è il tipo di ritorno. Le funzioni ritornano un valore quindi vengono richiamate così: sales_for_1995 := tot_sales (1504, 'C');
  • 4. Esempio di funzione FUNCTION company_type (type_code_in IN VARCHAR2) RETURN VARCHAR2 IS return_value VARCHAR2 (25) := NULL; BEGIN IF type_code_in = 'S' THEN return_value := 'SUBSIDIARY'; ELSIF type_code_in = 'P' THEN return_value := 'PARTNER'; END IF; RETURN return_value; END;
  • 5. Parametri IN e OUT I parametri IN sono passati per valore in parametri OUT per riferimento. PROCEDURE combine_and_format_names (first_name_inout IN OUT VARCHAR2, last_name_inout IN OUT VARCHAR2, full_name_out OUT VARCHAR2,name_format_in IN VARCHAR2 := 'LAST, FIRST') IS BEGIN /* Upper case the first and last names. */− first_name_inout := UPPER (first_name_inout); last_name_inout := UPPER (last_name_inout); /* Combine the names as directed by the name format string. */ IF name_format_in = 'LAST, FIRST' THEN full_name_out := last_name_inout || ', ' || first_name_inout; ELSIFname_format_in = 'FIRST LAST' THEN full_name_out := first_name_inout || ' ' || last_name_inout; END IF; END;
  • 6. Esempio: Giorni mese CREATE OR REPLACE FUNCTION “UTENTE"."F_GET_GIORNIMESE" ( pIntIDF_MESE T_RAPPORTINI.IDF_MESE%TYPE, pStrANNO T_RAPPORTINI.ANNO%TYPE ) return INTEGER as V_GIORNI_MESE INTEGER; BEGIN IF pIntIDF_MESE = 11 OR pIntIDF_MESE = 4 OR pIntIDF_MESE = 6 OR pIntIDF_MESE = 9 THEN V_GIORNI_MESE := 30; ELSIF pIntIDF_MESE = 2 THEN IF MOD(TO_NUMBER(pStrANNO), 4) = 0 THEN V_GIORNI_MESE := 29; ELSE V_GIORNI_MESE := 28; END IF; ELSE V_GIORNI_MESE := 31; END IF; RETURN V_GIORNI_MESE; END F_GET_GIORNIMESE;
  • 7. Esempio: Giorni mese CREATE OR REPLACE FUNCTION “UTENTE"."F_GET_GIORNIMESE" ( pIntIDF_MESE T_RAPPORTINI.IDF_MESE%TYPE, pStrANNO T_RAPPORTINI.ANNO%TYPE ) return INTEGER as V_GIORNI_MESE INTEGER; BEGIN IF pIntIDF_MESE = 11 OR pIntIDF_MESE = 4 OR pIntIDF_MESE = 6 OR pIntIDF_MESE = 9 THEN V_GIORNI_MESE := 30; ELSIF pIntIDF_MESE = 2 THEN IF MOD(TO_NUMBER(pStrANNO), 4) = 0 THEN V_GIORNI_MESE := 29; ELSE V_GIORNI_MESE := 28; END IF; ELSE V_GIORNI_MESE := 31; END IF; RETURN V_GIORNI_MESE; END F_GET_GIORNIMESE;