You are on page 1of 22

assignment 1

1.

create table Customer

First_Name char(20),

Last_Name char(20),

Addresschar(50),

City char(50),

Countrychar(20),

Birth_Date char(20)

);

2.

create table Office

Employee_id char(20),

Employee_Name char(30),

Employee_Address char(50),

Employee_Designation char(30),

Employee_Department char(20),

Employee_salary char(20)

);

3.

alter table Customer

add gender char(1);


4.

alter table Customer

add email char(30), telephone char(20);

5.

drop table Customer;

6.

drop table Office;

**************************************************

assignment 2

1.

create table Customer

First_Name char(20),

Last_Name char(20),

Addresschar(50),

City char(50),

Countrychar(20),

Birth_Date char(20)

);

alter table Customer RENAME to CON;

2.
alter table Customer MODIFY address char(100);

3.

alter table Customer DROP column birth_date;

4.

CREATE INDEX IDX_CUSTOMER_LAST_NAME

on CUSTOMER (Last_Name)

5.

CREATE INDEX IDX_CUSTOMER_LOCATION

on CUSTOMER (City, Country)

6.

create table store_information

store_name char(20),

sales int,

sale_date date

);

select store_name from store_information;

7.

SELECT DISTINCT store_name FROM Store_Information

8.

SELECT store_name
FROM Store_Information

WHERE Sales > 1000

******************************************************

assignment 3

create table Customer

First_Name char(50),

Last_Name char(50),

Addresschar(100),

City char(25),

Countrychar(50),

Birth_Date date

);

1. alter table Customer ADD gender char(1);

2. alter table Customer MODIFY address char(150);

3. ALTER table customer RENAME COLUMN Address TO Addr;

4. alter table Customer DROP column birth_date;

create table store_information

store_name char(50),

Sales float,

Date datetime
);

1.

INSERT INTO Store_Information

VALUES ('Pune', 900, 'Mar-04-2011');

2.

select * from store_information;

3.

UPDATE Store_Information

SET Sales = 1000

WHERE store_name = 'Pune' AND Date = 'Mar-04-1999';

4.

DELETE FROM Store_Information

WHERE store_name = 'Pune';

5.

drop table Customer;

************************************************************

assignemnt 4

1.

create table store_information

store_name char(50),

Sales float,

Store_Date datetime

);

INSERT INTO Store_Information


VALUES ('Mumbai', 1500, 'Mar-03-2011');

INSERT INTO Store_Information

VALUES ('Pune', 1000, 'Mar-04-2011');

INSERT INTO Store_Information

VALUES ('Delhi', 500, 'Mar-05-2011');

INSERT INTO Store_Information

VALUES ('Bangalore', 700, 'Mar-06-2011');

2.

UPDATE Store_Information

SET Sales = 1000

WHERE store_name = 'Delhi' AND Store_Date = 'Mar-05-1999';

select * from Store_Information;

3.

DELETE FROM Store_Information

WHERE store_name = 'Pune';

select * from Store_Information;

4.

select * from Store_Information

where sales BETWEEN 700 AND 2000;

5.

select * from Store_Information

where Store_Date BETWEEN 'Mar-03-2011' AND 'Mar-06-2011';


6.

select store_name from Store_Information

where store_name LIKE '%NE%';

7.

SELECT * FROM Store_Information

ORDER BY Sales DESC;

8.

SELECT store_name, SUM(Sales)

FROM Store_Information

GROUP BY store_name;

9.

SELECT store_name, SUM(sales)

FROM Store_Information

GROUP BY store_name

HAVING SUM(sales) > 500;

*************************************************************

assignment 5

10.

create table internet_sales

sales int,

salesDate date
);

insert into internet_sales

values (1500, '01-Mar-2011');

insert into internet_sales

values (100, '02-Mar-2011');

insert into internet_sales

values (700, '03-Mar-2011');

create table store_information

store_name varchar(50),

sales int,

salesdate date

);

insert into store_information

values ('mumbai',1500, '04-Mar-2011');

