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

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

Name -------------------EMPNO Null? -------------NOT NULL Type ---------------------NUMBER (5) Page 5 of 61 . 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)). 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. Table altered.

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 Null? Type Page 6 of 61 . After droping hiredate columns in new_Emp table SQL> desc new_Emp. Table altered. 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).

-------------------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. 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 .

Table altered.---------------------NOT NULL NOT NULL NUMBER (5) VARCHAR2 (15) CHAR (10) NUMBER (5) NUMBER (3) Page 8 of 61 . 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.SQL> alter table new_Emp add(constraint p_key primary key (ename)).---------------------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.

Name -------------------EMPNO ENAME JOB MGR DEPTNO ADDRESS CONTACTNO Null? Type -------------. Page 9 of 61 . Table altered.ADDRESS CONTACTNO VARCHAR2 (50) NUMBER (11) SQL> alter table new_Emp drop constraint p_key.---------------------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.

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

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

Delete and Select). Create the following table. 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.NO:2 DATE: DML COMMANDS Aim: To learn about basic Data Manipulation Commands (Insert.----------Page 12 of 61 -------------.EX.

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

SQL> INSERT INTO tablename values(&fieldname1. 'SALEM'. deptno.. SQL> insert into empdetails (empno. SQL> insert into empdetails values(&empno. &contactno). SQL> / Enter value for column1: value1 Enter value for column2: value2 …. &fieldname2 …. job. 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 . ename. mgr. 1000. 101. 'Saran '. contactno) values(1001. value2 …).). 9955248792). '&ename'. columnname2 …) VALUES (value1. '&job'. '&address'. 'PA'. &mgr.INSERT COMMAND Syntax: SQL> INSERT INTO tablename (columnname1. address. &deptno. 1 row created.

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

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

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.----------------SALEM chennai bangalore 9955248792 9988765643 9977678768 DELETE COMMAND Syntax: DELETE FROM table_name where predicates.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 -------.----------1000 99 1000 101 101 101 -------------. Page 17 of 61 .

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

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

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

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

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

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

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 . Create the following tables and execute the following queries.Aim: To learn about nested queries and join queries.

NESTED QUERIES SQL> Select * from deptdetails. deptno. 3. Select empno.----------1000 1000 1000 100 100 100 1000 100 -------------. Select all the employee details whose job is not ‘PA’ and employee name is not end with ‘n’.dlocation of the all employees. 4. Select all the employee details who are residing in the same city of their department location.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. DEPTNO DNAME DLOCATION MGR Page 25 of 61 . Select Deptno and Dname of managers who are residing in the same city of their department location.----------------SALEM 9955248792 9988765643 Chennai Bangolore 9870984353 9790865432 Chennai QUESTIONS: 1. ename.

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

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

Ex.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.

replace. Create the following tables and execute the following queries. drop. 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 . update.VIEW Aim: To learn about view in SQL (create. delete).

Create empview2 view with empno. and address fields who are residing in ‘Chennai’ by using EmpDetails table.Delete the empdeptview. Page 30 of 61 .----------1000 1000 1000 100 100 100 1000 100 -------------. 4. ename. Create empdeptview view with empno. Drop the empdeptview. ename.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 empview1 view with empno. 2. Update employee name of ‘Sudha’ as ‘Sudhakar’ in the empdeptview.----------------SALEM 9955248792 9988765643 Chennai Bangolore 9870984353 9790865432 Chennai QUESTIONS: 1. address and deptno fields who are residing in ‘Chennai’ by using EmpDetails. 5. ename. Create empview view from EmpDetails table. DeptDetails tables. and address fields from EmpDetails table. 3.

SQL> select * from empdetails. SQL>select * from empview.CREATE OR REPLACE VIEW Syntax: SQL>CREATE OR REPLACE VIEW view_name AS SELECT columns FROM table WHERE predicates.----------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 -------. 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 -------.----------------- .----------Page 31 of 61 -------------.

address from empdetails where address=’Chennai’.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. ename. ename. View Created. 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. SQL> select * from empview1. SQL> select * from empview2. EMPNO ---------1000 ENAME ---------ram ADDRESS -------------Chennai Page 32 of 61 . address from empdetails.

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

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

Page 35 of 61 . Ex. 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.Result: Thus the operations on view are executed and verified successfully.

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

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

---------88 64 88 68 99 57 94 99 58 99 222 246 264 180 297 ---------74 82 88 60 99 Page 38 of 61 . 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. 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

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

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

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

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

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

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

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.

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

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

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

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

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

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

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

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

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

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.