Concept explainers
a.
Stored procedures:
- A procedure is a collection of procedural and SQL statements.
- A procedure may have input parameter or output parameter or sometimes both the parameters.
- It is declared with a unique name with a unit of procedural code using the proprietary RDBMS and it is invoked by a host language library routine.
Syntax for stored procedure:
CREATE FUNCTION fun_name(argument IN data-type)RETRUN data-type[IS]
BEGIN
PL/SQL statements;
Return (value or expression);
END;

Explanation of Solution
Query to create stored procedure:
CREATE OR REPLACE PROCEDURE DISP_OWNER (I_OWNER_NUM IN OWNER.OWNER_NUM%TYPE) AS
I_FIRST_NAME OWNER.FIRST_NAME%TYPE;
I_LAST_NAME OWNER.LAST_NAME%TYPE;
BEGIN
SELECT FIRST_NAME, LAST_NAME
INTO I_FIRST_NAME, I_LAST_NAME
FROM OWNER
WHERE OWNER_NUM = I_OWNER_NUM;
DBMS_OUTPUT.PUT_LINE(I_OWNER_NUM);
DBMS_OUTPUT.PUT_LINE(I_FIRST_NAME);
DBMS_OUTPUT.PUT_LINE(I_LAST_NAME);
END;
/
Explanation:
- The above query is used to create a procedure named “DISP_OWNER” to select the records in the “OWNER” table.
- Change the “OWNER_NUM” into “I_OWNER_NUM” and place the “FIRST_NAME” and “LAST_NAME” values into “I_FIRST_NAME” and “I_LAST_NAME”.
- After placing these values, display the “I_OWNER_NUM”, “I_FIRST_NAME”, and “I_LAST_NAME” from the “OWNER” table.
- Once the stored procedure is created, it needs to be executed.
Query to view the owner name and ID:
BEGIN
DISP_OWNER ('AN175');
END;
The above query is used to view the owner ID, first name, and last name for the number “AN175”.
Output:
AN175
Bill
Anderson
Explanation of Solution
b.
Query to create stored procedure:
CREATE OR REPLACE PROCEDURE DISP_CONDO_UNIT
(I_CONDO_ID IN CONDO_UNIT.CONDO_ID%TYPE) AS
I_LOCATION_NUM CONDO_UNIT.LOCATION_NUM%TYPE;
I_UNIT_NUM CONDO_UNIT.UNIT_NUM%TYPE;
I_OWNER_NUM CONDO_UNIT.OWNER_NUM%TYPE;
I_FIRST_NAME OWNER.FIRST_NAME%TYPE;
I_LAST_NAME OWNER.LAST_NAME%TYPE;
BEGIN
SELECT LOCATION_NUM, UNIT_NUM, CONDO_UNIT.OWNER_NUM, FIRST_NAME, LAST_NAME
INTO I_LOCATION_NUM, I_UNIT_NUM, I_OWNER_NUM, I_FIRST_NAME, I_LAST_NAME
FROM CONDO_UNIT, OWNER
WHERE CONDO_UNIT.OWNER_NUM = OWNER.OWNER_NUM
AND CONDO_ID = I_CONDO_ID;
DBMS_OUTPUT.PUT_LINE(I_CONDO_ID);
DBMS_OUTPUT.PUT_LINE(I_LOCATION_NUM);
DBMS_OUTPUT.PUT_LINE(I_UNIT_NUM);
DBMS_OUTPUT.PUT_LINE(I_OWNER_NUM);
DBMS_OUTPUT.PUT_LINE(I_FIRST_NAME);
DBMS_OUTPUT.PUT_LINE(I_LAST_NAME);
END;
/
Explanation:
- The above query is used to create a procedure named “DISP_CONDO_UNIT” to select the records in the “CONDO_UNIT” and “OWNER” tables.
- Change the “CONDO_ID” into “I_CONDO_ID” and place the “LOCATION_NUM”, “UNIT_NUM”, “OWNER_NUM”, “FIRST_NAME”, and “LAST_NAME” values into “I_LOCATION_NUM”, “I_UNIT_NUM”, “I_OWNER_NUM”, “I_FIRST_NAME”, and “I_ LAST_NAME”.
- After placing these values, display the “I_CONDO_ID”, I_LOCATION_NUM”, “I_UNIT_NUM”, “I_OWNER_NUM”, “I_FIRST_NAME”, and “I_ LAST_NAME” from the “CONDO_UNIT” and “OWNER” tables.
- Once the stored procedure is created, it needs to be executed.
Query to view a result:
BEGIN
DISP_CONDO_UNIT(3);
END;
The above query is used to view the condo Id, location number, unit number, owner number, first name and last name for the condo id “3”.

