Number Varchar2 Varchar2 Number
Number Varchar2 Varchar2 Number
create table employee with employee name, employee id, employee salary and
salary should not exceed 50000, id should be unique, and name first should
always be in capital letter.
Inserts -
commit;
2. Display all table created by user and modify emp_id with 6 digits and also new
column emp_name.
Modify column -
Add column -
3. How will you add in an existing table,also remove an existing column from
table.
Add a new column -
4. Select name ,roll no. from table where name is started from R and roll no. is
greater than 10 less than 50,also count the no. of students those who belong to
this criteria.
student_id NUMBER(6),
roll_no NUMBER(4),
name VARCHAR2(100)
);
Insert data -
insert into student (student_id, roll_no, name ) values (1,08, 'Preeti Jyoti');
insert into student (student_id, roll_no, name ) values (2,10, 'Rajesh Kumar');
insert into student (student_id, roll_no, name ) values (3,11, 'Radha Kumari');
insert into student (student_id, roll_no, name ) values (4,20, 'Raman Dubey');
insert into student (student_id, roll_no, name ) values (5,55, 'Ramesh Joshi');
insert into student (student_id, roll_no, name ) values (6,68, 'Tarun Sharma');
insert into student (student_id, roll_no, name ) values (7,70, 'Ashish Saxena');
commit;
Query to list students with name starting with R and roll no greater than 10 and less than 50:
select * from student where name like 'R%' AND (roll_no > 10 AND roll_no < 50);
Count -
select count(*) from student where name like 'R%' AND (roll_no > 10 AND roll_no < 50);
5. Create two table A and B store item id,item name and item price in table
A.store item color , item id and item quantity in table B.
create table A (
item_id NUMBER(4),
item_name VARCHAR2(50),
item_price NUMBER(8,2)
)
create table B (
item_id NUMBER(4),
item_color VARCHAR(20),
item_quantity NUMBER(6)
)
commit;
6. Select item id item name and color with quantity item color is red.
7.Create table name worker with name,worker id , worker contact no, worker id
should be primary key salary should not exceed 5000.
)
8.Select all salaries of employees where salary is greater than 2000 and city is
Allahabad phone no. first 4 digit are 9839.
select worker_id, salary from worker where salary > 2000 AND city='Allahabad' AND worker_contact like
'9839%'
9.Retrieve the product no. and the total quantity ordered fro products ‘p0001’,
’p0004’ from the sales order table.
sales_order_no number,
client_no varchar2(20),
product_no varchar2(20),
unit_price number(20,2),
qty_sold integer ,
total_price number (20,2),
sales_person_id number
);
Query –
10.Retrieve the names of all personal who work in Mr.Pradeep’s dept. and have
worked on inventory control system as well from the table emp and inventory.
11. Retrieve the product no. their description and the total quantity ordered for
each product.
product_no varchar2(20),
product_name varchar2 (100),
description varchar2(256)
)
insert into product (product_no,product_name,description) values('p0001',' Product 1', 'This is description for
first product');
insert into product (product_no,product_name,description) values('p0002',' Product 2', 'This is description for
second product');
insert into product (product_no,product_name,description) values('p0003',' Product 3', 'This is description for
third product');
insert into product (product_no,product_name,description) values('p0004',' Product 4', 'This is description for
fourth product');
Query -
12. Retrieve the ordered no,client no. and salesman no. where a has been
serviced by more than one salesman from the sales-order table.
select sales_order_no,client_no,sales_person_id from sales_order where client_no in ( select client_no from
sales_order group by client_no having count(distinct sales_person_id) > 1);
13.Create table client master with the following mandatory fields:Client no. ,
name address1 and address2 column.
14. Create a table cline master such that the contents of the column client no.
are unique across the entire column.
15.Find out all ate product that are not being sokd from product master table
based on the products actually sold as shown in sate order.
select product_no, product_name from product where product_no not in ( select product_no from sales_order);