DBMS LAB
DBMS LAB
Employee(EMPNO,ENAME,JOB,
MANAGER_NO, SAL, COMMISSION)
Step 2: Create the Employee table and insert records using rollback:
CONNECT emp_user/password
EMPNO NUMBER,
ENAME VARCHAR2(50),
JOB VARCHAR2(50),
MANAGER_NO NUMBER,
SAL NUMBER,
COMMISSION NUMBER
);
ROLLBACK;
-- Check that the records were rolled back (should return 0 rows)
Step 5: Insert null values to the employee table and verify the result:
-- A empt to insert a record with a NULL value in a NOT NULL column (ENAME)
2. Create a table called Employee that contain a ributes EMPNO,ENAME,JOB, MGR,SAL & execute
the following.
ENAME VARCHAR(50),
JOB VARCHAR(50),
MGR INTEGER,
SAL DECIMAL(10, 2)
);
INSERT INTO Employee VALUES (101, 'Braham Kumar', 'Manager', NULL, 80000.00, 5000.00);
INSERT INTO Employee VALUES (102, 'Shubham Kumar', 'Analyst', 101, 60000.00, 3000.00);
INSERT INTO Employee VALUES (103, 'Aman Kumar', 'Clerk', 102, 40000.00, 1000.00);
INSERT INTO Employee VALUES (104, 'Rajan Gupta', 'Salesman', 101, 70000.00, 4000.00);
INSERT INTO Employee VALUES (105, 'Shiv Yadav', 'Clerk', 102, 38000.00, 800.00);
UPDATE Employee
UPDATE Employee
UPDATE Employee
◉ Create Employee table containing all Records E_id, E_name, Age, Salary.
◉ Count number of employee names from employee table.
◉ Find the Maximum age from employee table.
◉ Find the Minimum age from employee table.
◉ Find salaries of employee in Ascending Order.
◉ Find grouped salaries of employees.
E_name VARCHAR(100),
Age INTEGER,
Salary DECIMAL(10, 2)
);
Step 2: Insert Five Records into the Table:
Step 3: Count the number of employee names from the employee table:
FROM EMPLOYEE;
FROM EMPLOYEE;
FROM EMPLOYEE;
FROM EMPLOYEE
FROM EMPLOYEE
GROUP BY AGE;
4. Create a row level trigger for the customers table that would fire for INSERT or UPDATE or
DELETE opera ons performed on the CUSTOMERS table. This trigger will display the salary
difference between the old & new Salary. CUSTOMERS(ID,NAME,AGE,ADDRESS,SALARY)
NAME VARCHAR2(100),
AGE NUMBER,
ADDRESS VARCHAR2(200),
SALARY NUMBER
);
ON CUSTOMERS
DECLARE
v_old_salary CUSTOMERS.SALARY%TYPE;
v_new_salary CUSTOMERS.SALARY%TYPE;
v_salary_diff CUSTOMERS.SALARY%TYPE;
BEGIN
IF INSERTING THEN
v_old_salary := 0;
v_new_salary := :NEW.SALARY;
v_old_salary := :OLD.SALARY;
v_new_salary := :NEW.SALARY;
v_old_salary := :OLD.SALARY;
v_new_salary := 0;
END IF;
END;
Step 3: Test the Trigger: Now, perform INSERT, UPDATE, and DELETE opera ons on
the CUSTOMERS table to see the trigger in ac on.
UPDATE CUSTOMERS
WHERE ID = 1;
WHERE ID = 1;
BCS403 Program 5
5. Create cursor for Employee table & extract the values from the table. Declare the variables
,Open the cursor & extract the values from the cursor. Close the cursor. Employee(E_id, E_name,
Age, Salary)
E_name VARCHAR2(100),
Age NUMBER,
Salary NUMBER
);
DECLARE
v_E_id Employee.E_id%TYPE;
v_E_name Employee.E_name%TYPE;
v_Age Employee.Age%TYPE;
v_Salary Employee.Salary%TYPE;
CURSOR employee_cursor IS
SELECT E_id, E_name, Age, Salary FROM Employee;
BEGIN
OPEN employee_cursor;
LOOP
DBMS_OUTPUT.PUT_LINE('E_id: ' || v_E_id || ', E_name: ' || v_E_name || ', Age: ' || v_Age ||
', Salary: ' || v_Salary);
END LOOP;
CLOSE employee_cursor;
END;
6. Write a PL/SQL block of code using parameterized Cursor, that will merge the data available in
the newly created table N_RollCall with the data available in the table O_RollCall. If the data in the
first table already exist in the second table then that data should be skipped.
id NUMBER,
name VARCHAR2(100),
roll_date DATE
);
id NUMBER,
name VARCHAR2(100),
roll_date DATE
);
DECLARE
v_n_rollcall_id N_RollCall.id%TYPE;
v_n_rollcall_name N_RollCall.name%TYPE;
v_n_rollcall_date N_RollCall.roll_date%TYPE;
CURSOR c_merge_rollcall_data IS
SELECT 1
);
BEGIN
OPEN c_merge_rollcall_data;
LOOP
END LOOP;
CLOSE c_merge_rollcall_data;
COMMIT;
EXCEPTION
ROLLBACK;
END;
7. Install an Open Source NoSQL Data base MongoDB & perform basic CRUD(Create, Read, Update
& Delete) opera ons. Execute MongoDB basic Queries using CRUD opera ons.
use basictask;
db.users.insertOne({
age: 25,
email: "[email protected]",
});
age: 25,
email: "[email protected]",
},
age: 35,
email: "[email protected]",
},
age: 28,
email: "[email protected]",
},
age: 28,
email: "[email protected]",
]);
3. Read Query:
db.users.find();
OUTPUT:
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf6'),
age: 25,
email: '[email protected]',
},
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
age: 35,
email: '[email protected]',
},
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
age: 28,
email: '[email protected]',
},
_id: ObjectId('666c78f13c52fc36f3cdcdf9'),
age: 28,
email: '[email protected]',
◉ Find documents with specific criteria (e.g., find all users with age greater than 25):
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
age: 35,
email: '[email protected]',
},
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
age: 28,
email: '[email protected]',
},
_id: ObjectId('666c78f13c52fc36f3cdcdf9'),
age: 28,
email: '[email protected]',
4. Update Query:
db.users.updateOne(
{ $set: { age: 31 } }
);
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
age: 35,
email: '[email protected]',
db.users.updateMany(
{ age: { $gt: 28 } },
);
OUTPUT:
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
age: 35,
email: '[email protected]',
},
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
age: 31,
email: '[email protected]',
5. Delete Query:
5. Basic Queries:
db.users.count();
◉ Sor ng documents:
db.users.find().limit(5);
db.users.aggregate([
]);