Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
129 views

Program: Functions in PL/SQL Tax Calculation

This document contains two examples of PL/SQL functions. The first defines a function called calculate_tax that takes a number as a parameter, multiplies it by 0.07 to calculate tax, and returns the result. The second defines a factorial function that takes a number, initializes a variable to 1, uses a for loop to iteratively multiply the variable by integers from 1 to the parameter, and returns the final result. Both functions are then called and output is displayed to demonstrate their functionality.
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)
129 views

Program: Functions in PL/SQL Tax Calculation

This document contains two examples of PL/SQL functions. The first defines a function called calculate_tax that takes a number as a parameter, multiplies it by 0.07 to calculate tax, and returns the result. The second defines a factorial function that takes a number, initializes a variable to 1, uses a for loop to iteratively multiply the variable by integers from 1 to the parameter, and returns the final result. Both functions are then called and output is displayed to demonstrate their functionality.
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/ 2

FUNCTIONS IN PL/SQL

TAX CALCULATION
PROGRAM
1 create or replace function calculate_tax(t_value in number)return number is
2 begin
3 return(t_value*0.07);
4* end calculate_tax;
SQL> /
Function created.

OUTPUT
SQL> select calculate_tax(17000) from dual;
CALCULATE_TAX(17000)
-------------------1190

FACTORIAL OF A NUMBER
PROGRAM
SQL> get z:\f2.sql;
1 create or replace function factorial(a number) return number is
2 f number:=1;
3 i integer;
4 begin
5 for i in 1..a loop
6
f:=i*f;
7 end loop;
8 return f;
9* end factorial;
SQL> /
Function created.

OUTPUT
SQL> select factorial(7) from dual;
FACTORIAL(7)
-----------5040

You might also like