0% found this document useful (0 votes)
370 views

Assignment Gtu PLSQL

This document contains details of 10 practical assignments involving PL/SQL programming on various database tables. The assignments include writing PL/SQL blocks to generate reports and invoices, creating views, sequences, triggers and user-defined exceptions. Functions are to be created to return results based on conditions. Parameterized cursors need to be used to display results.

Uploaded by

xbsngb
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
370 views

Assignment Gtu PLSQL

This document contains details of 10 practical assignments involving PL/SQL programming on various database tables. The assignments include writing PL/SQL blocks to generate reports and invoices, creating views, sequences, triggers and user-defined exceptions. Functions are to be created to return results based on conditions. Parameterized cursors need to be used to display results.

Uploaded by

xbsngb
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

GujaratTechnologicalUniversity

Master of Computer Applications


Semester-II

SubjectName: Software Lab (DBMS: SQL & PL/SQL)


SubjectCode: 620006

PL/SQL Practical List:


1. Competition(Comp_code,Comp_name(Dancing,Painting,GK,etc.))
Participants(Part_no,Part_name,DOB,Address,EmailID,Contact_number)
Scorecard(Part_no,Comp_code,Judge_no[1,2,3],Marks)
Implement the following
:
A)
1.FindthoseparticipantswhohaveregisteredbothforDancingandPainting(Note:
Usesetoperator).
2.Findtheaveragescore,scoredineachcompetitionevent.
B)
CreateaPL/SQLblocktopreparereportinfollowingformat.
Displaythescorecardinthefollowingformat,fortheParticipantwhose
ID/Nameshouldbeprovidedbytheuser.
TalentWinner2011:::<ParticipantsName>
CompetitionnameJudge1Judge2Judge3

1.Painting
2.Dancing

TotalMarks:_______

2. Customer(Cust_Id,Cust_Name,Cust_Addr,Cust_City,EmailID,Contact_No)
Magazine(Mag_Id,Mag_Name,Unit_Rate,Type_of_subsciption[weekly,monthly,etc.])
Subscription(Cust_Id,Mag_Id,start_date,end_date)
Implement the following
:
A)
1.CreateaViewthatdisplaysCustomername,Magazinenamealongwithitsrate
whichwassubscribedduring01Sept2010to01Feb2011.
2.Findtopthreemagazineshavingthehighestsaleduringlastonemonthoftime.

B)

1.CreateafunctiontoreturnNo.ofcustomersincityGandhinagarwhohavesubscribed
themagazineOutlookafterAugust2010.Ifnosuchcustomerexists,throwauser
definedexceptionwithappropriatemessage.
2.CreateatriggerthatisfiredafteranINSERTstatementisexecutedfortheCustomer
table.Thetriggerwritesthenewcustomerscode,nameandthesysdateinatable
calledCustomer_Log.(createthetableCustomer_Log)

3. Account(ac_no,ac_name,act_type)
Transaction(ac_no,trans_date,tran_type,tran_amount,balance)
Note:Act_typemaybeSforsavingorCforcurrentandtran_typemaybeDfordeposit
orWforwithdrawal.
Implement the following
A)

1.Findoutthosesavingtransactionsthattookplacebetween10thJanuary2011and
20thJanuary2011andhavewithdrawnanamountgreaterthanRs.50,000.
2.CreateaSequencethatcanbeusedtoenternewaccountnumberintotheaccount
table.AddanewrecordintoAccounttableusingthecreatedsequence.

B)
1.Createatriggernotallowinginsertion,deletionorupdationonSaturdayandbefore
8:00AM&after6:00PMonAccounttable.
2.Createapackageforthefollowing:
Createafunctiontoreturnthecurrentbalanceforagivenaccountnumber.
4. Supplier(sid,sname,contactnum)
Parts(pid,pname,color,unitrate)
Catalog(sid,pid,qty)
Implement the following
:
A)
1.FindthetopthreePartsbeenorderedandhavethehighestsaletilldate.
2.Findthosesupplierswhochargemoreforsomepartthattheaveragecostofthatpart.
B)
CreateaPL/SQLblocktoprepareinvoiceinfollowingformat.
Displaytheinvoiceinthefollowingformat.Useparameterizedcursor.
Invoice:::<SuppliersName>
PartIdPartNameQuantityUnitPrice
TotalPrice

