You are on page 1of 105

DATA DEFINITION LANGUAGE

The DDL commands are: • • • • • Create Alter Drop Rename Truncate

CUSTOMER DETAILS TABLE STRUCTURE-1

FIELD NAME CUST_ID

TYPE NUMBER

SIZE 3 14 14 14 10

CONSTRAINTS -----------

CUST_FNAME ALPHANUMERIC CUST_LNAME ALPHANUMERIC CITY PHONENO ALPHANUMERIC NUMBER

1. Create command:SYNTAX:SQL> create table <table_name>(fieldname1 Datatype1, fieldname2 Datatype2,…, fieldname n Datatype n); EXAMPLE:SQL> create table custo21(id varchar2(3),fname varchar2(14),lname varchar2(14),city varchar2(14),phn number(10)); Table created. TABLE DESCRIPTION:SQL> desc custo21; Name Null? Type ----------------------- -------- ---------------------------ID VARCHAR2(3) FNAME VARCHAR2(14) LNAME VARCHAR2(14) CITY VARCHAR2(14) PHN NUMBER(10)

EMPLOYEE DETAILS Create the employee table with the following fields and assign the employee id as primary key. TABLE STRUCTURE-2

FIELD NAME EMP_ID EMP_FNAME EMP_LNAME DOJ BASIC PAY CREATE COMMAND SYNTAX:-

TYPE ALPHANUMERIC ALPHANUMERIC ALPHANUMERIC DATE NUMBER

SIZE 3 14 14 --10,2

CONSTRAINTS PK ---------

SQL> create table <table_name>(fieldname1 Datatype1 constraints <constraint_name> primary key, fieldname2 Datatype2,…, fieldname n Datatype n);

EXAMPLE:SQL> create table empl21(empid varchar2(2) constraints pkemp primary key,emp_fname varchar2(14),emp_lname varchar2(14),doj date,basic number(10,2)); Table created. TABLE DESCRIPTION:SQL> desc empl21; Name Null? Type --------------------------- -------- ---------------------------EMPID NOT NULL VARCHAR2(2) EMP_FNAME VARCHAR2(14) EMP_LNAME VARCHAR2(14) DOJ DATE BASIC NUMBER(10,2) 2. Alter command:-

EXAMPLE:SQL> alter table custo21 add(age number(2) constraints ckage check(age between 18 and 60)).---------------------------EMPID NOT NULL VARCHAR2(2) EMP_FNAME VARCHAR2(14) EMP_LNAME VARCHAR2(14) DOJ DATE BASIC NUMBER(10. Table altered. Name Null? Type --------------------------.-------. C) MODIFY SYNTAX:- . EXAMPLE:SQL> alter table employeel add(address varchar2(15)).…. TABLE DESCRIPTION:SQL> desc empl21. Table altered.2) ADDRESS VARCHAR2(15) b) ADD CONSTRAINTS SYNTAX:SQl> Alter table<table_name>add(fieldname1 Datatype1(size) constraints <constraint_name>check(field_name between val1 and val2. fieldname n Datatype n(size)). fieldnamen Datatype n(size)).….a) ADD SYNTAX:SQl> Alter table<table_name>add(fieldname1 Datatype1(size).

…. Name Null? Type . TABLE DESCRIPTION:SQL> desc empview.2) ADDRESS VARCHAR2(15) CREATE VIEW SYNTAX:SQL> create view <view_name> as select * from <table_name>. Table altered. EXAMPLE:SQL> alter table empl21 modify(emp_fname varchar2(20)). View created.SQl> Alter table<table_name>modify(fieldname1 Datatype1(size). TABLE DESCRIPTION:SQL> desc empl21.-------. fieldname n Datatype n(size)). Name Null? Type ----------------------------. EXAMPLE:SQL> create view empview as select * from empl21.-------------------------EMPID NOT NULL VARCHAR2(2) EMP_FNAME VARCHAR2(20) EMP_LNAME VARCHAR2(14) DOJ DATE BASIC NUMBER(10.

….---------------------------EMPID NOT NULL VARCHAR2(2) EMP_FNAME VARCHAR2(20) EMP_LNAME VARCHAR2(14) DOJ DATE BASIC NUMBER(10.------------------------. fieldname2 Datatype2.2) ADDRESS VARCHAR2(15) 3. . View dropped. EXAMPLE:SQL> drop view empview. CREATE CHILD TABLE SYNTAX:SQL>create table <table_name>(fieldname1 Datatype1 constraints <constraint_name>references mastertab_name(pkfield_name). fieldname n Datatype n). Table created.-------. Drop Command SYNTAX:SQL> drop view <view_name>. EXAMPLE:SQL> create table empl21_child(empid varchar2(2) constraints fkemp references empl21(empid) on delete cascade). TABLE DESCRIPTION:SQL> desc empl21_child.

CREATE DUPLICATE TABLE SYNTAX:SQL> create table <newtab_name>as select * from <oldtab_name>. 4.-------.---------------------------EMPID VARCHAR2(2) ALTER -ADD CONSTRAINTS SQL> alter table empl21 add(constraints ckbasic check(basic > 0)). Truncate Command . EXAMPLE-1:SQL> create table empl21_temp as select * from empl21. Table created. Table created.-------. Table altered.2) ADDRESS VARCHAR2(15) EXAMPLE-2:SQL> create table custo21temp as select * from custo21.---------------------------EMPID VARCHAR2(2) EMP_FNAME VARCHAR2(20) EMP_LNAME VARCHAR2(14) DOJ DATE BASIC NUMBER(10. Name Null? Type --------------------------.Name Null? Type ----------------------------. TABLE DESCRIPTION:SQL> desc empl21_temp.

EXAMPLE:SQL> rename custo21 to customer21. Rename Command SYNATX:SQL> rename <oldtab_name> to <newtab_name>.SYNTAX:SQL> truncate table <table_name>. Name Null? Type ----------------------------------------. EXAMPLE:SQL> truncate table custo21temp. ERROR: . TABLE DESCRIPTION:SQL> desc custo21. Table truncated. TABLE DESCRIPTION :SQL> desc custo21temp. Table renamed.-------.---------------------------ID VARCHAR2(3) FNAME VARCHAR2(14) LNAME VARCHAR2(14) CITY VARCHAR2(14) PHN NUMBER(10) AGE NUMBER(2) 5.

Name Null? Type -----------------------. Table altered.-------. TABLE DESCRIPTION:SQL> desc empl21. EXAMPLE:SQL> alter table empl21 add(desig varchar2(14)).---------------------------EMPID NOT NULL VARCHAR2(2) EMP_FNAME VARCHAR2(20) EMP_LNAME VARCHAR2(14) DOJ DATE BASIC NUMBER(10.2) ADDRESS VARCHAR2(15) DESIG VARCHAR2(14) SQL> alter table empl21 drop column desig. TABLE DESCRIPTION:- .---------------------------ID VARCHAR2(3) FNAME VARCHAR2(14) LNAME VARCHAR2(14) CITY VARCHAR2(14) PHN NUMBER(10) AGE NUMBER(2) DROP COMMAND SYNTAX:SQL> alter table <table_name> drop column <col_name>. Table altered.ORA-04043: object custo21 does not exist SQL> desc customer21. Name Null? Type ----------------------------------------.-------.

---------------------------EMPID NOT NULL VARCHAR2(2) EMP_FNAME VARCHAR2(20) EMP_LNAME VARCHAR2(14) DOJ DATE BASIC NUMBER(10.2) ADDRESS VARCHAR2(15) RESULT:Thus. the above DDL commands have been executed successfully. Select.SQL> desc empl21. Update. Name Null? Type ----------------------------------------. DATA MANIPULATION LANGUAGE The DML language comprises of the following:• • • • Insert.-------. Perform DML commands on the following table: EMPLOYEE DETAILS TABLE STRUCTURE-1 . Delete.

emp_fname.doj. SYNTAX:FOR INSERTING MANY RECORDS SQL> insert into<table_name>(fieldname1.. Enter value for empid: 01 Enter value for emp_fname: amber Enter value for emp_lname: marienne Enter value for doj: 01/jan/2000 .’&fieldname n’).'&emp_lname'.fieldname2.’&fieldname2’..'&doj'. EXAMPLE:SQL> insert into empl21(empid..'&basic'.'&address').'&emp_fname'...address) values('&empid'.2 CONSTRAINTS PK --------- 1.val2.val n).. Insert Command SYNTAX:FOR INSERTING A SINGLE RECORD SQL> insert into<table_name> values(val1.FIELD NAME EMP_ID EMP_FNAME EMP_LNAME DOJ BASIC PAY TYPE ALPHANUMERIC ALPHANUMERIC ALPHANUMERIC DATE NUMBER SIZE 3 14 14 --10. fieldnamen)values(‘&fieldname1’.emp_lname.basic.….

SQL> / Enter value for empid: 16 Enter value for emp_fname: louisa Enter value for emp_lname: beth Enter value for doj: 19/july/2001 Enter value for basic: 15000 Enter value for address: belgium 1 row created. SQL> / Enter value for empid: 08 Enter value for emp_fname: sofia Enter value for emp_lname: ruth Enter value for doj: 05/may/2001 Enter value for basic: 16000 Enter value for address: usa 1 row created. SQL> / Enter value for empid: 04 Enter value for emp_fname: kirsten Enter value for emp_lname: gray Enter value for doj: 06/may/2000 Enter value for basic: 16500 Enter value for address: usa 1 row created.Enter value for basic: 18000 Enter value for address: france 1 row created. . SQL> / Enter value for empid: 10 Enter value for emp_fname: natasha Enter value for emp_lname: jena Enter value for doj: 12/june/2001 Enter value for basic: 15800 Enter value for address: india 1 row created.

--------------18000 france 16500 usa 16000 usa 15800 india 15000 belgium INSERT VALUES INTO CHILD TABLE SQL> insert into empl21_child(empid)values('&empid'). SQL> / Enter value for empid: 08 old 1: insert into empl21_child(empid)values('&empid') new 1: insert into empl21_child(empid)values('08') 1 row created. Enter value for empid: 01 old 1: insert into empl21_child(empid)values('&empid') new 1: insert into empl21_child(empid)values('01') 1 row created.------------------.TABLE-RECORDS:SQL> select * from empl21.-----------01 amber marienne 01-JAN-00 04 kirsten gray 06-MAY-00 08 sofia ruth 05-MAY-01 10 natasha jena 12-JUN-01 16 louisa beth 19-JUL-01 BASIC ADDRESS ---------. SQL> / Enter value for empid: 10 old 1: insert into empl21_child(empid)values('&empid') new 1: insert into empl21_child(empid)values('10') . EM EMP_FNAME EMP_LNAME DOJ --------------------. SQL> / Enter value for empid: 04 old 1: insert into empl21_child(empid)values('&empid') new 1: insert into empl21_child(empid)values('04') 1 row created.

------------------. TABLE-RECORDS:SQL> select * from empl21. SQL> / Enter value for empid: 16 old 1: insert into empl21_child(empid)values('&empid') new 1: insert into empl21_child(empid)values('16') 1 row created.--------------19500 france . EM EMP_FNAME EMP_LNAME DOJ --------------------. Update Command SYNTAX:SQL> update <table_name> set fieldname=<expression> [where condition]. EXAMPLE-1:SQL> update empl21 set basic=basic+1500. 5 rows updated. EM ---01 04 08 10 16 2.1 row created.-----------01 amber marienne 01-JAN-00 BASIC ADDRESS ---------. TABLE-RECORDS:SQL> select * from empl21_child.

SYNTAX:SQL> select * from <table_name> where <condition>.000. Select Command 1) List down employee records whose salary is >= 18.employee first name and salary fields.---------. .--------------*01 amber marienne 01-JAN-00 21500 france 04 kirsten gray 06-MAY-00 18000 usa 2) List down the emp_id . EM EMP_FNAME EMP_LNAME DOJ --------------------.04 08 10 16 kirsten sofia natasha louisa gray ruth jena beth 06-MAY-00 18000 05-MAY-01 17500 12-JUN-01 17300 19-JUL-01 16500 usa usa india belgium EXAMPLE-2:SQL> update empl21 set basic=basic+2000 where empid=01.-----------*01 amber marienne 01-JAN-00 04 kirsten gray 06-MAY-00 08 sofia ruth 05-MAY-01 10 natasha jena 12-JUN-01 16 louisa beth 19-JUL-01 BASIC ADDRESS ---------.--------------21500 france 18000 usa 17500 usa 17300 india 16500 belgium 3. 1 row updated.-----------.------------------. EXAMPLE:SQL> select * from empl21 where basic>=18000. EM EMP_FNAME EMP_LNAME DOJ BASIC ADDRESS --------------------. TABLE-RECORDS:SQL> select * from empl21.------------------.

