--pl/sql procedure to swap 2 numbers without third variable create or replace procedure swapnum(a in out int, b in out int) is begin a:=a+b; b:=a-b; a:=a-b; dbms_output.put_line('After Swapping '||a||' '||b); end; declare a int :=5; b int :=7; begin dbms_output.put_line('Before Swapping '||a||' '||b); swapnum(a,b); end;
-- pl/sql procedure to find greatest of 3 numbers
declare a int:=1; b int:=2; c int:=3; d int; procedure maxof(x in int, y in int, z in int, w out int) IS begin if(x>y and x>z) then w:=x; elsif(y>x and y>z) then w:=y; else w:=z; end if; end; begin maxof(a,b,c,d); dbms_output.put_line('Greatest number is '||d); end;
-- pl/sql function for greatest of 3 numbers
create or replace function Largestof(x in out int, y in out int, z in out int) return int is begin if(x>y and x>z) then return x; elsif(y>x and y>z) then return y; else return z; end if; end; declare a int :=4; b int :=5; c int :=6; d int; begin dbms_output.put_line('Greatest number is '||Largestof(a,b,c)); end;
--pl/sql function to multiply 2 numbers
declare a int :=7; b int :=8; function multiply(x in int, y in int) return int is begin return x*y; end; begin dbms_output.put_line('Product is '||multiply(a,b)); end;