Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DBMS Lab

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 59

Ex no: 1 Date: AIM:

DDL, DML, and DCL COMMANDS IN RDBMS

To study DLL, DML and DCL commands in RDBMS. PROCEDURE: DDL (Data definition language) statements are used to define the database Structure of schema some examples CREATE: To create objects in the database ALTER: Alters the structure of the database DROP: Delete the objects from the database TRUNCATE: Remove all records from a table, including all spaces allocated for the records are removed. COMMENT: Add comments to the data directory RENAME: Rename a object DML (Data manipulation language) statements are used for managing data with in schema objects some examples SELECT: Retrieve data from the database INSERT: Insert data into a table UPDATE: Update existing data with in a table DELETE: Deletes all records from a table the space for the records remains MERGE_UPSERT: Operation (inserts or update) CALL: Call a PL/SQL or JAVA sub program EXPLAIN PLAN: Explain access path to data LOCK TABLE: control concurrency DCL (Data control languages) statement some examples GRANT: Gives users access privileges to database REVOKE: Withdraw access privileges gives with the GRANT command.

DDL COMMANDS:
1

Create Table Command: SQL> create table studentmarklist(name varchar(20),regno number(4), mark1 number(2),mark2 number(2),mark3 number(2)); Table created. Describe Command: SQL> desc studentmarklist; Name Null? Type ------------------------------- -------- ---NAME VARCHAR2(20) REGNO NUMBER(4) MARK1 NUMBER(2) MARK2 NUMBER(2) MARK3 NUMBER(2) Alter Command: (i) Modifying the tables: Before modifying the table: SQL> desc studentmarklist; Name Null? Type ------------------------------- -------- ---NAME VARCHAR2(20) REGNO NUMBER(4) MARK1 NUMBER(2) MARK2 NUMBER(2) MARK3 NUMBER(2) SQL> alter table studentmarklist modify(name varchar(25)); Table altered. After modifying the table: SQL> desc studentmarklist;
2

Name Null? Type ------------------------------- -------- ---NAME VARCHAR2(25) REGNO NUMBER(4) MARK1 NUMBER(2) MARK2 NUMBER(2) MARK3 NUMBER(2) (ii) Adding the columns in a table: SQL> alter table studentmarklist add(total number(3)); Table altered. SQL> desc studentmarklist; Name Null? Type ------------------------------- -------- ---NAME VARCHAR2(25) REGNO NUMBER(4) MARK1 NUMBER(2) MARK2 NUMBER(2) MARK3 NUMBER(2) TOTAL NUMBER(3) Drop Command: SQL> drop table studentmarklist; Table dropped. Truncate Command: SQL> truncate table studentmarklist; Table truncated.

DML COMMANDS:
3

Insert Command: SQL> insert into studentmarklist values('mahesh',101,50,50,50,150); 1 row created. Select Command: SQL> select * from studentmarklist; NAME ------------------------mahesh mahesh Update Command: Before modifying the existing data in the table: SQL> select * from studentmarklist; NAME ------------------------mahesh mahesh REGNO --------101 101 MARK1 -------50 50 MARK2 --------50 50 MARK3 --------50 50 TOTAL --------150 150 REGNO --------101 101 MARK1 -------50 50 MARK2 --------50 50 MARK3 --------50 50 TOTAL --------150 150

SQL> update studentmarklist set name='kumar' where name='mahesh'; 2 rows updated. After modifying the existing data in the table: SQL> select * from studentmarklist; NAME -------------------kumar kumar Delete Command: REGNO --------101 101 MARK1 --------50 50 MARK2 --------50 50 MARK3 TOTAL --------- --------50 150 50 150

Before deleting the columns in a table: SQL> select * from studentmarklist; NAME ------------------------mahesh mahesh REGNO --------101 101 MARK1 -------50 50 MARK2 --------50 50 MARK3 --------50 50 TOTAL --------150 150

SQL> delete from studentmarklist where name='kumar'; 2 rows deleted. After deleting the columns in a table: SQL> select * from studentmarklist; no rows selected DCL commands: SQL> create table e_1(eno number(4),ena varchar2(20),job varchar2(20)); Table created. SQL> insert into e_1 values (101,'mahesh','manager'); 1 row created. SQL> insert into e_1 values (102,'balu','supervisor'); 1 row created.

SQL> select * from e_1;


5

ENO --------101 102

ENA ----------mahesh balu

JOB ------------manager supervisor

SQL> grant alter,update,insert on e_1 to system; Grant succeeded. SQL> revoke alter,update,insert on e_1 from system; Revoke succeeded. SQL> delete from e_1 where eno=101; 1 row deleted. SQL> commit; Commit complete. SQL> savepoint s1; Savepoint created. SQL> rollback to s1; Rollback complete.

RESULT: Thus the DLL, DML and DCL commands in DBMS was studied.

Ex no: 2

CREATION OF SIMPLE PL/SQL BLOCK


7

DATE: AIM: To create a simple PL/SQL block for student details using the following procedure. ALGORITHM: Step1: Start the program Step2: Open the SQL Plus Step3: Create the table student and declare the required field name and its Data type Step4: Inserts the values to the fields Step5: And display the student table with field and its value Step6: And to display the contents from PL/SQL program using Set server output on Step7: By using the declare statement, we can initialize variable types Step8: We can define the executable statements with in the begin block Step9: And run the program Step10: Close the SQL Plus Step11: End the program

PROGRAM: SQL>create table student(student_number char(20),studentlastname char(20), studentfirstname char(20),address char(20),city char(20), state char(10), pincode char(6)); Table Created. SQL> desc student; Name Null? Type ------------------------------- -------- ---STUDENT_NUMBER STUDENTLASTNAME STUDENTFIRSTNAME ADDRESS CITY STATE PINCODE

CHAR(10) CHAR(20) CHAR(20) CHAR(50) CHAR(10) CHAR(10) CHAR(6)

SQL>insert into student values(101,sachin,tendulkar,kumar nagar,coimbatore,Tamil Nadu,641603); 1 row created. SQL> select * from student; STUDENT_NUMBER ---------- ---------------ADDRESS -------------101 kumar nagar STUDENTLASTNAME STUDENTFIRSTNAME ------------------------------------------------CITY STATE PINCODE ---------------------sachin tn tendulkar cbe tn 641603

SQL> set serveroutput on; SQL> declare 2 studentnumber char (20); 3 lastname char (20);
9

4 firstname char (20); 5 begin 6 studentnumber: ='101'; 7 select studentlastname,studentfirstname into lastname,firstname 8 from student where student_number=studentnumber; 9 dbms_output.put_line('the name is :'|| firstname || '' || lastname); 10 end; 11 /

10

OUTPUT: the name is :sachin tendulkar PL/SQL procedure successfully completed.

11

RESULT: Thus to create a simple PL/SQL block for student details are created and verified. Ex no: 3 Date: PROCEDURE IN PL/SQL

12

AIM: To write PL/SQL program to display the student details using procedure. ALGORITHM: Step1: Start the program Step2: Open the SQL plus Step3: Create a table student with following attributes such as student no, lastname, firstname, address, city, state, pincode Step4: Display the table Step5: Insert student values into table Step6: Select * from students (table) Step7: And display the attributes of table Step8: Create a procedure student into with following attributes Step9: Print the output Step10: close the SQL plus Step11: End the program

PROGRAM: SQL> create table student (student_number char(20),studentlastname char(20),


13

studentfirstname char(20),address char(20),city char(20), state char(20), pincode char(20)); Table created. SQL> desc student; Name Null? Type ------------------------------- -------- ---STUDENT_NUMBER CHAR(20) STUDENTLASTNAME CHAR(20) STUDENTFIRSTNAME CHAR(20) ADDRESS CHAR(20) CITY CHAR(20) STATE CHAR(20) PINCODE CHAR(20) SQL> insert into student values(101,'mahesh','kumar','kumar nagar','coimbatore','Tamil Nadu',641603); 1 row created. SQL> create procedure studinfo(studentnumber char) as 2 lastname char (20); 3 firstname char (20); 4 stat char (20); 5 begin 6 select studentlastname,studentfirstname,state into 7 lastname,firstname,stat 8 from student where student_number=studentnumber; 9 dbms_output.put_line('the name is :'||RTRIM(firstname) 10 || ' ' ||RTRIM(lastname)); 11 dbms_output.put_line('the state is'||stat); 12 exception 13 when NO_DATA_FOUND then 14 dbms_output.put_line('not a valid student'); 15 when OTHERS then 16 dbms_output.put_line('Error - '|| SQLERRM); 17 end; 18 / Procedure created.

