SlideShare ist ein Scribd-Unternehmen logo
1 von 8
FUNCTIONS
ORACLE (PL/SQL)
TOPIC PAGE NO.
DEFINITION 2
SYNTAX 2
METHODS TO CREATE FUNCTION
1. INDIVIDUALLY
2. WITHIN PL/SQL BLOCK
2,5
HOW TO EXECUTE FUNCTION 3-4
How to use functions with database table. 6
How to check errors. 7
FUNCTION WITH PARAMETER AS USER
DEFINED VALUES.
8
SOME EXAMPLES
1. FACTORIALPAGE-7
2. MAXIMUM OF TWO VALUES PAGE2
3. MULTIPLICATION. PAGE-5
4. PERCENTAGE OF STUDENTPAGE6
FUNCTIONS
ORACLE (PL/SQL)
DEFINITION
A function is a named PL/SQL Block which is similar to a procedure. The major difference
between a procedure and a function is, a function must always return a value, but a procedure
may or may not return a value.
SYNTAX
CREATE [OR REPLACE] FUNCTION function_name [parameters]
RETURN return_datatype;
IS
Declaration_section
BEGIN
Execution_section
Return return_variable;
EXCEPTION
exception section
Return return_variable;
END;
METHODS TO CREATE FUNCTIONS
1. FUNCTION CAN BE CREATED INDIVIDUALLY TO BE USED LATER ON ANY TIME.
2. FUNCTION CAN BE CREATED AS EMBEDDED PART OF PL/SQL.
FOR EX:
FIRST METHOD OF CREATING FUNCTION
FUNCTIONT O FIND GREATEST OF TWO VALUES (VALUES ARE PASSED AS ARGUMENT TO THE FUNC)
NOTE: RESULT OF THIS FUNCTION IS SHOWN AT PAGE-4
FUNCTIONS
ORACLE (PL/SQL)
How to execute a PL/SQL Function?
A function can be executed in the following ways.
1) Since a function returns a value we can assign it to a variable.
employee_name := employer_details_func;
If ‘employee_name’ is of datatype varchar we can store the name of the employee by assigning the
return type of the function to it.
2) As a part of a SELECT statement
SELECT employer_details_func FROM dual;
3) In a PL/SQL Statements like,
dbms_output.put_line(employer_details_func);
This line displays the value returned by the function.
USING SQL QUERY
USING PL/SQL (WITHOUT USING VARIABLE)
FUNCTIONS
ORACLE (PL/SQL)
USING PL/SQL (USING VARIABLE)
PICTURE SHOWING THE SECOND METHOD OF CREATING A FUNCTION.
DECLARE (PL/SQL)
BEGIN (PL/SQL)
END (PL/SQL)
FUNCTION
IS ( DECLARATION)
BEGIN (EXECUTION)
END
FUNCTIONS
ORACLE (PL/SQL)
SECOND METHOD OF CREATING A FUNCTION
FUNCTION TO FIND PRODUCT OF TWO VALUES(VALUES ARE PASSED AS ARGUMENT TO
FUNCTION)
An example of pl/sql function embedded in pl/sql code
NOTE: we need not to execute the function, the function calling process is done itself in the begin part
of pl/sql block.
We have used result variable, which stores the value returned by function.
FUNCTIONS
ORACLE (PL/SQL)
Another example of same method
USING FUNCTIONS WITH DATABASE TABLE
Now we will create a function that finds percentage of student based on student id passed as argument
to the function. The details of student are stored in std table of database.
FUNCTIONS
ORACLE (PL/SQL)
HOW TO CHECK ERRORS:
SHOW ERRORS FUNCTION <<FUNCTION NAME>>
FOR EX: SHOW ERRORS FUNCTION employer_details_func
Same for procedure ( show errors procedure <<procedure name>>
SOME EXAMPLES
FUNCTION TO FIND FACTORIAL OF NUMBER
DECLARE
num number;
factorial number;
BEGIN
num:= 6;
factorial := fact(num);
dbms_output.put_line(' Factorial '|| num || ' is ' || factorial);
END;
/
FUNCTION fact(x number)
RETURN number
IS
f number;
BEGIN
IF x=0 THEN
f := 1;
ELSE
f := x * fact(x-1);
END IF;
RETURN f;
END;
FUNCTIONS
ORACLE (PL/SQL)
FUNCTIONS ON USER DEFINED VALUES

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
02 Writing Executable Statments
02 Writing Executable Statments02 Writing Executable Statments
02 Writing Executable Statments
 
Sql oracle
Sql oracleSql oracle
Sql oracle
 
Pl sql guide
Pl sql guidePl sql guide
Pl sql guide
 
Chapter8 pl sql
Chapter8 pl sqlChapter8 pl sql
Chapter8 pl sql
 
Oracle Index
Oracle IndexOracle Index
Oracle Index
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
MySQL Views
MySQL ViewsMySQL Views
MySQL Views
 
4. plsql
4. plsql4. plsql
4. plsql
 
Sql Functions And Procedures
Sql Functions And ProceduresSql Functions And Procedures
Sql Functions And Procedures
 
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...
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
 
Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
Sql query [select, sub] 4
Sql query [select, sub] 4Sql query [select, sub] 4
Sql query [select, sub] 4
 

Andere mochten auch

Andere mochten auch (9)

Functions and return type
Functions and return typeFunctions and return type
Functions and return type
 
Types of functions 05272011
Types of functions 05272011Types of functions 05272011
Types of functions 05272011
 
Oracle SQL Functions
Oracle SQL FunctionsOracle SQL Functions
Oracle SQL Functions
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Function and types
Function  and typesFunction  and types
Function and types
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
Role of CPU
Role of CPURole of CPU
Role of CPU
 

Ähnlich wie Functions oracle (pl/sql)

Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQLKailash N
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)RajKumarSingh213
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbmsjain.pralabh
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3Belal Arfa
 
Oracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online TrainingOracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online Trainingsuresh
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programmingRushdi Shams
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, proceduresVaibhav Kathuria
 
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.pptOracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.pptDheerajKashnyal
 
Mysql creating stored function
Mysql  creating stored function Mysql  creating stored function
Mysql creating stored function Prof.Nilesh Magar
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management Systemsweetysweety8
 
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
 

Ähnlich wie Functions oracle (pl/sql) (20)

SQL Procedures & Functions
SQL Procedures & FunctionsSQL Procedures & Functions
SQL Procedures & Functions
 
Function
FunctionFunction
Function
 
plsql les02
 plsql les02 plsql les02
plsql les02
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 
Oracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online TrainingOracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online Training
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.pptOracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
Oracle_PLSQL_basic_tutorial_with_workon_Exercises.ppt
 
Oracle etl openworld
Oracle etl openworldOracle etl openworld
Oracle etl openworld
 
Mysql creating stored function
Mysql  creating stored function Mysql  creating stored function
Mysql creating stored function
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
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
 

Mehr von harman kaur

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlabharman kaur
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)harman kaur
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black treeharman kaur
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlideharman kaur
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.harman kaur
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gateharman kaur
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)harman kaur
 
Rules of inference
Rules of inferenceRules of inference
Rules of inferenceharman kaur
 
Virtual function
Virtual functionVirtual function
Virtual functionharman kaur
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++harman kaur
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornicsharman kaur
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programsharman kaur
 

Mehr von harman kaur (15)

Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black tree
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
 
Digital u1
Digital u1Digital u1
Digital u1
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gate
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
 
Msql query
Msql queryMsql query
Msql query
 
Rules of inference
Rules of inferenceRules of inference
Rules of inference
 
Virtual function
Virtual functionVirtual function
Virtual function
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornics
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 

Kürzlich hochgeladen

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 

