You are on page 1of 33
MIT-WPU ui ReerenPafs gar 11 Case Study Report For the Subject Database Management System (Trimester VII) Submitted by Name :- Rutumbara Chakor Panel :- D Batch :- D1 Rollno. :- 09 Under the Guidance of Prof. Shilpa Sonawane School of Computer Engineering and Technology MIT World Peace University, Kothrud, Pune 411 038, Maharashtra — India 2021-2022 1 Contents Abstract List of Figures . Sr no. Topic Introduction of the Tool 1.1 What is a Relational Database?. 1.1.4 Database Versions: 1.1.2 Relational model 1.1.3Keys 4.1.4 Relationships 4.1.5 Transactions 1.1.6 Stored procedures Architecture and Components Overview 2.1 Oracle Database Architecture 2.1.1 Database 2.1.2 Database Instance Brief on Basic Features 3.1 SQL and PL/SQL Support 3.2 Heterogeneous Replication 3.3 Passthrough SQL 3.4 Result Set Support 3.5 Data Dictionary Translations. 3.6 Date-Time Data Types 3.7 Two-Phase Commit Protocol 3.8 Piecewise LONG Data Type 3.9 SQL*Plus DESCRIBE Command 3.10 Oracle's Optimizer and Heterogeneous Services Brief on Advanced Features 4.1 Oracle Cloud 4.2 Distributed System 4.2.1 Oracle parallel server 4.2.2 Standby Database 4.2.3 Advanced replication 4.2.4 Parallel query 4.2.5 Parallel DML Strengths and Weakness 5.1Major Advantages of Oracle Database 5.1.1 Portability 5.1.2 Backup and Recovery 5.1.3 Multiple Database Support 5.1.4 Market Presence 5.1.5 Versions Changes 5.2 Disadvantages of Oracle Database 5.2.1 Complexity 5.2.2 Cost of Oracle Database 5.2.3 Difficult to Manage Study/Implementation with example Conclusion 33 References 33 I Abstract Oracle Database Oracle Database (commonly referred to as Oracle DBMS or simply as Oracle) is a multi-mode! database management system produced and marketed by Oracle Corporation. Itis a database commonly used for running online transaction processing (OLTP), data warehousing (DW) and mixed (OLTP & DW) database workloads. Oracle Database is available by several service providers on-prem, on-cloud, or as hybrid cloud installation, It may be run on third party servers as well as on Oracle hardware (Exadata on-prem, on Oracle Cloud or at Cloud at Customer) Oracle database products offer customers cost-optimized and high-performance versions of Oracle Database, the world's leading converged, multi-model database management system, as well as in-memory, NoSQL and MySQL databases. Oracle Autonomous Database, available on premises via Oracle Cloud@Customer or in the Oracle Cloud Infrastructure, enables customers to simplify relational database environments and reduce management workloads, In This case study we explore the features of oracle database 19c and implement some sample databases. With the help of the PL/SQL feature we implement some bulk processing of data and maintain the integrity with the help of triggers. Platform used is live.oracle provided by oracle corp. which allows us to try and execute oracle database commands without having to install the whole DBMS on local machine. i] List of Figures Sr.No. Figure Name Page No Architecture and Components Overview 6 Parallel server architecture 1 Standby database 12 Iv Chapter 1 Introduction of the Tool 1.1 What is a Relational Database? ‘A relational database is a type of database that stores and provides access to data points that are related to one another. Relational databases are based on the relational model, an intuitive, straightforward way of representing data in tables. In a relational database, each row in the table is a record with a unique ID called the key. The columns of the table hold attributes of the data, and each record usually has a value for each attribute, making it easy to establish the relationships among data points. 1.1.1 Database Versions: Oracle Database version 19c was used in the making of this project. A relational Database works on the relational model 1.1.2 Relational model Main article: Relational model This model organizes data into one or more tables (or "relations") of columns and rows, with a unique key identifying each row. Rows are also called records or tuples. Columns are also called attributes. Generally, each table/relation represents one "entity type" (such as customer or product). The rows represent instances of that type of entity (such as "Lee" or "chair") and the columns representing values attributed to that instance (such as address or price). For example, each row of a class table corresponds to a class, and a class corresponds to multiple students, so the relationship between the class table and the student table is "one to many" 1.1.3Keys Each row in a table has its own unique key. Rows in a table can be linked to rows in other tables by adding a column for the unique key of the linked row (such columns are known as foreign keys). Codd showed that data relationships of arbitrary complexity can be represented by a simple set of concepts. Part of this processing involves consistently being able to select or modify one and only one row in a table, Therefore, most physical implementations have a unique primary key (PK) for each row in a table. When a new row is written to the table, a new unique value for the primary key is generated; this is the key that the system uses primarily for accessing the table. System 5 performance is optimized for PKs. Other, more natural keys may also be identified and defined as alternate keys (AK). Often several columns are needed to form an AK (this is one reason why a single integer column is usually made the PK). Both PKs and AKs have the ability to uniquely identity a row within a table. Additional technology may be applied to ensure a unique ID across the world, a globally unique identifier, when there are broader system requirements. The primary keys within a database are used to define the relationships among the tables. When a PK migrates to another table, it becomes a foreign key in the other table. When each cell can contain only one value and the PK migrates into a regular entity table, this design pattern can represent either a one-to-one or one-to-many relationship. Most relational database designs resolve many-to-many relationships by creating an additional table that contains the PKs from both of the other entity tables — the relationship becomes an entity; the resolution table is then named appropriately and the two FKs are combined to form a PK. The migration of PKs to other tables is the second major reason why system-assigned integers are used normally as PKs; there is usually neither efficiency nor clarity in migrating a bunch of other types of columns. 1.1.4 Relationships Relationships are a logical connection between different tables, established on the basis of interaction among these tables. 1.1.5 Transactions In order for a database management system (DBMS) to operate efficiently and accurately, it must use ACID transactions. 1.1.6 Stored procedures Most of the programming within a RDBMS is accomplished using stored procedures (SPs). Often procedures can be used to greatly reduce the amount of information transferred within and outside of a system. For increased security, the system design may grant access to only the stored procedures and not directly to the tables. Fundamental stored procedures contain the logic needed to insert new and update existing data. More complex procedures may be written to implement additional rules and logic related to processing or selecting the data. Chapter 2 Architecture and Components Overview 2.1 Oracle Database Architecture A database server is the key to information management. In general, a server reliably manages a large amount of data in a multiuser environment so that users can concurrently access the same data. A database server also prevents unauthorized access and provides efficient solutions for failure recovery. Database and Instance ‘An Oracle database server consists of a database and at least one database instance (commonly referred to as simply an instance), Because an instance and a database are so closely connected, the term Oracle database is sometimes used to refer to both instance and database. In the strictest sense the terms have the following meanings: 2.1.1 Database: A database is a set of files, located on disk, that store data. These files can exist independently of a database instance. 2.1.2 Database instance: An instance is a set of memory structures that manage database files. The instance consists of a shared memory area, called the system global area (SGA), and a set of background processes. An instance can exist independently of database files. Figure 2-1 shows a database and its instance. For each user connection to the instance, the application is run by a client process. Each client process is associated with its own server process. The server process has its own private session memory, known as the program global area (PGA). Figure 2-1 Oracle Instance and Database Instance ‘System Global Area (SGA) Free Memory Shared Pool Large Poot UO Buter area Library Cache ts Shared SOL Ars] [Fives o =| | sau area cer ‘| | ares ooo PHON ‘ reonsl || |g? =", >| suon Ba) ee) | fe) | | Fee] [eae vey fre sees) | ses ache Cache >| RECO THON Daabave puter ache — seat Be omnes cS action Pees PGA ‘SOL Work Areas Session Memory | Private $QL Area Client Process A database can be considered from both a physical and logical perspective. Physical data is data viewable at the operating system level. For example, operating system utilities such as the Linux Is and ps can list database files and processes. Logical data such as a table is meaningful only for the database. A SQL statement can list the tables in an Oracle database, but an operating system utility cannot. The database has physical structures and logical structures. Because the physical and logical structures are separate, the physical storage of data can be managed without affecting access to logical storage structures. For example, renaming a physical database file does not rename the tables whose data is stored in this file. Chapter 3 Brief on Basic Features 3.1 SQL and PL/SQL Support SQL statements are translated and data types are mapped according to capabilities. PLISQL calls are mapped to non-Oracle system stored procedures. With SQL statements, if functionality is missing at the remote system, then either a simpler query is issued or the statement is broken up into multiple queries. Then, the desired results are obtained by post processing in the Oracle database. 3.2 Heterogeneous Replication Data can be replicated between a non-Oracle system and Oracle Database using materialized views. Materialized views instantiate data captured from tables at the non-Oracle master site at a particular time, This instant is defined by a refresh operation, which copies this data to Oracle Database and synchronizes the copy on the Oracle system with the master copy on the non-Oracle system. The materialized data is then available as a view on Oracle Database. Replication facilities provide mechanisms to schedule refreshes and to collect materialized views into replication groups to facilitate their administration, Refresh groups permit refreshing multiple materialized views as if they were a single object. 3.3 Passthrough SQL The passthrough SQL feature enables you to send a statement directly to a non-Oracle system without first being interpreted by Oracle Database. This feature can be useful if the non-Oracle system allows for operations in statements for which there is no equivalent in Oracle. 3.4 Result Set Support Various relational databases enable stored procedures to return result sets (one or more sets of rows). Oracle has a data type called a REF CURSOR. Like every other Oracle data type, a stored procedure can take this data type as an IN or OUT argument. With Oracle Database, a stored procedure must have an output argument of type REF CURSOR. It then opens a cursor for a SQL statement and places a handle to that cursor in that output parameter. The caller can then retrieve from the REF CURSOR the same way as from any other cursor. Oracle Database can do a lot more than return result sets, The REF CURSOR data type can be passed as an input argument to PL/SQL routines to be passed back and forth between client programs and PL/SQL routines or as an input argument between several PLISQL routines, 3.5 Data Dictionary Translations Most database systems have some form of data dictionary. A data dictionary is a collection of information about the database objects that were created by various users of the system. For a relational database, a data dictionary is a set of tables and views that contain information about the data in the database. This information includes information about the users who are using the system and about the objects that they created (such as tables, views, and triggers). Almost all data dictionaries (regardless of the database system) contain the same information, but each database system organizes the information differently. 3.6 Date-Time Data Types Oracle Database has five date-time data types: © TIMESTAMP © TIMESTAMP WITH TIME ZONE © TIMESTAMP WITH LOCAL TIME ZONE ¢ INTERVAL YEAR TO MONTH INTERVAL DAY TO SECOND 3.7 Two-Phase Commit Protocol Heterogeneous Services provides the infrastructure to implement the two-phase commit protocol. The extent to hich this is supported depends on the gateway and the remote system. 3.8 Piecewise LONG Data Type Earlier versions of gateways had limited support for the LONG data type. LONG is an Oracle data type that can store up to 2 GB of character data or raw data (LONG RAW). These earlier versions restricted the amount of LONG data to 4 MB because they treated LONG data as a single piece. This caused memory and network bandwidth restrictions on the size of the data that could be handled. Current gateways extended the functionality to support the full 2 GB of heterogeneous LONG data. The gateways now manage the data piecewise between the agent and Oracle Database, eliminating the large memory and network bandwidth requirements. ‘The HS_LONG_PIECE_TRANSFER_SIZE Heterogeneous Services initialization parameter can be used to set, the size of the transferred pieces. For example, consider retrieving 2 GB of LONG data from a heterogeneous source. A smaller piece requires less memory, but it requires more round-trips to retrieve all the data. A larger piece requires fewer round-trips, but it requires a larger amount of memory to store the intermediate pieces internally. The initialization parameter can be used to tune a system for the best performance, that is, for the best trade-off between round-trips and memory requirements. If the initialization parameter is not set, the system uses 64 KB as the default piece size. 3.9 SQL*Plus DESCRIBE Command 10 You can describe non-Oracle system objects using the SQL*Plus DESCRIBE command. However, there are some limitations. For example, using heterogeneous links, you cannot describe packages, sequences, synonyms, or types. 3.10 Oracle's Optimizer and Heterogeneous Services Oracle's optimizer can be used with Heterogeneous Services. Heterogeneous Services collects certain table and index statistics information on the respective non-Oracle system tables and passes this information back to Oracle Database. The Oracle cost-based optimizer uses this information when building the query plan. There are several other optimizations that the cost-based optimizer performs. The most important ones are remote sort elimination and remote joins. " Chapter 4 Brief on Advanced Features (Cloud Based and Distributed etc.) 4.1 Oracle Cloud Oracle Cloud is a cloud computing service offered by Oracle Corporation providing servers, storage, network, applications and services through a global network of Oracle Corporation managed data centers. The company allows these services to be provisioned on demand over the Internet. Oracle Cloud provides Infrastructure as a Service (laaS), Platform as a Service (PaaS), Software as a Service (SaaS), and Data as a Service (DaaS). These services are used to build, deploy, integrate, and extend applications in the cloud. This platform supports numerous open standards (SQL, HTMLS, REST, etc.), open-source applications (Kubernetes, Spark, Hadoop, Kafka, MySQL, Terraform, etc.), and a variety of programming languages, databases, tools, and frameworks including Oracle-specific, Open Source, and third-party software and systems. 4.2 Distributed System Oracle Corporation introduced inter-database connectivity with SQL*Net in Oracle Version 5 and simplified its usage considerably with the database links feature in Oracle Version 6, opening up a world of distributed possibilities. Oracle now supplies a variety of techniques that you can use to establish inter-database connectivity and data sharing. 4.2.1 Oracle parallel server Oracle parallel server(OPS) is a technology that allows two or more database instances, generally on different machines, to open and manipulate one database, as shown in Figure 4.1. In other words, the physical data files (and therefore data) in a database can be seen, inserted, updated, and deleted by users logging on to two or more different instances; the instances run on different machines but access the same physical database. 12 Figure 4-1. Parallel server architecture Database PMFG.BIGWHEEL.COM Muliple daatase instances ‘on matple nodes connect toa single physica database Node: curly Noe: arry ‘Node: moe Oracle instance; PMGC Oracle instance: PMGL ‘Oracle instance: PMGM Oracle parallel server requires an operating system that supports clustering and a distributed lock manager because the multiple database instances must share information about the data that is updated, the lock resources, and so on. For example, if a user on instance A updates a row, and a.user on instance B performs a query that would return that row, instance B must instruct instance A to write the updated data to the physical database so that the query will deliver the updated information. Oracle parallel server is intended to provide failover capabilities capabilities that allow a second machine to take over the processing being performed by the first in the event of machine failure (e.g., CPU or motherboard failure). It does not provide any protection from disk failure, Occasionally, parallel server technology is used to achieve horizontal scalability, a concept I'll discuss later in this chapter. 4.2.2 Standby Database Oracle introduced the standby database in Version 7.2, although some sites had created their own homegrown varieties earlier. A standby database is one that shadows a normal database and is always in recovery mode. Whenever a redo log is archived in the primary database, the archived redo log is applied to the standby database, as shown in Figure 4.2. Generally, the standby database resides on a separate machine and uses separate storage. 13 ‘Archived Redo Logs Hot standby database ina perpeval sate of media recovery. Since me database is mounted but ot open, it cannot be use. even for queries, unless i activated. Node: walrus Node: eggman Primary standby Figure 4-2. Standby database If the primary database fails, the DBA can open the standby database and point users to it instead of to the primary database. Once this occurs, what had been the standby database becomes the primary database, and it cannot be put back into standby mode again. 4.2.3 Advanced replication Advanced replication, also known as symmetric replication or multi-master replication , refers to maintaining a table or tables in multiple databases such that DML (Data Manipulation Language) can be issued in any of the databases and applied to the others automatically. The DML may be propagated synchronously (i.e. DML is committed locally and remotely as a single transaction) or asynchronously (i,e., DML committed locally is placed in a queue from which it is applied at the remote site later). Advanced replication can be used to deliver high availability, in the sense that the unavailability of any one site does not affect the others, or it may be used as part of a survivability policy in which every database has a replicated copy that can be used in the event of failure. Unlike parallel server, advanced replication involves numerous databases and numerous database instances. 4.2.4 Parallel query The parallel query option (PQO) is a technology that can divide complicated or long-running queries into several independent queries and allocate separate processes to execute the smaller queries. A coordinator process collects the results of the smaller queries and constructs the final result set. Parallel queries are effective only on machines that have multiple CPUs. 4.2.5 Parallel DML Oracle introduced the parallel DML feature in Oracle8. Parallel DML is similar to parallel query, except that the independent processes perform DML. For example, an update of several hundred thousand rows can be doled out to several processes that execute the update on separate ranges of the table. 14 Chapter 5 Strengths and Limitations 4.1 Strengths 4.1.1 Portability Well, the oracle database is ported to alll different platforms than all other its competition. It easily runs on almost 20 networking protocols and also on more than 100 hardware platforms. The same thing makes it easy for writing an oracle application easily by making changes safely in the operating system and hardware. 4.1.2 Backup and Recovery It is good to be used to take a proper backup of your entire oracle online backup as well as recovery too. With the help of oracle database, one can easily become able to make a point-in- time recovery. For the same, you have to require storage space and also archive mechanisms. High performance It means that making a good oracle database provides you with quite good speed and also with large databases. Also, the oracle database improves the performance and speed of consideration with transaction control and locking. 4.1.3 Multiple Database Support The best advantage which users get when they make use of the oracle database is that it easily manages the multiple databases within the same transaction. The same thing is best applicable, or you can say implemented in V7. So, all these are the best benefits which all the users of oracle database get when they make its use. To gather more information about the same process and to know how to make appropriate use of the oracle database, one should check out more and more reviews. The more reviews you go through when going to make use of the oracle database, the easier it becomes for you to get good results by using the same database. 4.1.4 Market Presence By far, Oracle is the largest RDBMS Vendor and spends more on Research and Development than the rest of its competitors. As far as the RDBMS market share is concerned, Oracle has the maximum share in VMS, UNIX, and OS/2 server fields. This clearly indicates that there are very few chances for you to be left in the lurch by Oracle as there are tons of third-party 15 interfaces supported. Further, you can get more assistance as the proficient staff is quite easy to get. 4.1.5 Versions Changes Oracle keeps you informed about the next major release for any potential changes so you can get prepared. It offers you good backward compatibility by which you will no longer be required to re-write an application while upgrading the DBMS. Many have worked with Oracle since V4 Beta and have never faced any unpleasant experiences in terms of syntax. 4.2 Limitations 4.2.1 Complexity One of the biggest disadvantages of Oracle Database is its complexity. It is not preferable to use Oracle, especially when the users are not technically sound and lack the technical ability that is needed in order to work with the Oracle Database. Further, itis also not advisable to use Oracle if the company or an individual is seeking a database that is easy to use and contains basic features. It is not as simple as installing Oracle and get started, rather it requires specialized skills to install and maintain as it is an incredibly complex engine. 4.2.2 Cost of Oracle Database The price of Oracle products can increase up to ten times compared to the MS SQL Server Database Solution for a mid-range solution. Hence, people tend to go with other options that are comparatively cheaper, for example, you can install MySQL for free or utilize any one of several engines in a solution like AWS by investing a very nominal amount. Further, there is no specific price to obtain an Oracle license as it usually changes over time depending upon a lot of factors like changes in the company's policies, patches, and updates. 4.2.3 Difficult to Manage Oracle is generally a lot more complex and difficult in terms of the management of certain activities. Hence, the pro tip here is to install a basic version and then perform configuration with minimal customization. Oracle Database is only useful when you need large size databases. The use of Oracle in small or medium-sized companies is not preferable where ‘small databases are needed. In such a scenario, the best option would be MySQL, which is more cost-effective. 16 Chapter 6 Study/Implementation with example Schema Diagram for Music Library Database | ‘enema Ovaoram formas Ura CREATE TABLE artist ( artist_id INT, artist_name VARCHAR (30), CONSTRAINT PK_artist PRIMARY KEY (artist_id) DESC artist; SELECT * FROM artist; CREATE TABLE collection ( collection_id INT, collection_type VARCHAR(30), CONSTRAINT PK_collection PRIMARY KEY (collection_id) y% DESC collection; SELECT * FROM collection; CREATE TABLE album ( album_id INT, album_name VARCHAR(30), year INT, artistid INT, collection_id INT, CONSTRAINT PK_album PRIMARY KEY (album_id), CONSTRAINT FK_album_art FOREIGN KEY (artist_id) REFERENCES artist (artist_id), CONSTRAINT FK_album_col FOREIGN KEY (collection_id) REFERENCES collection (collection_id) % DESC album; SELECT * FROM album; CREATE TABLE track track_id INT, track_name VARCHAR(20), time INT, album_id INT, price DECIMAL(6, 2), CONSTRAINT PK_track PRIMARY KEY (track_id, album_id), CONSTRAINT FK_track FOREIGN KEY (album_id) REFERENCES album (album_id) DESC track; SELECT * FROM track; INSERT INTO collection VALUES (1, ‘Indian Classical’); INSERT INTO collection VALUES (2, ‘Western Classical’); INSERT INTO collection VALUES (3, 'Pop’); INSERT INTO collection VALUES (4, 'K-Pop'); INSERT INTO collection VALUES (5, ‘Jazz’); insert into artist values (101, ‘aa'); 19 insert into artist values (102, 'bb’); insert into artist values (103, 'cc’); insert into artist values (104, 'dd'); insert into artist values (105, 'ee'); insert into artist values (106, 'bob azzam’); insert into artist values (107, ‘alice stewart’); insert into album values (1001, ‘album a’, 2003, 106, NULL); insert into album values (1002, ‘album b’, 1999, 106, NULL); insert into album values (1003, ‘album c', 2000, 102, NULL); insert into album values (1004, ‘album d', 2000, 103, 3); insert into album values (1005, ‘album e', 2003, 102, 2); insert into album values (1006, ‘album f', 2009, 107, 3); insert into album values (1007, ‘album u', 2005, 107, 5); 20 insert into album values (1008, ‘album g', 2006, 107, 3); insert into album values (1009, ‘album h', 2007, 107, 5); insert into album values (1012, ‘album k’, 2006, 107, 5); insert into album values (1010, ‘album i', 2002, 103, 3); insert into album values (1011, ‘album j', 2001, 103, 3); insert into track values (1, ‘blue eye a’, 5, 1006, 123.32); insert into track values (2, ‘romantic songt’, 6, 1005, 123.25); insert into track values (3, 're blue eye’, 7, 1006, 789.25); insert into track values (4, 'jazz_inst’, 8, 1007, 489.32); insert into track values (5, ‘romantic reprise’, 9, 1004, 45.25); insert into track values (6, ‘love f', 9, 1004, 486.22); insert into track values (7, ‘Till, 3, 1001, 156.14); 21 Statements 1 SELECT COUNT(track_id) AS no_of_tracks FROM track RIGHT OUTER JOIN album on track.album_id = album.album_id GROUP BY album.album_id; 2 SELECT COUNT(album.album_id) AS albumsCompiled FROM album RIGHT OUTER JOIN artist on artist.artist_id = album.artist_id GROUP BY artist.artist_id HAVING COUNT(album.album_id) > 1; 3 SELECT artist_name FROM artist WHERE EXISTS(SELECT * FROM album WHERE album_id IS NOT NULL AND artist.artist_id = album.artist_id); 4 SELECT * FROM (SELECT album_name, track_name FROM album, track ORDER BY time DESC) WHERE rownum <= 1; 5 SELECT album_name AS Jazz_Album FROM album, 22 collection where album.collection_id = collection.collection_id AND collection.collection_type = ‘Jazz’; 6 CREATE VIEW albumsinTwo AS SELECT a.artist_id, (COUNT(a.year)) AS albums_in_two FROM album a, album b WHERE azartist_id = b.artist_id AND b,year <= (a.year + 2) AND a.album_id != b.album_id AND a.year <= byear GROUP BY a.year, a.artist_id; SELECT artist_name FROM artist WHERE artist_id IN (SELECT artist_id FROM albumsinTwo WHERE albums_in_two = SELECT * FROM (SELECT albums_in_two FROM albumsinTwo ORDER BY albums_in_two DESC ) WHERE rownum <= 1); 7 SELECT album_id, track_name FROM track 23 WHERE time > (SELECT AVG(time) FROM track); 8 CREATE VIEW info AS SELECT artist_name, album_name, year FROM album, artist WHERE artist.artist_id = album.artist_id; SELECT * FROM info; 9 SELECT track_name FROM track WHERE price > (SELECT MIN(track.price) FROM track); 24 Output: Result Set 15 NO_OF_TRACK s 0 0 Download CSV 12 rows selected. Result Set 16 ALBUMSCOMPILED 25 2 2 Download CSV 4 rows selected, Result Set 17 ARTIST_NAME bob azzam bb cc alice stewart Download CSV 4 rows selected, Result Set 18 ALBUM_NAME TRACK_NAME album a romantic reprise Download CSV Result Set 19 JAZZ_ALBUM album uw album h album k Download CSV Result Set 20 26 ALBUM_ID TRACK_NAME 1006 re blue eye 1007 jazz_inst 1004 romantic reprise 1004 love f Download CSV Result Set 21 ARTIST.NAME ALBUM_NAME YEAR bob azzam album a 2003 bob azzam album b 1999 bb album c 2000 cc album d 2000 bb album e 2003 alice stewart album f 2009 alice stewart album u 2005 alice stewart album g 2006 alice stewart album h 2007 alice stewart album k 2006 cc album i 2002 cc album j 2001 Download CSV 27 Result Set 22 TRACK_NAME blue eye a romantic song1 te blue eye jazz_inst love f Till Download CSV 6 rows selected, 28 PL/SQL 1 UPDATE album SET album.year = EXTRACT(Year FROM SYSDATE) - album.year; ALTER TABLE album ADD year_creation INT; DESC album; UPDATE album SET album.year_creation = 2021 - album.year, 2 CREATE OR REPLACE PROCEDURE setprice(inalbumid IN NUMBER) Is v_ent INT; BEGIN SELECT year_creation INTO v_cnt from album WHERE album_id = inalbumid; IF (v_ent < 2) THEN UPDATE track SET price = price * 1.05 WHERE album_id = inalbumid; ELSIF (v_cnt <5) THEN UPDATE track SET price = price * 1.07 WHERE album_id = inalbumid; ELSE UPDATE track SET price = price * 1.1 WHERE album_id = inalbumid; end if; END; 29 3 CREATE OR REPLACE PROCEDURE firstCurs Is d NUMBER(10) DEFAULT 0; albumid NUMBER(10); CURSOR Get_cur IS SELECT album_id FROM album; BEGIN OPEN Get_cur; <> LOOP IF d=1 THEN EXIT Ibl; END IF; IF NOT d=1 THEN FETCH Get_cur INTO albumid; IF Get_cur%NOTFOUND THEN d := 1; END IF; setprice(albumid); END IF; END Loop; CLOSE Get_cur; END; I SELECT * FROM track; CALL firstCurs; SELECT * FROM track; 30 4 CREATE OR REPLACE FUNCTION maxprice(albumid NUMBER) RETURN NUMBER maxpr NUMBER(6, 2); BEGIN SELECT MAX(price) INTO maxpr FROM track WHERE album_id = albumid; RETURN maxpr; END; / SELECT maxprice(1004) FROM dual; PL/SQL OUTPUT Result Set 23 TRACK_ID TRACK_NAME TIME ALBUM_ID PRICE 1 blue eye a 5 1006 149.22 2 romantic song! 6 1005 149.14 3 re blue eye 7 1006 955 4 jazz_inst 8 1007 592.08 5 romantic 9 1004 54.76 reprise 6 love f 9 1004 588.32 7 Till 3 1001 188.93 31 Download CSV 7 rows selected. Statement processed. Result Set 24 TRACK_ID TRACK_NAME TIME ALBUM_ID PRICE 1 blue eye a 5 1006 164.14 2 romantic song1 6 1005 164.05 3 reblueeye 7 1006 1050.5 4 jazz_inst 8 1007 651.29 5 romantic 9 1004 60.24 reprise 6 love f 9 1004 647.15 7 Till 3 1001 207.82 Download CSV 7 rows selected. Result Set 25 MAXPRICE (1004) 647.15 Download CSV 32 Conclusion As a result of this activity we learned about the basics of a new Relational Database system from Oracle. Using the online oracle database compiler we executed some simple statements, joins (inner, outer), PL/SQL (Procedures, Functions, Triggers, Cursors). References Oracle Live SQL Oracle Live SQL - Code Library Oracle Live SQL - Tutorial: Introduction to SQL Oracle Live SQL - Script: EMP and DEPT Oracle Live SQL - Script: SQL Joins Oracle Live SQL - Tutorial: Sorting and Limiting Rows: Databases for Developers Oracle Live SQL - Tutorial: Bulk Processing with PL/SQL Oracle Live SQL - SQL Worksheet Oracle Database - Wikipedia SQL Tutorial - GeeksforGeeks 33

You might also like