Vous êtes sur la page 1sur 15

EXPERIMENT NO.- 2 AIM: Write a program to implement Transaction Control Statement i.e. Commit ,Rollback and Savepoint.

Commit Statement

SQL> select * from supplier; S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# nehru 30 chennai s4# priya 20 bombay s5# anand 30 delhi SQL> update supplier set s_name='priyanka' where s#='s4#'; 1 row updated. SQL> commit; Commit complete.

RollBack Statement
SQL> select * from supplier; S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# nehru 30 chennai s4# priyanka 20 bombay s5# anand 30 delhi SQL> update supplier set s_name='priya' where s#='s4#'; 1 row updated. SQL> select * from supplier;

S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# nehru 30 chennai s4# priya 20 bombay s5# anand 30 delhi SQL> rollback; Rollback complete. SQL> select * from supplier; S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# nehru 30 chennai s4# priyanka 20 bombay s5# anand 30 delhi

Savepoint Statement
SQL> select * from supplier; S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# nehru 30 chennai s4# priyanka 20 bombay s5# anand 30 delhi SQL> update supplier set s_name='neha' where s#='s3#'; 1 row updated.

SQL> select * from supplier;

S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# neha 30 chennai s4# priyanka 20 bombay s5# anand 30 delhi SQL> savepoint s1; Savepoint created. SQL> update supplier set s_name='priya' where s#='s4#'; 1 row updated. SQL> select * from supplier; S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# neha 30 chennai s4# priya 20 bombay s5# anand 30 delhi SQL> rollback to s1; Rollback complete. SQL> select * from supplier; S# S_NAME STATUS CITY ----- ---------- ---------- ---------s1# sarala 20 bombay s2# uma 10 chennai s3# neha 30 chennai s4# priyanka 20 bombay s5# anand 30 delhi

EXPERIMENT NO.- 3 AIM: Write a program to study about implementation of sequence i.e. Creating,Referencing,Altering and Dropping sequence.
Creating Sequence
SQL> Create sequence count 2 start with 1 3 increment by 1 4 maxvalue 20 5 minvalue 1 6 cycle 7 order 8 cache 2; Sequence created. SQL> select count.nextval from dual; NEXTVAL ---------1 SQL> select count.nextval from dual; NEXTVAL ---------2 SQL> SQL> select count.nextval from dual; NEXTVAL ---------3 SQL> select count.currval from dual; CURRVAL ---------3

Referencing Sequence:
SQL> create table emp1(eid number(5),ename varchar(10)); Table created.

SQL> insert into emp1 values(count.nextval,'neha'); 1 row created. SQL> insert into emp1 values(count.nextval,'shubhika'); 1 row created. SQL> select * from emp1; EID ENAME ---------- ---------4 neha 5 shubhika

Altering Sequence
SQL> alter sequence count 2 increment by 2; Sequence altered. SQL> select count.currval from dual; CURRVAL ---------5 SQL> select count.nextval from dual; NEXTVAL ---------7 SQL> alter sequence count nocycle; Sequence altered.

Dropping Sequence
SQL> drop sequence count; Sequence dropped. SQL> select count.currval from dual; select count.currval from dual * ERROR at line 1: ORA-02289: sequence does not exist

EXPERIMENT NO.- 4 AIM: Create a Database and use Set Operators ,Equi Join and Self Join on it
Create Table Deptt SQL> create table deptt(dept_id varchar(10),dept_location varchar(10),primary key(dept_id)); Table created.

Values Insertion in Deptt


SQL> insert into deptt values(&dept_id,'&dept_location'); Enter value for dept_id: 'ACC-101' Enter value for dept_location: delhi old 1: insert into deptt values(&dept_id,'&dept_location') new 1: insert into deptt values('ACC-101','delhi') 1 row created. SQL> / Enter value for dept_id: 'IT-102' Enter value for dept_location: banglore old 1: insert into deptt values(&dept_id,'&dept_location') new 1: insert into deptt values('IT-102','banglore') 1 row created. SQL> / Enter value for dept_id: 'HR-103' Enter value for dept_location: delhi old 1: insert into deptt values(&dept_id,'&dept_location') new 1: insert into deptt values('HR-103','delhi') 1 row created. SQL> / Enter value for dept_id: 'MEC-104' Enter value for dept_location: banglore old 1: insert into deptt values(&dept_id,'&dept_location') new 1: insert into deptt values('MEC-104','banglore') 1 row created.