Total:_______

5. Sailor(sid,sname,rating(010),DOB)
Boat(bid,bname,color)
Reserve(sid,bid,date)

Implement the following


:
A)
1.Findthesailor(s)whosebirthdayfallinaleapyear.
2.Findthenameofthesailorwhohasreservedeithertheredorgreencoloredboat.
3.
B)
1.Createaparameterizedcursortodisplaythesailordetailswhohavereservedany
boatafterNovember2010.Ifnorecordfound,throwanuserdefinedexceptionwith
appropriatemessage.
2.CreateafunctionthatgettheBoatcodefromtheuser.Displaythesailor_codewho
havereservedthisboatcode.Raiseanexceptionifnoinformationforboat/sailor
exists.
6. Movie(movie_id,movie_name,date_of_release)
Screen(screen_id,location,max_capacity)
Current(movie_id,screen_id,date_of_arrival,date_of_closure)
Note:
Valueofscreen_idmustwithletterS.
ScreenlocationcanbyanyoneofFF,SF,andTF.
Date_of_arrivalmustbelessthanDate_of_closure.
Max_capacityattributeshouldhaveavaluegreaterthan0.
Implement the following
:
A)
1.Findthetopthreemovieswhichhavethehighestscreenedrecord.
2.CreateaViewwhichdisplaysthemoviedetailsalongwiththeinformationaboutthe
screenonwhichitiscurrentlyscreened.
B)
1.CreateatriggerthatisfiredafteranINSERTstatementisexecutedfortheMovie
table.Thetriggerwritesthenewmoviescode,movienameandthesysdateinatable
calledMovie_Log.(createthetableMovie_Log)
2.CreateafunctionthatgettheScreenCodefromtheuseranddisplaysthemoviename
currentlyscreenedonit.Ifthegivenscreencodedoesnotexist,throwauserdefined
exceptionwithappropriatemessage.
7.

Employee_master(EmpCode,Emp_Name,Dept_Id,Emp_Address,DOB,Basic_Salary)
Department_master(Dept_Code,Dept_Name)
Implement the following
:
A)
1.CreateaViewthatdisplayssomeEmployeedetailssuchasEmployeecode,
Employeename,DepartmentNameandtheirBasicSalary.
2.FindthoseemployeeswhodonotbelongtoDepartmentD102orD105.(Note:Use
setoperator)
B)
CreateaPL/SQLblocktopreparereportinthefollowingformat:
Displaythesalaryslipfortheemployeeinthefollowingformat,whoseEmployee
Codeisprovidedbytheuser.

SalarySlipforthemonthJanuary2011.
EmployeeCode:<E102>EmployeeName:<JohnSmith>
DepartmentName:<Finance>

BasicSalaryDAHRAMedical
P.F.
___________________________________________________________
Deductions:

TotalSalary:_____________
Note:
HRAis15%ofbasicsalary
DAis30%ofbasicsalary
Medicalis1%ofbasicsalary
P.F.is10%ofbasicsalary
8. Competition (Comp_code, Comp_name (Dancing, Painting, GK, etc.) )
Participants(Part_no,Part_name,DOB,Address,EmailID,Contact_number)
Scorecard(Part_no,Comp_code,Judge_no[1,2,3],Marks)
Implement the following
:
A)
1.CreateasequencethatallowsenteringnewCompetitionCodethatmuststart
withCMP,wheneveraninsertionistriedtobedone.
2.Findtheeventnameswhichhavescoredthemaximumscorebytheeachjudgein
total.
B)
1.Createaparameterizedcursortodisplaythetotalscorescoredbyeachstudent
withthecompetitiondetails,thecompetitioneventnamehavetobesuppliedas
theparameter.Ifthegiveneventdoesnotexist,throwanuserdefinedexception
withappropriatemessage.
2.CreateatriggerthatcheckstheCompetitionCodemuststartwithCMP
wheneveraninsertionistriedtobedone.Raiseanuserdefinedexceptionifthe
ruleisviolated
9. Customer(Cust_Id,Cust_Name,Cust_Addr,Cust_City,EmailID,Contact_No)
Magazine(Mag_Id,Mag_Name,Unit_Rate,Type_of_subsciption[weekly,monthly,etc.])
Subscription(Cust_Id,Mag_Id,start_date,end_date)
Implement the following
:
A)
1.FindthosecustomerswhohaventsubscribedPCQuestorChipIndia.(Using
setoperator).
2.Findtoptwomagazineshavingthehighestsaleduringlastonemonth.
B)
1.Createapackageforthefollowing:
CreateafunctiontoreturnNo.ofcustomersincityAhmedabadwhohave
subscribedthemagazinePCQuestafterJuly2010.Ifnosuchcustomerexists,
throwauserdefinedexceptionwithappropriatemessage.
2.Createafunction,whichaccepttheMagazineCodeandreturntheMagazines
nameanditsrate.Ifthemagazinecodedoesnotexist,throwauserdefined
exceptionwithappropriatemessage.