Output:
3
1
306
AN175
Bill
Anderson
Explanation of Solution
c.
Query to insert the value:
CREATE OR REPLACE PROCEDURE ADD_OWNER
(I_OWNER_NUM IN OWNER.OWNER_NUM%TYPE,
I_LAST_NAME IN OWNER.LAST_NAME%TYPE,
I_FIRST_NAME IN OWNER.FIRST_NAME%TYPE,
I_ADDRESS IN OWNER.ADDRESS%TYPE,
I_CITY IN OWNER.CITY%TYPE,
I_STATE IN OWNER.STATE%TYPE,
I_POSTAL_CODE IN OWNER.POSTAL_CODE%TYPE) AS
BEGIN
INSERT INTO OWNER (OWNER_NUM, LAST_NAME, FIRST_NAME, ADDRESS, CITY, STATE, POSTAL_CODE)
VALUES
(I_OWNER_NUM, I_LAST_NAME, I_FIRST_NAME, I_ADDRESS, I_CITY, I_STATE,
I_POSTAL_CODE);
END;
/
Explanation:
The above query is used to create a stored procedure named “ADD_OWNER” to insert the new record in the “OWNER” table. Once the stored procedure is created, it needs to be executed.
Query to execute the stored procedure:
BEGIN
ADD_OWNER ('AZ245', 'William', 'John', '125 North St.', 'Mills', 'SC', 29707);
END;
After executing the above query, the new record is inserted into the table “OWNER”.

Output:
Query to view the contents in “OWNER” table is as follows:
SELECT * FROM OWNER;
Screenshot of output
Explanation of Solution
d.
Query to update stored procedure:
CREATE OR REPLACE PROCEDURE CHG_OWNER
(I_OWNER_NUM IN OWNER.OWNER_NUM%TYPE,
I_LAST_NAME IN OWNER.LAST_NAME%TYPE) AS
BEGIN
UPDATE OWNER
SET LAST_NAME = I_LAST_NAME
WHERE OWNER_NUM = I_OWNER_NUM;
END;
/
Explanation:
The above query is used to create a stored procedure named “CHG_OWNER” to update the last name of the owner whose number is stored in “I_OWNER_NUM” to the value presently found in “I_OWNER_NUM”, it needs to be executed.
Query to execute the stored procedure:
BEGIN
CHG_OWNER ('AZ245', 'Andrew');
END;
After executing the above query, the last name is changed in the table “OWNER”.

Output:
Query to view the contents in “OWNER” table is as follows:
SELECT * FROM OWNER;
Screenshot of output
Explanation of Solution
e.
Query to delete the value:
CREATE OR REPLACE PROCEDURE DELETE_OWNER
(I_OWNER_NUM IN OWNER.OWNER_NUM%TYPE) AS
BEGIN
DELETE
FROM OWNER
WHERE OWNER_NUM = I_OWNER_NUM;
END;
/
Explanation:
- The above query is used to create a procedure named “DELETE_OWNER” to delete a record in the “OWNER” table.
- Once the record is deleted, a procedure should create owner number as a parameter.
- Once the stored procedure is created, it needs to be executed.
Query to execute the stored procedure:
BEGIN
DELETE_OWNER ('AZ245');
END;
The above query is used to delete the order number AZ245.