Kürzlich hochgeladen (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 

Functions oracle (pl/sql)

  • 1. FUNCTIONS ORACLE (PL/SQL) TOPIC PAGE NO. DEFINITION 2 SYNTAX 2 METHODS TO CREATE FUNCTION 1. INDIVIDUALLY 2. WITHIN PL/SQL BLOCK 2,5 HOW TO EXECUTE FUNCTION 3-4 How to use functions with database table. 6 How to check errors. 7 FUNCTION WITH PARAMETER AS USER DEFINED VALUES. 8 SOME EXAMPLES 1. FACTORIALPAGE-7 2. MAXIMUM OF TWO VALUES PAGE2 3. MULTIPLICATION. PAGE-5 4. PERCENTAGE OF STUDENTPAGE6
  • 2. FUNCTIONS ORACLE (PL/SQL) DEFINITION A function is a named PL/SQL Block which is similar to a procedure. The major difference between a procedure and a function is, a function must always return a value, but a procedure may or may not return a value. SYNTAX CREATE [OR REPLACE] FUNCTION function_name [parameters] RETURN return_datatype; IS Declaration_section BEGIN Execution_section Return return_variable; EXCEPTION exception section Return return_variable; END; METHODS TO CREATE FUNCTIONS 1. FUNCTION CAN BE CREATED INDIVIDUALLY TO BE USED LATER ON ANY TIME. 2. FUNCTION CAN BE CREATED AS EMBEDDED PART OF PL/SQL. FOR EX: FIRST METHOD OF CREATING FUNCTION FUNCTIONT O FIND GREATEST OF TWO VALUES (VALUES ARE PASSED AS ARGUMENT TO THE FUNC) NOTE: RESULT OF THIS FUNCTION IS SHOWN AT PAGE-4
  • 3. FUNCTIONS ORACLE (PL/SQL) How to execute a PL/SQL Function? A function can be executed in the following ways. 1) Since a function returns a value we can assign it to a variable. employee_name := employer_details_func; If ‘employee_name’ is of datatype varchar we can store the name of the employee by assigning the return type of the function to it. 2) As a part of a SELECT statement SELECT employer_details_func FROM dual; 3) In a PL/SQL Statements like, dbms_output.put_line(employer_details_func); This line displays the value returned by the function. USING SQL QUERY USING PL/SQL (WITHOUT USING VARIABLE)
  • 4. FUNCTIONS ORACLE (PL/SQL) USING PL/SQL (USING VARIABLE) PICTURE SHOWING THE SECOND METHOD OF CREATING A FUNCTION. DECLARE (PL/SQL) BEGIN (PL/SQL) END (PL/SQL) FUNCTION IS ( DECLARATION) BEGIN (EXECUTION) END
  • 5. FUNCTIONS ORACLE (PL/SQL) SECOND METHOD OF CREATING A FUNCTION FUNCTION TO FIND PRODUCT OF TWO VALUES(VALUES ARE PASSED AS ARGUMENT TO FUNCTION) An example of pl/sql function embedded in pl/sql code NOTE: we need not to execute the function, the function calling process is done itself in the begin part of pl/sql block. We have used result variable, which stores the value returned by function.
  • 6. FUNCTIONS ORACLE (PL/SQL) Another example of same method USING FUNCTIONS WITH DATABASE TABLE Now we will create a function that finds percentage of student based on student id passed as argument to the function. The details of student are stored in std table of database.
  • 7. FUNCTIONS ORACLE (PL/SQL) HOW TO CHECK ERRORS: SHOW ERRORS FUNCTION <<FUNCTION NAME>> FOR EX: SHOW ERRORS FUNCTION employer_details_func Same for procedure ( show errors procedure <<procedure name>> SOME EXAMPLES FUNCTION TO FIND FACTORIAL OF NUMBER DECLARE num number; factorial number; BEGIN num:= 6; factorial := fact(num); dbms_output.put_line(' Factorial '|| num || ' is ' || factorial); END; / FUNCTION fact(x number) RETURN number IS f number; BEGIN IF x=0 THEN f := 1; ELSE f := x * fact(x-1); END IF; RETURN f; END;