Task - Stored Functions - org DB #13
Replies: 41 comments
-
DELIMITER &&
CREATE FUNCTION computeTax(salary int)RETURNS DECIMAL(10,2) DETERMINISTIC BEGIN
DECLARE incomeTax DECIMAL(10,2);
IF salary<=75000 THEN SET incomeTax=0.1*salary;
ELSEIF salary>75000 and salary<=150000 THEN SET incomeTax=0.2*salary;
ELSE SET incomeTax=0.3*SALARY;
END IF;
RETURN incomeTax;
END &&
DELIMITER ;
SELECT * ,computeTax(salary)FROM WORKER;
DELIMITER &&
CREATE PROCEDURE CALCULATEINCOMETAX(IN SALARY INT,OUT INCOMETAX DECIMAL(10,2))
BEGIN
SET INCOMETAX=computeTax(SALARY);
END &&
DELIMITER ;
CALL CALCULATEINCOMETAX(80000,@INCOMETAX);
SELECT @INCOMETAX;
|
Beta Was this translation helpful? Give feedback.
-
1USE org;
DELIMITER //
CREATE FUNCTION computeTax (salary INT)
RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE taxComputed DECIMAL(10,2);
IF salary <= 75000 THEN
SET taxComputed = salary * 10 / 100;
ELSEIF salary > 75000 AND salary <= 150000 THEN
SET taxComputed = salary * 20 / 100;
ELSEIF salary > 150000 THEN
SET taxComputed = salary * 30 / 100;
END IF;
RETURN taxComputed;
END //
DELIMITER ;
SELECT worker.*, computeTax(SALARY) AS computedTax FROM worker; 2USE org;
DELIMITER //
CREATE PROCEDURE calculateIncomeTax(IN SALARY INT, OUT computedTax DECIMAL (10,2))
BEGIN
DECLARE tax DECIMAL (10,2);
SET tax = computeTax(SALARY);
SELECT tax INTO computedTax;
END //
DELIMITER ;
CALL calculateIncomeTax(80000 , @taxAmount);
SELECT @taxAmount AS computedTax; |
Beta Was this translation helpful? Give feedback.
-
1.)
CREATE FUNCTION computeTax(
salary int
)
RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE tax DECIMAL(10,2);
IF salary <= 75000 THEN
SET tax = salary*10;
ELSEIF (salary > 75000 AND
salary <= 150000) THEN
SET tax = salary*20;
ELSEIF salary > 150000 THEN
SET tax = salary*30;
END IF;
-- return the customer level
SET tax=tax/100;
RETURN (tax);
END //
SELECT *,computeTax(salary) AS computed_Tax FROM worker;
2.)
CREATE PROCEDURE tax(IN salary INT,OUT computedTax DECIMAL(10,2))
BEGIN
SELECT computeTax(salary) INTO computedTax;
END //
CALL tax(60000,@tax);
SELECT @tax; |
Beta Was this translation helpful? Give feedback.
-
delimiter //
create function computeTax(salary int) returns decimal(10,2)
deterministic
begin
declare tax decimal(10,2);
if salary <=7500 then
set tax = salary*0.1;
elseif (salary>7500 and salary<=150000) then
set tax = salary*0.2;
else
set tax = salary*0.3;
end if;
return tax;
end//
delimiter ;
select worker_id,salary,computeTax(salary) from worker;
delimiter //
create procedure compute_tax_procedure(in salary int,out tax decimal(10,2))
begin
set tax = computeTax(salary);
select tax;
end//
delimiter ;
call compute_tax_procedure(100000,@tax);
|
Beta Was this translation helpful? Give feedback.
-
--1
DELIMITER;
CREATE FUNCTION incomeTax(salary INT)
RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE incometax DECIMAL(10,2);
IF( salary<75000) then
SET incometax= salary*.10;
ELSEIF (salary>75000 and salary<100000) then
SET incometax= salary*.20;
else
SET incometax= salary*.30;
end if;
RETURN incometax;
end //
DELIMITER;
select *, incomeTax(salary) as incomeTax from worker;
--2
DELIMITER //
CREATE PROCEDURE computeIncomeTax(IN salary INT, OUT incometax DECIMAL(10,2))
BEGIN
SET incometax=incomeTax(salary);
END //
DELIMITER ;
call computeIncomeTax(150000,@result);
select @result;
|
Beta Was this translation helpful? Give feedback.
-
use org;
DELIMITER //
CREATE FUNCTION computeTax(Salary int)
RETURNS Decimal(10,2)
DETERMINISTIC
BEGIN
DECLARE tax Decimal(10,2);
IF Salary <= 75000 THEN
SET tax = salary * 0.1 ;
ELSEIF Salary >= 75000 AND Salary <= 150000 THEN
SET tax = salary * 0.2;
ELSE
SET tax = salary * 0.3;
END IF;
RETURN tax;
END //
Select worker_id,salary,computeTax(salary) as IncomeTax from worker;
DELIMITER //
CREATE PROCEDURE calculatedIncomeTax(
IN sal INT,
OUT incomeTax DECIMAL(10,2)
)
BEGIN
SELECT computeTax(sal) INTO incomeTax;
END //
DELIMITER ; |
Beta Was this translation helpful? Give feedback.
-
1.2. |
Beta Was this translation helpful? Give feedback.
-
**1**
DELIMITER $$
CREATE FUNCTION computeTax (
salary INT
)
RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE incomeTax DECIMAL(10,2);
IF salary <= 75000 THEN
SET incomeTax = salary * 0.1;
ELSEIF salary > 75000 AND salary <= 150000 THEN
SET incomeTax = salary * 0.2;
ELSEIF salary > 150000 THEN
SET incomeTax = salary * 0.3;
END IF;
RETURN incomeTax;
END $$
DELIMITER ;
SELECT *,computeTax(salary) AS income_tax FROM worker;
**2**
DELIMITER $$
CREATE PROCEDURE calculate_Tax(IN salary INT,OUT IncomeTax DECIMAL(10,2))
BEGIN
SET IncomeTax = computeTax(salary);
END $$
DELIMITER ;
CALL calculate_Tax(120000 , @tax);
SELECT @tax; |
Beta Was this translation helpful? Give feedback.
-
|
1 delimiter //
create function computeTax(salary int) returns decimal(10,2)
deterministic
begin
declare tax decimal(10,2);
if salary <=7500 then
set tax = salary*0.1;
elseif (salary>7500 and salary<=150000) then
set tax = salary*0.2;
else
set tax = salary*0.3;
end if;
return tax;
end//
delimiter ;
select worker_id,salary,computeTax(salary) from worker;delimiter //
create procedure compute_tax_procedure(in salary int,out tax decimal(10,2))
begin
set tax = computeTax(salary);
select tax;
end//
delimiter ;
call compute_tax_procedure(100000,@tax); |
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
CREATE FUNCTION calcTax(
salary INT
)
RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE incomeTax DECIMAL(10,2);
SET incomeTax = 0;
IF (salary <= 75000) THEN
SET incomeTax = 10*salary;
ELSEIF (salary > 75000 and salary <= 150000) THEN
SET incomeTax = 20*salary;
ELSEIF (salary > 150000) THEN
SET incomeTax = 30*salary;
END IF;
SET incomeTax = incomeTax/100;
RETURN incomeTax;
END //
DELIMITER ;
SELECT *, calcTax(salary) FROM worker;DELIMITER //
CREATE PROCEDURE calculateIncomeTax(IN salary INT,OUT incomeTax DECIMAL(10,2))
BEGIN
SET incomeTax = calcTax(salary);
END//
DELIMITER ;
CALL calculateIncomeTax(100000,@incomeTax);
SELECT @incomeTax; |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
CREATE FUNCTION computeTax(salary int)RETURNS DECIMAL(10,2) DETERMINISTIC BEGIN
DECLARE incomeTax DECIMAL(10,2);
IF salary<=75000 THEN SET incomeTax=0.1*salary;
ELSEIF salary>75000 and salary<=150000 THEN SET incomeTax=0.2*salary;
ELSE SET incomeTax=0.3*SALARY;
END IF;
RETURN incomeTax;
END //
DELIMITER ;
select *, computeTax(salary) as computedTax from employees;
DELIMITER //
CREATE PROCEDURE CALCULATEINCOMETAX(IN SALARY INT,OUT INCOMETAX DECIMAL(10,2))
-> BEGIN
-> SET INCOMETAX=computeTax(SALARY);
-> END //
DELIMITER ;
call calculateIncomeTax(75600, @INCOMETAX);
select @INCOMETAX; |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
CREATE FUNCTION computeTax(
salary INT
)
RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE tax DECIMAL(10,2);
IF salary <= 75000 THEN
SET tax = 0.1*salary;
ELSEIF salary > 75000 AND salary <= 150000 THEN
SET tax = 0.2*salary;
ELSE
SET tax = 0.3*salary;
END IF;
RETURN tax;
END //
DELIMITER ;
select *, computeTax(salary) from worker;DELIMITER //
CREATE PROCEDURE calculateIncomeTax(
IN salary INT, OUT tax DECIMAL(10,2)
)
BEGIN
SET tax = computeTax(salary);
END//
DELIMITER ;
CALL calculateIncomeTax(50000, @tax);
SELECT @tax; |
Beta Was this translation helpful? Give feedback.
-
|
1 DELIMITER && DELIMITER ; SELECT *,computeTax(salary) as computedTax from worker; 2 DELIMITER && |
Beta Was this translation helpful? Give feedback.
-
delimiter //
create function computetax1(salary int)
Returns decimal(10,2)
DETERMINISTIC
BEGIN
DECLARE incometax decimal(10,2);
IF salary <= 75000 then
set incometax= 0.1*salary;
elseif (salary> 75000 and salary <=15000) then
set incometax= 0.2*salary;
else
set incometax= 0.3*salary;
END IF;
return incometax;
END //
delimiter ;
select * , computetax1(salary) from worker ;
delimiter //
create Procedure tax(in salary int, out incometax decimal(10,2))
BEGIN
set incometax= computetax1(salary);
end //
delimiter;
call tax(900000,@incometax);
select @incometax; |
Beta Was this translation helpful? Give feedback.
-
--1
DELIMITER / /
CREATE FUNCTION computingTax(salary int)
RETURNS decimal(10, 2)
DETERMINISTIC
BEGIN
DECLARE incomeTax decimal(10, 2);
IF salary <= 75000 THEN
SET incomeTax = (salary * 0.1);
ELSEIF ( salary <= 150000 AND salary > 75000 ) THEN
SET incomeTax = (salary * 0.2);
ELSE
SET incomeTax = (salary * 0.3);
END IF;
RETURN incomeTax;
END / /
DELIMITER ;
select worker_id, first_name, salary, computingTax(salary)
from worker order by first_name;
SHOW FUNCTION STATUS where db = 'org';
--2
Delimiter &&
CREATE PROCEDURE getTax(
IN sal INT, OUT IncTax DECIMAL(10,2)
)
BEGIN
SET IncTax = computingTax(sal);
END &&
DELIMITER ;
CALL getTax(50000, @IncTax);
select @IncTax;
SHOW CREATE PROCEDURE getTax;
SHOW PROCEDURE STATUS LIKE 'getTax'; |
Beta Was this translation helpful? Give feedback.
-
--Q1
DELIMITER &&
CREATE FUNCTION computeTax(salary int)
RETURNS DECIMAL(10,2) DETERMINISTIC BEGIN
DECLARE incomeTax DECIMAL(10,2);
IF salary<=75000 THEN SET incomeTax=0.1*salary;
ELSEIF salary>75000 and salary<=150000 THEN SET incomeTax=0.2*salary;
ELSE SET incomeTax=0.3*SALARY;
END IF;
RETURN incomeTax;
END &&
DELIMITER ;
select computeTax(salary) from worker;
--Q2
DELIMITER &&
CREATE PROCEDURE calculateIncomeTax(IN salary INT, OUT incomeTax DECIMAL(10,2))
BEGIN
SET incomeTax= computeTax(salary);
END &&
DELIMITER ;
CALL calculateIncomeTax(80000, @incomeTax);
SELECT @incomeTax; |
Beta Was this translation helpful? Give feedback.
-
--1. Write a stored function called computeTax that calculates income tax based on the salary for every worker in the Worker table as follows:
-- 10% - salary <= 75000
-- 20% - 75000 < salary <= 150000
-- 30% - salary > 150000
-- Write a query that displays all the details of a worker including their computedTax.
DELIMITER //
create FUNCTION computeTax (salary int) RETURNS int deterministic BEGIN
declare tax int;
if salary <= 75000 then
set tax = salary *.1;
ELSEIF salary > 75000
AND salary <= 150000 then
SET tax = salary *.2;
else
SET tax = salary *.3;
END if;
return tax;
END //
DELIMITER ;
SELECT * ,computeTax(76000)FROM WORKER;
--2. Define a stored procedure that takes a salary as input and returns the calculated income tax amount for the input salary. Print the computed tax for an input salary from a calling program. (Hint - Use the computeTax stored function inside the stored procedure)
delimiter //
create procedure calIncomeTax(IN salary int, out incomeTax decimal(10, 2))
begin
set incomeTax = computeTax(salary);
end //
delimiter;
call calIncomeTax(5000, @income);
select @income; |
Beta Was this translation helpful? Give feedback.
-
--1.
DELIMITER;
CREATE FUNCTION incomeTax(salary INT)
RETURNS DECIMAL(10,2)
DETERMINISTIC
BEGIN
DECLARE incometax DECIMAL(10,2);
IF( salary<75000) then
SET incometax= salary*.10;
ELSEIF (salary>75000 and salary<100000) then
SET incometax= salary*.20;
else
SET incometax= salary*.30;
end if;
RETURN incometax;
end //
DELIMITER;
select *, incomeTax(salary) as incomeTax from worker;
--2.
DELIMITER //
CREATE PROCEDURE computeIncomeTax(IN salary INT, OUT incometax DECIMAL(10,2))
BEGIN
SET incometax=incomeTax(salary);
END //
DELIMITER ;
call computeIncomeTax(500000,@result);
select @result;
|
Beta Was this translation helpful? Give feedback.
-
1. Write a stored function called computeTax that calculates income tax based on the salary for every worker in the Worker table as follows:. 10% - salary <= 75000. 20% - 75000 < salary <= 150000. 30% - salary > 150000Write a query that displays all the details of a worker including their computedTax.Solution 2. Define a stored procedure that takes a salary as input and returns the calculated income tax amount for the input salary. Print the computed tax for an input salary from a calling program. (Hint - Use the computeTax stored function inside the stored procedure)Solution |
Beta Was this translation helpful? Give feedback.
-
|
1.Write a stored function called computeTax that calculates income tax based on the salary for every worker in the Worker table as follows: 10% - salary <= 75000 2.Define a stored procedure that takes a salary as input and returns the calculated income tax amount for the input salary. Print the computed tax for an input salary from a calling program. (Hint - Use the computeTax stored function inside the stored procedure). |
Beta Was this translation helpful? Give feedback.
-
-- Discussion Forum 13 Part 1
use org;
delimiter $$
create function computeTax(
salary int
)
returns decimal(10,2)
deterministic
begin
declare ans decimal(10, 2);
set ans = case when salary <= 75000 then 0.1*salary
when salary between 75000 and 150000 then 0.2*salary
else 0.3 * salary
end;
return ans;
end $$
delimiter ;
select distinct FIRST_NAME, LAST_NAME, SALARY,
computeTax(salary) as INCOME_TAX,
JOINING_DATE, DEPARTMENT, WORKER_TITLE, AFFECTED_FROM, BONUS_AMOUNT, BONUS_DATE from worker w
left join title t on w.WORKER_ID = t.WORKER_REF_ID
left join bonus b on w.WORKER_ID = b.WORKER_REF_ID;
-- Discussion Forum 13 Part 2
drop procedure storedTax;
delimiter $$
create procedure storedTax(
in salary decimal(10, 2),
out ans decimal(10, 2)
)
begin
select computeTax(salary) into ans;
end $$
delimiter ;
call storedTax(10000, @tax);
select @tax; |
Beta Was this translation helpful? Give feedback.
-
|
drop function computedTax; select *,computedTax(salary) as incomeTax from worker; -- Q2 call computeTax(160000, @incomtax); |
Beta Was this translation helpful? Give feedback.
-
|
/* 1 Write a stored function called computeTax that calculates income tax based on the salary for every worker in the Worker table as follows: 10% - salary <= 75000 */ DELIMITER // end; delimiter ; select *,computeTax(SALARY) as Tax from worker; --2 Define a stored procedure that takes a salary as input and returns the calculated income tax amount for the input salary. Print the computed tax for an input salary from a calling program. (Hint - Use the computeTax stored function inside the stored procedure) DELIMITER // call compute_tax_proc(1234567,@tax_out); |
Beta Was this translation helpful? Give feedback.
-
|
-- 1. Write a stored function called computeTax that calculates income tax based on the salary for every worker in the Worker table as follows: -- 10% - salary <= 75000 DELIMITER $$ SELECT worker_ID, first_name, last_name, salary, joining_date, department, computeTax(salary) AS computedTax SHOW FUNCTION STATUS WHERE db = 'org'; -- 2. Define a stored procedure that takes a salary as input and returns the calculated income tax amount for the input salary. Print the computed tax for an input salary from a calling program. (Hint - Use the computeTax stored function inside the stored procedure) DELIMITER $$ |
Beta Was this translation helpful? Give feedback.
-
|
--1 --2 |
Beta Was this translation helpful? Give feedback.
-
|
#1 END; DELIMITER ; SELECT *, computeTax(salary) FROM worker; END DELIMITER ; |
Beta Was this translation helpful? Give feedback.
-
DELIMITER //
DELIMITER || |
Beta Was this translation helpful? Give feedback.
-
-- 10% - salary <= 75000 DELIMITER $$ CREATE FUNCTION computeTax( SELECT worker_id,first_name,computeTax(salary) AS tax FROM worker; 2 Define a stored procedure that takes a salary as input and returns the calculated income tax amount for the input salary. Print the computed tax for an input salary from a calling program. (Hint - Use the computeTax stored function inside the stored procedure) DELIMITER // call compute_tax_procedure(1234567,@tax_output); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Database =
orgDump file: org.sql
DB Schema
Calculating Income Tax
Write a stored function called
computeTaxthat calculates income tax based on thesalaryfor every worker in theWorkertable as follows:Write a query that displays all the details of a worker including their
computedTax.Define a stored procedure that takes a
salaryas input and returns the calculated income tax amount for the input salary. Print the computed tax for an input salary from a calling program. (Hint - Use thecomputeTaxstored function inside the stored procedure)Beta Was this translation helpful? Give feedback.
All reactions