Exp.
No: ER Mapping Page No :
Date:
Aim
To write a Entity Relationship Mapping for Matrimonial Website
Algorithm
STEP 1: Start
STEP 2: Open Oracle 11 g and create a database name.
STEP 3: Crete a Table for the application such that Registration, Requirements, Registered ID
and Message
Syntax: create table table_name
(
Column_name1 data_type,
Column_name2 data_type
);
STEP 4: And set the Constraints on the columns value.
STEP 5: Insert the data in the table using the following syntax
Syntax: insert into table_name
(Column_name1, Column_name2 , ... ) values ( value1 , Value2 , ... ) ;
STEP 6: Retrieve the data using the following syntax, Select * from Table_name ; ( or ) Select
Column_name from Table_name ;
STEP 7: End.
Program
A)Registration Table
I)Creating Registration Table
SQL> create table Registration(RID number(10) NOT NULL Primary key, Firstname varchar(20)
NOT NULL,Lastname varchar(20) NOT NULL,Gender varchar(10) NOT NULL,Qualification varchar(20),
DOB Date, Salary number(10), Mobile number(10),Age Number(3), Password varchar2(30));
Table created.
SQL> desc Registration;
Name Null? Type
----------------------------------- ------ -------- ----------------------------
RID NOT NULL NUMBER(10)
FIRSTNAME NOT NULL VARCHAR(20)
LASTNAME NOT NULL VARCHAR(20)
GENDER NOT NULL VARCHAR(10)
QUALIFICATION VARCHAR(20)
DOB DATE
SALARY NUMBER(10)
MOBILE NUMBER(10)
AGE NUMBER(3)
PASSWORD VARCHAR2(30)
II)Inserting Records into Table
SQL> insert into Registration values('1','Razid','Lathief','Male','Manager',' 22-JAN-1986',
’10000’,'NorthSt','8925372069','20','Razid@2002');
1 row created.
SQL> insert into Registration values('2','Ram','Ganesh','Male','HR',
' 29-NOV-2001',’20000’,'SouthSt','8754173083','20','Ram@2001');
1 row created
III)Retrieving Records from Table
RID First Last Gender Qualific DOB Salar Address Mobi Age Passw
-ation y le ord
Name Name
1 Razid Lathief Male Manager 22- 10000 North St 89253 20 Razid
JAN- 72069 @2002
2002
2 Ram Ganesh Male HR 29- 20000 South St 87541 21 Ram@
NOV 73083 2001
-
2001
B)Create Registered ID Table
SQL> create table RegisteredID(User ID number(10),Password varchar2(20));
Table created.
SQL> desc RegisteredID;
Name Null? Type
----------------------------------------- -------- ----------------------------
USERID NUMBER(10)
PASSWORD VARCHAR2(20)
II)Inserting Records into Table
SQL> insert into RegisteredID values('2001','Ram07');
1 row created.
SQL> insert into RegisteredID values('4824','Razid18');
1 row created.
III)Retrieving Records from Table
SQL> select * from RegisteredID;
User ID Password
2001 Ram07
4824 Razid18
C)Create Requirements Table
SQL> create table Requirements (ID number(10) references Registration(RID)on delete cascade,
Gender varchar(20)NOT NULL, Age number(3) NOT NULL, Salary Number(10) NOT NULL, Qualification
varchar(20) NOT NULL);
Table created.
SQL> desc Requirements;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NOT NULL NUMBER(10)
GENDER NOT NULL VARCHAR(20)
AGE NUMBER(3)
SALARY NUMBER(10)
QUALIFICATION VARCHAR(20)
II)Inserting Records into Table
SQL> insert into Requirements values(101,’Male’,20,15000,’Manager’);
1 row created.
SQL> insert into Requirements values(102,’Female’,22,30000,’Developer’);
1 row created.
III)Retrieving Records from Table
SQL> select * from Requirements
ID Gender Age Salary Qualification
101 Male 20 15000 Manager
102 Female 22 30000 Developer
D)Create Message Table
SQL> create table Message (MID number(10), From Name varchar(20)NOT NULL, To Name
varchar(20),Message varchar(255),Phone No number(10));
SQL> desc Message;
Name Null? Type
----------------------------------------- -------- ----------------------------
MID NUMBER(10)
FROM NAME VARCHAR(20)
TO NAME VARCHAR(20)
MESSAGE VARCHAR(255)
PHONE NO NUMBER(10)
II)Inserting Records into Table
SQL> insert into Message values(1,’Razid’,’Safawana’,’Hi! Good Morning’,8925372069);
1 row created.
SQL> insert into Message values(2,’Ram’,’Rajaselvi’,’Hi! ,8754173083);
1 row created.
III)Retrieving Records from Table
SQL> select * from Requirements
MID FromName ToName Message Phone No
1 Razid Safawana Hi! Good 8925372069
Morning
2 Ram Rajaselvi Hi! 8754173083
Result
Thus the above program ER Mapping was executed and the output is verified Successfully.
Exp.No: Normalization Page No :
Date:
Aim
To Convert the Normalization Form of the Matrimonial Application.
Algorithm
STEP 1: Start
STEP 2: Create a table and insert the data in the table.
STEP 3: And convert the table in First Normal Form using following rules,
1. All the column have unique column_name .
2. Attribute domain should not change.
3. All the column have only single value.
4. Unique Table_name.
STEP 4: Then Convert the table in Second Normal Form using following rules,
1. Table should be in 1NF
2. Each non key attributes depends on primary key
STEP 5: Then convert the table Third Normal Form using following rules,
1. Table should be in 2NF.
2. No Transitive Dependencies.
STEP 6: Now the data is successfully normalize.
STEP 7: End.
Exp.No: Cursor Page No :
Date:
Aim
To im
Algorithm
Step 1: Start
Step 2: Create a Customer table with the following fields such as ID, Name, Age, Cost ,
Address. By using the following Syntax
Syntax: create table table_name
(
Column_name1 data_type,
Column_name2 data_type
);
Step 3: Insert some values into the above Customer table using the following Syntax.
Syntax: insert into table_name
(Column_name1, Column_name2 , ... ) values ( value1 , Value2 , ... ) ;
Step 4: Retrieve all the records by using select command
Syntax: select * from table_name;
Step 5: Now Create the following cursor for displaying the records from the Customer Table.
Step 6: Now Run the PL/SQL program by using file location
Step 7: Stop
Program Coding
Creating Table
SQL> create table pass(id int,name varchar2(20),age int,cost int,address varchar2(20));
Table created.
Inserting Records for Table
SQL> insert into pass values(1,'Razid',20,250,'Ambai');
1 row created.
SQL> insert into pass values(2,'Ram',21,350,'Alwarkurichi');
1 row created.
SQL> insert into pass values(3,'Rahul',22,280,'Kallidai');
1 row created.
SQL> insert into pass values(4,'Subbu',23,400,'Veerai');
1 row created.
SQL> insert into pass values(5,'Maha',25,420,'Cherai');
1 row created.
Retrieving record from table
SQL> select * from pass;
ID NAME AGE COST ADDRESS
---------- -------------------- ---------- ---------- --------------------
1 Razid 20 250 Ambai
2 Ram 21 350 Alwarkurichi
3 Rahul 22 280 Kallidai
4 Subbu 23 400 Veerai
5 Maha 25 420 Cherai
cursor.sql
SET SERVEROUTPUT ON
declare
n number(10);
ino pass.id%type;
pname pass.name%type;
page pass.age%type;
pcost pass.cost%type;
addr pass.address%type;
begin
dbms_output.put_line(' To increment the cost of bus ticket prices');
dbms_output.put_line(' ------------------------------------------');
ino:=&ino;
select id,name,age,cost,address into ino,pname,page,pcost,addr from pass where id=ino;
if pcost<300 then
update pass set cost=cost+50 where id=ino;
dbms_output.put_line(ino||'cost is incremented');
else
dbms_output.put_line(pname||'already getting into maximum cost');
end if;
EXCEPTION
when No_Data_found then
dbms_output.put_line('No data Found');
end;
SQL> @"E:\Razid\cursor.sql"
23 /
Enter value for ino: 1
old 11: ino:=&ino;
new 11: ino:=1;
To increment the cost of bus ticket prices
------------------------------------------
1cost is incremented
PL/SQL procedure successfully completed.
SQL> select * from pass;
ID NAME AGE COST ADDRESS
---------- -------------------- ---------- ---------- --------------------
1 Razid 20 300 Ambai
2 Ram 21 350 Alwarkurichi
3 Rahul 22 280 Kallidai
4 Subbu 23 400 Veerai
5 Maha 25 420 Cherai
SQL> @"E:\Razid\cursor.sql"
23 /
Enter value for ino: 3
old 11: ino:=&ino;
new 11: ino:=3;
To increment the cost of bus ticket prices
------------------------------------------
3cost is incremented
PL/SQL procedure successfully completed.
SQL> select * from pass;
ID NAME AGE COST ADDRESS
---------- -------------------- ---------- ---------- --------------------
1 Razid 20 300 Ambai
2 Ram 21 350 Alwarkurichi
3 Rahul 22 330 Kallidai
4 Subbu 23 400 Veerai
5 Maha 25 420 Cherai
Result
Thus the above program Cursor using PL/SQL Program was executed and implemented successfully.
Exp.No: Procedure Page No :
Date:
Algorithm
Step 1: Start
Step 2: Create a Customer table with the following fields such as ID, Name, Pread, Cread, Unit,
Price By using the following Syntax
Syntax: create table table_name
(
Column_name1 data_type,
Column_name2 data_type
);
Step 3: Insert some values into the above Customer table using the following Syntax.
Syntax: insert into table_name
(Column_name1, Column_name2 , ... ) values ( value1 , Value2 , ... ) ;
Step 4: Retrieve all the records by using select command
Syntax: select * from table_name;
Step 5: Now Create the following procedure for displaying the records from the Customer Table.
Step 6: Now Run the PL/SQL program by using file location
Step 7: Stop
SQL> create table eb(ebno number(5)primary key,cname varchar(15),pread number(5),cread number(5),unit
number(5),price number(10));
Table created.
SQL> insert into eb values(101,'razid',500,900,'','');
1 row created.
SQL> insert into eb values(102,'ram',900,1500,'','');
1 row created.
SQL> insert into eb values(103,'rahul',800,900,'','');
1 row created.
SQL> insert into eb values(104,'Subbu',800,1200,'','');
1 row created.
SQL> insert into eb values(105,'maha',500,700,'','');
1 row created.
SQL> select * from eb;
EBNO CNAME PREAD CREAD UNIT PRICE
---------- --------------- ---------- ---------- ---------- ----------
101 razid 500 900
102 ram 900 1500
103 rahul 800 900
104 Subbu 800 1200
105 maha 500 700
Ebill.sql
create or replace procedure ebill(ebno in number,cname in varchar,pread in number,cread in number,unit out
number,price out number)is
begin
unit:=cread-pread;
if unit>0 and unit<=100 then
price:=0;
elsif unit>100 and unit<=200 then
price:=((unit-100)*1.50);
elsif unit>200 and unit<=500 then
price:=((100*1.50)+(200*2.00)+((unit-300)*3.00));
else
price:=((100*1.50)+(200*2.00)+((unit-300)*3.00))+((unit-500)*6.00);
end if;
end;
SQL> @"E:\Razid\ebill.sql";
14 /
Procedure created.
Bill.sql
SET SERVEROUTPUT ON
declare
CURSOR cu is SELECT * FROM eb where cread>pread;
e eb%rowtype;
u eb.unit%type;
a eb.price%type;
begin
open cu;
dbms_output.put_line('--------------------------------------------------------------');
dbms_output.put_line('ENO NAME PREAD CREAD UNIT AMOUNT ');
dbms_output.put_line('--------------------------------------------------------------');
loop
fetch cu into e;
exit when cu%notfound;
ebill(e.ebno,e.cname,e.pread,e.cread,u,a);
update eb set unit=u,price=a where ebno=e.ebno;
select * into e from eb where ebno=e.ebno;
dbms_output.put_line(e.ebno||' '||e.cname||' '||e.pread||' '||e.cread||' '||u||' '||a);
end loop;
close cu;
end;
SQL> @"E:\Razid\bill.sql";
21 /
ENO NAME PREAD CREAD UNIT AMOUNT
-------- --------- ---------- ---------- --------- ---------------
101 razid 500 900 400 850
102 ram 900 1500 600 2050
103 rahul 800 900 100 0
104 Subbu 800 1200 400 850
105 maha 500 700 200 150
PL/SQL procedure successfully completed.