Documente Academic
Documente Profesional
Documente Cultură
PROBLEM DESCRIPTION
The telephone information system maintains details about landline and mobile numbers and the
customers who bought it. It also maintains call logs for landline and mobile systems. The log will
contain the callee number,caller number, start and end time and duration . Local calls are
CUSTOMERID
charged
differently from theNAME
std calls. Similarly in mobiles, the customers are given privileges to
choose schemes and register numbers .The charging scheme will be different for the registered
numbers.
REGDATE
CUSTOMER
AREACODE
The following
assumptions are made:
ADDRESS
STREET
TELEPHONE
The customers can have more than one landline and mobile.
STD CODE
The first three digits of the landline number is the area code.
Duration of I minSTATE
is considered as one call.
OWNS
IS A
LANDLINE NO
The landline is charged under the
following
scheme:
SCHEME
ID
CITYcalls are charged Rs.2 for a call.
AREA STD
Local calls are charged Re,1 for a call.
NO
The mobile is chargedMOBILE
as follows
MOBILE
LANDLINE
LLNO
For schenm2:
STD calls are charged Rs2 for a call.
Local calls are carged Re.1 for a call.
For scheme 1:
Two mobile numbers can be registered.
The charge to the registered numbersSOURCESTD
is 50 p perLOGGING
call.
STIME
For calls to other numbers, the charges of scheme 2 will apply.
SOURCENO
LANDLINE CALLLOG
LOGGING
MOBILELOG
DESTNO
IS A
ER DIAGRAM
CALL LOG
CHARGE
AMOUNT
TOPUP
ETIME
TYPE
DURATION
DESTNO
TYPE
STIME
DURATION
ETIME
DESTSTD
SOURCENO
MSG LOG
DESTNO
MSG COUNT
DATE
CGARGE
TABLE DESIGN
CUSTOMER
SQL:
CREATE TABLE "CUSTOMER"
(
"CUSTOMERID" NUMBER,
"NAME" VARCHAR2(40),
"STREET" VARCHAR2(40),
"AREA" VARCHAR2(40),
"CITY" VARCHAR2(40),
"STATE" VARCHAR2(40),
CONSTRAINT "CUSTOMER_PK" PRIMARY KEY ("CUSTOMERID") ENABLE
);
DESIGN:
SLNO
1
2
3
4
5
6
FIELDS
CUSTOMERID
(PRIMARY KEY)
NAME
STREET
AREA
CITY
STATE
DATATYPE
NUMBER
VARCHAR(40)
VARCHAR(40)
VARCHAR(40)
VARCHAR(40)
VARCHAR(40)
LANDLINE
SQL:
CREATE TABLE "LANDLINE"
(
"CUSTOMERID" NUMBER,
"STDCODE" NUMBER,
"AREACODE" NUMBER,
"LLNO" NUMBER,
"REGDATE" DATE,
PRIMARY KEY("STDCODE","AREACODE","LLNO"),
CONSTRAINT fk_column
FOREIGN KEY ("CUSTOMERID")
REFERENCES customer ("CUSTOMERID")
);
DESIGN:
SLNO
1
FIELDS
CUSTOMERID
DATATYPE
NUMBER
2
3
4
5
(FOREIGN KEY)
STDCODE
AREACODE
LLNO
REGDATE
NUMBER
NUMBER
NUMBER
DATE
MOBILE
SQL:
CREATE TABLE "MOBILE"
( "CUSTOMERID" NUMBER,
"MOBILENO" NUMBER,
"REG_DATE" DATE,
"SCHEMEID" NUMBER,
PRIMARY KEY ("MOBILENO") ,
FOREIGN KEY ("CUSTOMERID")
REFERENCES customer ("CUSTOMERID")
);
DESIGN:
SLNO
1
2
3
4
FIELDS
MOBILENO
(PRIMARY KEY)
CUSTOMERID
(FOREIGN KEY)
REG_DATE
SCHEMEID
LANDLINECALLLOG
SQL:
CREATE TABLE "LANDLINECALLLOG"
(
"SOURCESTD" NUMBER,
"SOURCENO" NUMBER,
"DESTSTD" NUMBER,
"DESTNO" NUMBER,
"STIME" TIMESTAMP (6),
"ETIME" TIMESTAMP (6),
"DURATION" NUMBER,
"CHARGE" BINARY_FLOAT,
"TYPE" VARCHAR2(10)
);
DESIGN:
DATATYPE
NUMBER
NUMBER
DATE
NUMBER
SLNO
1
2
3
4
5
6
7
8
9
FIELDS
SOURCESTD
SOURCENO
DESTSTD
DESTNO
STIME
ETIME
DURATION
CHARGE
TYPE
DATATYPE
NUMBER
NUMBER
NUMBER
NUMBER
TIMESTAMP(6)
TIMESTAMP(6)
NUMBER
BINARY_FLOAT
VARCHAR(10)
MOBILELOG
SQL:
CREATE TABLE "MOBILELOG"
(
"SOURCENO" NUMBER,
"DESTNO" NUMBER,
"STIME" TIMESTAMP (6),
"ETIME" TIMESTAMP (6) NOT NULL ENABLE,
"DURATION" NUMBER,
"CHARGE" BINARY_FLOAT,
"TYPE" VARCHAR2(10)
);
DESIGN:
SLNO
1
2
3
4
5
6
7
FIELDS
SOURCENO
DESTNO
STIME
ETIME
DURATION
CHARGE
TYPE
DATATYPE
NUMBER
NUMBER
TIMESTAMP(6)
TIMESTAMP(6)
NUMBER
BINARY_FLOAT
VARCHAR(10)
MOBILE TOPUP
SQL:
CREATE TABLE "MOBILETOPUP"
(
"MOBILENO" NUMBER,
"TOPUP" NUMBER,
"TOPUPDATE" DATE
);
DESIGN:
SLNO
1
FIELDS
MOBILENO
DATATYPE
NUMBER
2
3
TOPUP
TOPUPDATE
NUMBER
DATE
SCHEMETABLE
SQL:
CREATE TABLE "SCHEMETABLE"
(
"MOBILENO" NUMBER,
"SCHEMEID" NUMBER,
"NUMBER1" NUMBER,
"NUMBER2" NUMBER
);
DESIGN:
SLNO
1
2
3
4
FIELDS
MOBILENO
SCHEMEID
NUMBER1
NUMBER2
DATATYPE
NUMBER
NUMBER
NUMBER
NUMBER
UPDATENO
SQL:
CREATE TABLE "UPDATENO"
(
"CUSTOMERID" NUMBER,
"NAME" VARCHAR2(40),
"STREET" VARCHAR2(40),
"AREA" VARCHAR2(40),
"CITY" VARCHAR2(40),
"STATE" VARCHAR2(40),
"MODDATE" DATE,
"OLD" NUMBER,
"NEW" NUMBER,
"LLNO" NUMBER
);
DESIGN:
SLNO
1
2
3
4
5
6
7
8
FIELDS
CUSTOMERID
NAME
STREET
AREA
CITY
STATE
MODDATE
OLD
DATATYPE
NUMBER
VARCHAR(40)
VARCHAR(40)
VARCHAR(40)
VARCHAR(40)
VARCHAR(40)
DATE
NUMBER
9
10
TABLE INSTANCE
CUSTOMER
LANDLINE
NEW
LLNO
NUMBER
NUMBER
MOBILE
MOBILETOPUP
SCHEMETABLE
LANDLINECALLLOG
<
MOBILELOG
QUERIES
1. List all the customers in rainbow nagar who have one landline and more than two
mobiles
2. Calculate and print the bill for a given number fo a given month.
3. Display the details of the customer who have made maximum number of STD calls on
may 1st and 31st night.
4. Update the area code from 224 to 221 and store the customer details of the updated
numbers in a separate table.
5. Display the number of topups for a given mobile number.
6. Display the in state and out state calls for each schema.
7. Print the call log of two months for a given number.
8. List the customers who habe bought new connection within two years from today.
DESCRIPTION OF QUERIES
1. LIST ALL THE CUSTOMERS IN RAINBOW NAGAR WHO HAVE ONE lANDLINE
AND MORE THAN TWO MOBILES
SQL:
select name from customer
where customerid in
(select customerid from mobile
group by customerid
having count(customerid)>2)
and area='rainbow nagar'
intersect
select name from customer
where customerid in
(select customerid from landline
group by customerid
having count(customerid)=1)
and area='rainbow nagar'
OUTPUT INSTANCE:
\
2. CALCULATE AND PRINT THE BILL FOR A GIVEN NUMBER FO A GIVEN
MONTH.
CALCULATION WHILE POPULATIMG THE TABLE
SQL:
declare
sstd landlinecalllog.sourcestd%type;
sno landlinecalllog.sourceno%type;
dstd landlinecalllog.deststd%type;
dno landlinecalllog.destno%type;
st landlinecalllog.stime%type;
et landlinecalllog.etime%type;
dur landlinecalllog.duration%type;
cost landlinecalllog.charge%type;
typ landlinecalllog.type%type;
begin
sstd:= :sourcestd;
sno:= :sourceno;
dstd:= :deststd;
dno:= :destno;
st:=:stime;
et:=:etime;
dur:=:duration;
if(sstd=dstd)then
begin
typ :='local';
cost:=dur*1;
end;
else
begin
typ:='std';
end;
cost:=dur*2;
end;
end if ;
insert into landlinecalllog
values(sstd,sno,dstd,dno,st,et,dur,cost,typ);
OUTPUT INSTANCE:
Statement processed.
PRINTING THE TOTAL AMOUNT OF BILL FOR A GIVEN NUMBER FOR A GIVEN MONTH
SQL:
select sum(charge) from landlinecalllog
where
sourcestd=:stdcode and
sourceno=:urnumber and
extract(month from stime)=:month
and extract(year from stime)=:year ;
OUTPUT INSTANCE:
OUTPTU INSTANCE:
4. UPDATE THE AREA CODE FROM 224 TO 221 AND STORE THE CUSTOMER
DETAILS OF THE UPDATED NUMBERS IN A SEPARATE TABLE.
SQL
update landline
set areacode=221
where areacode=224
TRIGGER
create or replace trigger "updteareacod"
before update of "areacode" on "landline"
for each row
when (new.areacode is not null)
declare pragma autonomous_transaction;
begin
insert into updateno
(select customer.customerid ,name , street,
area,city,state,sysdate,:old.areacode,:new.areacode,llno from
landline,customer,dual where areacode=:old.areacode and
customer.customerid=landline.customerid);
commit;
end;
OUTPUT INSTANCE:
1 row(s) updated.
OUTPUT INSTANCE:
FLAG:=1;
end;
end if;
end;
end if;
if(flag=0) then
begin
select state into ss from customer
where customerid in
(select customerid from mobile
where mobileno=sno);
select state into ds from customer
where customerid in
(select customerid from mobile
where mobileno=dno);
if(ss=ds)then
begin
typ :='local';
cost:=dur*1;
end;
else
begin
typ:='std';
cost:=dur*2;
end;
end if ;
end;
end if;
insert into mobilelog values(sno,dno,st,et,dur,cost,typ);
end;
OUTPUT INSTANCE:
Statement processed.
SQL:
SELECT SOURCENO,DESTNO,DURATION,CHARGE,TYPE,SCHEMEID
FROM MOBILELOG NATURAL JOIN MOBILE
WHERE MOBILE.MOBILENO=MOBILELOG.SOURCENO
ORDER BY SCHEMEID,TYPE
OUTPUT INSTANCE:
OUTPUT INSTANCE:
OUTPUT INSTANCE: