DDC Pratical - Exam Questions
DDC Pratical - Exam Questions
2) Insert 5 records.
INSERT INTO Students VALUES (1, 'John', 16, 'Pune', '2006/06/06');
INSERT INTO Students VALUES (2, 'Ajay', 15, 'Chennai', DATE '2023-02-02');
INSERT INTO Students VALUES (3, 'Ron', 12, 'Delhi', DATE'2010-12-08');
INSERT INTO Students VALUES (4, 'Joy', 16, 'Mumbai', DATE'2006-09-09'); //YYYY-MM-DD
INSERT INTO Students VALUES (5, 'Harry', 15, 'Hyderabad',DATE'2007-12-12');
Consider the following database and create table for the same
Employee(emp_id,emp_name,emp_city,emp_addr,emp_dept,join_date)
INSERT INTO Employee VALUES (1001, 'Ajay', 'Chennai', 'Chennai', 'Computer Engg', DATE
'2023-02-02');
INSERT INTO Employee VALUES (1002, 'Amit', 'Delhi', 'Delhi', 'Mechsnical Engg', DATE '2019-
02-02');
INSERT INTO Employee VALUES (1003, 'Mayur', 'Mumbai', 'Mumbai', 'Information Tech', DATE
'2012-04-23');
INSERT INTO Employee VALUES (1004, 'Mangesh', 'Pune', 'Pune', 'Mechanical Engg',
DATE '1999-04-15');
i) Display the emp_id of employee who live in city 'Pune' or 'Delhi' select
emp_id from Employee where emp_city='Pune' or emp_city-'Delhi';
branch varchar(30),
class varchar(30),
DOB date,
city varchar(30),
Contact_no number(12)
);
Create table for EMP (empno, deptno, ename, salary, designation, join_date,DOB,
dept_location). Write down SQL queries for following:
(
empno INT,
deptno INT,
ename VARCHAR2(30),
salary INT,
designation VARCHAR2(30),
join_date DATE,
DOB DATE,
dept_location VARCHAR2(30)
INSERT INTO EMP VALUES (1001, 20,'Amit', 50000, 'Manager', DATE '2019-02-02',
DATE '1982- 05-02','Mumbai');
INSERT INTO EMP VALUES (1002, 20,'Peter', 70000, 'Sr. Manager', DATE '2015-08-12',
DATE '1992-05-22','Pune');
INSERT INTO EMP VALUES (1003, 10,'Sharan', 40000, 'Manager', DATE '2012-04-12', DATE
'1987-06-18','Nashik');
Consider the structure for book table as BookMaster123 (bookid,bookname, author, no_of copies, price)
Write down SQL queries for following:
(i) Write a command to create Bookmaster123 table and insert min 5 records in it
INSERT INTO BookMaster123 VALUES (1001, 'Programming In C', 'Dennis Ritchie', 5000, 400.00);
INSERT INTO BookMaster123 VALUES (1001, 'Java Programming', 'E Balagurusamy', 8000, 800.00);
INSERT INTO BookMaster123 VALUES (1001, 'Data Structures Using C', 'Dr. E. F. Codd', 2000, 300.00);
INSERT INTO BookMaster123 VALUES (1001, 'Operating System', 'Navathe', 1000, 500.00); INSERT
INTO BookMaster123 VALUES (1001, 'Advanced Java Programming', 'E Balagurusamy', 3000,
700.00);
(iii)Display all books whose price is between Rs.500 & Rs. 800
SQL> Select * from BookMaster123 where price between 500 and 800;
OR
(iv) Display all books with details whose name start with 'D'
SQL> Select bookname from BookMaster123 where bookname like 'D%';
(vi) Display all books whose number of copies are less than
10
SQL>Select * from BookMaster123 where
no_of_copies<7000;
(ii) Find customer names having loan account but not the savings
account:
Select b.cust_name from borrower b minus Select d.cust_name from depositor d
Where d.cust_name=b.cust_name;
(
rollno number(5),
name char(20),
address varchar2(40),
DOB date,
percent number(5,2)
);
2) Insert Records
INSERT INTO Students_Info VALUES (1, 'John', 'Pune', 90.00,'Distiction');
INSERT INTO Students_Info VALUES (2, 'Ajay', 'Chennai',
60.65,'First Class'); INSERT INTO Students_Info VALUES (3, 'Ron', 'Delhi',
45.23,'Pass Class'); INSERT INTO Students_Info VALUES (4, 'Joy', 'Mumbai',
77.36,'First Class'); INSERT INTO Students_Info VALUES (5, 'Harry',
'Hyderabad',84.89,'Distiction');
Create tables for following schemas and insert records in both tables.
Stud(rollno, Stud_name, dt_of_birth,telephone)
Marks (rollno, sub1_marks, sub2_marks, per)
i) Display student's rollno, name, and marks of both subjects for all students.
Ans:
ii) Delete all those students records who secured less than 35%
Ans: Delete from Stud where rollno=(Select rollno from marks where per<55);
Create tables for following schemas and insert records in both tables.
empl{empid,empname,designation,salary,deptno}
And
empid INT,
ename VARCHAR2(30),
designation VARCHAR2(30),
salary INT,
deptno INT
(personid INT,
);
name VARCHAR(30),
address VARCHAR(30),
city VARCHAR(30),
telephone NUMBER(10)
i) Create sequence seq-pid with start value 100 and maximum value 120 and increment by 1.
Use seq-pid to insert personid into table person.
ii) Create view view-person containing details of persons from city "Mumbai" and
"Pune"
iii) Create synonym syn-person on table person owned by user 'Scott' delete
synonym syn-person.
Write a PL/SQL code to accept value of sales from employee and display its
comission.
if sales > 200000 them comission is 1 percentage of sales.
if sales <= 200000 AND n_sales > 100000 comission is 0.5
percentage of sales.
sales <= 100000 AND n_sales > 50000 comission is 0.3 percentage of
sales.
otherwise comission is 0.2 percentage of
sales.
DECLARE
BEGIN
END IF;
n_commission := n_sales * 0.03;
ELSE
n_commission := n_sales * 0.02;
END;
DECLARE
VARI NUMBER:=&VAR1;
VAR2 NUMBER;
BEGIN
VAR2:=1;
LOOP
DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
IF (VAR2=10) THEN
EXIT;
END IF;
VAR2: VAR2+1;
END LOOP;
END;
DECLARE
BEGIN
ELSE
END;
DECLARE
VARI NUMBER:=&VAR1;
VAR2 NUMBER;
BEGIN
VAR2:=1;
LOOP
DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
IF (VAR2=10) THEN
EXIT;
END IF;
VAR2: VAR2+1;
END LOOP;
END;
Write PL/SQL code to display 1 to 10 numbers in reverse
order.
DECLARE
VARI NUMBER;
BEGIN
VAR1:=10;
LOOP
DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
END LOOP;
END;
Write a PL/SQL program which accepts the customer_ID from the user. If theenters
an invalid ID then the exception invalid_id is raised using exception handling.
DECLARE
c_id numeric(10);
invalid_id_Exception Exception;
BEGIN
c_id:=&c_id;
if(c_id<0) then
raise invalid_id_Exception;
end if;
EXCEPTION
END;
/
A number:=20;
B number:=0;
C number;
BEGIN
Write a PL/SQL code to accept customer id from user display its name and address if found.
If record not found then display message "No such customer!"
create table customers
id number(5),
name char(30),
address varchar2(40)
);
DECLARE
BEGIN
FROM customers
WHERE id = c_id;
EXCEPTION
dbms_output.put_line('Error!');
END;
Create a table customers(id, name, address).
Insert 5 records int it.
Write a PL/SQL code to accept customer id from user display its name and address if found.
If record not found then display message "No such customer!"
If customer id is less than zero the raise an user defined exception invalid ID.
create table customers
id number(5),
name char(30),
address varchar2(40)
);
DECLARE
c_name customers.name%TYPE;
c_addr customers.address%TYPE;
ELSE
Raise user defined exception
FROM customers
WHERE id = c_id;
dbms_output.put_line ('Name: '|| c_name);
dbms_output.put_line ('Address: ' || c_addr);
END IF;
EXCEPTION
END;
WHEN ex_invalid_id THEN
--
dbms_output.put_line('Error!');
Write a PL/SQL code with cursor to display all records of id, name and address
from customer
table.
id number(5),
name char(30),
address varchar2(40)
);
DECLARE
c_id customers.id%TYPE;
c_name customers.name% TYPE;
c_addr customers.address%
TYPE;
CURSOR c_customers IS
SELECT id, name, address FROM
customers;
BEGIN
OPEN c_customers;
LOOP
EXIT WHEN
c_customers%NOTFOUND;
CLOSE c_customers;
END;
DECLARE
a number;
b number;
c number;
BEGIN
IF x <y THEN
Z:= x;
ELSE
z:= y;
END IF;
END;
BEGIN
a:= &a;
b:= &b;
findMin(a, b, c);
DECLARE
a number;
X := x * X;
END;
BEGIN
a:= &a;
squareNum(a);
Write PL/SQL Code e to calculate the factorial of a number accepted from user by calling
itself
recursively.
DECLARE
num number;
factorial number;
RETURN number
IS
f number;
BEGIN
IF x=0 THEN
f:= 1;
ELSE
f:= x* fact(x-1);
END IF;
RETURN f;
END;
BEGIN
num:= #
factorial := fact(num);
END;
Write a PL/SQL program to print n even numbers using For
Loop.
DECLARE
num number;
n number:=&n;
BEGIN
dbms_output.put_line('Even no are :');
IF(mod(num,2)=0) then
dbms_output.put_line(num);
END IF;
END LOOP;
END;
i number(10);
ans number(10);
n number(10):=&n;
BEGIN
ans:=0;
i:=1;
while i<=n
LOOP
ans:=ans+i;
i:=i+1;
END LOOP;
END;
/
iii) for create and drop privilege which are system privileges not specific to any object such as table
Ans: Grant connect, resource, DBA to Rahul;