Dbms PT Answers
Dbms PT Answers
Dbms PT Answers
1 I)
DECLARE
V_deptid department.deptid%TYPE;
V_deptname department.deptname%TYPE;
V_head_of_dept department.head_of_dept%TYPE;
BEGIN
V_deptid := 1;
END;
ii)
DECLARE
BEGIN
IF v_is_true THEN
ELSE
END IF;
END;
2)
CREATE OR REPLACE PROCEDURE update_employee_salaries AS
BEGIN
UPDATE employees
END;
DECLARE
CURSOR employee_cursor IS
FROM employees;
V_employee_id employees.employee_id%TYPE;
V_first_name employees.first_name%TYPE;
V_last_name employees.last_name%TYPE;
V_job_id employees.job_id%TYPE;
V_hire_date employees.hire_date%TYPE;
V_salary employees.salary%TYPE;
BEGIN
OPEN employee_cursor;
LOOP
DBMS_OUTPUT.PUT_LINE(‘Salary: ‘ || v_salary);
DBMS_OUTPUT.PUT_LINE(‘-----------------------‘);
END LOOP;
CLOSE employee_cursor;
END;
3)
BEGIN
END;
BEGIN
END;
/
CREATE OR REPLACE TRIGGER employees_before_statement_update
BEGIN
END;
BEGIN
END;
ii)
Vehicle_id IN NUMBER,
Num_adults IN NUMBER,
Num_children IN NUMBER
) RETURN NUMBER
IS
Vehicle_fare NUMBER;
Total_fare NUMBER;
BEGIN
FROM vehicles
RETURN total_fare;
END;
DECLARE
Fare NUMBER;
BEGIN
END;
4)
i)
P_dept_id IN NUMBER
) RETURN NUMBER
IS
V_emp_id NUMBER;
BEGIN
FROM departments
Invalid department ID
RETURN -1;
END IF;
FROM employees
RETURN -2;
END IF;
BEGIN
FROM employees
EXCEPTION
RETURN -2;
Other errors
RETURN -3;
END;
Return the employee ID
RETURN v_emp_id;
END;
DECLARE
V_emp_id NUMBER;
BEGIN
V_emp_id := sf_get_emp_id_by_deptid(10);
V_emp_id := sf_get_emp_id_by_deptid(20);
V_emp_id := sf_get_emp_id_by_deptid(25);
END;
ii)
DECLARE
BEGIN
FOR emp_rec IN (
FROM employees e
LOOP
DBMS_OUTPUT.PUT_LINE(‘Employee ID: ‘ || emp_rec.employee_id);
DBMS_OUTPUT.PUT_LINE(‘Name: ‘ || emp_rec.first_name);
DBMS_OUTPUT.PUT_LINE(‘Department: ‘ || emp_rec.department_id);
DBMS_OUTPUT.NEW_LINE;
END LOOP;
END;
5)
i)
DECLARE
V_commission_pct employees.commission_pct%TYPE;
V_salary employees.salary%TYPE;
V_total_salary employees.salary%TYPE;
BEGIN
FROM employees
SELECT 1
FROM employees
) THEN
UPDATE employees
END IF;
END;
ii)
DECLARE
CURSOR c_emp IS
FROM employees
BEGIN
Loop through the employees in the department and display their details
‘, Salary: ‘ || emp.salary ||
END LOOP;
END;
/
6)
i)
DECLARE
V_country_code VARCHAR2(2);
BEGIN
INSERT INTO countries (country_id, country_name, region_id) VALUES (‘SG’, ‘Singapore’, 3);
ELSE
END IF;
INSERT INTO countries (country_id, country_name, region_id) VALUES (‘LK’, ‘Sri Lanka’, 3);
ELSE
END IF;
END;
/
ii)
INCREMENT BY 1
NOCACHE
NOCYCLE;
7)
i)
DECLARE
V_count NUMBER;
BEGIN
IF v_count = 0 THEN
ELSE
END IF;
END;
ii)
DECLARE
V_min_salary jobs.min_salary%TYPE;
BEGIN
:new.salary := v_min_salary;
END IF;
END;