. SYNTAX:SQL> select field_name1. SYNTAX:SQL> select field_name1. BASIC ---------16500 17300 17500 18000 21500 4) List down the employee salaries in descending order.basic from empl21. EM ---01 04 08 10 16 EMP_FNAME -------------------amber kirsten sofia natasha louisa BASIC ---------21500 18000 17500 17300 16500 3) List down the employee salaries in ascending order.. from <table_name> order by basic desc. fieldname n from <table_name> where <condition>.emp_fname. from <table_name> order by basic. EXAMPLE:SQL> select empid.. EXAMPLE:- . EXAMPLE:SQL> select basic from empl21 order by basic.SYNTAX:SQL> select field_name1...

EXAMPLE:SQL> select max(basic) from empl21. BASIC ---------21500 18000 17500 17300 5) Display the maximum salary. EXAMPLE:SQL> delete from empl21 where empid=01. . SYNTAX:SQL> select max(field_name) from <table_name>. 1 row deleted. MAX(BASIC) -----------------21500 4.SQL> select basic from empl21 order by basic desc. TABLE-RECORDS:SQL> select * from empl21. Delete Command SYNTAX:SQL> delete from <table_name> [where <condition>].

Syntax: Commit Rollback Save point Grant Revoke . the above DML commands are executed successfully.------------------.-----------.EM EMP_FNAME EMP_LNAME DOJ BASIC ADDRESS --------------------.---------.--------------04 kirsten gray 06-MAY-00 18000 usa 10 natasha jena 12-JUN-01 17300 india 16 louisa beth 19-JUL-01 16500 belgium RESULT:Thus. DATA CONTROL LANGUAGE The DCL commands are: • • • • • COMMIT: Commit command tells the DBMS to make permanent changes made to temporary copies of the data updating the permanent database tables to match the updated temporary copies.

Syntax: SQL> rollback .’pondy’). Example: SQL> insert into cust values(‘4’.’pondy’). They are used to identify a point in transaction to which we can later rollback.’xxx’. SQL> commit. SQL> set auto commit off . Thus save point is used in conjunction with rollback to rollback portions of the current transaction. SQL> rollback. Syntax: SQL>Savepoint<name>. SQL> savepoint m1.’aaa’. SQL>commit .SQL> set auto commit on . Example: SQL> delete from cust where custid =’11’. Example: SQL> insert into cust values ( ‘12’. SAVE POINT: Save points are like markers to divide a very lengthy transaction to smaller ones. ROLLBACK: Rollback tells the DBMS to undo any changes made to the DBMS after the most recent commit. GRANT: .

Example: SQL> grant all on cust to 05mca03. mark number(3) ). REVOKE: Revoke removes specific SQL statement access previously granted on individual database objects from a user or group of users. SQL> grant insert on cust to 05mca03. Example: SQL> revoke all on dcl from 05mca03.Grant gives specific SQL statement access or individual data objects to a user or a group of users. Syntax: SQL> Revoke <privileges> on <tablename> from user . Syntax: SQL>grant <privileges> on <table name> to user . TABLE DESCRIPTION: SQL> desc dcl. Name Null? Type . TABLE CREATION: SQL> create table dcl ( rono number(3) constraints ass primary key. Table created. name varchar2(20).

1 row deleted. SQL> insert into dcl values (222. SQL> savepoint m1.100). Table Committed TABLE RECORDS: SQL> select * from dcl.t'.'ram'. COMMIT: SOL> commit.200). Savepoint created .----------111 kugan. 1 row created.-------------------. RONO NAME MARK ---------.---------------------------RONO NOT NULL NUMBER(3) NAME VARCHAR2(20) MARK NUMBER(3) INSERTING RECORDS: SQL> insert into dcl values(111. 1 row created.'kugan.----------------------------------------.t 100 222 ram 200 SAVEPOINT: SQL> delete from dcl where rono=111.

Grant succeeded. SQL> select * from dcl. .---------111 kugan. SQL> grant insert on dcl to 05mca03.t 00 222 ram 200 GRANT: SQL> grant all on dcl to 05mca03.SQL> select * from dcl. SQL> grant delete on dcl to 05mca03. Grant succeeded. Rollback complete. Grant succeeded. RONO NAME MARK ------------------------------------------222 ram 200 ROLLBACK : SQL> rollback to savepoint m1.-------------------. REVOKE: SQL> revoke all on dcl from 05mca03. RONO NAME MARK ---------.

RESULT: Thus the above DCL commands are executed successfully. Student Name Mark 1 DATATYPE Numeric Alpha Numeric Numeric SIZE 4 14 3 CONSTRAINTS Primary Key Not Null Not Null . STUDENT MARKLIST-1 AIM: Create the following table and insert records into the table and execute the queries given below.Revoke succeeded. TABLE STRUCTURE: FIELD NAME Roll No.

Enter value for rollno: 111 Enter value for sname: aaa . '&sname'. mark3 number(3) not null. sname varchar2(14) not null. '&mark2'. Name Null? Type ----------------------------------------. '&mark3' ). mark2 number(3) not null. mark1 number(3) not null. mark3 ) values ( '&rollno'. Table created. total number(3).Mark 2 Mark 3 Total Grade Numeric Numeric Numeric Characters 3 3 3 1 Not null Not Null ---Nil-----Nil--- TABLE CREATION: SQL> create table studentmarklist ( rollno number(4) constraints pkey primary key. mark2.---------------------------ROLLNO NOT NULL NUMBER(4) SNAME NOT NULL VARCHAR2(14) MARK1 NOT NULL NUMBER(3) MARK2 NOT NULL NUMBER(3) MARK3 NOT NULL NUMBER(3) TOTAL NUMBER(3) GRADE VARCHAR2(1) INSERTING-RECORDS : SQL> insert into studentmarklist ( rollno. '&mark1'. mark1. sname. grade varchar2(1) ). TABLE DESCRIPTION: SQL> desc studentmarklist.-------.

. 1 row updated. SQL> / Enter value for rollno: 222 Enter value for sname: bbb Enter value for mark1: 55 Enter value for mark2: 60 Enter value for mark3: 50 1 row created. UPDATING: SQL> update studentmarklist set total=mark1+mark2+mark3. SQL> update studentmarklist set grade = 'O 'where total>200. SQL> / Enter value for rollno: 333 Enter value for sname: ccc Enter value for mark1: 50 Enter value for mark2: 51 Enter value for mark3: 47 1 row created. SQL> / Enter value for rollno: 444 Enter value for sname: ddd Enter value for mark1: 35 Enter value for mark2: 40 Enter value for mark3: 20 1 row created. 4 rows updated.Enter value for mark1: 85 Enter value for mark2: 89 Enter value for mark3: 90 1 row created.

SQL> update studentmarklist set grade = 'A' where total >=150 and total <=200; 1 row updated. SQL> update studentmarklist set grade = 'B' where total>100 and total<=149; 1 row updated. SQL> update studentmarklist set grade='F' where total<100; 1 row updated. TABLE – RECORDS: SQL> select * from studentmarklist; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ----------------------------------------------------------------------------------------------------111 aaa 85 89 90 264 O 222 bbb 55 60 50 165 A 333 ccc 50 51 47 148 B 444 ddd 35 40 20 95 F 4 Rows selected. QUERIES: 1) Display the student’s name which starts with the letter ‘s’. SQL> select sname from studentmarklist where sname like 's%'; no rows selected 2) Display the student’s name which starts with the letter ‘a’. SQL> select sname from studentmarklist where sname like 'a%'; SNAME -------------aaa 3) Display the student’s record whose name starts with letter ‘a’.

SQL> select * from studentmarklist where sname like 'a%'; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ----------------------------------------------------------------------------------------------111 aaaa 85 89 90 264 O 4) Display the student’s name which ends with the letter ‘c’. SQL> select sname from studentmarklist where sname like '%c'; SNAME ----------ccc 5) Display the student’s record whose name ends with the letter ‘c’. SQL> select * from studentmarklist where sname like '%c'; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G --------------------------------------------------------------------------------------------333 ccc 50 51 47 148 B 6) Display the student’s record who have got more than 80 in all subjects. SQL> select * from studentmarklist where mark1>80 and mark2>80 and mark3>80; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ---------------------------------------------------------------------------------------------111 aaa 85 89 90 264 O

7) Display the maximum total of marks obtained. SQL> select max(total)from studentmarklist; MAX(TOTAL) -----------------264 8) Display the minimum total of marks obtained. SQL> select min(total) from studentmarklist;

MIN(TOTAL) ----------------95 9) Display the student’s record who have got the grade ‘F’. SQL> select * from studentmarklist where grade='f'; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G -----------------------------------------------------------------------------------------------444 ddd 35 40 20 95 F 10) Display the student’s record who have got the grade ‘O’. SQL> select * from studentmarklist where grade = 'O' ; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ------------------------------------------------------------------------------------------------111 aaa 85 89 90 264 O

RESULT: Thus the student table is created and the above queries are executed successfully.

STUDENT MARKLIST-2
AIM: Create the following table and insert records into the table and execute the queries given below.

TABLE STRUCTURE 1: Field name Rollno Name Data type Number Alphanumeric Size 3 14 Constraints Primary key Not Null

TABLE STRUCTURE 2: Field name Rollno Mark1 Mark2 Mark3 Total Grade Data type Number(3) Number(3) Number(3) Number(3) Number(3) Alphanumeric Size 3 3 3 3 3 1 Constraints Foreign Key Between 0 and 100 Between 0 and 100 Between 0 and 100 - .

Table created. total number(5). Table created. Name Null? Type ----------------------------------------. TABLE DESCRIPTION: SQL> desc student. mark3 number(3) constraints chk3 check(mark3 between 0 and 100).--------------------ROLLNO NUMBER(3) MARK1 NUMBER(3) MARK2 NUMBER(3) MARK3 NUMBER(3) TOTAL NUMBER(5) GRADE VARCHAR2(1) .-------.TABLE CREATION: MASTER TABLE CREATION: SQL> create table student(rollno number(3) constraints prollno primary key.---------------. Name Null? Type --------------------------------------. TABLE DESCRIPTION: SQL> desc cstudent. mark2 number(3) constraints chk2 check(mark2 between 0 and 100).------------------------ROLLNO NOT NULL NUMBER(3) SNAME NOT NULL VARCHAR2(14) CHILD TABLE CREATION: SQL> create table cstudent( rollno number(3) constraints csid references student(rollno) on delete cascade. mark1 number(3) constraints chk1 check(mark1 between 0 and100). grade varchar2(1)). sname varchar2(14) constraints non not null).

1 row updated. UPDATING RECORDS: SQL> update cstudent set total=mark1+mark2+mark3. 3 rows updated.'&sname'). SQL> / Enter value for rollno: 2 Enter value for sname: sruthi 1 row created. 1 row updated. SQL> update cstudent set grade='B' where total<=199 and total>150. SQL> update cstudent set grade='O' where total>250. SQL> update cstudent set grade='F' where total<=99. .sname)values('&rollno'. SQL> update cstudent set grade='C' where total<=149 and total>100. SQL> update cstudent set grade='A' where total<=249 and total>200.INSERTING RECORDS: SQL> insert into student(rollno. 1 row updated. Enter value for rollno: 1 Enter value for sname: suchi 1 row created. 1 row updated. 4 rows updated.

----------.---------1 82 75 92 249 A 3 76 45 65 186 B 4 100 78 82 260 O 4) To display the students record who have secured the maximum total: SQL> select max(total) from cstudent.QUERIES: 1) To display the students records whose name starts with s : SQL> select * from student where sname like 's%'.-----------. ROLLNO SNAME -----------. ROLLNO MARK1 MARK2 MARK3 TOTAL GRADE -----------.---------.---------.----------3 naveen 3) To display the students records who have secured more than 150: SQL> select * from cstudent where total>150.----------. ROLLNO MARK1 MARK2 MARK3 TOTAL GRADE -----------. ROLLNO -----------1 2 SNAME -------------suchi sruthi 2) To display the students records whose name ends with n: SQL> select * from student where sname like '%n'.----------2 50 60 30 140 C .---------.---------.---------. MAX(TOTAL) -----------------260 5) To display the students records who have got ‘c’ grade: SQL> select * from cstudent where grade='C'.

6) To display the student record who have got ‘o’ grade: SQL> select * from cstudent where grade='O'. .----------4 100 78 82 260 O 7) To display the students records who have secured the second maximum total: SQL> select max(total) from cstudent where total <(select max(total) from cstudent). MAX(TOTAL) ------------------249 Result: Thus the student tables are created and the above queries are executed successfully.---------.----------.---------. ROLLNO MARK1 MARK2 MARK3 TOTAL GRADE ------------.---------.

Create the above table. TABLE STRUCTURE:2 Field name Cust_name Cust_addr Cust_city Std_con Isd_con Data type Varchar2 Varchar2 Varchar2 Varchar2 Varchar2 Size 20 40 10 Constraints Not null Not null Not null Not null 1 1 Not null .TELEPHONE DIRECTORY MAINTENANCE AIM: Create the following table and insert records into the table and execute the queries given below: TABLE STRUCTURE:1 Field name Tno Occupation Data type Number Varchar2 Size 10 20 Constraints Primary key Not null 1. Add the following fields in the created table. 2.

cust_addr varchar2(40) constraints c2 not null. std_con varchar2(1) constraints c4 not null. cust_city varchar2(10) constraints c3 not null.TABLE CREATION: SQL> create table tele ( tno number(10) constraints t1 primary key. Name -------------------------TNO OCCU TABLE ALTERATION: SQL> alter table tele add(cust_name varchar2(20) constraints c1 not null. Table created. occu varchar2(20)constraints oc not null). Null? ------------NOT NULL NOT NULL Type ---------------------------NUMBER(10) VARCHAR2(20) . isd_con varchar2(1) constraints c5 not null). TABLE DESCRIPTION: SQL> desc tele. Table altered.