14

OUTPUT: SQL> set serveroutput on; SQL> execute studinfo(101); The name is: kumar mahesh The state is: Tamil Nadu PL/SQL procedure successfully completed.

15

RESULT: Thus the PL/SQL program to display the student details using procedure was created and verified. Ex No: 4 Date: FUNCTION AND PROCEDURE IN PL/SQL

16

AIM: To write a PL/SQL program to calculate the available seats enrolled for a particular section using function and procedure. ALGORITHM: Step1: Start the program Step2: Open the SQL plus Step3: Create a table student with following attributes such as number, name, city, address, pincode and constraint value i.e., primary key Step4: Insert student values into table Step5: Create a table instructor with attributes and insert values into table Step6: Create a table course code with attributes and insert values into table Step7: Create a table enrollment with attributes and insert values into the table Step8: Create a function to calculate the number of seats enrolled Step9: Create the procedure Step10: Print the result Step11: Close the SQL plus Step12: End the program

PROGRAM: SQL> create table student1 (student_number char(20) constraint pk_student

17

primary key, student_last_name char (20),student_first_name char(20), address char(20), city char (20), state char (20),zin char(9)); Table created. SQL> insert into student1values(101,'kumer','arun','palanipuram','palani', 'tamilnadu', 6288299); 1 row created. SQL> create table instrutor (instrutor_id char (20) constraint pk_instrutor primary key, instrutor_last_name char (20), instrutor_first_name char (20), instrutor_phone char (20)); Table created. SQL> insert into instrutor values (201,'mani','balu', 776665753); 1 row created. SQL> create table course (course_code char (20) constraint pk_course primary key, course_title char (20),credit_hours char(20)); Table created. SQL> insert into course values (1001,'cse',8); 1 row created.

SQL> create table section (section_id char (20) constraint pk_section primary key, time_offered char(20),days_offered char(20),section_room char(20),
18

class_size char(20),constraint ck_class_size check(class_size>=0), number_enrolled number(3,0), constraint ck_number_enrolled check(number_enrolled>=0), instrutor_id char(20), constraint fk_section_instrutor foreign key(instrutor_id) references instrutor,course_code char(20), constraint fk_section_course foreign key (course_code) references course); Table created. SQL> insert into section values (301,'2hrs',5,6,5,5,201,1001); 1 row created. SQL> create table enrolment(student_number char(20),section_id char(20), grade char(20),constraint pk_enrolment primary key(student_number,section_id), constraint fk_enrolment_student foreign key(student_number) references student1, constraint fk_enrolment_section foreign key(section_id) references section); Table created. SQL> insert into enrolment values (101,301,'A'); 1 row created. SQL> create or replace function clac_seats(sectionsize in number,enrolled in number) 2 return number as 3 seats number (20); 4 begin 5 seats: =sectionsize-enrolled; 6 return seats; 7 end; 8 / Function created.

SQL> create or replace procedure disp(sectionid char)as 2 sectionsize number(20);


19

3 enrolled number(20); 4 avalible number(20); 5 begin 6 select class_size,number_enrolled into 7 sectionsize,enrolled from section 8 where section_id=sectionid; 9 avalible:=clac_seats(sectionsize,enrolled); 10 dbms_output.put_line('avalible seats='||avalible); 11 exception 12 when no_data_found then 13 dbms_output.put_line('not a valid section'); 14 when OTHERS then 15 dbms_output.put_line('error-||sqlerrm'); 16 end; 17 / Procedure created.

OUTPUT:
20

SQL> set serveroutput on; SQL> execute disp(301); avalible seats=0 PL/SQL procedure successfully completed. SQL> update section set number_enrolled=3 where section_id=301; 1 row updated. SQL> execute disp(301); avalible seats=2 PL/SQL procedure successfully completed.

21

RESULT: Thus the PL/SQL program to calculate the available seats enrolled for a particular section using function and procedure are created and verified.

Ex no: 5 Date:

TRIGGER IN PL/SQL

22

AIM: To create a trigger in PL/SQL using procedure. ALGORITHM: Step1: Start the program Step2: Open the SQL plus Step3: Create a table for employee details with following attributes such as employee name, salary number, designation, id number Step4: Insert values into a table Step5: Create table for employee details with its attributes Step6: Delete one row from the table Step7: Create a trigger and display table Step8: Delete another row from emp1details Step9: Print the result Step10: Close the SQL plus Step11: End the program

PROGRAM: SQL> create table emp1details (ename varchar2 (20), salary number (6),
23

designation varchar2 (20),empid number(5)); Table created. SQL> insert into emp1details values ('dravid',20000,'manager',4); 1 row created. SQL> insert into emp1details values('kumble',40000,'supervisor',5); 1 row created. SQL> insert into emp1details values('balaji',60000,'clerk',10); 1 row created.varchar SQL> select * from emp1details; ENAME -----------dravid kumble balaji SALARY DESIGNATION ---------------------------20000 manager 40000 supervisor 60000 clerk EMPID --------4 5 10

SQL>create table empd(ename varchar2(20),salary number(6), 2 designation varchar2(20),empid number(5)); SQL> create or replace trigger empd after delete on emp1details 2 for each row 3 begin 4 insert into empd 5 values(:old.ename,:old.salary,:old.designation,:old.empid); 6 end; 7 / Trigger created. OUTPUT: SQL> delete from emp1details where empid=4;

24

1 row deleted. SQL> select * from empd; ENAME SALARY DESIGNATION -------------------- --------- -------------------- --------dravid 20000 manager 4 SQL> select * from emp1details; ENAME SALARY DESIGNATION -------------------- --------- -------------------- --------kumble 40000 supervisor 5 balaji 60000 clerk 10 EMPID EMPID

25

RESULT: Thus the program to create a trigger in PL/SQL are created and verified.

26

EX NO: 06 DATE: AIM:

CURSOR IN PL/SQL

To create a cursor in PL/SQL program using following procedure. ALGORITHM: Step1:Start the program Step2:Open the SQL plus Step3:Create a table section with its attributes Step4:Insert section values into the table Step5:Declare the following attributes such as section cursorand select classize,number enrolled, course code from thetable Step6:Open the attribute section cursor and fetch the values from Section cursor and insert into table Step7:close the SQL plus Step8: End the program

PROGRAM:

27

SQL> create table section(class_size number(10),number_enrolled number(10),course_code number(10)); Table created. SQL> insert into section values(100,75,03); 1 row created. SQL> set serveroutput on; SQL> declare 2 cursor section_cursor is 3 select class_size,number_enrolled 4 from section 5 where course_code=03; 6 classsize section.class_size%type; 7 numberenrolled section.number_enrolled%type; 8 begin 9 open section_cursor; 10 fetch section_cursor into classsize,numberenrolled; 11 dbms_output.put_line(numberenrolled||'out of'||classsize||'enrolled'); 12 end; 13 /

OUTPUT:
28

75 out of 100 enrolled PL/SQL procedure successfully completed.

29

RESULT: Thus the program to create cursor in PL/SQL are created and verified. Ex no: 7 Date: PACKAGE IN PL/SQL

30

AIM: To write a PL/SQL program to create a table and to update and delete rows in a table using package. ALGORITHM: Step1:Start the program Step2:Open the SQL plus Step3:Create a table route_detail with the fields route_id Place_id&non stop Step4:Insert the corresponding values in the route_details Table Step5:Insert upto four values Step6:Create a package route_pack Step7:Create a package boby Step8:Update the route_details non_stop=n, where Route_id=id Step9:Then delete the route_details where route_id=rid Step10:End the package boby Step11:close the SQL plus Step12:End the program

PROGRAM:

31

SQL> create table route_detail (route_id number (3), place_id number (4), nonstop char (2), constraints pk primary key (route_id)); Table created. SQL> insert into route_detail values (&route_id,&place_id,'&nonstop'); Enter value for route_id: 101 Enter value for place_id: 55 Enter value for nonstop: n old 1: insert into route_detail values(&route_id,&place_id,'&nonstop') new 1: insert into route_detail values(101,55,'n') 1 row created. SQL> / Enter value for route_id: 102 Enter value for place_id: 77 Enter value for nonstop: s old 1: insert into route_detail values(&route_id,&place_id,'&nonstop') new 1: insert into route_detail values(102,77,'s') 1 row created. SQL> / Enter value for route_id: 103 Enter value for place_id: 88 Enter value for nonstop: n old 1: insert into route_detail values(&route_id,&place_id,'&nonstop') new 1: insert into route_detail values(103,88,'n') 1 row created. SQL> / Enter value for route_id: 104 Enter value for place_id: 33 Enter value for nonstop: n old 1: insert into route_detail values(&route_id,&place_id,'&nonstop') new 1: insert into route_detail values(104,33,'n') 1 row created. SQL> select * from route_detail;
32

ROUTE_ID PLACE_ID NO ----------------- -101 55 n 102 77 s 103 88 n 104 33 n SQL> create or replace package route_pack is 2 procedure route_update(rid route_detail.route_id%type); 3 procedure route_delete(rid route_detail.route_id%type); 4 end route_pack; 5/ Package created. SQL> create or replace package body route_pack is 2 procedure route_update(rid route_detail.route_id % type) is 3 begin 4 update route_detail set nonstop='n' where route_id=rid; 5 dbms_output.put_line('update'); 6 end; 7 procedure route_delete(rid route_detail.route_id % type) is 8 begin 9 delete from route_detail where route_id=rid; 10 dbms_output.put_line('deleted'); 11 end; 12 end route_pack; 13 / Package body created.

OUTPUT:
33

SQL> exec route_pack.route_update(102); PL/SQL procedure successfully completed. SQL> select * from route_detail; ROUTE_ID PLACE_ID NO --------- --------- -101 55 n 102 77 n 103 88 n 104 33 n SQL> exec route_pack.route_delete(104); PL/SQL procedure successfully completed.

34

RESULT: Thus the PL/SQL program to create a table and to update and delete rows in a table using packages was written, executed and its outputs were verified. Ex no: 08 Date: DESIGN OF PAYROLL PROCESSING SYSTEM

35

AIM: To write a PL/SQ L program for design of payroll processing system. ALGORITHM: Step1:Start the program Step2:Open the SQL plus Step3:Create the table for employee details and salary Details Step4:Insert the values into tables Step5:Declare the variable Step6:Print the employee details Step7:Initialize the integer i=1 Step8:If c3.cno=c4.eno, then calculate al&d Step9:Calculate gp1 and np1 Step10:Display employee details for each employee Step11;If c1 is not found then exit out from loop Step12:End all the loop Step13:Close the SQL plus Step14:End the program

PROGRAM:

36

SQL> create table employeedetails(eno1 number(4) constraint ep primary key,ename varchar2(12),dob date,sex varchar2(1) constraint ep1 check(sex='f' or sex='m'),add1 varchar2(10),add2 varchar2(10), Phon number(6)); Table created. SQL> create table salarydetails(eno number(4) constraint ep3 references employeedetails(eno1),cdob date,basicp number(5),hra number(3),da number(3), ta number(3),ma number(3),lic number(4),ded number(4), gp number(8,2),np number(8,2)); Table created. SQL> insert into employeedetails values(111,'RAMA','07-MAY-80','','RAJA NAGER','SALEM',554433); 1 row created. SQL> insert into employeedetails values(222,'RAVI','07-MAY-80','','RAM NAGER','SALEM',554437); 1 row created. SQL> insert into employeedetails values(333,'SELVI','08-MAY80','','G_NAGER','RASIPURAM',554439); 1 row created. SQL> select * from employeedetails; ENO1 ENAME DOB SEX --------- ------------ --------- - ------111 RAMA 07-MAY-80 M 222 RAVI 07-MAY-80 M 333 SELVI 08-MAY-80 F ADD1 ADD2 -----------------RAJA NAGER SALEM RAM NAGER SALEM G_NAGER RASIPURAM PHONE 554433 554437 554439

37

SQL> insert into salarydetails values(111,'01-sep -99',5500,300,150,50,36,78,250,0,0); 1 row created. SQL> insert into salarydetails values(222,'01-feb99',5000,500,300,200,190,110,200,0,0); 1 row created. SQL> insert into salarydetails values(333,'01-sep-99',9000,33,55,22,34,345,434,0,0); 1 row created. SQL> select * from salarydetails; ENO CDOB BASICP HRA DA TA MA LIC DED GP -------- --------- --------- --------- --------- --------- --------- --------- --------- --------NP -------111 01-SEP-99 5500 300 150 50 36 78 250 0 0 222 01-FEB-99 0 0 333 01-SEP-99 0 0 9000 33 55 22 34 345 434 5000 500 300 200 190 110 200

SQL> set serveroutput on; SQL> declare 2 cursor c1 is select * from salarydetails; 3 cursor c2 is select * from employeedetails;
38

4 c3 c1%rowtype; 5 c4 c2%rowtype; 6 gp1 integer; 7 np1 integer; 8 d integer; 9 al integer; 10 i integer :=1; 11 begin 12 dbms_output.put_line(' '||' Employee Details'); 13 dbms_output.put_line(' '||' ******************'); 14 dbms_output.put_line(' '); 15 for c3 in c1 loop 16 for c4 in c2 loop 17 if c3.eno=c4.eno1 then 18 al:=c3.hra+c3.da+c3.ta; 19 d:=c3.lic+c3.ded; 20 exit when c2% notfound; 21 dbms_output.put_line(' '||' Rec.no:'||i); 22 dbms_output.put_line('------'); 23 dbms_output.put_line(' '); 24 gp1:=c3.basicp+c3.hra+c3.da+c3.ta; 25 np1:=gp1-c3.ded-c3.lic; 26 i:=i+1; 27 dbms_output.put_line('Empname :'|| c4.ename); 28 dbms_output.put_line('Empno :'|| c4.eno1); 29 dbms_output.put_line('Basicpay :'|| c3.basicp); 30 dbms_output.put_line('allowances :'|| al); 31 dbms_output.put_line('Deductions :'|| d); 32 dbms_output.put_line('Net_paye :'|| np1); 33 update salarydetails set gp=gp1,np=np1 where c3.eno=eno; 34 dbms_output.put_line('------------------------'); 35 end if; 36 end loop; 37 exit when c1% notfound; 38 end loop; 39 end; 40 / OUTPUT:

39

Employee Details ****************** Rec.no:1 -----Empname :RAMA Empno :111 Basicpay :5500 allowances :500 Deductions :328 Net_paye :5672 -----------------------Rec.no:2 -----Empname :RAVI Empno :222 Basicpay :5000 allowances :1000 Deductions :310 Net_paye :5690 -----------------------Rec.no:3 -----Empname :SELVI Empno :333 Basicpay :9000 allowances :110 Deductions :779 Net_paye :8331 -----------------------PL/SQL procedure successfully completed.

SQL> select * from salarydetails;

40

ENO CDOB

BASICP

HRA

DA

TA

MA

LIC

DED

GP --------- --------- --------- --------- --------- --------- --------- --------- --------- --------NP --------111 01-SEP-99 5500 300 150 50 36 78 250 6000 5672 222 01-FEB-99 6000 5690 333 01-SEP-99 8331 5000 9000 500 33 300 55 200 22 190 34 110 345 200 434 9110

41

RESULT: Thus the PL/SQ L program for design of payroll processing system was written, executed and its output was verified. EXNO: 9 DATE: LIBRARY INFORMATION SYSTEM

42

AIM: To write a PL/SQL program to design a library information system. ALGORITHM: Step1:Start the program Step2:Open the SQL plus Step3:Create a table for library information that Include book name,author,publisher, Book_copies,library_branch Step4:Insert values into the table Step5:Create a cursor to display all the fields of a particular Second Step6:Close the SQL plus Step7:End the program

PROGRAM: SQL> create table libraryinformation(book_name varchar2(10),book_author

43

2 varchar2(10),publishers varchar2(10),book_copies number(10), 3 library_branch varchar2(10)); Table created. SQL> insert into libraryinformation values('vb','herbert','TMG',50,'cse'); 1 row created. SQL> insert into libraryinformation values('c','balaguru','TMG',100,'cse'); 1 row created. SQL> insert into libraryinformation values('c++','krishnan','TMG',10,'cse'); 1 row created. SQL> set serveroutput on; SQL> declare 2 cursor c1 is select * from libraryinformation; 3 c2 c1%rowtype; 4 i integer:=1; 5 begin 6 dbms_output.put_line(''||'libraryinformationsystem'); 7 dbms_output.put_line(''||'****************') 8 dbms_output.put_line(''); 9 for c2 in c1 loop 10 dbms_output.put_line('Record no:'||i); 11 dbms_output.put_line('Book name:'||c2.book_name); 12 dbms_output.put_line('Book author'||c2.book_author); 13 dbms_output.put_line('publisher:'||c2.publishers); 14 dbms_output.put_line('Book copies:'||c2.book_copies); 15 dbms_output.put_line('library branch:'||c2.library_branch); 16 exit when c1%notfound; 17 end loop; 18 end; 19 / OUTPUT:

44

Libraryinformationsystem **************** Record no:1 Book name:vb Book authorherbert publisher:TMG Book copies:50 library branch:cse Record no:1 Book name:c Book authorbalaguru publisher:TMG Book copies:100 library branch:cse Record no:1 Book name:c++ Book authorkrishnan publisher:TMG Book copies:10 library branch:cse PL/SQL procedure successfully completed.

45

RESULT: Thus the PL/SQL program to design a library information system was written, executed and its output was verified. EX: NO: 10 DATE: STUDENTINFORMATIONSYSTEM

46

AIM: To create student information table and write PL/SQL block to find the total, average and result. ALGORITHM: Step1:Start the program Step2:Open the SQL plus Step3:Create a table student that include fields rollno, Name,subject,total,average and result Step4:Insert values inot the table Step5:Declare the variables Step6:Create a cursor to display the name and marks of a particular student Step7:Calculate total and average Step8:If all the marks are greater than or equal to 40 then Result is pass,else fail Step9:Update the table with total,average and result Step10:Display total,average and result Step11:Close the SQL plus Step12:End the program.

PROGRAM: SQL> create table studentinformation(rollno number(10),name varchar2(10),


47

2 tamil number(10),eng number(10), 3 mat number(10),total number(10),average number(10),result varchar2(10)); Table created. SQL> insert into studentinformation values(101,'muruga',90,96,93,NULL,NULL,''); 1 row created. SQL> insert into studentinformation values(102,'arun',89,98,97,NULL,NULL,''); 1 row created. SQL> set serveroutput on; SQL> declare 2 tot number(10); 3 averg number(10,2); 4 res varchar2(10); 5 na studentinformation.name%type; 6 a studentinformation.tamil%type; 7 b studentinformation.eng%type; 8 c studentinformation.mat%type; 9 cursor s is select name,tamil,eng,mat from studentinformation; 10 begin 11 open s; 12 loop 13 fetch s into na,a,b,c; 14 exit when s%notfound; 15 tot:=a+b+c; 16 averg:=tot/3; 17 if((a>=40)and(b>=40)and(c>=40))then 18 res:='pass'; 19 else res:='fail'; 20 end if; 21 update studentinformation set total=tot,average=averg,result=res 22 where name=na; 23 dbms_output.put_line('tot'||tot); 24 dbms_output.put_line('average'||averg); 25 dbms_output.put_line('result'||res); 26 end loop;
48

27 close s; 28 end; 29 /

OUTPUT:

49

Tot:279 Average:93 Result:pass Tot:284 Average:94.67 Result:pass PL/SQL procedure successfully completed

50

RESULT: Thus the program to create a student information table and write PL/SQL block to find the total, average and result was written, executed and its output was verified. EX NO: 11 DATE:
51

ELECTRICITY BILL

AIM: To write a PL/SQL program to design an electricity bill system using cursor. ALGORITHM: Step1:Start the program Step2:Open the SQL plus Step3:Create a table bill with fields cno,Cname,units,punits And cunits Step4:Insert values into table Step5:Declare the variables Step6:Cursor ss and w are created Step7:Select cno,punit,cunit for ss and punit,cunit for w Step8:Begin the cursor Step9:If unit<=100,then display tot:=un*.50 Step10:If unit<=200,then display tot:=un*1 Step11:If unit<=300,then display tot:=un*2 Step12:If unit<=400,then display tot:=un*3 Step13:Else,tot:=un*3.update amount=tot Step14:Close the SQL plus Step15:End the program

PROGRAM:

52

SQL> create table ebills(cno number(5),cname varchar(10),units number(6), 2 amount number(10),punit number(6),cunit number(6)); Table created. SQL> insert into ebills values(1,'Liju',4300,null,null,null); 1 row created. SQL> set serveroutput on; SQL> declare 2 tot number(8,2); 3 un number(6); 4 cnoo number(5); 5 cun number(5); 6 na ebills.cname%type; 7 a ebills.cno%type; 8 b ebills.units%type; 9 c ebills.punit%type; 10 d ebills.cunit%type; 11 pu ebills.punit%type; 12 cu ebills.cunit%type; 13 cursor ss is select cno,cname,punit,cunit from ebills; 14 cursor w is select punit,cunit from ebills where cno=cnoo; 15 begin 16 cnoo:=&temp; 17 cun:=&temp; 18 open ss; 19 loop 20 fetch ss into a,na,c,d; 21 exit when ss%NOTFOUND; 22 if(a=cnoo)then 23 update ebills set punit=cunit,cunit=cun where cno=cnoo; 24 open w; 25 fetch w into pu,cu; 26 un:=cu-pu; 27 update ebills set units=un where cno=cnoo; 28 if(un<=100)then 29 tot:=un*.50; 30 else 31 if(un<=200)then
53

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

tot:=un*1; else if(un<=300)then tot:=un*2; else if(un<=400)then tot:=un*3; else tot:=un*4; end if; end if; end if; end if; update ebills set amount=tot where cno=cnoo; dbms_output.put_line('tot'||tot); end if; end loop; close w; close ss; end; /

OUTPUT: Enter value for temp: 1


54

old 16: cnoo:=&temp; new 16: cnoo:=1; Enter value for temp: 4000 old 17: cun:=&temp; new 17: cun:=4000; tot0 PL/SQL procedure successfully completed. enter value for temp: 1 old 16: cnoo:=&temp; new 16: cnoo:=1; enter value for temp: 5000 old 17: cun:=&temp; new 17: cun:=5000; tot:4000 PL/SQL procedure successfully completed. SQL> select*from ebills; CNO CNAME UNITS AMOUNT PUNIT -------- ---------- --------- --------- --------- --------1 Liju 1000 4000 4000 CUNIT 5000

55

RESULT: Thus the PL/SQL program to design an electricity bill system using cursor was written, executed and its output was verified.

Ex.no:12 Date:

DESIGN OF A BANKING SYSTEM USING E-R MODEL

56

AIM: To design a banking system using E-R Model. SYMBOLS USED IN E-R MODEL:

E-R DIAGRAM FOR BANKING DATABASE:

57

58

RESULT: Thus designed a banking system using E-R Model

59

You might also like