EX.

NO: 1 DATE: DATA DEFINITONS LANGUAGE COMMANDS

Aim:
To learn about Data Definition, Table Creation, Constraints Commands (Create, Alter, Drop and Rename) in SQL. Create the following table and execute the following queries.

Table: EmpDetails

COLUMN NAME DATA TYPE(SIZE) EMPNO ENAME JOB MGR HIREDATE DEPTNO Number (5) Varchar2(15) Char(10) Number (5) Date Number(3)

QUESTIONS: 1. Create a new table new_Emp from already existing table EmpDetails. 2. Create a new table new_Emp1 with some of the fields of existing table EmpDetails. 3. Add address and contactno column in the table new_Emp. 4. Modify size of the address column from 20 to 50 in the table new_Emp. 5. Drop hiredate column in the table new_Emp.
Page 1 of 61

6. Add primary key constraint for the field ENAME in the table new_Emp. 7. Drop primary key constraint of the field ENAME in the table new_Emp. 8. Rename the table name new_Emp into new_Emp2. 9. Drop the table new_Emp1.

SQL QUERIES: TABLE CREATION Syntax: CREATE TABLE tablename (column_name data_ type constraints, …);
SQL> CREATE TABLE EmpDetails ( EmpNo Number(5) CONSTRAINT PKey PRIMARY KEY, EName VarChar(15), Job Char(10) CONSTRAINT Unik1 UNIQUE, Mgr Number(5) CONSTRAINT FKey1 REFERENCES EMP (EmpNo), Hiredate Date, DeptNo Number(3) CONSTRAINT FKey2 REFERENCES DEPT(DeptNo)); SQL> desc EmpDetails; Name -------------------EMPNO ENAME JOB MGR HIREDATE DEPTNO Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) DATE NUMBER (3)

CREATE TABLE FROM AN EXISTING TABLE
Page 2 of 61

Syntax: Create table newtablename as select * from oldtablename;

SQL> create table new_Emp as select * from EmpDetails; Table created. SQL> desc new_Emp; Name -------------------EMPNO ENAME JOB MGR HIREDATE DEPTNO Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) DATE NUMBER (3)

SQL> create table new_Emp1 as select empno, ename, job, deptno from EmpDetails; Table created.

SQL> desc new_Emp1; Name -------------------EMPNO ENAME JOB DEPTNO Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (3)

ALTER TABLE
Page 3 of 61

ADD COLUMN(S) Before adding columns in new_Emp table SQL> desc new_Emp. Name -------------------EMPNO ENAME JOB Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) Page 4 of 61 . …). Contactno number (11)). Table altered.ALTER COLUMNS Syntax: Alter table tablename Add / Modify / Drop (column_name data_ type constraints. Name -------------------EMPNO ENAME JOB MGR HIREDATE DEPTNO Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) DATE NUMBER (3) SQL> alter table new_Emp add (Address varchar2 (20). After adding address and contactno columns in new_Emp table SQL> desc new_Emp.

Table altered. Name -------------------EMPNO Null? -------------NOT NULL Type ---------------------NUMBER (5) Page 5 of 61 . After modifying address columns in new_Emp table SQL> desc new_Emp.MGR HIREDATE DEPTNO ADDRESS CONTACTNO NUMBER (5) DATE NUMBER (3) VARCHAR2 (20) NUMBER (11) MODIFY COLUMN(S) Before modifying columns in new_Emp table SQL> desc new_Emp. Name -------------------EMPNO ENAME JOB MGR HIREDATE DEPTNO ADDRESS CONTACTNO Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) DATE NUMBER (3) VARCHAR2 (20) NUMBER (11) SQL> alter table new_Emp modify(address varchar2(50)).

Name Null? Type Page 6 of 61 .ENAME JOB MGR HIREDATE DEPTNO ADDRESS CONTACTNO VARCHAR2 (15) CHAR (10) NUMBER (5) DATE NUMBER (3) VARCHAR2 (50) NUMBER (11) DROP COLUMN(S) Before droping columns in new_Emp table SQL> desc new_Emp. Name -------------------EMPNO ENAME JOB MGR HIREDATE DEPTNO ADDRESS CONTACTNO Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) DATE NUMBER (3) VARCHAR2 (50) NUMBER (11) SQL> alter table new_Emp drop(hiredate). Table altered. After droping hiredate columns in new_Emp table SQL> desc new_Emp.