SQL> / Enter value for dept_id: 'MRk-105' Enter value for dept_location: delhi old 1: insert into deptt values(&dept_id,'&dept_location') new 1: insert into deptt values('MRk-105','delhi') 1 row created. SQL> select * from deptt; DEPT_ID DEPT_LOCAT ---------- ---------ACC-101 delhi IT-102 banglore HR-103 delhi MEC-104 banglore MRk-105 delhi Create Table Employee SQL> create table employee(empid number(10),first_name varchar2(15),last_name varchar2(15),dept_id varchar(10),mgr_id number(10),primary key(empid),foreign key(dept_id) references deptt(dept_id)); Table created.

Values Insertion in Employee


SQL> insert into employee values(&empid,'&first_name','&last_name','&dept_id',&mgr_id); Enter value for empid: 1 Enter value for first_name: neha Enter value for last_name: jolly Enter value for dept_id: IT-102 Enter value for mgr_id: 4 old 1: insert into employee values(&empid,'&first_name','&last_name','&dept_id',&mgr_id) new 1: insert into employee values(1,'neha','jolly','IT-102',4) 1 row created. SQL> / Enter value for empid: 2 Enter value for first_name: shubhika Enter value for last_name: jindal

Enter value for dept_id: ACC-101 Enter value for mgr_id: 3 old 1: insert into employee values(&empid,'&first_name','&last_name','&dept_id',&mgr_id) new 1: insert into employee values(2,'shubhika','jindal','ACC-101',3) 1 row created. SQL> / Enter value for empid: 3 Enter value for first_name: leena Enter value for last_name: mittal Enter value for dept_id: HR-103 Enter value for mgr_id: 10 old 1: insert into employee values(&empid,'&first_name','&last_name','&dept_id',&mgr_id) new 1: insert into employee values(3,'leena','mittal','HR-103',10) 1 row created.

SQL> / Enter value for empid: 4 Enter value for first_name: shipra Enter value for last_name: goel Enter value for dept_id: IT-102 Enter value for mgr_id: 10 old 1: insert into employee values(&empid,'&first_name','&last_name','&dept_id',&mgr_id) new 1: insert into employee values(4,'shipra','goel','IT-102',10) 1 row created. SQL> select * from employee; EMPID FIRST_NAME LAST_NAME DEPT_ID ---------- --------------- --------------- ---------- ---------1 neha jolly IT-102 4 2 shubhika jindal ACC-101 3 3 leena mittal HR-103 10 4 shipra goel IT-102 10 MGR_ID

Set Operators: UNION:


SQL> select dept_id from deptt

2 UNION 3 select dept_id from employee; DEPT_ID ---------ACC-101 HR-103 IT-102 MEC-104 MRk-105

UNION ALL:
SQL> select dept_id from deptt 2 UNION ALL 3 select dept_id from employee; DEPT_ID ---------ACC-101 IT-102 HR-103 MEC-104 MRk-105 IT-102 ACC-101 HR-103 IT-102 9 rows selected.

INTERSECT:

SQL> select dept_id from deptt 2 INTERSECT 3 select dept_id from employee; DEPT_ID ---------ACC-101 HR-103 IT-102

MINUS:
SQL> select dept_id from deptt 2 MINUS 3 select dept_id from employee; DEPT_ID ---------MEC-104 MRk-105

EQUI JOIN
SQL> select e.first_name,d.dept_location from employee e,deptt d where e.dept_id=d.dept_id; FIRST_NAME DEPT_LOCAT --------------- ---------neha banglore shubhika delhi leena delhi shipra banglore

