Java, Python, Database, Flutter, Matlap, Micorcontroller, Tutorials, Swing Framework

Hancie e-Learning Studio

Learn Java, Learn HTML, CSS, PHP, Javascript, Python Tutorials || Download program source codes || Java Project and Source code available here || All types error troubleshooting tips available here

How to use function in PL/SQL?

 


Example 1
CREATE OR REPLACE FUNCTION AddItems (a Number, b Number)
Return Number
Is
Total_Sum Number;
Begin
Total_Sum:=a+b;
Return Total_Sum;
End;



Declare
Total_Sum Number;
Begin
Total_Sum:=AddItems(2,2);
dbms_output.put_line('The sum of two number is '|| Total_Sum);
End;

Example 2
create or replace function greaternumber(a Number, b Number)
Return Number
Is
Result Number;
Begin
If a>b then
Result:=a;
Else
Result:=b;
End If;
Return Result;
End;



Declare
Result Number;
Begin
Result:=GreaterNumber(10,5);
dbms_output.put_line('The Greatest number is '|| Result);
End;

Example 3
create or replace FUNCTION salary
RETURN NUMBER IS
    result NUMBER;
BEGIN
    SELECT COUNT(*) INTO result FROM Employees;
    RETURN result;
END;


SELECT salary FROM dual;

Example 4
create or replace FUNCTION get_employee_salary(
    id IN NUMBER
) RETURN NUMBER 
IS
    result NUMBER;
BEGIN
    SELECT Salary INTO result FROM Employees WHERE Employee_ID = id;
    RETURN result;
END;



Declare
Result Number;
Begin
Result:=get_employee_salary(198);
dbms_output.put_line(Result);
End;
Welcome all to Hancie e-learning studio
Friends,
I have brought an e-learning platform for you from where you can teach internet, website, programming language, error troubleshooting, etc. Blogger, WordPress templates, themes are available for free on this website, which are not charged for downloading, so that you can earn money by blogging using such templates and this is not a difficult task and this You can do it now. You keep uploading new posts by us and keep taking advantage of this website. The aim of which is to spread the knowledge related to internet, career, web designing and technology to the people and contribute to the development of the country.