Name -------------------EMPNO ENAME JOB MGR DEPTNO ADDRESS CONTACTNO Null? -------------NOT NULL Type ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) NUMBER (3) VARCHAR2 (50) NUMBER (11) Page 7 of 61 .-------------------EMPNO ENAME JOB MGR DEPTNO ADDRESS CONTACTNO -------------NOT NULL ---------------------NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) NUMBER (3) VARCHAR2 (50) NUMBER (11) ALTER CONSTRAINT(S) Syntax: Alter table tablename add / Modify / Drop (constraint constraintname [constrainttype] [(column name)]). ADD CONSTRAINT(S) Before adding constraint in new_Emp table SQL> desc new_Emp.

---------------------NOT NULL NOT NULL NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) NUMBER (3) VARCHAR2 (50) NUMBER (11) DROP CONSTRAINTS Before dropping constraint in new_Emp table SQL> desc new_Emp. Table altered.SQL> alter table new_Emp add(constraint p_key primary key (ename)). Name -------------------EMPNO ENAME JOB MGR DEPTNO ADDRESS CONTACTNO Null? Type -------------. Name -------------------EMPNO ENAME JOB MGR DEPTNO Null? Type -------------. After adding constraint in new_Emp table SQL> desc new_Emp.---------------------NOT NULL NOT NULL NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) NUMBER (3) Page 8 of 61 .

ADDRESS CONTACTNO VARCHAR2 (50) NUMBER (11) SQL> alter table new_Emp drop constraint p_key. Table altered. Page 9 of 61 .---------------------NOT NULL NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) NUMBER (3) VARCHAR2 (50) NUMBER (11) RENAME TABLE SYNTAX: Alter table oldtablename rename to newtablename. After adding constraint in new_Emp table SQL> desc new_Emp. Name -------------------EMPNO ENAME JOB MGR DEPTNO ADDRESS CONTACTNO Null? Type -------------.

SQL> drop table new_Emp1. Table dropped. ERROR: ORA-04043: object new_Emp1 does not exist SQL> select * from tab.DROP TABLE Syntax: Drop table tablename. TNAME TABTYPE CLUSTERID -----------------------------.------------.---------------MARKLIST NEW_STAFF1 PRIYA S EMPDETAILS TABLE TABLE TABLE TABLE TABLE Page 10 of 61 . SQL> desc new_Emp1.

Result: Thus the basic Data Definition Commands are executed and verified successfully. Page 11 of 61 .

NO:2 DATE: DML COMMANDS Aim: To learn about basic Data Manipulation Commands (Insert.----------------- . Update. Table: EmpDetails COLUMN NAME DATA TYPE(SIZE) EMPNO ENAME JOB MGR DEPTNO ADDRESS CONTACTNO Number (5) Varchar2(15) Char(10) Number (5) Number(3) Varchar2(50) Number(10) Insert the following records in the EmpDetails: EMPNO ENAME CONTACTNO ------------------JOB ---------MGR DEPTNO ADDRESS -------. insert some rows of information and execute the following queries. Delete and Select).EX. Create the following table.----------Page 12 of 61 -------------.

Count the no. of distinct department in the EmpDetails. Select empno. Update employee number as 1000 of the employee 10001 in the table EmpDetails. 11.1001 10001 1002 Saran ram viji PA manager PAT 1000 99 1000 101 101 101 SALEM chennai bangalore 9955248792 9988765643 9977678768 QUESTIONS: 1. 9. 12. of employees in the EmpDetails. Select empno. Select all the details of the employee whose employee number is greater then 1002 order by address is ascending and employee name in descending in the table EmpDetails. Delete employee details who are all resides at Bangalore in the table EmpDetails. 5. Count the no. Update job as MANAGER of the employee 1000 in the table EmpDetails. 7. deptno who are all resides at Salem in the table EmpDetails. Page 13 of 61 . 4. Select employee details such as empno. 10. 8. Count the no. 2. Select all the details of the employee whose employee name has ‘a’ in the table EmpDetails. 13. 6. Select all the details of the employee whose employee name is starts with‘s’ in the table EmpDetails. ename of the employee whose employee number between 1000 and 1002 in the table EmpDetails. Select empno. ename. 3. ename of the employee whose employee number is greater then 1002 order by employee name in descending in the table EmpDetails. of employees based on address in the EmpDetails. ename of the employee whose address is Chennai or Bangalore in the table EmpDetails.