SELF JOIN
SQL> select e1.first_name,e2.empid as mgr_id,e2.first_name as mgr_name from employee e1,employee e2 where e1.mgr_id=e2.empid; FIRST_NAME MGR_ID MGR_NAME --------------- ---------- --------------neha 4 shipra shubhika 3 leena

EXPERIMENT NO.- 5 AIM: Write a program to create index on table and drop index.
Table Selection SQL> select * from salgrade; GRADE LOSAL HISAL ---------- ---------- ---------1 700 1200 2 1201 1400 3 1401 2000 4 2001 3000 5 3001 9999

Creating Unique Indexes SQL> create unique index sal_un_index on salgrade(grade); Index created.

Creating Non Unique Indexes SQL> create index sal_nonun_index on salgrade(losal); Index created.

Creating Composite Indexes SQL> create unique index sal_un_com_index on salgrade(grade,losal); Index created.

Creating Bitmap Indexes SQL> create bitmap index sal_bit_index on salgrade(hisal); Index created.

Dropping Indexes SQL> drop index sal_un_index;

Index dropped.

EXPERIMENT NO.- 6 AIM: To Study About PL/SQL and to write PL/SQL Block For Inserting Rows Into empdet table with the following calculations.
Table Creation
SQL> create table empdet(Basic number(5),HRA number,DA Number,PF number,NET_PAY number); Table created. PL/SQL Procedure SQL> DECLARE 2 Basic number(5) := &Enter_EMP_BASIC_SALARY; 3 HRA Number; 4 DA Number; 5 PF Number; 6 NET_PAY Number; 7 BEGIN 8 HRA := 0.50*Basic; 9 DA := 0.20*Basic; 10 PF := 0.07*Basic; 11 NET_PAY := (Basic + HRA + DA + PF); 12 insert into empdet 13 values(Basic,HRA,DA,PF,NET_PAY); 14 END; 15 / Enter value for enter_emp_basic_salary: 1000 old 2: Basic number(5) := &Enter_EMP_BASIC_SALARY; new 2: Basic number(5) := 1000; PL/SQL procedure successfully completed. SQL> / Enter value for enter_emp_basic_salary: 10000 old 2: Basic number(5) := &Enter_EMP_BASIC_SALARY; new 2: Basic number(5) := 10000; PL/SQL procedure successfully completed. Table Selection SQL> select * from empdet; BASIC HRA DA PF NET_PAY ---------- ---------- ---------- ---------- ---------1000 500 200 70 1770

10000

5000

2000

700

17700

EXPERIMENT NO.- 7 AIM: Write PL/SQL Block to check the balance of given account no. charging fine if balance is less than minimum balance.
Table Creation SQL> create table customer(account_no number,account_amount number); Table created. Values Insertion SQL> insert into customer values(7902,200); 1 row created. SQL> insert into customer values(7903,600); 1 row created. SQL> select * from customer; ACCOUNT_NO ACCOUNT_AMOUNT ---------- -------------7902 200 7903 600 SQL> SET SERVEROUTPUT ON ; PL/SQL Procedure SQL> DECLARE 2 Acc_no number :=&Enter_Account_no; 3 Min_balance number:= 500; 4 Amount number; 5 BEGIN 6 select account_amount into Amount 7 from customer 8 where account_no=Acc_no; 9 10 IF Amount < Min_balance THEN 11 DBMS_OUTPUT.PUT_LINE('You are fined because your account balance is less than 500 Rs');

12 END IF; 13 End; 14 / Enter value for enter_account_no: 7902 old 2: Acc_no number :=&Enter_Account_no; new 2: Acc_no number :=7902; You are fined because your account balance is less than 500 Rs PL/SQL procedure successfully completed. SQL> / Enter value for enter_account_no: 7903 old 2: Acc_no number :=&Enter_Account_no; new 2: Acc_no number :=7903; PL/SQL procedure successfully completed.

Vous aimerez peut-être aussi