0% found this document useful (0 votes)
13 views3 pages

HW Adbms

Uploaded by

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

HW Adbms

Uploaded by

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

dmbh rzkk eqgv qyub

Que 1.
This query retrieves and prints the details of personnel with salaries greater than
30,000 using a cursor loop.

Que2.

Not declare the table and


DECLARE
CURSOR c1 IS
SELECT snum, city FROM personnel p, branch b WHERE p.div = b.div;

v_city branch.city%TYPE;
v_snum personnel.snum%TYPE;
v_salary1 NUMBER := 30000;
v_salary2 NUMBER(4) := 25000;
v_salary3 NUMBER := 20000;
v_salary personnel.salary%TYPE;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO v_snum, v_city;
EXIT WHEN c1%NOTFOUND;

IF v_city = 'LONDON' THEN


v_salary := v_salary1;
ELSIF v_city = 'BRISTOL' THEN
v_salary := v_salary2;
ELSE
v_salary := v_salary3;
END IF;

-- Correct the table name in the update statement


UPDATE personnel SET salary = v_salary WHERE snum = v_snum;
END LOOP;
CLOSE c1;
END;

Que3
CREATE OR REPLACE PROCEDURE average_salary IS
average NUMBER(7, 2);
BEGIN
SELECT AVG(salary) INTO average FROM personnel;
DBMS_OUTPUT.PUT_LINE ('As of ' || SYSDATE);
DBMS_OUTPUT.PUT_LINE ('The average salary is ' || Average);
DBMS_OUTPUT.PUT_LINE ('Prepared by ' || USER);
END;
/

ALTER PROCEDURE average_salary COMPILE;

Que 4.
"ORA-00955: name is already used by an existing object"

Que 5.
CREATE OR REPLACE PROCEDURE average_salary(branchID CHAR) IS
Today DATE := SYSDATE;
Average NUMBER(7,2);
Begin
SELECT AVG(salary) INTO Average FROM Personnel WHERE div = branchID;
DBMS_OUTPUT.PUT_LINE ('As of ' || Today);
DBMS_OUTPUT.PUT_LINE ('The average for branch ' || branchID || ' is ' ||
Average);
DBMS_OUTPUT.PUT_LINE ('Prepared by ' || USER);
END;
/

commands for execute average salary


EXECUTE average_salary('10');
EXECUTE average_salary('20');

Que 6.
OUtput:
4 inner procedure one
5 inner procedure one
6 inner procedure one
6 inner procedure two
7 inner procedure one
8 inner procedure one
8 inner procedure two
9 inner procedure one
10 inner procedure one
10 inner procedure two

Que 7.

CREATE OR REPLACE PROCEDURE avemiles(divisionName varchar2)


is
V_divID Branch.div%type; -- Variable to store the division ID
V_aveMiles personnel.salary%type; -- Variable to store the average mileage

BEGIN
SELECT div into v_divID
FROM branch WHERE divname=divisionName;
v_aveMiles := get_aveMiles(v_divID);

DBMS_OUTPUT.PUT_LINE('Division ' || v_divID || ' has ' || v_aveMiles || ' average


mileage');
END;

CREATE OR REPLACE FUNCTION get_aveMiles (i_div IN NUMBER)


RETURN number
IS
v_aveMiles Transport.Mileage%type; -- Variable to store the average mileage

BEGIN
SELECT avg(Mileage)
INTO v_aveMiles FROM Transport
WHERE div = i_div;

RETURN v_aveMiles;
END get_aveMiles;
CREATE OR REPLACE FUNCTION get_maxMiles (i_div IN NUMBER)
RETURN number
IS
v_maxMiles Transport.Mileage%type; -- Variable to store the maximum mileage

BEGIN
SELECT max(Mileage)
INTO v_maxMiles FROM Transport
WHERE div = i_div;

RETURN v_maxMiles;
END get_maxMiles;

Que 8.

You might also like