10. Account(ac_no,ac_name,act_type)
Transaction(ac_no,trans_date,tran_type,tran_amount,balance)
Note:Act_typemaybeSforsavingorCforcurrentandtran_typemaybeDfor
depositorWforwithdrawal.
Implement the following
:
A)
1.Findoutthosesavingtransactionsthattookplacebetween10thJanuary2011and
20thJanuary2011andhavewithdrawnanamountgreaterthanRs.50,000.
2.CreateaViewthatdisplaytheaccountinformationhavingabalancegreaterthan
Rs.1,00,000.
B)
1.Createatriggernotallowinginsertion,deletionorupdationonSaturdayandbefore
8:00AM&after6:00PMonAccounttable.
2.Afterevery6monthsallthecustomersaregiven5%interest.Soforcurrentdate,give
interestof6%toallthecustomerswhosebalancearegreaterthanorequalto2000
andinterestof,ontheirbalance.
11. Supplier(sid,sname,contactnum)
Parts(pid,pname,color,unitrate)
Catalog(sid,pid,qty)

Implement the following


:
A)
1.FindthosesupplierswhohaventorderedanyParts..
2.CreateaViewthatdisplaysthesupplierdetailswhohaveorderedanyitemhaving
unitrategreaterthanRs.500.
B)
CreateaPL/SQLblocktoprepareinvoiceinfollowingformat.
PreparethisreportPartinformationwise.Useparameterizedcursor.
PartDetails:::
PartIdPartNameQuantity(inHand)UnitPrice

TotalPartsAvailable:<TotalCount>

12. Sailor(sid,sname,rating(010),DOB)
Boat(bid,bname,color)
Reserve(sid,bid,date)
Implement the following
:
A)
1.Findthenameofthesailorwhohasnotreservedtheredcoloredboat.
2.Findthenameofthesailorwhoisyoungestamongall.

B)

3.CreateatriggerthatcheckstheBoatCodemuststartwithBwheneveraninsertion
istriedtobedone.Raiseauserdefinedexceptioniftheruleisviolated.
4.CreateaprocedurethatgettheSailorCodefromtheuserandcheckwhetherthat
Sailorwasborninaleapyearornot.Ifthegivensailorcodedoesnotexist,throwa
userdefinedexceptionwithappropriatemessage.

13. Movie(movie_id,movie_name,date_of_release)
Screen(screen_id,location,max_capacity)
Current(movie_id,screen_id,date_of_arrival,date_of_closure)
Note:
Valueofscreen_idmustwithletterS.
ScreenlocationcanbyanyoneofFF,SF,andTF.
Date_of_arrivalmustbelessthanDate_of_closure.
Max_capacityattributeshouldhaveavaluegreaterthan0.

Implement the following


:
A)
1.MovieStarwarsIIIwasreleasedinthe7thweekof2005.Findoutthedateofits
releaseconsideringthatamoviereleasesonlyonFriday.
2.Getthedetailsofmoviethatclosedondate15January2010.
B)
1.Createatriggerthatchecksthescreen_idmuststartwithSwheneveraninsertion
istriedtobedone.Raiseauserdefinedexceptioniftheruleisviolated.
2.Createapackageforthefollowing:
CreateaproceduretoprintMovieNamewhereMoviecodeisbeensuppliedbythe
user.
14. Patient(Patient_code,Patient_name,Address,City,DOB,Gender)
Implement the following
:
A)
1.CreateaSequencethatcanbeusedtoenternewPatientcodeintothePatienttable.
AddanewrecordintoPatienttableusingthecreatedsequenceusingtheformat
PT1001.
2.FindthosepatientswhodonotbelongtoAhmedabadorMehsanacity.(Useset
operator)
B)
CreateaPL/SQLblocktogeneratethefollowingreport:
Gender(PatientsinAgegroup)
1202140
Male
Female
Total