std_con.'&std_con'.cust_addr. SQL> / Enter value for tno: 989434523 Enter value for occu: teacher Enter value for cust_name: mano Enter value for cust_addr: no.cust_name. SQL> / Enter value for tno: 94434234 Enter value for occu: doctor .10 main road Enter value for cust_city: chennai Enter value for std_con: y 1 row created.'&cust_city'.'&cust_addr'.isd_con) 2 values('&tno'. Enter value for tno: 2343245 Enter value for occu: manager Enter value for cust_name: kayal Enter value for cust_addr: no. Name ----------------------------TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD_CON ISD_CON Null? ----------NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL NOT NULL Type ---------------------------NUMBER(10) VARCHAR2(20) VARCHAR2(20) VARCHAR2(40) VARCHAR2(10) VARCHAR2(1) VARCHAR2(1) INSERTING RECORDS SQL> insert into tele(tno.'&occu'.12. 3 '&isd_con').new st Enter value for cust_city: pondy Enter value for std_con: y 1 row created.TABLE DESCRIPTION: SQL> desc tele.occu.'&cust_name'.cust_city.

8. . TABLE-RECORDS SQL> select * from tele.8. List down the customers having std connection.10 main road chennai y n 2. SQL> select * from tele where std_con='y' and isd_con='y'.2nd cross pondy n n 9344719313 student haran mariamman st.12. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD ----------------------------------------------------------------------------------------------------------2343245 manager kayal no.Enter value for cust_name: srinivasan Enter value for cust_addr: no. cuddalore n y QUERIES: 1.new st pondy y y 989434523 teacher mano no.new st pondy y y 989434523 teacher mano no. SQL> / Enter value for tno: 9344719313 Enter value for occu: student Enter value for cust_name: haran Enter value for cust_addr: mariamman Enter value for cust_city: cuddalore Enter value for std_con: n 1 row created.2nd cross Enter value for cust_city: pondy Enter value for std_con: n 1 row created.12.10 main road chennai y n 94434234 doctor srinivasan no. SQL> select * from tele where std_con='y'. List down the customers record who are having both isd and std connection. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD ---------------------------------------------------------------------------------------------------------2343245 manager kayal no.

8.new st pondy y y 3.12. List down the customer records whose telephone number start with 9 and 4 SQL> select * from tele where tno like '9%4'.12. SQL> select * from tele.new st pondy y y 989434523 teacher mano no.new st pondy y y 4. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD ----------------------------------------------------------------------------------------------------------9344719313 student haran mariamman cuddalore n y 2343245 manager kayal no. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD ----------------------------------------------------------------------------------------------------------2343245 manager kayal no.2nd cross pondy n n 5. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD --------------------------------------------------------------------------------------------------------2343245 manager kayal no. SQL> select * from tele order by cust_name.12. List down the all customer records from the table.new st pondy y y .TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD ----------------------------------------------------------------------------------------------------------2343245 manager kayal no. List down the customer record whose occupation is manager and having isd connection. SQL> select * from tele where occu='manager' and isd_con='y'. List out the customer record in the ascending order of customer name.10 main road chennai y n 94434234 doctor srinivasan no. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD --------------------------------------------------------------------------------------------------------94434234 doctor srinivasan no.2nd cross pondy n n 9344719313 student haran mariamman cuddalore n y 6.8.12.

new st pondy y y 9344719313 student haran mariamman cuddalore n y 8.8.989434523 94434234 teacher doctor mano srinivasan no.2nd cross chennai pondy y n n n 7.new st pondy y y 989434523 teacher mano no. List down the customers whose occupation is manager. SQL> select * from tele where occu='manager' or occu='salesman' or occu='teacher'. List out the customer record in the decending order of customer name.12.salaesman. SQL> select * from tele order by cust_name desc.10 main road chennai y n 2343245 manager kayal no. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD ----------------------------------------------------------------------------------------------------------94434234 doctor srinivasan no.12.clerk or teacher.10 main road no. TNO OCCU CUST_NAME CUST_ADDR CUST_CITY STD ISD ----------------------------------------------------------------------------------------------------------2343245 manager kayal no.2nd cross pondy n n 989434523 teacher mano no.8.10 main road chennai y n .

EMPLOYEE INFORMATION SYSTEM AIM: Create the following table and insert records into the table and execute the queries given below. TABLE STRUCTURE: .RESULT: Thus the above table is created and the above queries are executed successfully.

Field name Empid Emp_fname Emp_lname Desigination Doj Salary Depart no. Data type Number Varchar2 Varchar2 Varchar2 Date Number Number Size 4 15 15 14 Date 7. doj date. empfname varchar2(15). . emplname varchar2(15). desi varchar2(14). salary number(7.2 4 Constraints Primary key - TABLE CREATION: SQL> create table emp(empid number(4) constraints ee1 primary key.2).

Enter value for empid: 110 Enter value for empfname: kayal Enter value for emplname: vizhi Enter value for desi: manager Enter value for doj: 5-aug-05 Enter value for salary: 10000 Enter value for departno: 330 1 row created.'&empfname'. TABLE DESCRIPTION: SQL> desc emp.2) NUMBER(4) INSERTING RECORDS: SQL> insert into emp(empid.emplname.'&doj'. Name --------------------------EMPID EMPFNAME EMPLNAME DESI DOJ SALARY DEPARTNO Null? ------------NOT NULL Type ---------------------------NUMBER(4) VARCHAR2(15) VARCHAR2(15) VARCHAR2(14) DATE NUMBER(7.departno number(4)).departno)values ('&empid'.'&desi'. SQL> / Enter value for empid: 111 Enter value for empfname: mano Enter value for emplname: haran Enter value for desi: engineer Enter value for doj: 7-jan-03 .'&departno').empfname.'&salary'.doj.'&emplname'.desi.salary. Table created.

TABLE –RECORDS: SQL> select * from emp. List down the employee firstname in the desc-order SQL> select empfname from emp order by empfname desc.Enter value for salary: 40000 Enter value for departno: 331 1 row created. SQL> / Enter value for empid: 112 Enter value for empfname: devi Enter value for emplname: priya Enter value for desi: lecturer Enter value for doj: 12-feb-04 Enter value for salary: 15000 Enter value for departno: 332 1 row created. SQL> / Enter value for empid: 113 Enter value for empfname: jackuline Enter value for emplname: mary Enter value for desi: student Enter value for doj: 3-may-01 Enter value for salary: 25000 Enter value for departno: 333 1 row created. EMPFNAME . EMPID EMPFNAME EMPLNAME DESI DOJ SALARY DEPTNO ----------------------------------------------------------------------------------------------------------110 kayal vizhi manager 05-AUG-05 10000 330 111 mano haran engineer 07-JAN-03 40000 331 112 devi priya lecturer 12-FEB-04 15000 332 113 jackuline mary student 03-MAY-01 25000 333 QUERIES: 1.

----------------mano kayal jackuline devi 2. SQL> select departno.empfname from emp group by departno. ROW_COUNT ------------------4 4. MAX(SALARY) --------------------40000 6. Find all emp-id whose salary has got null values. To count the number of employees and specify the field name as row-count. Find the max salary in the emp table. EMPID . DEPARTNO EMPFNAME --------------------------------------330 kayal 331 mano 332 devi 333 jackuline 5.empfname. SQL> select count(*) as row_count from emp. List down emp fname with respect of department no. SQL> select empid from emp where salary is null. SQL> select * from emp where empfname like ('kay_l'). EMPID EMPFNAME EMPLNAME DESI DOJ SALARY DEPTNO ----------------------------------------------------------------------------------------------------------110 kayal vizhi manager 05-AUG-05 10000 330 3. List down the employee whose first name are five letters long that begins with ‘kay’ and ends with ‘l’. SQL> select max(salary) from emp.

List down the details of the employee who gets the maximum salary. DEPTNO COUNT(*) -----------.12*avg(salary) from emp group by deptno. EMPID EMPFNAME EMPLNAME DESI DOJ SALARY DEPTNO -------. Find the average salary in the emp table and specify the fields as ave-salary. SQL> select avg(salary) as avg_salary from emp. List down the details of the employee whose desigination is not student.----------113 7.----------111 mano haran engineer 07-JAN-03 40000 331 8. SQL> select * from emp where desi<>'manager'. AVG_SALARY ------------------21666. SQL> select deptno.-----------------.---------------.desi.---------330 1 331 1 332 1 333 1 12*AVG(SALARY) ------------------------120000 480000 180000 300000 . count(*).6667 10.----------.-------------------. SQL> select * from emp where salary=(select max(salary) from emp). EMPID EMPFNAME EMPLNAME DESI DOJ SALARY DEPTNO ----------------------------------------------------------------------------------------------------------111 mano haran engineer 07-JAN-03 40000 331 112 devi priya lecturer 12-FEB-04 15000 332 113 jackuline mary student 03-MAY-01 25000 333 9. To count the employees and calculate the average annual salary for each desigination in each department.

3 y integer. new 6: x:=3. 9 dbms_output. PROGRAM: SQL>set serveroutput on. OUTPUT: Sum=6 . 5 begin 6 x:=&x.put_line('Sum='|| z). new 7: y:=3. ADDITION OF TWO NUMBERS AIM: To write the PL/SQL program to find the Addition of Two Numbers. Enter value for y: 3 old 7: y:=&y. SQL> / INPUT: Enter value for x: 3 old 6: x:=&x.RESULT: Thus the above table is created and the above queries are executed successfully. 4 z integer. 10* end. 7 y:=&y. 8 z:=x+y. SQL> 1 declare 2 x integer.

12 dbms_output.. SQL> 1 declare 2 n number. PROGRAM: SQL>set serveroutput on. OUTPUT: The factorial is: 120 RESULT: Thus the above PL/SQL program is executed successfully.put_line ('The factorial is:'||f). 4 i number. . 7 f: =1. FACTORIAL OF A NUMBER AIM: To write the PL/SQL program to find the Factorial of a number. 13* end. 11 end loop. 8 for i in 1.RESULT: Thus the above PL/SQL program is executed successfully. 5 begin 6 n:=&n.n 9 loop 10 f: =f*i. new 6: n: =5. SQL> / INPUT: Enter value for n: 5 old 6: n: =&n. 3 f number.

8 for i in 1. 11 end loop.. . 12 dbms_output. PROGRAM: SQL>set serveroutput on. OUTPUT: Sum=15 RESULT: Thus the above PL/SQL program is executed successfully. new 6: n:=5.put_line ('Sum='||s). 3 s number.n 9 loop 10 s:=s+i. 4 i number. 7 s:=0. INPUT: SQL> / Enter value for n: 5 old 6: n:=&n. 5 begin 6 n:=&n. 13* end. SQL> 1 declare 2 n number.SUM OF THE SERIES[1+2+…+N] AIM: To write the PL/SQL program to find the Sum of n numbers.

new 8: n:=5.. 13 for i in 1. 5 c number.n 14 loop 15 c:=a+b.put_line('The fibonacci series'). 3 a number. 6 i number. 9 a:=-1. SQL> declare 2 n number. 16 a:=b. 12 dbms_output. 17 b:=c. 10 b:=1. 21 / INPUT: Enter value for n: 5 old 8: n:=&n. 19 end loop.put_line(c). 20 end. PROGRAM: SQL>set serveroutput on. 11 c:=0. 4 b number.FIBONACCI SERIES AIM: To write a PL/SQL program to generate Fibonacci series. 7 begin 8 n:=&n. OUTPUT: The fibonacci series 0 RESULT: Thus the above PL/SQL program is executed successfully. 1 1 2 3 . 18 dbms_output.

TABLE DESCRIPTION: SQL> desc trig1.TRIGGERS AIM: To write a PL/SQL program using triggers to do the following: a) Insert records to another table automatically b) Delete records in another table automatically c) Update records to another table automatically TABLE STRUCTURE: Table name :Trig1 Field name Roll no Name Mark1 Mark2 Data type Numeric Alphanumeric Numeric Numeric Size 3 15 3 3 TABLE CREATION: SQL> create table trig1 (rno number(3). Name Null? Type ------------------------.mark2 number(3)).name varchar2(15).---------------------------RNO NUMBER(3) NAME VARCHAR2(15) MARK1 NUMBER(3) MARK2 NUMBER(3) .mark1 number(3). Table created.-------.

Table created.name varchar2(15). 9 / Trigger created.rno. 8 end.--------.mark2 number(3)).mark2=:new.name.:new.mark1.--------------------------RNO NUMBER(3) NAME VARCHAR2(15) MARK1 NUMBER(3) MARK2 NUMBER(3) TRIGGER: SQL> create or replace trigger trig_in_up_del after insert or delete or update on trig1 for each row begin 2 if inserting then insert into trig2 values(:new. Data type Numeric Alphanumeric Numeric Numeric Size 3 15 3 3 .rno.Table name : trig2 Field name Roll no Name Mark1 Mark2 TABLE CREATION: SQL> create table trig2 (rno number(3).mark1. 5 else 6 update trig2 set mark1=:new. 7 end if.mark2.mark1 number(3). Name Null? Type -----------------------.mark2).:new.:new. TABLE DESCRIPTION: SQL> desc trig2. 3 elsif deleting then 4 delete from trig2 where rno=:old.

TABLE-RECORDS: SQL> select * from trig1.name. RNO NAME MARK1 MARK2 ------------------------------------------------1 suchi 8 89 2 sruthi 87 85 3 sen 98 97 SQL> select * from trig2.'&mark1'. RNO NAME MARK1 MARK2 -------------------------------------------------1 suchi 8 89 2 sruth 87 85 3 sen 98 97 .'&mark2').mark2) values ('&rno'.mark1.INPUT: Insertion: SQL> insert into trig1(rno. SQL> / Enter value for rno: 2 Enter value for name: sruthi Enter value for mark1: 87 Enter value for mark2: 85 1 row created.'&name'. Enter value for rno: 1 Enter value for name: suchi Enter value for mark1: 8 Enter value for mark2: 89 1 row created.

RNO NAME MARK1 MARK2 ----------------------------------------------2 sruthi 97 85 3 sen 98 97 SQL> select * from trig2. 1 row deleted.Deletion: SQL>delete from trig1 where rno = ‘1’. 1 row updated. RNO NAME MARK1 MARK2 ----------------------------------------------2 sruthi 87 85 3 sen 98 97 SQL> select * from trig2. RNO NAME MARK1 MARK2 ----------------------------------------------2 sruthi 87 85 3 sen 98 97 Updation: SQL>update trig1 set mark1= 97 where rno= 2. RNO NAME MARK1 MARK2 ----------------------------------------------2 sruthi 97 85 3 sen 98 97 . SQL> select * from trig1. SQL> select * from trig1.

.mark2=:new.:new.mark2 where rno=:old.mark2). UPDATION: SQL> create or replace trigger trig_up after update on trig1 for each row 2 begin 3 update trig2 set mark1=:new. 4 end.:new.ALTERNATIVE METHOD: INSERTION: SQL> create or replace trigger trig_ins after insert on trig1 for each row 2 begin 3 insert into trig2 values(:new. 5 / Trigger created. 4 end. 4 end.name.rno.:new.mark1.rno. RESULT: Thus the given PL/SQL program using triggers is created and executed successfully.rno. DELETION: SQL> create or replace trigger trig_del after delete on trig1 for each row 2 begin 3 delete from trig2 where rno=:old. 5 / Trigger created. 5 / Trigger created.mark1.

’4000’. Name --------------LOANNO AMOUNT BN Null? -------Type --------------------NUMBER(4) NUMBER(5) VARCHAR2(14) INSERTING RECORDS: SQL> insert into loan values( ‘111’. TABLE STRUCTURE: Field name Loan no Amount Branch name Data type Numeric Numeric Alphanumeric Size 4 5 14 TABLE CREATION: SQL> create table loan( loanno number(4). .TRIGGERS AIM: To write a PL/SQL program using triggers to restrict insert. TABLE DESCRIPTION: SQL> desc loan. delete and Update operation in a table.amount number(5). 1 row created.'mount road' ). Table created.bn varchar2(14) ).

7600.'anna salai'). 12 / Trigger created.TR_IN_UP_DE".'insertion is not possible').'chennai') * ERROR at line 1: ORA-20006: insertion is not possible ORA-06512: at "05MCA45.------------4000 mount road 5000 anna salai . 10 end if. LOANNO -------------111 222 TRIGGER: SQL> create or replace trigger tr_in_up_de after insert or delete 2 or update on loan 3 begin 4 if inserting then 5 raise_application_error(-20006.7600.TR_IN_UP_DE' AMOUNT BN -------------. line 3 ORA-04088: error during execution of trigger '05MCA45.'deletion is not possible'). 6 elsif deleting then 7 raise_application_error(-20007.'chennai'). 8 else 9 raise_application_error(-20008. OUTPUT: SQL> insert into loan values(555. 11 end.SQL> insert into loan values(‘222’.’5000’. 1 row created.'updation is not possible'). insert into loan values(555. SQL> select * from loan.

2. line 5 ORA-04088: error during execution of trigger '05MCA45. 5 / Trigger created. line 7 ORA-04088: error during execution of trigger '05MCA45. DELETION: SQL> create or replace trigger trig_de after delete on loan 2 begin 3 raise_application_error(-20002.TR_IN_UP_DE' SQL> delete from loan where loanno=111. INSERTION: SQL> create or replace trigger trig_in after insert on loan 2 begin 3 raise_application_error(-20001.'insertion is not possible'). 4 end.TR_IN_UP_DE".SQL> update loan set amount=5899 where loanno=111.TR_IN_UP_DE' ALTERNATIVE METHOD: 1.'deletion is not possible').TR_IN_UP_DE". delete from loan where loanno=111 * ERROR at line 1: ORA-20007: deletion is not possible ORA-06512: at "05MCA45. . 5 / Trigger created. 4 end. update loan set amount=5899 where loanno=111 * ERROR at line 1: ORA-20008: updation is not possible ORA-06512: at "05MCA45.

'updation is not possible'). . UPDATION: SQL> 1 create or replace trigger trig_updation after update on loan 2 begin 3 raise_application_error(-20005.3. 4 end. 5 / Trigger created. RESULT: Thus the given PL/SQL program using triggers is created and executed successfully.

---------------------------USERNAME VARCHAR2(15) SYSTEMDATE DATE ACTION VARCHAR2(10) .-------. Table created. systemdate date. login date and the action done by the user when logging-in Oracle. TABLE STRUCTURE: Field name User name System date Action Data type Alphanumeric Date Alphanumeric Size 15 10 TABLE CREATION: SQL> create table logs (username varchar2(15). TABLE DESCRIPTION: SQL> desc logs.TRIGGERS AIM: To write a PL/SQL program using triggers to insert the username. Name Null? Type -----------------------. action varchar2(10)).

4 end. OUTPUT: SQL> select * from logs. USERNAME SYSTEMDAT ACTION --------------------------------.TRIGGERS: SQL> create or replace trigger trig_login after logon on schema 2 begin 3 insert into logs logon values(user. .sysdate.'Login'). 5 / Trigger created.---------05MCA51 20-SEP-06 Login RESULT: Thus the given PL/SQL program using triggers is created and executed successfully.

action varchar2(15) ). TABLE DESCRIPTION: SQL> desc logoff. logdate date.TRIGGERS AIM: To write a PL/SQL program using triggers to insert the user name. login date and the action done by the user while logging out oracle. Table created. Name Null? Type -------------------------------------------------------------------USERNAME VARCHAR2(15) LOGDATE DATE ACTION VARCHAR2(15) . TABLE STRUCTURE: Field name User name System date Action Data type Alphanumeric Date Alphanumeric Size 15 15 TABLE CREATION: SQL> create table logoff ( username varchar2(15).

TRIGGERS: SQL> create or replace trigger tri_logoff before logoff on schema begin insert into logoff values(user.sysdate. end. USERNAME ---------------05MCA02 LOGDATE -------------25-SEP-06 ACTION -----------log off RESULT: Thus the given PL/SQL program using trigger is created and executed successfully.'log off'). . OUTPUT: SQL> select * from logoff. Trigger created.

TABLE STRUCTURE: FIELD NAME DATATYPE SIZE CONSTRAINTS Name Rollno Marks Alphanumeric Number Number 20 3 3 Notnull - TABLE CREATION:SQL> create table res(sname varchar2(20). Name Null? Type ----------------------------------------.-------. rn number(3).---------------------------SNAME VARCHAR2(20) RN NUMBER(3) MARKS NUMBER(3) . TABLE DESCRIPTION:SQL> desc res. marks number(3)). Table created.TRIGGERS AIM: To write a PL/SQL program using triggers to restrict any changes in the table on a particular day.

TRIG_RUST' RESULT: Thus the above table is created and the trigger is executed successfully.12.TRIG_RUST' DELETING RECORDS:SQL> delete from res where rn=1.TRIG_RUST' UPDATING RECORDS:SQL> update res set marks=marks+10. line 2 ORA-04088: error during execution of trigger '05MCA21. line 2 ORA-04088: error during execution of trigger '05MCA21. end if.TRIG_RUST".90) * ERROR at line 1: ORA-20012: Any changes to the table is NOT allowed ORA-06512: at "05MCA21. SQL> / Trigger created. INSERTING RECORDS: SQL> insert into res values('sri'.90). insert into res values('sri'.TRIG_RUST". update res set marks=marks+10 * ERROR at line 1: ORA-20012: Any changes to the table is NOT allowed ORA-06512: at "05MCA21.'Any changes to the table is not allowed’). end. line 2 ORA-04088: error during execution of trigger '05MCA21.12.'day'))='wednesday' then raise_application_error(-20012. delete from res where rn=1 * ERROR at line 1: ORA-20012: Any changes to the table is NOT allowed ORA-06512: at "05MCA21.TRIGGERS: SQL> create or replace trigger trig_rust after insert or delete or update on res begin if trim(to_char(sysdate.TRIG_RUST". .

TRIGGERS AIM: Create two tables with the following table structures and show the master-child relationship:i) Insert records into the child table automatically. Table structure-1: FIELD NAME Accno Street DATA TYPE SIZE CONSTRAIN TS Not null Alphanumeric 5 Alphanumeric Alphanumeric 14 14 Not null Not null City Table structure-2: FIELD NAME Accno Branch_name Branch_code DATA TYPE Alphanumeric Alphanumeric Alphanumeric SIZE 5 14 14 CONSTRAINTS Not null Not null Not null . ii) If any child record is deleted the corresponding record in master table should also be deleted automatically. iii) If any child record is updated the corresponding record in the master table should also be updated automatically.

Table created. TABLE DESCRIPTION: SQL> desc cus. Name ------------ACCNO STREET CITY Null? Type ------------. TABLE DESCRIPTION: SQL> desc account. branch_name varchar2(14). street varchar2(14). city varchar2(14) ). Table created. Name Null? -------------------------ACCNO BRANCH_NAME BRANCH_CODE Type ------------VARCHAR2(5) VARCHAR2(14) VARCHAR2(14) .---------------------NOT NULL VARCHAR2(5) VARCHAR2(14) VARCHAR2(14) TABLE CREATION: SQL> create table account(accno varchar2(5) constraints frk references cus(accno) on delete cascade.TABLE CREATION: SQL> create table cus ( accno varchar2(5) constraints prk primary key. branch_code varchar2(14)).

'chennai'). end. INSERTING RECORDS: SQL> insert into cus values('a123'.'nehru st'.Triggers [insertion to table 2]: SQL> create or replace trigger trig_i1 after insert on cus for each row begin insert into account values(:new. TABLE-RECORDS: SQL> select * from cus.'pondy'). ACCNO ----------a123 BRANCH_NAME ------------------------Mount road BRANCH_CODE ----------------------chennai DISABLE TRIGGERS: SQL> alter table cus disable all triggers.accno.'Mount road'. Table altered. SQL> / Trigger created. . 1 row created. ACCNO ----------a123 STREET -------------nehru st CITY -------------pondy SQL> select * from account.

Triggers [insertion to table 1]: SQL> create or replace trigger ti2 after insert on account for each row begin insert into cus values(:new.accno,'zigzag rd','delhi'); end; SQL> / Trigger created. INSERTING RECORDS: SQL> insert into account values('12','xyz','x222'); 1 row created. TABLE –RECORDS: SQL> select * from account; ACCNO ----------a123 12 BRANCH_NAME ------------------------Mount road xyz BRANCH_CODE ----------------------chennai x222

TABLE-RECORDS: SQL> select * from cus; ACCNO STREET ----------- -------------a123 nehru st 12 zigzag rd CITY ------------pondy delhi

Triggers [updation to table 2]: SQL> create or replace trigger tu1 after update on cus for each row begin update account set branch_name='hyd' where accno=:old.accno; end; SQL> / Trigger created.

UPDATING RECORDS: SQL> update cus set city='hyd' where accno='a123'; 1 row updated. TABLE-RECORDS : SQL> select * from cus; ACCNO STREET CITY ----------- -------------- -------------a123 nehru st hyd 12 zigzag rd delhi TABLE-RECORDS : SQL> select * from account; ACCNO ----------a123 12 BRANCH_NAME -----------------------hyd xyz BRANCH_CODE -----------------------chennai

Q

DISABLE TRIGGERS: SQL> alter table cus disable all triggers; Table altered. Triggers [updation to table 1]: SQL> create or replace trigger tu2 after update on account for each row begin update cus set street='jain st' where accno=:old.accno; end; SQL> / Trigger created.

UPDATING RECORDS: SQL> update account set branch_name='banglore' where accno='12'; 1 row updated. TABLE -RECORDS: SQL> select * from cus; ACCNO ----------a123 12 STREET CITY -------------- -------------nehru st hyd jain st delhi

TABLE -RECORDS: SQL> select * from account; ACCNO ----------a123 12 BRANCH_NAME BRANCH_CODE -------------------------- -----------------------hyd chennai banglore x222

DISABLE TRIGGERS: SQL> alter table cus disable all triggers; Table altered DISABLE FOREIGN KEY: SQL> alter table account disable constraints frk; Table altered. DISABLE PRIMARY KEY: SQL> alter table cus disable constraints prk; Table altered

-------------. 1 row created. end.accno. SQL> insert into account values('a345'. TABLE-RECORDS : SQL> select * from cus.Triggers [deletion from table 2]: SQL> create or replace trigger td1 after delete on cus for each row begin delete from account where accno=:old.'hyd').accno.-------------12 jain st delhi TABLE-RECORDS: SQL> select * from account. ACCNO STREET CITY ----------.'kgu st'.'b167'). 1 row created. 1 row deleted. . Triggers [deletion from table 1]: SQL> create or replace trigger td3 after delete on account for each row begin delete from cus where accno=:old.'vivek vihar'. SQL> / Trigger created. Trigger created. DELETING RECORDS: SQL> delete from cus where accno='a123'. end.------------------------banglore x222 INSERTING RECORDS: SQL> insert into cus values('a222'. ACCNO ----------12 BRANCH_NAME BRANCH_CODE -----------------------.

.DELETING RECORDS: SQL> delete from account where accno='12'.-------------------------vivek vihar b167 RESULT: Thus the above tables are created and the triggers are executed successfully. ACCNO -----------a222 STREET --------------kgu st CITY ------------hyd TABLE RECORDS: SQL> select * from account. ACCNO ----------a222 BRANCH_NAME BRANCH_CODE ------------------------. 1 row deleted. TABLE RECORDS: SQL> select * from cus.

percentage number(5. m1 number(3). TABLE CREATION : SQL> create table student(rollno varchar2(10) constraints pk11 primary key. m4 number(3). course varchar2(10). . result varchar2(10)).2). gend varchar2(7). m2 number(3).STUDENT MARKLIST MAINTENANCE AIM: To write a program to design the Student Mark list maintenance using Visual Basic-Oracle. tot number(3). m5 number(3). m3 number(3). dob date. name varchar2(20).

FORM DESIGN: .

Recordset Private Sub ADD_Click() Call txtclear rs.pwd=*****.MoveFirst rs.SetFocus End Sub Private Sub DELETE_Click() Dim Y Y = InputBox(RTrim(LTrim(" ENTER THE ROLL NUMBER TO BE DELETED "))) rs.Find ("rollno='" & Y & "'") If rs.EOF Then MsgBox (" NO SUCH RECORD ") Else Call dbtotxt rs.MoveFirst End Sub Private Sub Form_Load() cn.SetFocus End Sub Private Sub first_Click() Call dbtotxt rs. adOpenKeyset.") rs.DELETE End If End Sub Private Sub EDIT_Click() Text1.MoveLast End Sub .uid=05mca17. adLockOptimistic If rs.Connection Dim rs As New ADODB.Open ("select * from student").CODING: Dim cn As New ADODB.AddNew Text1.EOF And rs.Open ("dsn=kaja.BOF Then MsgBox " RECORD NOT FOUND " End If End Sub Private Sub last_Click() Call dbtotxt rs. cn.

EOF Then Call dbtotxt Else rs.Text = "" Text13.MovePrevious If Not rs.Show End Sub Private Sub SAVE_Click() Call txttodb rs.Text = "" Text6.Update MsgBox " SAVED SUCCESSFULLY " End Sub Public Sub txtclear() Text1.MoveLast End If End Sub Private Sub previous_Click() rs.Text = "" Text5.Text = "" Text10.Text = "" Text11.Text = "" Text2.Text = "" Text12.Text = "" Text3.Private Sub next_Click() rs.Text = "" Text7.Text = "" Text8.Text = "" .MoveFirst End If End Sub Private Sub QUIT_Click() End End Sub Private Sub REPORT_Click() DataReport1.Text = "" Text9.MoveNext If Not rs.EOF Then Call dbtotxt Else rs.Text = "" Text4.

Text rs.Text = rs.Text = rs.Fields(11) Text13.Text rs.Fields(7) Text9.Fields(1) = Text2.Fields(10) = Text11.Fields(9) = Text10.Fields(8) Text10.Text = rs.Text = rs.Text rs.Fields(0) Text2.Text rs.Text = rs.Text = rs.End Sub Public Sub txttodb() rs.Fields(6) Text8.Fields(0) = Text1.Text rs.Fields(11) = Text12.Text rs.MoveFirst rs.Text rs.Fields(3) = Text4.Text = rs.Fields(4) = Text5.Text rs.Fields(9) Text11.Find ("rollno= ' " & Y & "'") If rs.Text = rs.Fields(1) Text3.Text rs.Text = rs.Text rs.Fields(2) Text4.Fields(12) = Text13.Fields(12) End Sub Private Sub SEARCH_Click() Dim Y Y = InputBox(RTrim(LTrim(" ENTER THE ROLL NUMBER TO BE DELETED "))) rs.Text = rs.Fields(8) = Text9.Fields(7) = Text8.Fields(10) Text12.Text = rs.Fields(3) Text5.Text End Sub Public Sub dbtotxt() Text1.Fields(4) Text6.Text rs.Fields(2) = Text3.Fields(5) = Text6.EOF Then MsgBox (" NO SUCH RECORD ") Else Call dbtotxt End If End Sub .Fields(6) = Text7.Text rs.Text = rs.Text = rs.Fields(5) Text7.

Text = "FAIL" End If End Sub REPORT: RESULT: Thus the given program is executed successfully.Text) + Val(Text10. .Text = "PASS" Else Text13.Private Sub Text10_Change() Text11.Text) / 5 If (Val(Text6) >= 40 And Val(Text7) >= 40 And Val(Text8) >= 40 And Val(Text9) >= 40 And Val(Text10) >= 40) Then Text13.Text) + Val(Text9.Text) + Val(Text7.Text = Val(Text6.Text = Val(Text11.Text) + Val(Text8.Text) Text12.

custcity varchar2(10). Booking Details Table: SQL> create table gas ( custno number(4) constraints forg2 references gas(custno) on delete cascade. custname varchar2(14). TABLE CREATION : Customer Details Table: SQL> create table gas ( custno number(4) constraints pkg1 primary key. bookdate date. deldate date). amount number(3. Table created.2). custcity number(10)). custadd varchar2(14). Table created.GAS BOOKING SYSTEM AIM: To write a program to design the gas booking maintenance using Visual Basic-Oracle. .

FORM DESIGN: .

Show End Sub .Show End Sub Private Sub Cmdcustdetails_Click() Form2.Show End Sub Private Sub CMDEXIT_Click() End End Sub Private Sub cmdreport_Click() DataReport1.CODING: FORM 1: Private Sub cmdbookdetails_Click() Form3.

Find ("custno='" & z & "'") If rs1.Text rs1.Update MsgBox "record uupdated" End Sub Public Sub txttodb() rs1.EOF Then MsgBox "no such customer no.:"))) rs1.Text rs1.Delete End If Call txtoclear End Sub Private Sub CMDMAIN_Click() Form1.Show End Sub Private Sub CMDUPD_Click() Call txttodb rs1.SetFocus End Sub Private Sub CMDDEL_Click() Dim z z = InputBox(RTrim(LTrim("enter the cusotmer no.AddNew Text1.Text rs1.Connection Dim rs1 As New ADODB.Fields(2) = Text3.Fields(3) = Text4.Recordset Private Sub CMDADD_Click() Call txtoclear rs1.Fields(4) = Text5.FORM 2: Dim cn1 As New ADODB.Text rs1.Text End Sub ." Else Call dbtotxt rs1.MoveFirst rs1.Fields(0) = Text1.Fields(1) = Text2.

Text = "" End Sub .Fields(0) Text2.Open ("select * from gas").Text = rs1.Fields(2) Text4.uid=05mca02. : "))) rs1. cn1.Find ("custno='" & z & "'") If rs1. adLockOptimistic If rs1.Text = "" Text2.Text = rs1.Public Sub dbtotxt() Text1.Text = rs1. adOpenDynamic.") rs1." Else Call dbtotxt End If End Sub Private Sub Form_Load() cn1.Fields(4) End Sub Private Sub CMDVIEW_Click() Dim z z = InputBox(RTrim(LTrim("enter the customer no.Text = "" Text5.pwd=********.Text = "" Text3.BOF Then MsgBox "no record exists" End If End Sub Public Sub txtoclear() Text1.Open ("dsn=anudeep.MoveFirst rs1.Text = "" Text4.Text = rs1.Text = rs1.EOF Then MsgBox "no such customer no.Fields(1) Text3.EOF And rs1.Fields(3) Text5.

Show End Sub Private Sub CMDUPDATE1_Click() Call txttodb rs2.MoveFirst rs2.EOF Then MsgBox "no such customer no.Recordset Private Sub CMDADD1_Click() Call txtoclear rs2.:"))) rs2.Fields(0) = Text1." Else Call dbtotxt rs2.SetFocus End Sub Private Sub CMDDEL1_Click() Dim z z = InputBox(RTrim(LTrim("enter the cusotmer no.Fields(1) = Text2.Fields(2) = Text3.Text rs2.Text rs2.Text rs2.Update MsgBox "record uupdated" End Sub Public Sub txttodb() rs2.Connection Dim rs2 As New ADODB.Text End Sub .Fields(3) = Text4.AddNew Text1.FORM 3: Dim cn2 As New ADODB.Delete MsgBox "record deleted" End If Call txtoclear End Sub Private Sub cmdmain1_Click() Form1.Find ("custno='" & z & "'") If rs2.

