0% found this document useful (0 votes)
9 views4 pages

P 1

The document contains a series of SQL commands for managing a database, including inserting, updating, deleting, and selecting data from various tables. It also includes commands for creating tables with specific constraints and modifying existing tables. Additionally, there are examples of using SQL functions and expressions to manipulate and retrieve data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

P 1

The document contains a series of SQL commands for managing a database, including inserting, updating, deleting, and selecting data from various tables. It also includes commands for creating tables with specific constraints and modifying existing tables. Additionally, there are examples of using SQL functions and expressions to manipulate and retrieve data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

insert into sales_order values('o19008','c05',TO_DATE('2016-05-24' ,'YYYY-MM-

DD'),'s05','p','y',TO_DATE('2016-05-26','YYYY-MM-DD'),'in process');
insert into sales_order_details values('o46865','p07868',3,3150);

DELETE FROM salesman WHERE salmt = 3500;


delete row details with this property

UPDATE table_ name SET salary = 60000 WHERE employee_id = 101;


update row with this details

CREATE TABLE order_details AS SELECT * FROM sales_order_details; copy


table with all data
CREATE TABLE order_details AS SELECT * FROM sales_order_details where 1=0; copy
table with only structure

ALTER TABLE client ADD telphone number(10); add column


in table
ALTER TABLE product MODIFY sell price number(6,2); change the
attributes of column

select * from client where name like 'b%'; all letters after b give
table with name starting with b
select * from client where name like 'b_'; one latter after b give
table with name=b+ one word
select * from client where name in 'harsh'; give table
with name=harsh
select * from client where name not in 'harsh'; give table
without name=harsh
select name from client where name not in 'harsh'; only give
name field with not in harsh
select * from client where pincode between 100000 and 999999; give
table with pincode between 100000 to 999999

select * from client where city='mumbai' or city='chennai';


select * from salesman where salary=3000;
select distinct * from table_name where condtion;

INTRO PRACTICAL 3

insert into sales_data values(5,'watch',2,1000,TO_DATE('2012-12-18' ,'YYYY-MM-


DD'));
select upper(product_name) from sales_data; -----------------------------------
convert details in uppercase
select lower(product_name) from sales_data; -----------------------------------
convert details in lowercase
select sysdate from sales_data; -----------------------------------------------
return current date of system
select substr(product_name,1,3) from sales_data; ------------------------------
return substring of field
select concat(product_name,quantity) from sales_data; -------------------------
concat 2 field values
select product_name||' '|| quantity from sales_data; --------------------------
concat 2 or more field values
select upper(product_name) as lowerp from sales_data; -------------------------show
the title of table
update sales_data set newcolum = 10 where product_name = 'laptop'; ------------
update the valye of column
select round(newcolum,1) from sales_data; -------------------------------------
round value till 1 decimal point
select round(newcolum) from sales_data; ---------------------------------------
round value(nearest integer)
select product_name,months_between(sysdate,dates) from sales_data; ------------
return the difference between today's date and field's date

PRACTICAL 3

SELECT LOWER(first_name) AS first_name_lower,UPPER(last_name) AS last_name_upper


FROM employees WHERE employee_id BETWEEN 80 AND 150;
SELECT first_name FROM employees WHERE TRUNC(SYSDATE) - hire_date > 5 * 365;
SELECT first_name,LENGTH(first_name) AS first_name_length FROM employees WHERE
INSTR(SUBSTR(last_name, 4), 'b') > 0;
SELECT first_name,job_id,REGEXP_SUBSTR(job_id, '^[^ ]+') AS first_word_in_job_title
FROM employees;
SELECT first_name,salary,salary*1.12 as salary_raise,round(1.12*salary) as
salary_whole,floor(1.12*salary) as salary_down from employees;
SELECT first_name,hire_date-10 as hire_minus_10,hire_date+ interval '1' month as
month_plus_one,sysdate-hire_date as total_days from employees;
SELECT first_name,last_name,hire_date FROM employees WHERE TO_CHAR(hire_date, 'MM')
= '05';
SELECT first_name,last_name,salary,CASE
WHEN salary BETWEEN 0 AND 5000 THEN 'A'
WHEN salary BETWEEN 5001 AND 15000 THEN 'B'
WHEN salary BETWEEN 15001 AND 20000 THEN 'C'
ELSE 'D'
END AS salary_grade FROM employees;
SELECT first_name,last_name,salary,NVL(TO_CHAR(commission_pct), 'No Commission') AS
commission_pct FROM employees;
SELECT first_name,last_name,salary,NVL(commission_pct, 0) AS commission_pct FROM
employees;
SELECT first_name,TO_CHAR(hire_date, 'DD') AS hire_day,TO_CHAR(hire_date, 'YYYY')
AS hire_year FROM employees;
SELECT UPPER(last_name) AS last_name,TO_CHAR(salary, '9,999.999') AS
salary,TO_CHAR(hire_date, 'DD/MM/YYYY') AS hire_date FROM employees WHERE
SUBSTR(last_name, 1, 1) IN ('D', 'K');
SELECT first_name,hire_date,ADD_MONTHS(hire_date, 12) AS hire_date_plus_one_year
FROM employees;
select first_name,last_name,phone_number,replace(phone_number,515,815) as
new_phone_number from employees;
select last_name from employees where length(last_name)>8;
select first_name || last_name || hire_date from employees;
SELECT first_name,last_name,CONCAT(CONCAT(LOWER(SUBSTR(first_name, 1, 1)),
LOWER(SUBSTR(last_name, -3))), '@oracle.com') AS email FROM employees;
SELECT LOWER(first_name) AS first_name_lower,UPPER(last_name) AS last_name_upper
FROM employees WHERE employee_id BETWEEN 80 AND 150;

practical 4
create table clients (id number(6) NOT NULL);
create table client2 (age int check(age >= 8);
create table client4(age number(3) check(age in(5,10,15)));
create table student_data(roll varchar(10) check(substr(roll,3,3) in
('bce','bcm','btm')));
alter table student_data add constraint pk primary
key(roll);------------------------------------ all values in this column should be
unique
create table student1(roll number(10) primary key,name
varchar(6));------------------------------ declare primary key while creating the
table
insert into student1
values(101,'meet');---------------------------------------------------------
alter table student1 add constraint pk1 primary
key(name);--------------------------------------- table can have only primary key
alter table student1 modify name varchar(10) not null;
------------------------------------------ update column with not null attribute
create table student2 (roll number(10), foreign key(roll) references
student1(roll));

1.create table client0(clientno varchar2(6) primary key check(substr(clientno,1,1)


in ('c')),name varchar2(20) not null,city varchar(15),pincode number(8),state
varchar2(15),baldue number(10,5));
2.create table product0(productno varchar2(6) primary key
check(substr(productno,1,1) in ('p')),description varchar(15) not
null,profitpercent number(4,2) not null,unitmeasure varchar2(10) not null,qtyonhand
number(8) not null,reorderlvl number(8) not null,sellprice number(8,2) not null
check(number != 0),costprice number(8,2) not null check(costprice!=0));
3.create table sales_order0(orderno varchar2(6) primary key
check(substr(orderno,1,1) in ('o')),clientno varchar2(6),foreign key(clientno)
references client0(clientno),orderdate date not null,
salesmanno varchar2(6) foreign key(salesmanno) references
salesman0(salesmanno),delaytype char(1) default 'f' check(delaytype in
('p','f')),billyn char(1),
delaydate date check(delaydate > orderdate),orderstatus varchar2(10)
check(orderstaus in ('inprocess','fulfilled','backorder','cancelled')));
4. create table sales_

alter table salesman0 modify remarks varchar2(60) not null;

------------------------
select table_name from user_tables;
-------------------------------------------------------------- to show all created
table
------------------------

practical 6

1.
select salary from employees where salary>(select salary from employees where
employee_id=100);
select * from employees where salary=(select max(salary) from employees);
select department_id from employees group by department_id having min(salary)>
(select max(salary) from employees where department_id=60);

2.
select * from employees where salary in (select salary from employees where
department_id=90);
select * from employees where salary > any (select salary from employees where
department_id=60);
select * from employees where salary > all (select salary from employees where
department_id=30);
select * from employees where manager_id in (select manager_id from employees where
employee_id in (110,30)) and department_id in (select department_id from employees
where employee_id in (110,30));
select first_name, last_name , department_id from employees;

3.
select * from employees where department_id in (select department_id from employees
group by department_id having max(salary));
select department_id from employees group by department_id;

practical 5

create table sales(sale_id number(2),product_name varchar(20),category


varchar(20),qty number(3),sale_amt number(5),year number(4));

insert into sales values(6,'bookshelf','furniture',3,3000,2023);


select category,sum(sale_amt) from sales group by category;
select year,sum(qty) from sales group by year;
select year,sum(qty) from sales group by year having sum(qty)>5;

SELECT product.description, sales_order_details.qtyordered


FROM product
INNER JOIN sales_order_details ON product.productno=sales_order_details.productno;

select sales_order.clientno,avg(sales_order_details.qtyordered) from sales_order


join sales_order_details on sales_order.orderno=sales_order_details.orderno
join client on sales_order.clientno=client.clientno where client.baldue<=15000
group by sales_order.clientno;

select sum(sales_order_details.qtyordered*sales_order_details.productdate) from


sales_order_details join sales_order on
sales_order_details.orderno=sales_order.orderno
where extract(month from sales_order.orderdate)=5;

You might also like