4160

6180

81100Total

15. SubjectMaster(Sub_code,Sub_name)
StudentMaster(Roll_no,Stud_Name,Gender,DOB,Address)
Result(Roll_No,Sub_code,Marks)

Implement the following


:
A)
1.Findouttheaveragescoreinpercentageforeachsubject.
2.Findoutthestudentswhosebirthdayfallsintoleapyear.
B)
CreateaPL/SQLblocktogeneratethemarksheetsubjectwiseaccordingtothefollowing
format:
100909080807070606050
<50

SubCode:
SubName:

Total(ineachgroup):

16.

Book_catalog(book_code,title,Publisher_Name,Category_Name,
yr_of_release,total_copies)
Member(member_code,member_name,mem_ship_dt)
Issue(Issue_id,member_code,book_code,issu_ret,issue_date,issue_ret_dt)
Note:
AddaconstrainttoIssuetable,whichwillallowonlyIorRtobeenteredinthe
ISSUE_RETcolumn,whichstorestheactionwhetherthebookisbeingissuedor
returned.

Implement the following


:
A)
1.Findthebookdetailswhicharecurrentlyissuedtothemembersandhavecrossedthe
returndate,getdetailsstartingwiththecurrentdate.
2.Howmanymembershaveregisteredinthelastthreemonths?Displaytheirdetails.
B)
1.Createafunctionwhichprovidesthetotalnumberofcopiesavailablefortheissuefor
agivenbook.BookCodetobeprovidedbytheuser.
2.Createapackageforthefollowing.
CreateafunctiontoprintthebooktitlewhenBookcodeisbeensuppliedbytheuser.

17. Item_master(Item_Cd,Item_Name,Item_Price)
Item_received(Item_Cd,Month,Year,Day,Rec_Qty)
Item_stock(Item_Cd,Month,Year,Open_Stock,Rec_Qty,Close_Stock)
Implement the following
:
A)
1.Createasequencethatcanbeusedtoenternewitemsintoitemtable.
2.ListitemswhoserangeliesbetweenRs.250andRs.500
B)
1.WritetriggersthataffectItem_stocktablefortheinsert,updateanddeleteon
Item_receivedtable.

2.WriteaproceduretoacceptItemNameasinputifitexistsdisplaytheItemPrice
otherwisedisplaythepropermessagethroughtheuseofexception.

18. Team Master (Team_Id, Team_Name)


Player Master(Team_Id,Player_Id,Player_Name,Bt_dt)
Bowler(Team_Id,Bowler_Id,Over,Maiden,Run,Wicket)
Batsman(Team_Id,Player_Id,Score,Out_type,Baller_Id,Bteam_Id)
Extra_run(Team_Id,Wide_Run,No_run,Bye_Run,Legbye_Run)
Implement the following
:
A)
1.Displaythedetailofplayerwhohashighestscore.
2.DisplaytheageofeachplayerinIndiaTeam.
B)
Writeaproceduretodisplayscoreboardofthegiventeamnameinproperformat.
19. Dept_master(Dept_Id,Dept_Name)
Course_master(Dept_Id,Course_Id,Course_Name)
Strength_Master(Dept_Id,Course_Id,Max_Stud_Allow)
Stud_Det(Dept_Id,Course_Id,Stud_No,Stud_Name)
Implement the following
:
A)
1.Displaythedepartment&coursewheremaximumstudentsregistered.
2.Selectname,department&courseofstudentswhosenamesbeginwithA.
B)
Createapackagewhichcontainsthefollowingprocedures.
1.CreateaProcedurewhichtakesDepartmentnameasanargumentandreturnsthe
coursesinthatdepartmentandMaximumstudentallowinthatcourse.
2.CreateaFunctionwhichtakesDepartmentnameandCoursenameasanargument
andreturnthetotalnumberofstudentsregisteredinthatdepartmentforthatcourse
20. ItemMaster(Item_Cd,Item_Name,It_Stock,Item_Unit,Item_Price)
CustMaster(Cust_Code,Cust_Name,Cust_Addr,Due_Amount)
Bill Master(Bill_No,Bill_Date,Cust_Code)
BillTran(Bill_No,Item_Cd,Item_Qty)
Implement the following
:
A)
1.DisplaycustomerdetailswhosedueamountisinbetweenRs.5000toRs.20,000.
2.SelecttheitemswhosepriceisbelowtheRs.500.
B)
Forgivenbillnumbergeneratethefollowingreport.
Customer

Sr#.
1.
2.
3.

ItemName

<code>
<name>
<address>
ItemQty

BillNo :<no>
BillDate :<date>
ItemUnitItemPrice

Amount

TotalAmount:
21. Empmaster(Emp_No,Emp_Name,Basic)
Holidays(Month,Year,No.ofWeeklyOff,No.ofHolidays)
EmpTran(Emp_No,Month,Year,PresenceDays,LoanAmount)
Note:1.
2.
2.
3.
4.

HRAis20%ofbasicsalary
DAis45%ofbasicsalary
Medicalis5%ofbasicsalary
P.F.is4%ofbasicsalary
Salaryisgivenfor(Attendance+Holidays+weeklyoff)days

Implement the following


:
A)
1.AddacolumnEmp_AddresstotheEmpmastertablewiththenotnullconstraint.
2.Deletetherecordsoflasttwoyearsfromthecurrentdate.
B)
AnorganizationwanttoprintthepayslipsinfollowingformatforgivenEmployee
Name,Month&Year.
Month:IssueDate:
Year:DaysinMonth:
_____________________________________________________________
EmployeeNo:EmployeeName:
Presence:

Holidays:

Absence:

SalaryDays:
Earnings
=======
Basic
Medical
H.R.A.
D.A.
TotalEarning:

:
:
:

Deductions
========
:
P.F.
:
Loan
Prof.Tax
:20Rs.

:
TotalDeduction:

TotalAmounttopay:_____________
22. Student(Stud_Id,Stud_Name,Address,DateofBirth)
Stud-Edu(Stud_Id,DegreeName,YearofPassing,Percentage,Grade)
Implement the following
:
A)
1.Displaythestudentswhoseageismorethan24years.
2.Displaythedataoftop3studentsinMCA,2010.
B)
1.WriteaPL/SQLblocktodisplaythedetailofstudentswhohavedone
MCA.
2.Writeaproceduretoacceptstudidasinputandhandleuserdefinedexception
whennodatafound.

23. Weather(City_Id,Nameofcity,Temperature,Humidity)
Implement the following
:
A)
1.Createasequencethatcanbeusedtoenternewcityintoweathertable.
2.DisplaythedetailofcitywhosenamestartswithM.
B)

1.Writeafunctionwhichacceptsthenameofcity&returnstheTemperature&
Humidify.Alsohandleanexceptionifnameofcitydoesnotexist.
2.Writeatriggerbeforeupdateonweatherforeachrowifnewtemperature>
50thengivethemessageotherwiseupdatethevalue.

24. Item Master(ItemCode,ItemName,Price,Unit)


Stock(ItemCode,PurchasedQty,SoldQty)
Implement the following
:
A)
1.UpdatethePriceofItemCodeI3fromRs.500toRs.550.
2.Displaythetop3costlyitems.
B)
1.WriteatriggerbeforeupdateforeachrownotallowingtoupdateifSold
Qty>PurchasedQty.
2.WriteaproceduretoinsertthenewrecordinItemMastertable.IfItemisalready
existthanraisetheexception.
25. Employee Master(Emp_Code,Emp_Name,Birth_Date)
Department Master(Dept_Code,Dept_Name,Budget)
Salary(Dept_Code,Emp_Code,Salary)
Implement the following
:
A)
1.Countthenumberofemployeeineachdepartment.
2.Createaviewtodisplayemployeename&itssalary.
B)
1.WriteatriggerbeforeinsertnewrowintosalarytableforconstraintTotalsalaryfor
departmentisnotexceedingthebudget.
2.WriteafunctionwhichaccepttheEmployeeNameasanargumentandreturn
thesalaryofthatemployee.Ifemployeenamedoesnotexiststhanraisethe
exception.

Reference Books:

1.Oracle9iPL/SQL,OraclePress
2.IvanBayross,SQL,PL/SQLTheProgrammingLanguageOracle

You might also like