'&ename'.INSERT COMMAND Syntax: SQL> INSERT INTO tablename (columnname1. value2 …). job. 'PA'. 'Saran '. &contactno). &fieldname2 …. mgr. '&address'. '&job'.). 1000. 9955248792). &deptno.. 101. SQL> INSERT INTO tablename values(&fieldname1. contactno) values(1001. SQL> insert into empdetails (empno. &mgr. ename. columnname2 …) VALUES (value1. address. Enter value for empno: 10001 Enter value for ename: ram Enter value for job: manager Enter value for mgr: 99 Enter value for deptno: 101 Enter value for address: chennai Enter value for contactno: 9988765643 Page 14 of 61 . deptno. 1 row created. SQL> / Enter value for column1: value1 Enter value for column2: value2 …. SQL> insert into empdetails values(&empno. 'SALEM'.

'&ename'. 1000. &deptno. &mgr. 'ram'. 101. SQL> / Enter value for empno: 1002 Enter value for ename: viji Enter value for job: PAT Enter value for mgr: 1000 Enter value for deptno: 101 Enter value for address: bangalore Enter value for contactno: 9977678768 old 1: insert into empdetails values(&empno. &contactno) new 1: insert into empdetails values(10001. 'PAT'. 99. '&job'. 'bangalore'. 'viji'. '&address'. '&job'. Page 15 of 61 . &mgr. 'chennai'.old 1: insert into empdetails values(&empno. &contactno) new 1: insert into empdetails values(1002. 101. SQL> select * from empdetails. '&ename'. &deptno. 9977678768) 1 row created. 9988765643) 1 row created. '&address'. 'manager'.

EMPNO ENAME CONTACTNO ---------1001 10001 1002 SQL>commit. EMPNO ENAME CONTACTNO ---------1001 1000 ---------Saran ram JOB ---------PA manager MGR DEPTNO ADDRESS -------.----------1000 99 1000 101 101 101 -------------.----------------SALEM chennai 9955248792 9988765643 Page 16 of 61 . 1 row updated.----------------SALEM chennai bangalore 9955248792 9988765643 9977678768 UPDATE COMMAND Syntax: SQL> update table_name set col_name1=value where predicates. ---------Saran ram viji JOB ---------PA manager PAT MGR DEPTNO ADDRESS -------. SQL> select * from empdetails. Commit complete.----------1000 99 101 101 -------------. SQL> update empdetails set empno=1000 where empno =10001.

----------1000 99 1000 101 101 101 -------------. Page 17 of 61 .----------------SALEM chennai bangalore 9955248792 9988765643 9977678768 DELETE COMMAND Syntax: DELETE FROM table_name where predicates. SQL> select * from empdetails.1002 viji PAT 1000 101 bangalore 9977678768 SQL> update e empdetails set job=’&job’ where empno=&empno. SQL> select * from empdetails. EMPNO ENAME CONTACTNO ---------1001 1000 1002 ---------Saran ram viji JOB ---------PA MANAGER PAT MGR DEPTNO ADDRESS -------. Enter value for job: MANAGER Enter value for empno: 1000 old 1: update emp_demo set job=’&job’ where empno=1000 new 1: update emp_demo set job=MANAGER where empno =102 1 row updated.

SQL> select * from empdetails.----------1000 99 101 101 -------------. Page 18 of 61 .----------1000 99 1000 101 101 101 -------------. EMPNO ENAME CONTACTNO ---------1001 1000 ---------Saran ram JOB ---------PA MANAGER MGR DEPTNO ADDRESS -------.----------------SALEM chennai 9955248792 9988765643 SELECT COMMAND Syntax: SELECT columns FROM tables WHERE predicates. 1 row deleted.----------------SALEM chennai bangalore 9955248792 9988765643 9977678768 SQL> delete from empdetails where address=’bangalore’.EMPNO ENAME CONTACTNO ---------1001 1000 1002 ---------Saran ram viji JOB ---------PA MANAGER PAT MGR DEPTNO ADDRESS -------.

ename.----------------SALEM 9955248792 9988765643 Chennai Bangolore 9870984353 9790865432 Chennai SQL> select empno. EMPNO ---------1001 ENAME ---------Saran DEPTNO ----------101 SQL> select empno.----------1000 1000 1000 101 101 101 1000 101 -------------. Page 19 of 61 .SQL> select * from empdetails. EMPNO ---------1001 1000 1002 ENAME ---------Saran ram Arun SQL> select empno. Bangalore). deptno from empdetails where address=’SALEM’. ename from empdetails where empno between 1000 and 1002. ename from empdetails where address in (Chennai. EMPNO ENAME CONTACTNO ---------1001 1000 1002 1003 ---------Saran ram Arun Sudha JOB ---------PA MANAGER PAT Admin MGR DEPTNO ADDRESS -------.

ename from empdetails where empno>=1002 order by ename desc. EMPNO ENAME CONTACTNO JOB MGR Page 20 of 61 DEPTNO ADDRESS . EMPNO ---------1001 1000 1002 ENAME ---------Saran ram Arun SQL>select * from empdetails where empno>=1003 order by address desc.EMPNO ---------1000 1002 1003 ENAME ---------ram Arun Sudha ORDERBY CLAUSE Syntax: SELECT columns FROM tables WHERE predicates order by columns asc or desc. SQL> select empno. ename asc.

----------------SALEM 9955248792 9988765643 9790865432 Chennai Chennai Bangolore 9870984353 LIKE OPERATOR Syntax: SELECT columns FROM tables WHERE predicates like pattern. EMPNO ENAME CONTACTNO JOB MGR Page 21 of 61 DEPTNO ADDRESS . SQL> select * from empdetails where ename like 's%'.----------1000 101 1000 101 -------------.----------------SALEM 9955248792 9790865432 Chennai SQL> select * from empdetails where ename like '%a_'.---------1001 1000 1003 1002 ---------Saran ram Sudha Arun ---------PA MANAGER Admin PAT -------. EMPNO ENAME CONTACTNO ---------1001 1003 ---------Saran Sudha JOB ---------PA Admin MGR DEPTNO ADDRESS -------.----------1000 1000 101 101 1000 1000 101 101 -------------.

COUNT(ENAME) -----------------------4 SQL>select count(distinct deptno) from empdetails. COUNT(DISTINCTDEPTNO) -------------------------------1 Syntax: SQL> select column_name.count(ename) from empdetails group by address. ADDRESS COUNT(ENAME) -----------------------------------Page 22 of 61 .----------------SALEM 9955248792 9988765643 Chennai AGGREGATE FUNCTION COUNT Syntax: SQL> select count(column_name) from table_name.---------1001 1000 ---------Saran ram ---------PA MANAGER -------.----------1000 1000 101 101 -------------. count(column_name) from table_name group by column_name. SQL> select count(ename) from empdetails. SQL> select address.

Ex.SALEM Chennai Bangalore 1 2 1 Result: Thus the basic DML and DCL are executed and verified successfully.No: 3 DATE: NESTED QUERIES AND JOIN QUERIES Page 23 of 61 .

Aim: To learn about nested queries and join queries. Create the following tables and execute the following queries. Table: DeptDetails DATA TYPE(SIZE) COLUMN NAME DEPTNO DNAME DLOCATION MGR Number(3) Varchar2(20) Varchar2(30) Number (5) DEPTNO ----------100 101 102 DNAME ------------- DLOCATION ----------------99 1000 1001 MGR --------- Healthcare Chennai Manlog IME Delhi Bangalore Table: EmpDetails COLUMN NAME DATA TYPE(SIZE) EMPNO Number (5) Page 24 of 61 .

deptno. Select Deptno and Dname of managers who are residing in the same city of their department location. 3. NESTED QUERIES SQL> Select * from deptdetails. DEPTNO DNAME DLOCATION MGR Page 25 of 61 . Select empno. Select all the employee details who are residing in the same city of their department location.dlocation of the all employees.----------1000 1000 1000 100 100 100 1000 100 -------------.----------------SALEM 9955248792 9988765643 Chennai Bangolore 9870984353 9790865432 Chennai QUESTIONS: 1. 4.ENAME JOB MGR DEPTNO ADDRESS CONTACTNO EMPNO ENAME CONTACTNO ---------1001 1000 1002 1003 ---------Saran ram Arun Sudha JOB ---------PA MANAGER PAT Admin MGR Varchar2(15) Char(10) Number (5) Number(3) Varchar2(50) Number(10) DEPTNO ADDRESS -------. 2. ename. Select all the employee details whose job is not ‘PA’ and employee name is not end with ‘n’.

----------1000 1000 1000 100 100 100 1000 100 -------------.deptno).----------100 101 102 ------------- ----------------99 1000 --------- Healthcare Chennai Manlog IME Delhi Bangalore 1001 SQL> select * from empdetails.----------------SALEM 9955248792 9988765643 Chennai Bangolore 9870984353 9790865432 Chennai SQL> select deptno. Page 26 of 61 . dname from deptdetails where dlocation=(select address from empdetails where job =' MANAGER').deptno=empdetails. EMPNO ENAME CONTACTNO ---------1001 1000 1002 1003 ---------Saran ram Arun Sudha JOB ---------PA MANAGER PAT Admin MGR DEPTNO ADDRESS -------. DEPTNO ---------100 DNAME -------------------Healthcare SQL>select * from empdetails where address=(select dlocation from deptdetails where deptdetails.

deptno.----------------Chennai Chennai 9988765643 9790865432 SQL> select e. deptdetails d where e.e.EMPNO ENAME CONTACTNO ---------1000 1003 ---------ram Sudha JOB ---------MANAGER Admin MGR DEPTNO ADDRESS -------.d.----------1000 100 1000 100 -------------. d. EMPNO ---------1001 ENAME DEPTNO DLOCATION -------------------chennai Page 27 of 61 --------------.deptno.----------------Chennai Chennai 9988765643 9790865432 SQL>select * from empdetails where job<>'PA' and ename in(select ename from empdetails where ename not like'%n'). EMPNO ENAME CONTACTNO ---------1000 1003 ---------ram Sudha JOB ---------MANAGER Admin MGR DEPTNO ADDRESS -------.deptno=d.ename.----------1000 100 1000 100 -------------.empno.-----------Saran 100 .dlocation from empdetails e.

No:4 DATE: Page 28 of 61 .1002 1000 1003 Arun RAM Sudha 100 100 100 chennai chennai chennai Result: Thus the nested and join queries are executed and verified successfully. Ex.

delete).VIEW Aim: To learn about view in SQL (create. drop. update. replace. Create the following tables and execute the following queries. Table: DeptDetails COLUMN NAME DATA TYPE(SIZE) DEPTNO DNAME DLOCATION MGR Number (3) Varchar2(20) Varchar2(30) Number (5) DEPTNO ----------100 101 102 DNAME ------------- DLOCATION ----------------99 1000 1001 MGR --------- Healthcare Chennai Manlog IME Delhi Bangalore Table: EmpDetails COLUMN NAME DATA TYPE(SIZE) Page 29 of 61 .

----------------SALEM 9955248792 9988765643 Chennai Bangolore 9870984353 9790865432 Chennai QUESTIONS: 1.----------1000 1000 1000 100 100 100 1000 100 -------------. 2.Delete the empdeptview. Page 30 of 61 . Update employee name of ‘Sudha’ as ‘Sudhakar’ in the empdeptview. address and deptno fields who are residing in ‘Chennai’ by using EmpDetails. ename. 4. and address fields from EmpDetails table. DeptDetails tables. ename. Create empview2 view with empno. and address fields who are residing in ‘Chennai’ by using EmpDetails table. 5. Drop the empdeptview.EMPNO ENAME JOB MGR DEPTNO ADDRESS CONTACTNO EMPNO ENAME CONTACTNO ---------1001 1000 1002 1003 ---------Saran ram Arun Sudha JOB ---------PA MANAGER PAT Admin MGR Number (5) Varchar2(15) Char(10) Number (5) Number(3) Varchar2(50) Number(10) DEPTNO ADDRESS -------. Create empview view from EmpDetails table. ename. 3. Create empview1 view with empno. Create empdeptview view with empno.

CREATE OR REPLACE VIEW Syntax: SQL>CREATE OR REPLACE VIEW view_name AS SELECT columns FROM table WHERE predicates. SQL> select * from empdetails. View Created.----------------SALEM 9955248792 9988765643 Chennai Bangalore 9870984353 9790865432 Chennai SQL>Create or replace view empview as select * from empdetails. EMPNO ENAME CONTACTNO ------------------- JOB ---------- MGR DEPTNO ADDRESS -------. SQL>select * from empview.----------1000 1000 1000 100 100 100 1000 100 -------------. EMPNO ENAME CONTACTNO ---------1001 1000 1002 1003 ---------Saran ram Arun Sudha JOB ---------PA MANAGER PAT Admin MGR DEPTNO ADDRESS -------.----------------- .----------Page 31 of 61 -------------.

address from empdetails. ename. address from empdetails where address=’Chennai’. EMPNO ---------1000 ENAME ---------ram ADDRESS -------------Chennai Page 32 of 61 . SQL> select * from empview1. View Created. SQL> select * from empview2.1001 1000 1002 1003 Saran ram Arun Sudha PA MANAGER PAT Admin 1000 1000 1000 1000 100 100 100 100 SALEM Chennai Bangalore Chennai 9955248792 9988765643 9870984353 9790865432 SQL> create or replace view empview1 as select empno. EMPNO ---------1001 1000 1002 1003 ENAME ---------Saran ram Arun Sudha ADDRESS -------------SALEM Chennai Bangalore Chennai SQL> create or replace view empview2 as select empno. View Created. ename.

SQL>select * from empdeptview. EMPNO ---------1000 1003 ENAME ADDRESS DEPTNO ---------100 100 Page 33 of 61 --------------.empno. deptdetails d where e.1003 Sudha Chennai SQL> create or replace view empdeptview as select e.deptno=d.deptno and e. View Created.e.-------------ram Sudhakar Chennai Chennai .deptno from empdetails e.address=’Chennai’.d. SQL> select * from empdeptview. e.address. SQL>update empdeptview set ename='Sudhakar' where ename='Sudha'.ename.-------------ram Sudha Chennai Chennai UPDATE VIEW Syntax: SQL>update viewname set columnname=values where predicates. EMPNO ---------1000 1003 ENAME ADDRESS DEPTNO ---------100 100 --------------. View Updated.

ERROR: ORA-04043: object empdeptview does not exist Page 34 of 61 . no rows selected DROP VIEW Syntax: SQL>drop view viewname. SQL>delete from empdeptview. SQL>select * from empdeptview. View dropped. SQL>drop view empdeptview.DELETE VIEW Syntax: SQL> delete from viewname. SQL> desc empdeptview. 2 rows deleted.

Ex.Result: Thus the operations on view are executed and verified successfully. No: 5 DATE: IMPLEMENTATION OF PROCEDURE AND FUNCTION Aim: To write a PL/SQL program to calculate total and average of student by using procedure and function. Page 35 of 61 .

-----.os.avg number(5.2)). REGNO --------1 2 3 4 NAME --------raja ramu jeeva jothi DBMS OS MATHS TOTAL AVG ------- -------. total number(3).2) SQL> insert into student(regno.dbms number(3). &os. Name -----------------------------REGNO NAME DBMS OS MATHS TOTAL AVG Null? Type ----------------------------------- NUMBER(10) VARCHAR2(20) NUMBER(3) NUMBER(3) NUMBER(3) NUMBER(3) NUMBER(5.name.&dbms.maths number(3).PROGRAM Table Creation SQL> create table student (regno number(10). &maths).os number(3).dbms. SQL> desc student.---------77 88 77 54 88 64 88 68 57 95 99 59 Page 36 of 61 ---------- .'&name'.name varchar2(20). (Insert the following values) SQL> select * from student.maths)values(&regno.

maths. 4 avg1 number(5.regno=cur. 8 avg1:=f_avg(tot). PL/SQL PROGRAM SQL> declare 2 cursor c is select * from student. 10 end loop. os in number.avg=avg1 where student.5 suresh 99 99 99 PROCEDURE SQL>create or replace procedure p_total 2 ( dbms in number. 5 / Function created.regno. 3 tot number(3).dbms. 7 end. 3 tot out number) as 4 begin 5 6 tot:=dbms+os+maths. 12 / Page 37 of 61 . maths in number.cur. 4 end.os. 9 update student set total=tot. FUNCTION SQL> create or replace function f_avg(tot in number ) return number is 2 begin 3 return (tot/3). 8/ Procedure created.2). 11 end. 5 begin 6 for cur in c loop 7 p_total(cur.cur.tot).

REGNO --------1 2 3 4 5 SQL> NAME --------raja ramu jeeva jothi suresh 77 88 77 54 99 DBMS OS MATHS TOTAL AVG ------- -------.-----.PL/SQL procedure successfully completed.---------88 64 88 68 99 57 94 99 58 99 222 246 264 180 297 ---------74 82 88 60 99 Page 38 of 61 . OUTPUT SQL> select * from student.

Result:
Thus the PL/SQL program to calculate total and average of student by using procedure and function is created and executed successfully.

Ex. No: 6 DATE: IMPLEMENTATION OF TRIGGER

Aim:
To write a PL/SQL program to raise trigger before update data on student table.
Page 39 of 61

PROGRAM Table Creation
SQL> create table student (regno number(10),name varchar2(20),dbms number(3),os number(3),maths number(3), total number(3),avg number(5,2)); SQL> desc student; Name -----------------------------REGNO NAME DBMS OS MATHS TOTAL AVG Null? -------Type ---------------------------NUMBER(10) VARCHAR2(20) NUMBER(3) NUMBER(3) NUMBER(3) NUMBER(3) NUMBER(5,2)

SQL> insert into student(regno,name,dbms,os,maths)values(&regno,'&name',&dbms, &os, &maths); (Insert the following values)

SQL> select * from student; REGNO --------1 2 3 4 5 NAME --------raja ramu jeeva jothi suresh 77 88 77 54 99 DBMS OS MATHS

-------- ------ ---------88 64 88 68 99 57 95 99 59 99
Page 40 of 61

TRIGGER

create or replace trigger stud before update on student for each row when (new.dbms<0 or new.os<0 or new.maths<0 or new.dbms>100 or new.os>100 or new.maths>100) begin raise_application_error(-20000,'Must enter marks between 0 and 100'); end; /

PL/SQL PROGRAM
declare dbms number(3); os number(3); maths number(3); regno number(10);

begin update student set dbms=&dbms,os=&os,maths=&maths where regno=&regno; end; /

OUTPUT

Enter value for dbms: -5
Page 41 of 61

STUD".os=56. new 7: update student set dbms=-5. declare * ERROR at line 1: ORA-20000: Must enter marks between 0 and 100 ORA-06512: at "SURESH.maths=78 where regno=8.Enter value for os: 56 Enter value for maths: 78 Enter value for regno: 8 old 7: update student set dbms=&dbms.maths=&maths where regno=&regno.STUD' ORA-06512: at line 7 Page 42 of 61 .os=&os. line 2 ORA-04088: error during execution of trigger 'SURESH.

Result: Thus the PL/SQL program to raise trigger before update data on student table is created and executed successfully. EXNO: DATE: MENU DESIGNS Aim: To perform menu designs using visual c++ Procedure: Page 43 of 61 .

10.rc. 13. 5. File view and Class view are created.LPARAM lParam) Page 44 of 61 . Give the project name in selected location (eg c:\.h (drag and place it to the header files). LRESULT CALLBACK WndProc(HWND hwnd. From Insert menu -> Resource-> menu then click new.. Click Visual C++ and choose the project tab and select win32 application. A dialog box appears in that choose filetype as all files then select Script1.WPARAM wParam. Menu editor is displayed. In File view choose source file and double click on the C++ source file with extension . A dialog box appears in that choose filetype as all files then select Resource. 6. Select Project->Insert Project into workspace. 2.) and click ok.h> #include"resource. 3. Empty application is created. From Insert menu -> Resource-> icon and click new.UINT msg. 14. 16. and click File->save all in your correct project folder (default name of file is Script1). Select Project menu ->Add to project ->new. Design the menus and submenus in the menu editor. Delete script2 files and resource1 files. Select the Script1.1. 8.. Select an empty project and click finish. then design your own icon 12. Finally build and execute the program. 9.h. In new dialog box.rc from script2 files and drag it to place it into the source files. choose C++ source file and give the file name. Coding: #include<windows. 15. 4. Select Project->Insert Project into workspace. 7. Now click OK/YES for all the popup windows.. Repeat the same for Resource. Now click OK/YES for all the popup windows.h" const char g_szClassName[]="My Window Class".cpp and enter the code in the corresponding window. 11.

case ID_EDIT_GO: MessageBox(hwnd. } Page 45 of 61 .msg."Woo!"."you clicked exit". case WM_DESTROY: PostQuitMessage(0). break.wParam. break."Woo!". default: return DefWindowProc(hwnd. break. } case WM_CLOSE: DestroyWindow(hwnd).{ switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case ID_FILE_EXIT: MessageBox(hwnd. } return 0.MB_OK).0).WM_CLOSE. break.0. PostMessage(hwnd."You Clicked Go".lParam).MB_OK).

wc. return 0.int nCmdShow) { WNDCLASSEX wc.lpszClassName=g_szClassName."Window Registration Failed". wc.cbClsExtra=0.cbSize=sizeof(WNDCLASSEX).HINSTANCE hPrevInstance.hCursor=LoadCursor(NULL.hIconSm=(HICON)LoadImage(GetModuleHandle(NULL). HWND hwnd. wc.hInstance=hInstance.hIcon=LoadIcon(GetModuleHandle(NULL).LPSTR lpCmdLine. Page 46 of 61 . wc.MAKEINTRESOURC E(IDI_ICON1).lpszMenuName=MAKEINTRESOURCE(IDR_MENU1). wc. wc.int WINAPI WinMain(HINSTANCE hInstance.MAKEINTRESOURCE(IDR_MENU1 )). if(!RegisterClassEx(&wc)) { MessageBox(NULL.16.lpfnWndProc=WndProc.MB_ICONEXCLAMATION|MB_OK). wc.0).hbrBackground=(HBRUSH)(COLOR_WINDOW+1). wc.style=0.16. wc."error".cbWndExtra=0. wc. MSG msg. wc.IMAGE_ICON. wc.IDC_ARROW).

} ShowWindow(hwnd.240.CW_USEDEFAULT."WindowCreation Failed". } return msg.NULL. UpdateWindow(hwnd).} hwnd=CreateWindowEx(WS_EX_CLIENTEDGE. if(hwnd==NULL) { MessageBox(NULL.0)) { TranslateMessage(&msg).CW_USEDEFAULT.hInstance.20. while(GetMessage(&msg.NULL. DispatchMessage(&msg).WS_OVERLAPPEDWINDOW.NULL).0. return 0."error".MB_ICONEXCLAMATION|MB_OK).wParam. NULL."A Menu".g_szClassName. } Page 47 of 61 .nCmdShow).

Page 48 of 61 .

Page 49 of 61 .

Page 50 of 61 .

Page 51 of 61 .

Ex:No:8 Date: LIBRARY INFORMATION SYSTEM Page 52 of 61 .Result: Thus the program for menu creation is designed and executed successfully.

text Page 53 of 61 . Coding: Dim con As New ADODB.Connection Dim rs As New ADODB.Text=”” Text3.Caption=” No of Books” Text1.Recordset Private Sub cmdadd_Click() Rs.SetFocus End Sub Private Sub cmdborrow_Click() rs(0)=Text1.Text=”” Text2.Text=”” Text5.AddNew Label5.Text=”” Text1.Text=”” Text4.text rs(1)=Text2.AddNew Private Sub cmdadd_Click() rs.Aim: To implement the library information system using Visual Basic as frontend and Oracle as backend.text rs(2)=Text3.

text rs(5)=rs(5)+1 If rs(5)>rs(4) Then rs.CancelUpdate MsgBox “No books are available for borrowing” Else rs.Update MsgBox “Book borrowed” Endif rs.Text=rs(4)-rs(5) End Sub Private Sub cmdcancel_Click() rs.Text=rs(3) Text5.Caption=”Available books” rs.MoveFrist Text1.Text=rs(2) Text4.CancelUpdate Label5.Text=rs(0) Text2.Text=rs(1) Text3.Text=rs(0) Page 54 of 61 .rs(3)=Text4.MoveFirst Text1.

Text=rs(4)-rs(5) End Sub Private Sub cmdexit_Click() rs.Text=rs(2) Text4.Delete MsgBox”record deleted” rs.Text=rs(3) Text5.Text=rs(3) Text5.Text=rs(2) Text4.Text=rs(1) Text3.Close Con.Text=rs(1) Text3.MoveFirst Text1.Text=rs(4)-rs(5) End Sub Private Sub cmddelete_Click() rs.Text2.Close Unload Me End Sub Page 55 of 61 .Text=rs(0) Text2.

Text=rs(4)-rs(5) End Sub Private Sub cmdlast_Click() If Not rs.Text=rs(3) Text5.EOF Then Page 56 of 61 .Text=rs(1) Text3.MoveFirst If rs.MoveFirst Text1.MoveLast Text1.Text=rs(0) Text2.Text=rs(0) Text2.Text=rs(4)-rs(5) End Sub Private Sub cmdnext_Click() rs.Text=rs(2) Text4.BOF Then rs.Text=rs(1) Text3.BOF Then rs.Text=rs(3) Text5.Private Sub cmdfirst_Click() If Not rs.Text=rs(2) Text4.

text rs(3)=Text4.Update MsgBox “Book Returned” End if Page 57 of 61 .CancelUpdate MsgBox”All books are in rack.rs.Text=rs(0) Text2.MoveLast MsgBox”Last Record” End if Text1.Text=rs(3) Text5.Text=rs(2) Text4.Text=rs(1) Text3.Not possible for returninig” Else Rs.text rs(2)=Text3.text rs(1)=Text2.Text=rs(4)-rs(5) End Sub Private Sub cmdreturn_Click() rs(0)=Text1.text rs(5)=rs(5)-1 if rs(5)<0 then rs.

Text=rs(0) Text2.BOF Then rs.text Page 58 of 61 .MovePrevious If rs.MoveLast MsgBox”First Record” End if Text1.rs.Text=rs(3) Text5.Text=rs(4)-rs(5) End Sub Private Sub cmdsave_Click() rs(0)=Text1.Text=rs(1) Text3.Text=rs(1) Text3.Text=rs(4)-rs(5) End Sub Private Sub cmdprevious_Click() rs.Text=rs(0) Text2.Text=rs(2) Text4.Text=rs(2) Text4.Text=rs(3) Text5.MoveFirst Text1.

text rs(4)=val(text5.Update MsgBox” Record Update” rs.Caption=”available Books” End Sub Private Sub Form_Activate() Con.text rs(3)=Text4.adLockOptimistic rs.RecordCount=0 Then Page 59 of 61 .1.con. rs(5)=0 rs.CursorLocation=adUseClient Con.Open”Provider=MSDAORA.UserID=mukkani.MoveFirst Text1.Text=rs(0) Text2.MoveFirst If rs.rs(1)=Text2.Data Source=mce” rs.Text=rs(3) Text5.Text=rs(4)-rs(5) Label5.Text=rs(2) Text4.Text=rs(1) Text3.Open “Select * from book”.text rs(2)=Text3.Password=cse.text).adOpenDynamic.

MsgBox”No records in table” Else Text1.Text=rs(2) Text4.Text=rs(4)-rs(5) End If End Sub Page 60 of 61 .Text=rs(3) Text5.Text=rs(0) Text2.Text=rs(1) Text3.

Result: Thus the library information system is implemented using Visual Basic with Oracle. s Page 61 of 61 .

Sign up to vote on this title
UsefulNot useful