Output:
Query to view the contents in “OWNER” table after deleting the order number AZ245 as follows:
SELECT * FROM OWNER;
Screenshot of output
Want to see more full solutions like this?
Chapter 8 Solutions
A GUIDE TO SQL
- Design a dynamic programming algorithm for the Longest Alternating Subsequence problem described below: Input: A sequence of n integers Output: The length of the longest subsequence where the numbers alternate between being larger and smaller than their predecessor The algorithm must take O(n²) time. You must also write and explain the recurrence. Example 1: Input: [3, 5, 4, 1, 3, 6, 5, 7, 3, 4] Output: 8 ([3, 5, 4, 6, 5, 7, 3, 4]) Example 2: Input: [4,7,2,5,8, 3, 8, 0, 4, 7, 8] Output: 8 ([4, 7, 2, 5, 3, 8, 0,4]) (Take your time with this for the subproblem for this one)arrow_forwardDesign a dynamic programming algorithm for the Coin-change problem described below: Input: An amount of money C and a set of n possible coin values with an unlimited supply of each kind of coin. Output: The smallest number of coins that add up to C exactly, or output that no such set exists. The algorithm must take O(n C) time. You must also write and explain the recurrence. Example 1: Input: C24, Coin values = = [1, 5, 10, 25, 50] Output: 6 (since 24 = 10+ 10+1+1 +1 + 1) Example 2: Input: C = 86, Coin values = [1, 5, 6, 23, 35, 46, 50] Output: 2 (since 86 = 46+35+5)arrow_forwardDesign a dynamic programming algorithm for the Longest Common Subsequence problem de- scribed below Input: Two strings x = x1x2 xm and y = Y1Y2... Yn Output: The length of the longest subsequence that is common to both x and y. . The algorithm must take O(m n) time. You must also write and explain the recurrence. (I want the largest k such that there are 1 ≤ i₁ < ... < ik ≤ m and 1 ≤ j₁ < ... < jk ≤ n such that Xi₁ Xi2 Xik = Yj1Yj2 ··· Yjk) Example 1: Input: x = 'abcdefghijklmnopqrst' and y = 'ygrhnodsh ftw' Output: 6 ('ghnost' is the longest common subsequence to both strings) Example 2: Input: x = 'ahshku' and y = ‘asu' Output: 3 ('asu' is the longest common subsequence to both strings)arrow_forward
- Design a dynamic programming algorithm for the problem described below Input: A list of numbers A = = [a1,..., an]. Output: A contiguous subsequence of numbers with the maximum sum. The algorithm must take O(n) time. You must also write and explain the recurrence. (I am looking for an i ≥ 1 and k ≥ 0 such that a + ai+1 + ···ai+k has the largest possible sum among all possible values for i and k.) Example 1: Input: A[5, 15, -30, 10, -5, 40, 10]. Output: [10, 5, 40, 10] Example 2: Input: A = [7, 5, 7, 4, -20, 6, 9, 3, -4, -8, 4] Output: [6,9,3]arrow_forwardDesign a dynamic programming algorithm for the Longest Increasing Subsequence problem described below: Input: A sequence of n integers Output: The length of the longest increasing subsequence among these integers. The algorithm must take O(n²) time. You must also write and explain the recurrence. Example 1: Input: [5, 3, 6, 8, 4, 6, 2, 7, 9, 5] Output: 5 ([3, 4, 6, 7, 9]) Example 2: Input: [12, 42, 66, 73, 234, 7, 543, 16] Output: 6 ([42, 66, 73, 234, 543])arrow_forwardDesign a dynamic programming algorithm for the Subset Sum problem described below: Input: A set of n integers A and an integer s Output: A subset of A whose numbers add up to s, or that no such set exists. The algorithm must take O(n·s) time. You must also write and explain the recurrence. Example 1: Input: A = {4, 7, 5, 2, 3}, s = 12 Output: {7,2,3} Example 2: Input: A{4, 7, 5,3}, s = 6 Output: 'no such subset'arrow_forward
- TECNOLOGIE DEL WEB 2023/2023 (VER 1.1) Prof. Alfonso Pierantonio 1. Project Requirements The project consists in designing and implementing a Web application according to the methodology and the technologies illustrated and developed during the course. This document describe cross-cutting requirements the application must satisfy. The application must be realized with a combination of the following technologies: PHP MySQL HTML/CSS JavaScript, jQuery, etc templating The requirements are 2. Project size The application must have at least 18 SQL tables The number of SQL tables refers to the overall number of tables (including relation normalizations). 3. Methodology The application must be realized by adopting separation of logics, session management, and generic user management (authentication/permissions). Missing one of the above might correspond to a non sufficient score for the project. More in details: 3.1 Separation of Logics The separation of logics has to be realizse by using…arrow_forwardWrite a C program to calculate the function sin(x) or cos(x) using a Taylor series expansion around the point 0. In other words, you will program the sine or cosine function yourself, without using any existing solution. You can enter the angles in degrees or radians. The program must work for any input, e.g. -4500° or +8649°. The function will have two arguments: float sinus(float radians, float epsilon); For your own implementation, use one of the following relations (you only need to program either sine or cosine, you don't need both): Tip 1: Of course, you cannot calculate the sum of an infinite series indefinitely. You can see (if not, look in the program) that the terms keep getting smaller, so there will definitely be a situation where adding another term will not change the result in any way (see problem 1.3 – machine epsilon). However, you can end the calculation even earlier – when the result changes by less than epsilon (a pre-specified, sufficiently small number, e.g.…arrow_forwardWrite a C program that counts the number of ones (set bits) in the binary representation of a given number. Example:Input: 13 (binary 1101)Output: 3 unitsarrow_forward
- I need help to resolve or draw the diagrams. thank youarrow_forwardYou were requested to design IP addresses for the following network using the addressblock 166.118.10.0/8, connected to Internet with interface 168.118.40.17 served by the serviceprovider with router 168.118.40.1/20.a) Specify an address and net mask for each network and router interface in the table provided. b) Give the routing table at Router 1.c) How will Router 1 route the packets with destinationi) 168.118.10.5ii) 168.118.10.103iii) 168.119.10.31iii) 168.118.10.153arrow_forwardI would like to get help to draw an object relationship diagram for a typical library system.arrow_forward
- A Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology PtrDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781285196145Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos CoronelPublisher:Cengage LearningDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781305627482Author:Carlos Coronel, Steven MorrisPublisher:Cengage Learning