insert into store_information

values ('pune',100, '05-Mar-2011');

insert into store_information

values ('delhi',700, '06-Mar-2011');

11.

select sales, salesDate from internet_sales

UNION

select sales, salesdate from store_information;

12.
select sales, salesDate from internet_sales

INTERSECT

select sales, salesdate from store_information;

13.

select avg(sales) from store_information;

14.

select count(store_name) from store_information;

15.

select max(sales) from store_information

16.

select min(sales) from store_information

******************************************************

assignment 6

1.

create table store_information

store_name varchar(50),

sales int,

salesdate date

);

insert into store_information values ('mumbai',1500, '05-Mar-2000');

insert into store_information values ('pune',250, '07-Mar-2000');


insert into store_information values ('mumbai',300, '08-Mar-2000');

insert into store_information values ('kolkata',250, '10-Mar-2000');

create table geography

region_name varchar(10),

store_name varchar(50)

);

insert into geography values ('east', 'kolkata');

insert into geography values ('east', 'ranchi');

insert into geography values ('west', 'mumbai');

insert into geography values ('east', 'pune');

select region_name,sum(sales)

from store_info , geography

where store_info.store_name= geography.store_name

group by region_name;

2.

select lower(store_name) from store_info;

3.

select upper(store_name) from store_info;

4.

SELECT SUBSTR(store_name, 0)

FROM Geography
WHERE store_name = 'mumbai';

SELECT SUBSTR(store_name, 2)

FROM Geography

WHERE store_name = 'mumbai';

SELECT SUBSTR(store_name, 5)

FROM Geography

WHERE store_name = 'mumbai';

SELECT SUBSTR(store_name, 6)

FROM Geography

WHERE store_name = 'mumbai';

SELECT SUBSTR(store_name, 7)

FROM Geography

WHERE store_name = 'mumbai';

5.

SELECT LENGTH('kolkata_east') FROM STORE_INFO;

6.

SELECT TRIM(' PUNE')

FROM DUAL;

7.SELECT RTRIM('RANCHI ')

FROM DUAL;
8.

SELECT TO_CHAR(DATE1) FROM STORE_INFO

WHERE SALES=1500;

9.

SELECT region_name || ' ' || store_name FROM Geography;

10.

SELECT DATEADD(month, 2, salesdate)

from store_information

where store_name = 'Pune';

****************************************************************

assignment 7

-- was in a ppt madam ji showed in class --

-- must be in your notebooks --

****************************************************************

assignment 8

1.

grant ALL on book, section to arif,sanjit;

2.

grant SELECT on book(section_idno) to public;


3.

revoke all on book, section from arif,sanjit ;

4.

revoke all on book from public;

5.

create view vstore_info

as

select lending_data from book;

6.

create view v_book

as

select book_title, section

from books;

7.

create view v_employee

as

select emp_name, emp_id, deptno, emp_job

from employee

where emp_job = 'clerk'

WITH CHECK OPTION;

8.
create index indx

on store_info (store_name);

9.

drop index indx;

10.

create procedure proc

as

begin

INSERT INTO store_info VALUES ('delhi',700,'17-MAR-2000');

UPDATE store_info SET sales = sales + 5000 WHERE sales = 250;

DELETE FROM store_info WHERE sales=300;

COMMIT;

end proc;

execute proc;

*********************************************************************

assignment 9

1.

create table acct_mstr

acc_no number (10,2),

c_bal number (10,2),

name varchar(25)
);

insert into acct_mstr values (111, 1000.00, ‘xyz’);

DECLARE

current_bal number(11,2);

account_no varchar(10);

fine_amt number(5):=100;

min_bal(5) number(10,2):=5000.00;

BEGIN

account_no := &account_no;

select current-bal into current_bal

from acct_mstr where acc_no=account_no;

if current_bal < min_bal

then update acct_mstr set c_bal=c_bal-fine_amt

where acct_no= account_no;

end if ;

end;

2.

DECLARE

num number :=0;

BEGIN

