0% found this document useful (0 votes)
19 views

Create Function Sum2nos (A Number, B Number) Return Number Is S Number Begin S: A+b Return S End

The document discusses functions and procedures in PL/SQL. It provides examples of creating functions that: 1) Accept two numbers as parameters and return their sum. 2) Accept three values as parameters and return their sum. 3) Accept two numbers as parameters and return the bigger value. 4) Accept a department number and return the total salaries in that department. 5) Accept three numbers and return the biggest number.

Uploaded by

nagarajuvcc123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Create Function Sum2nos (A Number, B Number) Return Number Is S Number Begin S: A+b Return S End

The document discusses functions and procedures in PL/SQL. It provides examples of creating functions that: 1) Accept two numbers as parameters and return their sum. 2) Accept three values as parameters and return their sum. 3) Accept two numbers as parameters and return the bigger value. 4) Accept a department number and return the total salaries in that department. 5) Accept three numbers and return the biggest number.

Uploaded by

nagarajuvcc123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Functions: It is nothing but a group of statements will be execute. It can return a value.

Procedure: It is nothing but a group of statements will be execute. It cannot return a value.
Function:
Create or Replace Function <function name>(<Arguments>) return <Datetype - Number / Varchar / Date> is
.........
Declaration Part; We can declare all the variable for this func.
..........
Begin
...........
executable part;
...........
return variable/value;
Exception
When <exception name> then
.... Error handling Statements ......
End;
Example:
.........
Example:
1. Create a plsql function to accept two numbers and return sum of those numbers.
Step 1: In Toad open New Sql window type the following code then select all the code
Step 2: Click on Execute as Script (or) Ctrl+<enter Key>
Step 3: Function should be created message without errors.
create function sum2nos(a number, b number)
return number is
s number;
begin
s:=a+b;
return s;
end;
Step 4: We can call this function any time or any number of times to passing two parameters as input it can return sum of
those numbers.
Step 5: Calling Above function in two methods.
a) By using sub program. Set Dbms_output on in Toad. Select the following code and run as script.
Declare
x number:=10;
y number:=75;
z number;
Begin
z:=sum2nos(x,y);
dbms_output.put_line('Sum is :'||z);
End;
b) By using the Select Statement.
Select sum2nos(400,200) from dual;
=> If you want to Open existing Function for Editing or Review the code.
1. Mouse right click on Connection (Apps)=> New => Schema Browser, Then select Functions tab.
2. Select your corresponding function name then code will be displayed in the right side editor it is in read only. If you
want to change anything in that code. Mouse Right click on the function name then select ' Load in the Editor'. then you
can edit the code and compile the code. It will be saved automatically in the database.
2. Write a function to accept 3 values as parameters and return sum.
3. Write a function to accept 2 values as parameters and return biggest value.
create function big2nos ( a number, b number) return number is
big number;
begin
if a>b then
big:=a;
else
big:=b;
end if;
return big;
end big2nos;
4. Write a function to accept deptno number and return total salaries in that deptno.
5. Write a function to accept 3 numbers and return big number.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy