Lab Book FYBBA (CA) Sem2
Lab Book FYBBA (CA) Sem2
(CA) Semester- II
2019-20
Lab Book
(Web Technology and RDBMS)
• Students are expected to carry this workbook every time they come to the lab for
practical.
• Students should prepare for the assignment by reading the relevant material which is
mentioned in ready reference.
• Instructor will specify which problems to solve in the lab during the allotted slot and
student should complete them and get verified by the instructor. However, student
should spend additional hours in Lab and at home to cover all workbook assignments if
needed.
• Students will be assessed for each assignment on a scale from 0 to 5
Not done 0
Incomplete 1
Late Complete 2
Needs improvement 3
Complete 4
Well Done 5
Editors:
Mr. Yogesh Ingale Dr. D. Y. Patil ACS College, Pimpri, Pune
Mr. Satyavan Kunjir Dr. D. Y. Patil ACS College, Pimpri, Pune
Mrs. Malati V. Tribhuwan Dr. D. Y. Patil ACS College, Pimpri, Pune
Reviewed By:
Dr. Ranjit D. Patil Dr. D. Y. Patil ACS College, Pimpri, Pune
Section I
Web Technology
(HTML, CSS, Java Script)
Table of contents (Section-I: HTML and Java Script)
Exercise 8: JavaScript
Assignment Completion Sheet
(out of 5) Sign
6 Image Mapping
8 JavaScript
Introduction:
Hypertext Markup Language (HTML) is the standard markup language used to
create web pages and web applications. HTML was invented in 1990 by a scientist
called Tim Berners-Lee
Following figure shows basic HTML structure
A Html document begins with opening <html> tag and end with closing </html>
tag and is divided into two sections
1. Head
2. Body
1. Head Section: This section contains title of a web page
2. Body section: The body element contains the information that you want to
display on a web page.
Html elements:
Html documents are simply a text file made up of html elements, these elements
are called as html tags
Html Tags:
Html tags tells the browser how to present information on web page
Html tag name must enclosed between opening and closing angle brackets < tag
name >
Html tags are not case sensitive
Html tags can be of two types
1. Paired tags:
In paired tag, first tag is called as opening tag and second tag is called as
closing tag.
The opening tag actives the effect and closing tag turns the effect off.
Paired tags has three parts i.e opening tag, tag content and closing tag
Eg. <b> Text in Bold </b>
2. Singular tags: the singular tags are stand-alone tags which does not require any
companion tag.
Tag Attribute:
Some html tag contains attributes, which provides additional information
about element
Attributes are always specified in the start tag and come in name=value pair
e.g. <font size=28> Text in Size 28 </font>
The body tag contains all the content of html document such as text, images,
lists, tables, hyperlink etc.
<h1> …. </h1>
<h2 align=left> ….. </h2>
<h3 align=center> …. </h3>
<h4>….. </h4>
<h5> …..</h5>
<h6 align=right> …..</h6>
<p> Tag:
The html <p> tag is used to define a paragraph
<p> tag has attribute “align” whose value can be left, right, center or justify
<p> tag is a singular tag
e.g. <p> ….
<p align=center> ….
<br> Tag:
The html <br> tag is used to specify line break
<br> tag is a singular tag
Center Tag: <center> … </center>
The content enclosed between center tag will be aligned at center place of web
page
e.g. <center> Text aligned at enter </center>
Marquee Tag:
A marquee tag is used to display scrolling text on a web page
Scrolling text is displayed either horizontally across or vertically down of a web
page depending on the setting
hspace Pixels Specifies the whitespace on left and right side of an image
When you move the mouse over a link, the mouse arrow will turn into a little hand.
Hyperlinks are defined with the HTML <a> tag:
<a href="url">link text</a>
Ex.
<a href="C:\Yogesh\test.html">Click Here</a>
Clicking on the link text will send you to the specified address.
HTML Links - The target Attribute:
This example will open the linked document in a new browser window/tab:
Then, add a link to the bookmark ("Jump to Chapter 4"), from within the same
page:
<a href="#C4">Jump to Chapter 4</a>
Assignment:
Set A:
1. Create an html5 page which will display names of your family members on
separate lines in different sizes. State size of each line in its text.
2. Create an html5 page which will display names of players of Indian cricket
team with all the different text styles (bold, italic and underlined) and its
combinations on separate lines. State style of each line in its text.
Set B:
Assignment Evaluation
Signature of Instructor
Exercise 2: Creating List through HTML
HTML offers web authors three ways for specifying lists of information. All lists
must contain one or more list elements. Lists may contain −
1. <ul> − An unordered list. This will list items using plain bullets.
2. <ol> − An ordered list. This will use different schemes of numbers to list
your items.
3. <dl> − A definition list. This arranges your items in the same way as they
are arranged in a dictionary.
Assignments:
Set A:
Set B
1. Write HTML code which generates the following output And Display each
element of list in different size, color & font
1. DYP
• Courses
BCS
BCA
2. Indira
• Courses
BCA
MCs
3. ATSS
• Courses
BBA
BCS
2. Write HTML code which generates the following output and display each
element of list in different size, color & font
• Honda
Petrol
1) Honda City
2) Brio
Diesel
1) Amaze
2) Brio
• Maruti-Suzuki
Petrol
1) Swift
2) Ritz
Diesel
1) Swift-Desire
3. Write the HTML5 code which generates the following output.
1. Coffee
2. Tea
a. Green Tea
b. Black Tea
i. Africa
ii. China
3. Milk
Assignment Evaluation
Signature of Instructor
Exercise 3: Creating Tables through HTML
Introduction:
The HTML <table> tag is used for defining a table. The table tag contains other
tags that define the structure of the table. The <table> tag defines an HTML table.
An HTML table consists of the <table> element and one or more <tr>, <th>,
and <td> elements.
The <tr> element defines a table row, the <th> element defines a table header, and
the <td> element defines a table cell.
Specific Attributes:
The HTML <table> tag also supports the following additional attributes −
Attribute Value Description
align right Specifies Visual alignment.
left
center
justify
char
bgcolor rgb(x,x,x) Specifies the background color of the table.
#hexcode
colorname
border Pixels Specifies the border width. A value of "0" means no
border.
cellpadding pixels or Specifies the space between the cell borders and their
% contents.
cellspacing pixels or Specifies the space between cells.
%
Assignments:
Set A
Set B
Price
Book_No Book_Name
RS Paise
101 DBMS 200 50
102 C-Prog 150 75
103 JAVA 300 00
104 PHP 250 50
105 ASP 100 00
Price
Book_No Book_Name
RS Paise
101 DBMS 200 50
102 C-Prog 150 75
103 JAVA 300 00
104 PHP 250 50
105 ASP 100 00
5. Write HTML code to create following table.
Assignment Evaluation
Signature of Instructor
Exercise 4: Creating Frames through HTML
Introduction:
<Frameset> Tag:
The <frameset> element holds one or more <frame> elements. Each <frame>
element can hold a separate document.
The <frameset> element specifies HOW MANY columns or rows there will be in
the frameset, and HOW MUCH percentage/pixels of space will occupy each of
them.
Attributes of Frameset Tag:
<frame> tag:
The <frame> tag defines one particular window (frame) within a <frameset>.
Attributes of <frame>:
Assignments:
Set A:
1. Write a HTML code to divide the web page into 4 setion using frame as
follows
2. Write a HTML code to divide the web browser in to 4 section using frame as
follows
Set B
1. Create HTML page to Divide the frames in to different sections as shown
below and add appropriate HTML files to each frame.
2. Write HTML code to design a web as per given specification. Divide the
browser screen into two frames. The first frame will display the heading.
Divide the second frame into two columns. The frame on the left should be
name of cities consisting of hyperlinks. Clicking on any one of these
hyperlinks will display related information in right hand side frame as shown
below
IT Industries in INDIA
City Pune
1. Pune • Infosys
2. Mumbai • Persistent
3. Write a HTML code which will divide web page in three frames. First frame
should consists of name of college as heading. Second frame should consists
of name of courses with hyperlink. Once click on any course it should
display subject of that course in third frame.
Assignment Evaluation
Signature of Instructor
Exercise 5: Creating Form through HTML
Introduction:
The <form> Element:
The HTML <form> element defines a form that is used to collect user input. An
HTML form contains form elements.Form elements are different types of input
elements, like text fields, checkboxes, radio buttons, submit buttons, and more.
The <input> Element
The <input> element is the most important form element.The <input> element can
be displayed in several ways, depending on the type attribute.
The action attribute defines the action to be performed when the form is submitted.
Normally, the form data is sent to a web page on the server when the user clicks on
the submit button.
<form action="/action_page.php">
The Method Attribute: The method attribute specifies the HTTP method
(GET or POST) to be used when submitting the form data:
<form action="/action_page.php" method="get">
Grouping Form Data with <fieldset>:
The <fieldset> element is used to group related data in a form.
The <legend> element defines a caption for the <fieldset> element.
Ex
<form action="/action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
The <select> element defines a drop-down list: The <option> elements defines an
option that can be selected. By default, the first item in the drop-down list is
selected. Use the multiple attribute to allow the user to select more than one value
To define a pre-selected option, add the selected attribute to the option:
Ex.
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
Set A:
Set B
4) Design a HTML form for Bus Ticket Reservation consisting of fields for Name,
Address, contact no, source station(Dropdown list), Destination station, Date of
booking, date of journey, no of passenger, name of passenger, gender of
passenger etc. (Use proper alignment)
Assignment Evaluation
Signature of Instructor
Exercise 6: Image Mapping
Introduction:
The Image:
The image is inserted using the <img> tag. The only difference from other images
is that you must add a usemap attribute:
<img src="workplace.jpg" usemap="#mymap”>
The usemap value starts with a hash tag # followed by the name of the image map,
and is used to create a relationship between the image and the image map.
The Map:
Then add a <map> element. The <map> element is used to create an image map,
and is linked to the image by using the name attribute:
<map name="mymap">
The name attribute must have the same value as the usemap attribute.
The Areas:
Then add the clickable areas.
A clickable area is defined using an <area> element.
Shape:
You must define the shape of the area, and you can choose one of these values:
• rect - defines a rectangular region
• circle - defines a circular region
• poly - defines a polygonal region
• default - defines the entire region
Coordinates:
You must define some coordinates to be able to place the clickable area onto the
image.
The coordinates come in pairs, one for the x-axis and one for the y-axis.
The coordinates 34, 44 is located 34 pixels from the left margin and 44 pixels from
the top:
Ex. <area shape="rect" coords="34, 44, 270, 350" href="computer.htm">
Circle:
To add a circle area, first locate the coordinates of the center of the circle:
337, 300
Then specify the radius of the circle:
44 pixels
<area shape="circle" coords="337, 300, 44" href="coffee.htm">
Assignments:
Set A:
Create a picture in paint brush consisting of circle, triangle and square. Insert this
picture on webpage. Create image map such that once click on circle shape it
should display web page about circle, once click on square square should display
separate page in new tab and so on
Set B
Display India.jpg image on web page consisting of different states. Once click on
any state, it should open new web page consisting of information about that state
Assignment Evaluation
Signature of Instructor
Exercise 7: Styling HTML with CSS
Introduction:
CSS stands for Cascading Style Sheets.
CSS describes how HTML elements are to be displayed on screen, paper, or in
other media. CSS saves a lot of work. It can control the layout of multiple web
pages all at once.
Inline CSS:
An inline CSS is used to apply a unique style to a single HTML element. An inline
CSS uses the style attribute of an HTML element. This example sets the text color
of the <h1> element to blue:
Example:
<h1 style="color:blue;">This is a Blue Heading</h1>
Internal CSS:
An internal CSS is used to define a style for a single HTML page. An internal CSS
is defined in the <head> section of an HTML page, within a <style> element:
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External CSS:
An external style sheet is used to define the style for many HTML pages. With an
external style sheet, you can change the look of an entire web site, by changing one
file!. To use an external style sheet, add a link to it in the <head> section of the
HTML page:
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor. The file must not contain
any HTML code, and must be saved with a .css extension.
Here is how the "styles.css" looks:
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}
External References:
External style sheets can be referenced with a full URL or with a path relative to
the current web page. This example uses a full URL to link to a style sheet:
Assignments:
Set A
1. Create HTML web page with following specifications
Set B
2. Write HTML code which generates the following output And Display each
element of list in different size, color & font. Use external CSS to format the
list
• Non flowering plants
o Fern
o Spore
• Flowering plants
Lilly
Rose
1. Red Rose
2. Pink Rose
3. Create HTML page with following specifications
Assignment Evaluation
0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]
3: Need Improvement [ ] 4: Complete [ ] 5: Well Done [ ]
Signature of Instructor
Exercise 8: JavaScript
Introduction:
JavaScript is the programming language of HTML and the Web. JavaScript is one
of the 3 languages all web developers must learn:
JavaScript in <head>
In this example, a JavaScript function is placed in the <head> section of an HTML
page. The function is invoked (called) when a button is clicked:
JavaScript Display Possibilities
JavaScript can "display" data in different ways:
• Writing into an HTML element, using innerHTML.
• Writing into the HTML output using document.write().
• Writing into an alert box, using window.alert().
• Writing into the browser console, using console.log().
Using innerHTML:
Assignments:
Set A
1. Write a java script program to accept a number form user and display its
multiplication table
2. Write a java script program to accept a number form user and calculate and
display its sum of digits
3. Write a java script program to accept a number from user and check whether
it is Armstrong number or not
4. Write a java script program to accept a number from user and check whether
it is perfect number or not.
5. Write java script program to accept a number from user and check whether it
is prime number or not
6. Write a java script program to accept a string from user and display the
count of vowel characters from that string.
7. Write a java script program to accept a string and character from user and
check the count of occurrences of that character in string.
8. Write a JavaScript program to Display current Day, Date, Month, Year and
Time on the web
9. page and greet the user accordingly.
10.Write a java script program to accept the value of n and display all odd
numbers up to n.
*
* *
* * *
Set B
13.Write a JavaScript Program to read a number from user, store its factors into
the array and display that array. (Handle onClick Event)
14.Design a student registration form with fields Name, Address, city and Pin-
Code.
15.Write a java script program to perform following validation Check name
should not be empty and contain alphabets onlyPin-code must be 6 digits
only
16.Design a login form with fields User Name, Password and Login button.
Write a java script code to accept username and password, validate login
details and display a message accordingly.
17.Write a java script code to accept a sentence from the user and alters it as
follows: Every space is replaced by * and digits are replaced by ?
18.Write a JavaScript Program to accept user name and password from an user,
if User name and Password is same then display his score card on the next
page as shown below.
19.Write a java script code to accept a number from user and write a function to
calculate sum of all odd digits of that number.
Assignment Evaluation
Signature of Instructor
Section II
(RDBMS)
Table of Contents for Section-II (RDBMS)
(out of 5) Sign
4 Procedure
5 Cursor
6 Trigger
7 Package
Numeric Smallint
2-byte small-range integer
Types
integer, int A signed, fixed precision 4-byte
Bigint stores whole numbers, large range 8 byte
Real 4-byte, single precision, floating-point number
Serial 4-byte auto incrementing integer
double precision 8-byte, double precision, floating-point number
Where m is the total digits and d is the number of
numeric(m,d) digits after
the decimal.
Character character(n), char(n) Fixed n-length character strings.
Types character varying(n), A variable length character string with limit.
varchar(n)
A variable length character string of unlimited
Text length.
Monetary
Types Money currency amount,8 bytes
Boolean type Boolean It specifies the state of true or false,1 byte.
Date/Time
Type Date date (no time of day),4 byte.
Time time of day (no date),8 byte
time with time zone times of day only, with time zone,12 bytes
PLSQL Block:
A PL/SQL block is program structure which is used to write a SQL and PL/SQL
statements.
Declaration
Variable declaration section
Begin
Execution Section
Exception
Exception Section
End;
In the given structure,
PL/SQL variables and cursors have attributes, which are properties that let
you reference the datatype and structure of an item from table without repeating its
definition. A percent sign (%) is used to represent the attribute.
%TYPE If you want to declare variables that will hold database values
then %TYPE attribute is used.
Syntax: VariableName TableName.ColumnName%TYPE;
Example: my_title books.title%TYPE;
%ROWTYPE If you want to declare a variable that will hold number of records
then %ROWTYPE attribute is used
Syntax: VariableName Table_Name%ROWTYPE;
VaribleName Cursor_Name%ROWTYPE;
Example:
1. My_Book book%ROWTYPE;
2. CURSOR c1 is Select * from book;
Book_rec c1%ROWTYPE;
declare
a number := &a;
b number :=&b;
c number;
begin
c:=a+b;
dbms_output.put_line('Addition is ' || c);
end;
Example 2: PL/SQL block which accept value from user to insert it into
student table (Using %TYPE attribute)
Declare
stud_rec student%ROWTYPE;
Begin
select * into stud_rec from student ;
dbms_output.put_line(‘Student Roll=’||stud_rec.rno);
dbms_output.put_line(‘Student Name=’||stud_rec.sname);
dbms_output.put_line(‘Student Percentage=’||stud_rec.per);
End;
Control Statement: According to the structure theorem, any computer program
can be written using the basic control structures. They can be combined in any way
necessary to deal with a given problem.
• The Condition structure tests a condition, then executes one sequence of
statements instead of another, depending on whether the condition is true or
false. A condition any variable or expression that returns a Boolean value
(TRUE or FALSE).
• The iteration structure executes a sequence of statements repeatedly as
long as a condition holds true. The sequence structure simply executes a
sequence of statements in the order in which they occur.
Conditional Statements:
A conditional statement specifies an action (or set of actions) that should
be executed by checking some logical condition, based on the result of
logical condition the sequence of statements are executed.
1. IF…. THEN Statement: IF….THEN statement, a statement or block of
statements is executed if given condition evaluates true.
Syntax:
IF condition THEN
Statements;
END IF;
Example:
IF class=’FY’ THEN
dbms_output.put_line('Welcome FY’);
END IF;
CASE [expression]
WHEN condition1 THEN result1
WHEN condition2 THEN result2
....................
WHEN condition_n THEN result_n
ELSE result
END;
Example:
DECLARE
grade char(1) := 'C';
BEGIN
CASE grade
when 'A' then
dbms_output.put_line('Distinction');
when 'B' then
dbms_output.put_line('First class');
when 'C' then
dbms_output.put_line('Second class');
when 'D' then
dbms_output.put_line('Pass class');
else
dbms_output.put_line('Failed');
END CASE;
END;
LOOP
Statements;
EXIT;
[or EXIT WHEN condition;]
END LOOP;
Example
DECLARE
i NUMBER := 1;
BEGIN
LOOP
dbms_output.put_line(i);
i := i+1;
EXIT WHEN i>5;
END LOOP;
END;
Syntax:
WHILE [condition]
LOOP Statements;
END LOOP;
Example:
DECLARE
i INTEGER := 1;
BEGIN
WHILE i <= 5 LOOP
dbms_output.put_line(i);
i := i+1;
END LOOP;
END;
3. PL/SQL FOR Loop: It is used to execute a set of statements for a fixed number
of times. It is iterated between the start and end integer values.
Syntax:
FOR counter IN initial_value .. final_value LOOP
LOOP statements;
END LOOP;
Example
BEGIN
FOR k IN 1..5 LOOP
dbms_output.put_line(k) ;
END LOOP;
END;
Assignments:
SET A:
3. Write a PL/SQL block which will accept two numbers from user, check
whether numbers are positive or negative. If positive number then display
only the odd numbers between the entered numbers.
SET B
1. Write a PL/SQL block which will accept roll number of a student and
display record of student from student table( use %ROWTYPE attribute)
2. Write a PL/SQL block which will accept roll number from student, select
name and percentage of the student and calculate grade using percentage
value. Display the record.(use %TYPE)
Assignment Evaluation
Signature of Instructor
Assignment No. 2: Error and Exception Handling
An error occurred during the execution (run time) of program is called exception
in PL/SQL. PL/SQL provides the facility to catch errors by declaring conditions in
exception block in the program and necessary action to be taken to rectify the
error. Exception can be User defined (these are logical error defined by user) or
System defined.
Syntax:
Declare
< Declaration Section>
Begin
<Statements>
Exception
When condition Then
Handler statements
End;
Example:
DECLARE
Salary number;
BEGIN
Salary:=&Salary;
EXCEPTION
WHEN Salary<=0 THEN
DBMS_OUTPUT.PUT_LINE('Error:: Salary must be a positive
number..');
END;
Types of Exception
1. Predefined / System Defined Exception :
Predefined exception is raised automatically whenever there is a violation of
Oracle coding rules. Predefined exceptions are those like ZERO_DIVIDE, which
is raised automatically when we try to divide a number by zero. Other built-in
exceptions are given below.
TOO_MANY_ROWS When a select query returns more than one row and
the destination variable can take only single value.
PL/SQL block to accept customer name, address and display. If not found
then use system defined exception.
DECLARE
c_id customers.id%type := 5;
c_name customers.name%type;
c_addr customers.address%type;
BEGIN
SELECT name, address INTO c_name, c_addr FROM customers
WHERE id = c_id;
DBMS_OUTPUT.PUT_LINE ('Name: '|| c_name);
DBMS_OUTPUT.PUT_LINE ('Address: ' || c_addr);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such customer!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
2. User-defined Exceptions:
PL/SQL allows you to define your own exceptions according to the need of
your program. A user-defined exception must be declared and then raised
explicitly, using either a RAISE statement or the
procedure DBMS_STANDARD.RAISE_APPLICATION_ERROR
Syntax:
DECLARE
exception_name EXCEPTION;
BEGIN
<Execution block>
RAISE <exception_name>
EXCEPTION
WHEN <exception_name> THEN
<Handler>
END;
WHEN exception_nameTHEN
Example :
Create an exception Negative_No and raise the exception when entered number is
negative.
Declare
Negative_No Exception;
Num number;
Begin
Num:=&Num;
if Num<0 then
RAISE Negative_No;
else
dbms_output.put_line('Num='||Num);
End If;
Exception
When Negative_No then
dbms_output.put_line('error:: Enter positive number...!');
End;
Assignments:
SET A:
Consider the following entities and their relationships.
Wholesaler (w_no, w_name, address, city)
Product (product_no, product_name, rate)
Relation between Wholesaler and Product is Many
to Many with quantity as descriptive attribute.
Constraint: Primary key, rate should be > 0.
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the
following:
1. Write a function to accept quantity from user. Quantity must be within range
50-200. If user enters the quantity out of range then raise an user defined
exception “quantity_out_of _range” otherwise enter the record in table.
2. Write a PL/SQL block which accept rate from user. If user enters rate less
than or equal to zero then raise an user defined exception
“Invalid_Rate_Value” otherwise display message “Correct Input”.
SET B:
Assignment Evaluation
Signature of Instructor
Assignment No. 3: Procedure
The PL/SQL stored procedure or simply a procedure is a PL/SQL block which
performs one or more specific tasks. It is just like procedures in other
programming languages. The procedure contains a header and a body section
Header: The header contains the name of the procedure and the parameters
or variables passed to the procedure.
Body: The body contains a declaration section, execution section and
exception section similar to a general PL/SQL block.
Syntax:
Example:
CREATE OR REPLACE PROCEDURE display AS
BEGIN
dbms_output.put_line('This is a procedure demo…!');
END;
/
After executing above code using SQL prompt, it will show “Procedure Created
“message.
Executing Procedure:
A standalone procedure can be executed by using two ways
BEGIN
display;
END;
The above call will display the output:
This is a procedure demo…!
PL/SQL procedure successfully completed.
Welcome Aarushi
The following example accepts two IN parameter and one OUT parameter and
checks the maximum number.
Create a procedure
Create or Replace PROCEDURE getMax(x IN number, y IN number, z OUT
number) IS
BEGIN
IF x < y THEN
z:= x;
ELSE
z:= y;
END IF;
END;
The following example accepts one parameter as INOUT and calculate square of a
given number.
Create a procedure
Assignments:
SET A:
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the following:
1) Write a procedure to calculate city wise total cost of each newspaper
2) Write a procedure which display details of news papers having cost greater
than 2 Rs.
3) Write a procedure which take display details of cities where English news
paper is supplied.
SET B:
Consider the following entities and their relationships.
Library(Lno, Lname, Location, Librarian, no_of_books)
Book(Bid, Bname, Author_Name, Price, publication)
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the
following:
1) Write a procedure which will accept publication name from user and
display details of books published by it.
2) Write a procedure which will accept Library number from user and
display Book name and their price.
3) Write a procedure to display names of Libraries having books written by
“Mr. Patil”.
Assignment Evaluation
Signature of Instructor
Assignment No. 4: Function
The PL/SQL Function is very similar to PL/SQL Procedure. The main difference
between procedure and a function is, a function must always return a value, and on
the other hand a procedure may or may not return a value. Except this, all the other
things of PL/SQL procedure are similar for PL/SQL function.
1. Create a function
2. Write a PLSQL block to call the function and execute block
Or execute function using select statement.
2) Write a function which will return minimum maturity amount of all policies.
3) Write a function which will return total number of policies opened no “1-
Jan-2020”
SET B:
Assignment Evaluation
Signature of Instructor
Assignment No.5: Cursors
A cursor is a pointer that points to a result of a query. PL/SQL controls the context
area through a cursor. A cursor holds the rows (one or more) returned by a SQL
statement. The set of rows cursor holds is referred to as the active set.
PL/SQL has two types of cursors: Implicit cursors and Explicit cursors.
The following table specifies the status of the cursor with each of its
attribute.
Attribute Description
%FOUND Its return value is TRUE if DML statements like INSERT,
DELETE and UPDATE affect at least one row or more
rows or a SELECT INTO statement returned one or more
rows. Otherwise it returns FALSE.
DECLARE
s_rno Student.rno%TYPE;
s_name Student.name% TYPE;
s_per Student.per% TYPE;
CURSOR Stud IS SELECT rno, name, per FROM Student;
BEGIN
OPEN Stud;
LOOP
FETCH Stud into s_rno, s_name, s_per;
EXIT WHEN c_customers%notfound;
dbms_output.put_line(s_rno || ' ' || s_name || ' ' || s_per);
END LOOP;
CLOSE Stud; END; /
Example 2: Display the record of a particular student using parameterized
cursor
DECLARE
Stud_rec Student%ROWTYPE;
CURSOR Stud(no number) IS SELECT * FROM Student where rno=no;
BEGIN
OPEN Stud(5);
LOOP
FETCH Stud into Stud_rec;
EXIT WHEN Stud%notfound;
dbms_output.put_line(Stud_rec.rno || ' ' || Stud_rec.name || ' ' ||
Stud_rec.per);
END LOOP;
CLOSE Stud;
END;
Assignments:
SET A:
Consider the following entities and their relationships.
SET B:
Assignment Evaluation
Signature of Instructor
Assignment No. 6: Triggers
A trigger is a stored procedure in database which automatically invokes
whenever a special event in the database occurs. For example, a trigger can be
invoked when a row is inserted into a specified table or when certain table columns
are being updated or deleted.
A trigger is fired when a DML statements like Insert, Delete, Update is executed
on a database table. A trigger is triggered automatically when an associated DML
statement is executed.
Syntax:
1. Row-Level Trigger: A row-level trigger fires once for each row that is
affected by a triggering event.
For example, if Delete operation is defined as a triggering event for a
particular table, and a single DELETE statement deletes five rows from that
table, the trigger fires five times, once for each row.
2. Statement-Level Trigger: A statement-level trigger fires only once for
each statement. Using the previous example, if deletion is defined as a
triggering event for a particular table, and a single DELETE statement
deletes five rows from that table, the trigger fires once.
3. BEFORE Trigger: BEFORE trigger executes before the DML statement
(INSERT, UPDATE, DELETE) execute.
4. AFTER Trigger: AFTER trigger executes after the DML statement
(INSERT, UPDATE, DELETE) executed.
5. Combination Trigger: Combination trigger are combination of two trigger
type,
Before Statement Trigger, Before Row Trigger, After Statement Trigger,
After Row Trigger
Example:
1) Before Update: This trigger will raise before salary is updated on “Employee”
table
Create or replace trigger emp_update before update on employee for each
row
Declare
invalid_salary Exception;
Begin
if(:new.salary<=0) then
raise invalid_salary;
end if;
Exception
when invalid_salary then
raise_application_error(-20003,'Error:: Salary must be a positive
number');
End;
2) Before Insert or update: This trigger will raise before salary is inserted or
updated on
“Employee” table
3) Before Delete: This trigger will raise before salary is deleted on “Employee”
table
Create or replace trigger del_Emp before delete on employee for each row
Declare
del_Emp Exception;
Begin
raise del_Emp;
Exception
when del_Emp then
raise_application_error(-20001,'Error:: Record can not be deleted');
End;
Output:
delete from employee where eno=3;
delete from employee where eno=3
*
ERROR at line 1:
ORA-20001: Error:: Record can not be deleted
ORA-06512: at "MVT.DEL_EMP", line 9
ORA-04088: error during execution of trigger 'MVT.DEL_EMP'
4) After Insert: This trigger will raise after record is inserted and mobile number
is not with in
range on “Employee” table.
create or replace trigger emp_insert after insert on employee for each row
Declare
invalid_mobile Exception;
len number;
Begin
len:=length(:new.mobile);
if(len<10 or len>10) then
raise invalid_mobile;
end if;
Exception
when invalid_mobile then
raise_application_error(-20006,'Error:: Mobile number must be 10
digit....!');
End;
Assignments:
SET A :
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the
following:
1) Write a trigger which will fire before insert or update on Investment having
investment amount less than 10000. (Raise user defined exception and give
appropriate message)
2) Write a trigger which will fire before insert or update on Employee having
Emp id less than equal to zero (Raise user defined exception and give
appropriate message)
3) Write a trigger which will fire before insert or update on Investment having
investment date greater than current date. (Raise user defined exception and
give appropriate message)
SET B :
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the
following:
1) Write a trigger which will fire before insert or update on Menu having
price less than or equal to zero. (Raise user defined exception and give
appropriate message)
2) Write a trigger which will fire before insert or update on Bill having day
other than seven week days. (Raise user defined exception and give
appropriate message)
3) Write a trigger which will fire before insert or update on Bill having total
less than or equal to 10 Rs. (Raise user defined exception and give
appropriate message)
Assignment Evaluation
Signature of Instructor
Assignment No. 7: Package
Packages are schema objects that groups logically related PL/SQL types,
variables, and subprograms. A package will have two mandatory parts −
1. Package Specification:
Package specification contains the information about the content of the
package. It is the interface to the package which DECLARES the types, variables,
constants, exceptions, cursors, and subprograms that can be referenced from
outside the package.
Following example creates a package which consist one function and one
procedure
exception
when no_data_found then
dbms_output.put_line('Employee does not exist');
END;
end emp_pack;
Declare
enumber number:=&enumber;
emp1 emp%rowtype;
tsal number;
Begin
tsal:=emp_pack.total_sal();
emp_pack.empdetails(enumber,emp1);
dbms_output.put_line('Total salary of Employees is '||tsal);
dbms_output.put_line('Details of a given Employee is
'||emp1.eno||emp1.ename||emp1.salary);
End;
Assignments:
SET A:
Create a RDB in 3NF and write PL/SQL blocks in Oracle for the
following:
1) Write a package, which consists of one procedure and one function. Pass
college code as a parameter to procedure and display details of college.
Write a function which will return teacher name having maximum salary.
2) Write a package, which consists of one cursor and one trigger. Cursor
should display teachers detail and trigger should fire on Teacher table
before insert or update salary having salary less than or equal to zero.
Assignment Evaluation
Signature of Instructor