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

function create in sql screen

Uploaded by

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

function create in sql screen

Uploaded by

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

SQL> create or replace function adder (n1 in number, n2 in number)

2 return number
3 is
4 n3 number(8);
5 begin
6 n3:=n1+n2;
7 return n3;
8 end;
9 /

Function created.

Now call the funcation:

SQL> declare
2 n3 number(2);
3 begin
4 n3:=adder(11,22);
5 dbms_output.put_line('addition is: '||n3);
6 end;
7 /

PL/SQL procedure successfully completed.

Now

SQL> declare
2 n3 number(2);
3 begin
4 n3:=adder(11,22);
5 dbms_output.put_line('addition is: '||n3);
6 end;
7 /

addition is: 33

PL/SQL procedure successfully completed.

Now Q2.
Max no a,b,c
SQL> DECLARE
2 a number;
3 b number;
4 c number;
5 function findmax(x in number, y in number)
6 return number
7 is
8 z number;
9 begin
10 if x>y then
11 z:=x;
12 else
13 z:=y;
14 end if;
15 return z;
16 end;
17 begin
18 a:=23;
19 b:=45;
20 c:=findmax(a,b);
21 dbms_output.put_line('max of (23,45): ->' ||c);
22 end;
23 /
max of (23,45): ->45

PL/SQL procedure successfully completed.

Q3. SQL> select * from customerdummy


2 ;

ID NAME DEPARTMENT SALARY


---------- ---------- -------------------- ----------
1a web 35000
2r program 45000
3m web des 35000
4d database 44000

SQL> create or replace function totalcustomers


2 return number
3 is
4 total number(2):=0;
5 begin
6 select count(*
7 ) into total
8 from customerdummy;
9 return total;
10 end
11 ;
12 /

Function created.

Call the function:


SQL> declare
2 c number(2);
3 begin
4 c:=totalcustomers();
5 dbms_output.put_line('Total no of customers:' || c);
6 end;
7 /
Total no of customers:4

PL/SQL procedure successfully completed.

You might also like