PRACTICAL - 11 To 20
PRACTICAL - 11 To 20
:- IU0000000000 DBMS(CE0317)
PRACTICAL- 11
Write a PL/SQL block to insert record into emp table. Accept value at
runtime.
DECLARE
l_emp_name VARCHAR2(250);
l_emp_no NUMBER;
l_salary NUMBER;
l_manager VARCHAR2(250);
BEGIN
INSERT INTO emp(emp_name,emp_no,salary,manager)
VALUES(‘BBB’,1000,25000,’AAA’);
INSERT INTO emp(emp_name,emp_no,salary,manager)
VALUES('XXX',1001,10000,’BBB);
INSERT INTO emp(emp_name,emp_no,salary,managed
VALUES(‘YYY',1002,10000,'BBB');
INSERT INTO emp(emp_name,emp_no,salary,manager)
VALUES(‘ZZZ',1003,7500,'BBB'):
COMMIT;
Dbms_output.put_line(‘Values Inserted');
UPDATE EMP
SET salary=15000
WHERE emp_name='XXX';
COMMIT;
Dbms_output.put_line(‘Values Updated');
DELETE emp WHERE emp_name='ZZZ';
COMMIT:
Dbms_output.put_line('Values Deleted );
SELECT emp_name,emp_no,salary,manager INTO
l_emp_name,l_emp_no,l_salary,l_manager FROM emp WHERE emp_name='XXX';
Output :
Page No. 1
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 12
Write a PL/SQL block to reserve a given number.
DECLARE
num NUMBER;
rev NUMBER;
BEGIN
num:=#
rev:=0;
WHILE num>0 LOOP
rev:=(rev*10) + mod(num,10);
num:=floor(num/10);
END LOOP;
DBMS_OUTPUT.PUT_LINE('Reverse of the number is: ' || rev);
END;
/
Output :
Page No. 2
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 13
Write a PL/SQL block to check if a given num is odd or even.
declare
n number:=&n;
begin
if mod(n,2)=0
then
dbms_output.put_line('The given number is even');
else
dbms_output.put_line('The given number is odd');
end if;
end;
/
Output :
Page No. 3
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 14
Write a PL/SQL block to accept id of employee (emp table) from user and
fetch a record of that employee. Check the salary and update the salary
Column as follows:
a. If salary >10000 and salary<=20000, then salary = salary+30% of salary.
b. If salary>20000 and salary<=30000, then salary =salary+ 40% of salary.
SET SERVEROUTPUT ON
DECLARE
v_employee_id emp.emp_id%TYPE;
v_employee_salary emp.salary%TYPE;
BEGIN
-- Accept employee ID from the user
v_employee_id := &emp_id; -- The '&' symbol is used to accept
user input
Page No. 4
Enrollment No. :- IU0000000000 DBMS(CE0317)
END;
/
Page No. 5
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 15
Write a PL/SQL block that will display the information Of the first 5
employees holding the highest salary of the emp table.
DECLARE
-- Declare a cursor to select the top 5 employees with the
highest salary
CURSOR top_employees_cursor IS
SELECT empno, ename, sal
FROM emp
ORDER BY sal DESC
FETCH FIRST 5 ROWS ONLY;
BEGIN
-- Open the cursor
OPEN top_employees_cursor;
Page No. 6
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 16
Write a PL/SQL block that merge ft_work and pt_work. Fetch name of emp
from pt_work, check if it is in ft_work. If it is not there then insert that record
in ft_work, otherwise display appropriate message.
DECLARE
v_emp_name pt_work.emp_name%TYPE;
BEGIN
FOR pt_rec IN (SELECT emp_name FROM pt_work) LOOP
v_emp_name := pt_rec.emp_name;
IF SQL%ROWCOUNT = 1 THEN
DBMS_OUTPUT.PUT_LINE('Record for ' || v_emp_name || '
inserted into ft_work.');
ELSE
DBMS_OUTPUT.PUT_LINE('Record for ' || v_emp_name || '
already exists in ft_work.');
END IF;
END LOOP;
END;
/
Page No. 7
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 17
Create trigger on supplier table which allow access between 9 AM to 5 PM
only.
Page No. 8
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 18
Create trigger on Supplier Detail on update or insert of Sname to convert
Sname into capital letter.
Output :
Page No. 9
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 19
Create a stored procedure which accepts CNUM from the user and print that
order is placed by that customer or not. Also write a PL/SQL block for using
this procedure.
DECLARE
v_CustomerNumber NUMBER := 12345; -- Replace with the desired
customer number
BEGIN
CheckOrderPlacement(v_CustomerNumber);
END;
/
Page No. 10
Enrollment No. :- IU0000000000 DBMS(CE0317)
PRACTICAL- 20
Create a database
DECLARE
v_table_exists NUMBER;
BEGIN
-- Check if the table already exists
SELECT COUNT(*)
INTO v_table_exists
FROM user_tables
WHERE table_name = 'Employees';
Page No. 11