loop num: = num+2;

exit when num >10;


end Loop;

3.

create table inactv_acct_mstr

acct_no varchar(10),

opndt date,

type varchar(2)

);

DECLARE

pacct_no varchar(10);

pans varchar(5);

popendt date;

ptype varchar(5);

BEGIN

pact_no :=&pact_no;

select ‘yes’ into pans

from trans_mstr

where acct_no=pact_no

group by acct_no

having max(sysdate-dt)>365;

if pans=’yes’ then

goto mark_ststus;

else
dbms_output.put_line(‘Account no ‘|| pact_no || 'is active');

end if;

****************************************************************************

assignment 10

1.

create or replace function f_itemlockchk(vitem_id in varchar)

return num is ditem_id varchar(20);

begin

select distinct item_id into ditem_id

from trans_mstr where item_id= vitem_id;

return 1;

exception

when no_data_found then return 0;

end;

2.

CREATE OR REPLACE PACKAGE emp_mgmt AS

FUNCTION hire (last_name VARCHAR2, job_id VARCHAR2,

manager_id NUMBER, salary NUMBER,

commission_pct NUMBER, department_id NUMBER)

RETURN NUMBER;

FUNCTION create_dept(department_id NUMBER, location_id NUMBER)

RETURN NUMBER;

PROCEDURE remove_emp(employee_id NUMBER);

PROCEDURE remove_dept(department_id NUMBER);


PROCEDURE increase_sal(employee_id NUMBER, salary_incr NUMBER);

PROCEDURE increase_comm(employee_id NUMBER, comm_incr NUMBER);

no_comm EXCEPTION;

no_sal EXCEPTION;

END emp_mgmt;

***************************************************************************

assignment 11

1.

create table emp_mstr

name varchar(25),

emp_no varchar(10),

branch_no varchar(10)

insert into emp_mstr values (‘xyz’, ‘e101’, ‘b100’);

BEGIN

update emp_mstr set branch_no = &branch_no where emp_no = &emp_no;

if sql%found then

dbms_output.put_line(‘Employee Successfully Transfer’);

end if ;

if sql%notfound then

dbms_output.put_line(‘Employee number does not exist’);


2.

create table inactv_acct_mstr

acct_no varchar(10),

opndt date,

type varchar(2)

DECLARE

cursor trans Is

select acct_no, status, opndt, type

from inactv_acct_mstr

WHERE acct_no in (

select acct_no from trans_mstr

group by acct_no

having max(sysdate-dt)>365);

BEGIN

for notrans_rec in Trans

loop

update acct_mstr set status='s'

where acct_no=notrans_rec.acct_no;

insert into inactv_acct_mstr

values (notrans_rec.acct_no, notrans_rec.opndt, notrans_rec.type);

end loop;
end;

********************************************************************************

assignment 12

1.

create table audit_cust

cust_no varchar(20),

fname varchar(25),

mname varchar(25),

lname varchar(25),

dob_inc date,

occup varchar(25),

pin varchar(25),

signature varchar(25),

pancopy varchar (1),

form60 varchar(1),

operation varchar(10),

userid varchar(10),

odate date

);

create table audit_mstr

fname varchar(25),

mname varchar(25),
lname varchar(25),

address varchar(25)

);

create trigger a_trigal

after update or delete on cust_mstr

for each row

DECLARE

oper varchar(10);

BEGIN

if updating then oper: =’update’;

end if;

if deleting then

oper: =’delete’;

end if;

insert into audit_cust values(

:old.cust_no ,

:old.fname,

:old.mname,

:old.lname,

:old.dob_inc,

:old.occup,

:old.pin,

:old.signature ,

:old.pancopy ,
:old.form60,

oper,

useri,

sysdate

);

End;

2.

create or replace trigger cust_no_gen

before insert on cust_mstr

for each row

declare

primary_key_value varchar(20);

begin

select ‘c’ || to_char(cust_seq.nextval)

into primary_key_value from dual;

:new.cust_no := primary_key_value;

end;

You might also like