") rs2. adLockOptimistic If rs2.Find ("custno='" & z & "'") If rs2.BOF Then MsgBox "no record exists" End If End Sub Public Sub txtoclear() Text1.MoveFirst rs2.Text = rs2.EOF And rs2.Public Sub dbtotxt() Text1.Text = "" Text3.Text = "" Text4.Fields(1) Text3.Fields(2) Text4.Text = rs2.Text = "" End Sub .pwd=*******.Fields(3) End Sub Private Sub CMDVIEW1_Click() Dim z z = InputBox(RTrim(LTrim("enter the customer no. adOpenDynamic.Fields(0) Text2. cn2.Text = rs2.Open ("select * from gas1").Open ("dsn=anudeep." Else Call dbtotxt End If End Sub Private Sub Form_Load() cn2.Text = "" Text2.uid=05mca02.Text = rs2.EOF Then MsgBox "no such customer no. : "))) rs2.

.REPORT: RESULT: Thus the given program is executed successfully.

min_bala. Trigger created. TABLE CREATION: SQL> create table tt(accno varchar2(4).sysdate). Trigger created.dat date).min_bala where accno=:old. Trigger created. SQL> create or replace trigger trig_u22 after insert or update on tt for each row begin insert into trans2 values(:new.accno.accno. Table created.accno.min_bala number(4). Table created. TRIGGERS: SQL> create or replace trigger trig_del11 after delete on tt for each row begin delete from trans1 where accno=:old.:new. Table created.min_bala number(4)). . end. SQL> create table trans1(accno varchar2(4).BANK TRANSACTION SYSTEM AIM: To write a program to design a bank transaction system using Visual BasicOracle.min_bala number(4)). SQL> create table trans2(accno varchar2(4). end. end. SQL> create or replace trigger trig_up11 after update on tt for each row begin update trans1 set min_bala=:new.

FORM DESIGN: .

.

Text) = "admin" Or Trim(Text1.Hide Else MsgBox "invalid user id and pwd". vbExclamation End If i=i+1 Else MsgBox "invalied access to login".CODING: FORM -1 Dim i As Integer Private Sub Command1_Click() If i < 3 Then If Trim(Text1.Show Form1.Text) = "MCA" Or Trim(Text2.Text) = "ADMIN" And Trim(Text2.Hide End Sub . vbCritical End End If End Sub Private Sub Command2_Click() Form3.Text) = "mca" Then Form2.Show Form1.

Text & "'.Execute "insert into trans1(accno.Find "accno='" & a & "'" If rs.Show End Sub .Refresh DataReport1.MoveFirst rs.Recordset Private Sub Command1_Click() cn.min_bala) values('" & Text1.Execute "delete from tt where accno='" & a & "'" MsgBox "record deleted" End If End Sub Private Sub Command4_Click() End End Sub Private Sub Command5_Click() Form2.Text & "'. '" & Text2.Text & "')" MsgBox "Record is inserted". vbDefaultButton4 End Sub Private Sub Command3_Click() Dim a a = InputBox(LTrim(RTrim("enter the acc no to be deleted"))) rs.FORM-2 Dim cn As New ADODB. '" & Text2.Text & "')" cn.Connection Dim rs As New ADODB.EOF Then MsgBox "invalid acc no" Else cn.Execute "insert into tt values('" & Text1.Show Form1.Recordset Dim rs1 As New ADODB.Hide End Sub Private Sub Command6_Click() DataReport1.

adOpenDynamic. cn.EOF Then MsgBox "Invalid account no".Enabled = True Text1.Enabled = False End If End Sub Private Sub Command2_Click() End End Sub Private Sub Form_Load() cn.pwd=******. vbApplicationModal Else Frame1.Text & "'" If rs.Enabled = False End Sub Private Sub Option1_Click() Form4. adLockOptimistic If rs. cn.EOF And rs.MoveFirst rs." rs.Find "accno='" & Text1.uid=05mca21.uid=05mca21.Open "dsn=usha." rs.Show Form3. cn.BOF Then MsgBox "no records" End If Frame1.Recordset Private Sub Command1_Click() rs. adOpenDynamic. adOpenDynamic. adLockOptimistic rs1.EOF And rs.Connection Dim rs As New ADODB.Open "select * from tt".Private Sub Form_Load() cn.BOF Then MsgBox "no records" End If End Sub FORM-3 Dim cn As New ADODB.Open "select * from tt". adLockOptimistic If rs.Open "dsn=usha.pwd=******.Hide End Sub .Open "select * from trans1".

Private Sub Option2_Click() Form5.MoveFirst X = LTrim(RTrim(Text1." & rs.Enabled = True Dim a a = InputBox(LTrim(RTrim("enter the acc no="))) rs.Fields(0) End If End Sub .Execute "update tt set min_bala='" & amt & "' where accno='" & X & "'" Label3.EOF Then MsgBox "invalid acc no" Else Y = Val(Text2.Recordset Private Sub Command1_Click() Dim X.Text)) rs.Text) amt = rs.Fields(1) .Connection Dim rs As New ADODB.Find "accno='" & a & "'" If rs.Hide End Sub Private Sub Command3_Click() Frame2. Y.MoveFirst rs.Show Form4. amt As Integer rs.Find "accno='" & X & "'" If rs.Show Form3.Caption = amt MsgBox "record upt" End If End Sub Private Sub Command2_Click() Form3.Hide End Sub FORM-4 Dim cn As New ADODB.Y cn.Caption = "Rs.Fields(1) Label4.EOF Then MsgBox "no such account no". vbCritical Else Label3.Caption = rs.

Hide End Sub .Caption = amt MsgBox "record upt" End If 'Dim x.BOF Then MsgBox "no records" End If Frame2.Enabled = False End Sub FORM-5 Dim cn As New ADODB.Open "dsn=usha.Text) 'acc = rs. cn. amt rs.MoveFirst X = LTrim(RTrim(Text1.Private Sub Form_Load() cn.Recordset Private Sub Command1_Click() Dim X.EOF Then MsgBox "invalid acc no" Else Y = Val(Text2. adLockOptimistic If rs.Text) amt = rs.Fields(1) + Y cn.Connection Dim rs As New ADODB.Execute "update tt set bal='" & amt & "' where accno='" & acc & "'" 'MsgBox "record upt" End Sub Private Sub Command2_Click() Form3. acc. adOpenDynamic.Text)) rs.Open "select * from tt".Show Form5.EOF And rs.Find "accno='" & X & "'" If rs." rs.Fields(1) . Y.pwd=******.Fields(0) 'amt = rs.x 'cn.Execute "update tt set min_bala='" & amt & "' where accno='" & X & "'" Label4.uid=05mca21. amt 'x = Val(Text1.

Enabled = False End Sub REPORT: RESULT: Thus the given program is executed successfully." & rs.Open "dsn=usha.Caption = "Rs.MoveFirst rs.uid=05mca21.Enabled = True Dim a a = InputBox(LTrim(RTrim("enter the acc no="))) rs.Fields(0) End If End Sub Private Sub Form_Load() cn. vbCritical Else Label4.Find "accno='" & a & "'" If rs.Open "select * from tt". . adLockOptimistic If rs. adOpenDynamic.BOF Then MsgBox "no records" End If Frame2.EOF Then MsgBox "no such account no".pwd=******.Private Sub Command3_Click() Frame2.Caption = rs." rs.Fields(1) Label6.EOF And rs. cn.

'&dept'.marks.&marks.dept.name.marks.'&name'.'ee'.total)values(&rollno.marks number(3).67.name varchar2(15).'&dept'.&tota new 1: insert into stue21(rollno.total number(3)).total)values(2.total)values(&rollno.&total).78) 1 row created. TABLE INSERTION: SQL> insert into stue21(rollno. SQL> / Enter value for rollno: 2 Enter value for name: bbb Enter value for dept: eee Enter value for marks: 56 Enter value for total: 67 old 1: insert into stue21(rollno.marks.dept.&marks.name.total)values(1.'&dept'.dept.'aaa'.'&name'.CURSORS AIM: Create a PL/SQL block that deletes students records whose department is EEE and display the number of records deleted and the remaining number of records.dept.'bbb'.dept varchar2(14).total)values(&rollno.&tota new 1: insert into stue21(rollno.marks.name.name.'eee'.67) 1 row created. Table created.marks.name. TABLE CREATION: SQL> create table stue21(rollno number(3). .&marks.'&name'.dept.56. Enter value for rollno: 1 Enter value for name: aaa Enter value for dept: ee Enter value for marks: 67 Enter value for total: 78 old 1: insert into stue21(rollno.

name.67) 1 row created.'ddd'. ROLLNO NAME ------------.dept.'&dept'. SQL> / Enter value for rollno: 4 Enter value for name: ddd Enter value for dept: cse Enter value for marks: 56 Enter value for total: 67 old 1: insert into stue21(rollno.dept.name.name.total)values(3.marks.&tota new 1: insert into stue21(rollno.marks.marks.'eee'.'ccc'.dept.'it'.dept.name. TABLE-RECORDS: SQL> select * from stue21.total)values(5.'&dept'.'ece'.total)values(&rollno.89) 1 row created.name.name.78.total)values(&rollno.'cse'.89) 1 row created.'&name'.'&dept'.------------.'&name'.------------1 aaa 2 bbb 3 ccc 4 ddd 5 eee DEPT MARKS TOTAL -----------.---------ee 67 78 eee 56 67 ece 78 89 cse 56 67 it 78 89 . SQL> / Enter value for rollno: 5 Enter value for name: eee Enter value for dept: it Enter value for marks: 78 Enter value for total: 89 old 1: insert into stue21(rollno.56.'&name'.dept.total)values(&rollno.marks.&tota new 1: insert into stue21(rollno.&marks.marks.dept.&tota new 1: insert into stue21(rollno.78.&marks.marks.&marks.SQL> / Enter value for rollno: 3 Enter value for name: ccc Enter value for dept: ece Enter value for marks: 78 Enter value for total: 89 old 1: insert into stue21(rollno.total)values(4.

18 commit 19 end. 14 end loop.putline('Deleted Records'||n). ROLLNO NAME ------------. 16 dbms_output. 3 a%rowtype.putline('Remaining Records'||(c%rowcount-n)). 20 / deleted records 1 Remaining records 4 SQL> select * from stue21. . 17 close c.------------. 9 exit when c% notfound. 15 dbms_output. 5 begin 6 open c.dept='EEE' then 11 delete from student where dept='EEE'. 10 if a. 12 n:=n+1. 13 endif.CODING: SQL> declare 2 cursor c is select * from studente21. 7 loop 8 fetch c into a.---------ee 67 78 ece 78 89 cse 56 67 it 78 89 RESULT: Thus. the above PL/SQL program using cursors is executed successfully.------------1 aaa 3 ccc 4 ddd 5 eee DEPT MARKS TOTAL -----------. 4 n number:=0.

CURSORS AIM: Create a PL/SQL block to determine the top 5 scores from the student table and to insert these records into a new table.name.dept varchar2(10). Table created. TABLE CREATION: SQL> create table stuee21(rollno number(3).'xxx'. SQL> create table tempee22(rollno number(3).78) 1 row created.'&dept'.'ece'.name.total number(3)).'&dept'.total)values(&rollno.name varchar2(15).dept.dept varchar2(14).name.'aaa'. Table created.dept. SQL> / Enter value for rollno: 2 Enter value for name: xxx Enter value for dept: ece Enter value for total: 89 old 1: insert into stuee21(rollno.name varchar2(14).&total) Enter value for rollno: 1 Enter value for name: aaa Enter value for dept: eee Enter value for total: 78 old 1: insert into stuee21(rollno.name.total)values(2.total)values(1.'&name'.total)values(&rollno. .dept.'&dept'.89) 1 row created.total number(3)).name.dept.'eee'.&total) new 1: insert into stuee21(rollno.'&name'.'&name'.total)values(&rollno.&total) new 1: insert into stuee21(rollno.dept. TABLE INSERTION: SQL> insert into stuee21(rollno.

name.SQL> / Enter value for rollno: 3 Enter value for name: ddd Enter value for dept: it Enter value for total: 98 old 1: insert into stuee21(rollno.'&name'.'&dept'.'&name'.&total) new 1: insert into stuee21(rollno.dept. SQL> / Enter value for rollno: 4 Enter value for name: rrr Enter value for dept: mca Enter value for total: 99 old 1: insert into stuee21(rollno.dept.&total) new 1: insert into stuee21(rollno.'&dept'.'ddd'.'&name'.name. ROLLNO ---------------1 2 3 4 5 NAME ---------aaa xxx ddd rrr fff DEPT TOTAL ----------.'&dept'.'rrr'.dept. SQL> / Enter value for rollno: 5 Enter value for name: fff Enter value for dept: cse Enter value for total: 67 old 1: insert into stuee21(rollno.total)values(3.name.total)values(5.name.--------------eee 78 ece 89 it 98 mca 99 cse 67 .&total) new 1: insert into stuee21(rollno.dept.total)values(4.dept.67) 1 row created.99) 1 row created.'mca'.'cse'.total)values(&rollno.name.dept.98) 1 row created. TABLE-RECORDS: SQL> select * from stuee21.name.total)values(&rollno.'it'.total)values(&rollno.'fff'.

12 close c.dept. 10 insert into tempee22 values(a. 11 end loop.-------------4 rrr mca 99 3 ddd it 98 2 xxx ece 89 1 aaa eee 78 5 fff cse 67 RESULT: Thus. SQL> declare 2 cursor c is select * from stuee21 order by total desc. the above PL/SQL program using cursors is executed successfully.----------. 4 n number:=0. 7 loop 8 fetch c into a.name. . 5 begin 6 open c. 14 end.CODING: SQL> set serveroutput on. DISPLAY TABLE: SQL> select * from tempee22. 13 commit. 9 exit when c%notfound or c%rowcount>5.-------------.a.a. ROLLNO NAME DEPT TOTAL -------------.total).rollno. 15 / PL/SQL procedure successfully completed. 3 a stuee21%rowtype.a.

&m3).dept varchar2(15).m1 number(3). Table created.total number(3).name.name varchar2(15).&m1.'&name'. Name Null? Type ---------------------------------------------------------ROLLNO NUMBER(3) NAME VARCHAR2(15) M1 NUMBER(3) M2 NUMBER(3) M3 NUMBER(3) TOTAL NUMBER(3) GRADE VARCHAR2(2) INSERTING RECORDS: SQL> insert into stue23(rollno.m2 number (3). .grade varchar2(2)).m3)values(&rollno. Enter value for rollno: 1 Enter value for name: aaa Enter value for dept: eee Enter value for m1: 78 Enter value for m2: 77 Enter value for m3: 75 1 row created. TABLE DESCRIPTION: SQL> desc stue23. TABLE CREATION: SQL> create table stue23(rollno number(3).PROCEDURE AIM: Create a procedure to insert the total grade values into the student table.dept.&m2.m1.m2.'&dept'.m3 number(3).

SQL> / Enter value for rollno: 2 Enter value for name: bbb Enter value for dept: ece Enter value for m1: 56 Enter value for m2: 67 Enter value for m3: 78 1 row created. . SQL> / Enter value for rollno: 4 Enter value for name: ddd Enter value for dept: cse Enter value for m1: 78 Enter value for m2: 89 Enter value for m3: 98 1 row created. SQL> / Enter value for rollno: 3 Enter value for name: ccc Enter value for dept: it Enter value for m1: 89 Enter value for m2: 98 Enter value for m3: 87 1 row created. SQL> / Enter value for rollno: 5 Enter value for name: eee Enter value for dept: bme Enter value for m1: 78 Enter value for m2: 85 Enter value for m3: 64 1 row created.

----. .name. PL/SQL procedure successfully completed. OR execute p1.m3. 18 commit. 9 exit when c%notfound. 19 close c. 15 end if.RECORDS: SQL> select * from stue23.m3 from stue23. 20* end.-----1 aaa eee 78 77 75 2 bbb ece 56 67 78 3 ccc it 89 98 87 4 ddd cse 78 89 98 5 eee bme 78 85 64 CODING: SQL> create or replace procedure p1 is cursor c is select rollno.rollno. 3 tot number. 11 if a.----.m1+a.----.m2.m3>50 then 12 g:='A'. 17 end loop. 2 a c%rowtype.grade=g where rollno=a.m2+a.----------.-------.m1. 4 g char. 16 update stue23 set total=tot.TABLE . 13 else 14 g:='F'.m2>50 and a. SQL> exec p1. SQL> / Procedure created. 7 loop 8 fetch c into a. 5 begin 6 open c.m1>50 and a. ROLLNO NAME DEPT M1 M2 M3 TOTAL GR -----------. 10 tot:=a.---------.

the above procedure inserts the total grade values into the student table using procedures successfully.TABLE-RECORDS: SQL> select * from stue23. ROLLNO NAME DEPT M1 M2 M3 TOTAL GR ------------------------------------------------------------------------1 aaa eee 78 77 75 230 A 2 bbb ece 56 67 78 201 A 3 ccc it 89 98 87 274 A 4 ddd cse 78 89 98 265 A 5 eee bme 78 85 64 227 A RESULT: Thus. .