10g sql e book

3,202 views

Published on

ORACLE 10 G SQL

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,202
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
225
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

10g sql e book

  1. 1. Oracle 10g SQL This book belongs to Name : ______________________________________ Batch : ______________________________________ SQL Star International Ltd. SQL Star House, No. 8-2-293/174/A 25, Road No. 14, Banjara Hills, Hyderabad - 500 034, Andhra Pradesh, INDIA© SQL Star International Ltd.
  2. 2. Copyright © 2008 Second Edition SQL STAR INTERNATIONAL LIMITED SQL Star House,8-2-293/174/A25, Road No.14, Banjara Hills, Hyderabad - 500 034. Tel. No. 91- 40-23101600(30 lines) Fax No. 23101663 Toll Free No: 1800 425 2944 Email: info@sqlstar.comNo part of this publication may be reproduced (incl. photocopying) in any way, without prioragreement and written permission of SQL Star International Ltd., Hyderabad. SQL StarInternational Ltd., Hyderabad assumes no responsibility for its use, nor for any infringementsof patents or other rights of third parties which could result.© SQL Star International Ltd. i
  3. 3. Table of Contents Oracle 10g SQL CHAPTER CHAPTER TITLE PAGE No. NO 1. Database concepts 1-39 2. Introduction to Oracle 10g 40-49 3. Data Retrieval 50-78 4. Enhancing Data Retrieval 79-95 5. Generating formatted reports using isql*plus 96-128 6. SQL single Row Functions 129-154 7. Working with Grouped Data 155-163 8. Joins 164-186 9. Understanding Sub queries 187-201 10. Advanced Sub queries 202-221 11. Data Manipulation 222-248 12. Managing Tables 249-293 13. Managing Constraints 294-318 14. Views 319-342 15. Other Database Objects 343-371 16. Data Dictionary Views 372-380 17. Security Implementation 381-393 18. Manipulating Large Data Sets 394-413 19. Regular Expressions 414-422© SQL Star International Ltd. ii
  4. 4. Chapter 1 Database Concepts Typical Database Architecture DBMS Types of DBMS Normalization Entity Relationship (E-R) Model Features of SQL© SQL Star International Ltd. 1
  5. 5. ObjectivesAt the end of this chapter, you will be able to:Understand the basic concepts of a databaseIdentify the disadvantages with Flat File systemsIdentify the advantages of a DBMSUnderstand the types of DBMSUnderstand the E-R ModelUnderstand the features of SQLDescribe the Codd‘s Rules© SQL Star International Ltd. 2
  6. 6. Database ManagementThe approach of the new millennium has brought with it several challenges, therebymaking it mandatory for companies and organizations to maintain high level ofefficiency in their computing systems, so as to stand the test of time. Databases anddatabase systems are the essential backbone of any organization.DatabaseWhen one hears the word Database, one thinks of a collection or a store of mutuallyrelated data. The implicit properties of a database are as follows:  A database represents some aspects of the real world and any changes to the real world should get reflected in the database. For example, a manufacturing concern keeps details of the products it manufactures and also of the suppliers it deals with. Any change in the pricing of the product or a change in the suppliers who supply raw materials must be immediately reflected in the database.  A database is a logical collection of relevant data, reflecting some inherent meaning. Any random grouping of data cannot be referred to as a database. A manufacturing concern requires data about its customers, products, as well as its suppliers. Details regarding each of them form a logical group of data.  A database is populated with data for a purpose. It has an audience that is interested in its contents. For instance, in the above example, the manufacturing concern needs the customer details to identify its regular customers and also their credit worthiness. Similarly product detail helps in determining the stock depletion level (i.e. when to place fresh order for raw materials).Now a day, the term „database‟ is mostly used in connection with computerizeddatabases. Therefore, today, a study of database systems involves also a study of theassociated technology employed to store, access and manipulate the computerizeddatabases.Traditionally, data accessed through computers has been stored on different storagemedia in the form of individual files. Files proved to be quite satisfactory as long ascomputerization was limited to a few application areas and the use of computersrestricted to a privileged few. However, as actual users grew in number, especiallywith the advent of online time-sharing systems, the file systems gave rise to manyserious problems. The discipline of database systems evolved in response to theseproblems. Let us first consider what these problems are so as to understand thedifferent features of database systems more clearly.File Systems and the Associated ProblemsMost data processing systems in existence today, especially in India, use files forstoring, accessing and manipulating data. Files are stored typically on magnetictapes and disks.© SQL Star International Ltd. 3
  7. 7. Most of the problems with files arise out of the fact that files are specific to anapplication, e.g., a set of files may be designed for the sales analysis system of acompany.Programs of the same application system can use these files. However, if someother new application needs source data from this system, there may be difficulties.Therefore, in many cases, new files, with considerable data in common with theexisting files, may have to be designed for the new applications.Therefore, as applications proliferate, the total number of computerized files growsconsiderably. Also, as the number of actual users of the computer grows, thenumber of applications increases, in turn resulting in an increase in the number offiles.A large number of files give rise to the following problems:  Files involve a high level of redundancy in data. As we have mentioned above, proliferation of files results in the same data item being stored at many different places.  Redundancy in data often results in inconsistency of data. The same data item being used by different applications may exist in different versions. What is worse, it may exist in different stages of update at different places and thus may have different values. This may ultimately result in inconsistencies amongst reports generated by the two application systems.  Individual files are not amendable to rapid changes, especially with respect to the way the data items are structured within the file. If an application wants data from an existing file but structured differently, it cannot be provided quickly and easily. For this purpose, either conversion programs have to be written or new files have to be created.  Because of the inflexibility of files, many ad hoc queries cannot be answered.  Yet another consequence of the inflexibility of files is that it is usually expensive to make changes to a file system. It is also a very slow process. It may even involve modification of application programs.  What is worse, modification in one program may require modifications in other programs, which interface with this program. This process may set off a chain reaction of modifications.The above problems give rise to further difficulties detailed below:  The Management Information Systems (MIS) finds it difficult to control data, especially when the actual users develop applications on their own.  Major changes required in the system while modifying files increase the maintenance load on Data Processing (DP) professionals substantially, thus making them unavailable for development of new systems.  High-level data redundancy entails repetitive data entry and redundant storage with the accompanying costs.© SQL Star International Ltd. 4
  8. 8. As has been already stated, Database Systems provide an effective solution to theabove problems. Let us see how.Data IndependenceYou have just seen, files give rise to several problems because they are applicationspecific. Consequently, the applications become data-dependent, that is, theydepend upon the organization and access method for the data on the secondarystorage. This happens because, with conventional application development tools suchas COBOL, the application logic incorporates the knowledge of data organization andaccess methods. Therefore, most changes in data organization or access methodsaffect the application logic substantially. If problems arising due to this fact are to beavoided, the data organization (and the access method) and the application logichave to be made independent of each other. Database Systems do precisely this.The first step towards this goal is to distinguish between data as is actually stored(called as the physical representation of data) and data as is presented to anindividual user (called as the logical representation of data).The Physical Representation of DataThe smallest named unit of data physically stored in the database is known as a―stored field‖, and a named collection of associated stored fields is known as a―stored or physical record‖. The named collection of all occurrences of one type ofphysical record is known as a ―stored or a physical file‖. This concept will be clearerafter we discuss the logical representation of data.The Logical Representation of DataA logical field, record or file is, the field, record or file as it appears to the users, thatis, as it is defined in the user‘s application programs. In all traditional systems, thelogical and physical data are practically the same, which is the root cause of all themajor problems with traditional files. This is not the case with database systems.Similarly, the structure of stored and logical records can be different. A logicalrecord type may be obtained by selectively combining fields from different storedrecords.The logical and physical views of a file could also be different in terms of, say, thekey fields for sequencing the records in the file.With such a separation of the logical and physical data, the database can be modifiedand developed without affecting existing applications. The database architectureachieves this separation.A Typical Database SystemTypical database architecture divides the database into three levels of abstraction;the internal, conceptual and external levels.At the internal level is the physical database, while at the external level; one has thedifferent logical views corresponding to an individual application. The conceptuallevel is an intermediate level, which is a single abstract representation of the entiredatabase.© SQL Star International Ltd. 5
  9. 9. Data Base Management System (DBMS) is software, which interacts with all thethree levels enabling the users to deal with the data in terms of its logical viewrather than the actual physical database.A diagrammatic representation of the typical database architecture is shown below:Let us now consider the different individual entities in the architecture in furtherdetail. Let us start with the actual or physical database and see how the architecturebrings about a transformation in the data representation to get the data to the userin the form he wants.The Internal DatabaseThe internal (or physical) database is stored on secondary storage devices, mainlythe magnetic disk. It itself can be conceptually viewed at different levels ofabstraction. At its lowest level, it is stored in the form of bits with the associatedphysical addresses on the secondary storage device.At its highest level, it can be viewed in the form of files and simple data structures. Itis this level that we shall study when we discuss the physical organization fordatabases in later chapters.© SQL Star International Ltd. 6
  10. 10. The physical database is described by means of a physical scheme or an internalscheme. It essentially describes the various types of stored records, the differentindexes that are employed for accessing these and the representations for differentstored fields. It is also called as the ―storage structure definition‖.The Conceptual DatabaseThe conceptual model, also called as the data model, represents information contentof the database in its entirety, but is abstract with respect to the physical database.Broadly speaking, the conceptual model provides a view of the data as it really is.This model consists of multiple occurrences of multiple types of a conceptual record.A conceptual record represents relevant information content only. In this sense, it ismuch closer to the external record than a stored record is.However, it is not the same as the external record.It contains all the information to build relevant external records. A conceptual stockrecord may consist of the quantity of material and the buying rate but not its value;still the user‘s external record may consist of the value of the stock. A conceptualmodel may consist of occurrences of such stock records, a collection of supplierrecord occurrences and a collection of assembly records.Obviously, the conceptual model is derived from the physical model. For this, thedatabase needs a conceptual/physical mapping, which specifies how conceptualrecords and fields map into their counterparts in the physical database. Theconceptual database is described by means of a conceptual scheme. Needless tosay, the conceptual scheme is independent of the physical characteristics of data,such as storage structures, physical sequences, stored field representations etc.Ideally the conceptual scheme should include many features in addition to just thedefinitions of conceptual records. These may include relevant authorization checksand validation procedures, the uses of data, the source and destination of data etc.The conceptual database is a real-world view of data from the organization point ofview. As the real world changes, changes have to be made to the conceptualdatabase and scheme as well. In such a case, it is usually possible to limit thecorresponding changes to only those external schemes, which use the conceptualelements that are changed.The External DatabaseThe external model (or view) is application-specific. Therefore, the user views thedatabase through an external model, and there are as many external views as thereare applications. External views are the proper interface between the user and thedatabase as an individual user can hardly be expected to be interested in the entiredatabase.Generally, an external model consists of multiple occurrences of multiple types ofexternal record. An example of an external record is the record of a file as defined inthe data division of COBOL program.Each external model is defined by means of an external scheme, which describeseach external record type in the external model.The external model is derived from the conceptual model. For this purpose, thecorrespondence between the particular external models has to be defined. An© SQL Star International Ltd. 7
  11. 11. external/conceptual mapping similar to the conceptual/physical mapping does this.However, a separate mapping has to be defined for each external view.An explicit definition of the mapping should be documented, preferably in thecorresponding external scheme.The user interacts with the database through a high-level language such as COBOL,PL/I or some special purpose language. This language is known as the hostlanguage. It includes a data sub-language (DSL). The user carries out the retrievaland storage operations on the database through the DSL.In fact, the Database Task Group (DBTG) report published in April 1971, containsproposals for three distinct languages, two of which relate very closely to the conceptof a DSL. These are sub scheme Data Description Language (DDL) and DataManipulation Language (DML). The sub scheme DDL is used for defining the externalviews while the DML is used for carrying out operations on the database.In addition to the languages, the user is also supposed to be provided with aworkspace. This workspace is an area meant for receiving or transmitting all datatransferred between the user and the database. This is simply the input-output areafor a program.Let us now consider what a database management system is, which interacts withthe three levels and the mappings.What is a Database Management System?The DBMS is the software, which handles all accesses to the database. Conceptually,if a user requests a certain data item, the DBMS intercepts and interprets therequest, retrieves the relevant stored occurrences from the physical database,constructs the required conceptual record occurrences using the physical/conceptualmapping, then derives the required external record occurrence from the conceptualrecords constructed using the relevant conceptual/external mapping.Advantages of DBMSYou have seen that data independence and the consequential benefits are both anessential feature and a major advantage of database systems. Yet another essentialfeature is the centralization of related data. This phenomenon results in furtheradvantages of database systems. These are:  The stored data can be shared relatively easily  New applications may be developed using the existing database  Standards for representation of data can be laid down and enforced among different installations. This can significantly reduce the maintenance activity and enhance data compatibility among installations.  With a centralized control of data, the database system may be designed for an overall optimal performance from the viewpoint of the entire organization.© SQL Star International Ltd. 8
  12. 12.  Ensuring data security becomes much easier as access to the database can be controlled through establishment of proper channels and authorization checks.However, to realize the above benefits, proper organizational infrastructure isneeded. The most popular way to support the Database environment is to establishthe office of the Database Administrator (DBA). In fact, the DBA may be a singleperson or a team. He is responsible for the centralized control of the database.The Database AdministratorThe database administrator is responsible for the overall planning of the company‘sdata resources, for the design of data, and for the day-to-day operational aspects ofdata management.The overall planning of corporate data is the strategic aspect of the databaseadministration function and involves company-wide planning of existing data andassessment of organization-wise data standards.Some of the design aspects of database administration work are:  Deciding on the storage structures and access methods  Selecting database software and hardware  Designing restart and recovery procedures to take care of system outages or crashes  Designing means of reconstructing data in the event of abnormal loss of the same  Designing scheme  Designing the means of reorganizing or tuning databases periodically  Designing database searching strategies  Designing authorization checks and validation procedures  Specifying techniques for monitoring database performanceThe operations management of database administration deals with data problemsarising on a day-to-day basis. Specifically, the responsibilities include:  Investigation of errors found in the data  Supervision of restart and recovery procedures in the event of a failure  Supervision of reorganization of databases  Initiation and control of all periodic dumps of data.© SQL Star International Ltd. 9
  13. 13. In addition, this aspect of database administration includes maintenance of datasecurity, which involves maintaining security authorization tables, conductingperiodic security audits, investigating all known security breaches.To carry out all these functions, it is crucial that the DBA has all the accurateinformation about the company‘s data readily on hand. For this purpose he maintainsa data dictionary. The data dictionary contains definitions of all data items andstructures, the various schemes, the relevant authorization and validation checksand the different mapping definitions. It should also have information about thesource and destination of a data item and the flow of a data item as it is used by asystem. This type of information is a great help to the DBA in maintaining centralizedcontrol of data.Types of DBMSThe different types of DBMS available are:  Hierarchical database management system  Network database management system  Relational database management system  Object Relational database management systemHierarchical DBMSHierarchical DBMS (HDBMS) is one of the oldest methods used for organizing andstoring data. In a hierarchical database, data is organized in a pyramid fashion, justlike the branches of a tree extending downwards.In a hierarchical database you need to understand the concepts of record type andparent-child relationship. Let us take an example.In the order processing of any organization, orders are placed for different products.Orders comprise the following information, which are also called field values: • Order number • Order date© SQL Star International Ltd. 10
  14. 14. • Customer number • Product numberSimilarly, products comprise a collection of: • Product number • Product type • Product name • Quantity • PriceThe collections of these field values are called records and groupings of records ofthe same type are called record types. Related records are grouped together so thatyou can have higher-level records and lower-level records, similar to how the parentsin a family tree sit above the subordinated children.In the example, Orders and Products are the two record types and the relationshipbetween them is the parent-child relationship. Hierarchical Database Management SystemIn the diagram, the parent record (Orders) at the top of the pyramid is called theroot record. The parent record has three child records linked to it. The root of thehierarchical model cannot act as the child record type. Except the root, every recordtype acts as a child record type in exactly one parent-child relationship.The child records can have only one parent record. In contrast, a parent record mayhave more than one child record linked to it. Each child record can also be a parentwith child records underneath it.Hierarchical DBMS works by moving from the top of the pyramid to its bottom. Arecord search is conducted by working down through the pyramid from parent tochild until the suitable child record is found.The pyramid like structure and the defining of relationship between records inadvance makes it easy to access and update hierarchical databases.© SQL Star International Ltd. 11
  15. 15. However, there are few limitations with HDBMS. The relationship between childrecords is not permitted, even if they make a logical sense. Moreover, thehierarchical design is so rigid that adding a new record requires the redefinition ofthe entire database.Network DBMSNetwork DBMS (NDBMS) is an extension of HDBMS. Instead of having a pyramid likestructure, a NDBMS looks more like a spider web or interconnected network ofrecords. In NDBMS, child records are called members and parent records are calledowners.In the network data model too, data is stored in records and descriptions of thestructure of a group of records of the same type are stored in record types. Recordtypes are linked or related using the set types. Set types consist of: • A set type name • An owner record type • A member record typeConsider an example of orders and it‘s products. The two record types are Orderand Product, the former being the owner record type and the latter being themember record type. They are linked using the set type ProdOrder, whichrepresents the relationship between orders and products in them. The relationship isof 1:N meaning that there will be many set occurrences (or instances) where onerecord from the owner record type Order relates to a set of records from themember record type Product. That is, an order can have one or more products in it.Therefore, set occurrences are composed of: • One record from the owner record type • A number of records (zero or more) from the member record type Network Database Management System© SQL Star International Ltd. 12
  16. 16. In the figure there are three set occurrences of ProdOrder set type, which areProduct1, Product2, Product3.A record of the member record type cannot exist in more than one set occurrence,that is, two customers cannot buy the same product.Similar to HDBMS, NDBMS structure and relationship must be defined in advance.The number of connections that can be made between records is also limited.Relational DatabaseThe databases mentioned so far including the file system databases were not veryefficient. In the file system, users cannot simultaneously access data from the samefile, managing the files is very tedious when data stored is complex and accessingdata from files is also very tedious. HDBMS and NDBMS does not allow many-to-many relationships, has complex path to navigate and retrieve data, and therelationship between data is in the form of pointers.The objective of developing the relational model was to overcome the shortcomingsof those systems that existed at the end of the 1960s, and to make DBMS productsmore appealing to all kinds of users. Dr. E. F. Codd first introduced the relationalmodel when he proposed the relational model principles in a paper called ―ARelational Model of Data for Large Shared Data Banks‖ in June 1970.A relational database stores data using relations where each relation resembles atable of values. Each row in a table contains collection of data values. For example, auniversity stores information about all it‘s students using tables referred to as aStudent table and a Course table.Student table contains details about students, such as, their student number, nameand the course code. As different data is stored in the two tables, we may need tocombine them to answer particular questions such as details about students pursuingcourse ‗Electronics‘. An RDBMS enables to relate data in one table to the data inanother. It does so by identifying the relationships, which are represented byprimary key and foreign key. A primary key is assigned to that column, which willenable you to identify each row of data in a table uniquely. For example, in theCourse table the column containing the course code is the primary key as it helps toidentify each course uniquely. A foreign key is assigned to a column of a table, whichrefers to the primary key column in another table. For example, in the Student tablethe column containing the course code refers to CourseCode column of the Coursetable.© SQL Star International Ltd. 13
  17. 17. Object Relational DatabaseHierarchical, network and relational database models have been quite successful instoring data for traditional business applications. But, object oriented databasesevolved to handle more complex applications such as databases for scientificexperiments, geographic information system, engineering design and manufacturing.An object oriented database stores data, their relationships and the way theyinteract with other data. As compared to the relational database approach, whichdeals with data at the lowest level, that is, columns and rows, the object orientedapproach deals with data at a higher level, that is, with the objects surrounding thedata.RDBMSDr. E.F.Codd outlined the principles of the relational model, which formed the basisfor the evolution of the Relational Database Management System.A Relational Database Management System is defined as a collection of tablesrelated to each other through common values.Evolution of RDBMSBefore the acceptance of Codd‘s Relational Model, database management systemswas just an ad hoc collection of data designed to solve a particular type of problem,later extended to solve more basic purposes. This led to complex systems, whichwere difficult to understand, install, maintain and use. These database systems wereplagued with the following problems:  They required large budgets and staffs of people with special skills that were in short supply.  Database administrators‘ staff and application developers required prior preparation to access these database systems.  End-user access to the data was rarely provided.© SQL Star International Ltd. 14
  18. 18.  These database systems did not support the implementation of business logic as a DBMS responsibility.Hence, the objective of developing a relational model was to address each and everyone of the shortcomings that plagued those systems that existed at the end of the1960s decade, and make DBMS products more widely appealing to all kinds of users.The existing relational database management systems offer powerful, yet simplesolutions for a wide variety of commercial and scientific application problems. Almostevery industry uses relational systems to store, update and retrieve data foroperational, transaction, as well as decision support systems.Basic Relational Database TerminologyIn a relational database, the entities of the ERD are represented as tables and theirattributes as the columns of their respective tables in a database schema. Thecomponents of a database schema include:  Tables: Tables are the basic storage structures of a database where data about something in the real world is stored. It is also called a relation or an entity.  Rows: Rows represent collection of data required for a particular entity. In order to identify each row as unique there should be a unique identifier called the primary key, which allows no duplicate rows. For example in a library every member is unique and hence is given a membership number, which uniquely identifies each member. A row is also called a record or a tuple.  Column: Columns represent characteristics or attributes of an entity. Each attribute maps onto a column of a table. Hence, a column is also known as an attribute.  Relationship: Relationships represent a logical link between two tables. A relationship is depicted by a foreign key column.Some optional properties of relational tables include the following:  Data items (fields) must have a single value.  Data values in columns are of the same kind. This property states that all values in a given column must come from the same domain.Let us understand the concept of a domain. Suppose, you have a CourseNamecolumn in the Course table, which is defined to be a character string of length 15.The possible values this column could have are:  Oracle10g  Java  E-commerce  C++© SQL Star International Ltd. 15
  19. 19.  Visual BasicLet us name this list as ‗course-names’ and define a rule that the contents ofCourseName should not only be characters of length less than 15, but must alsocontain values that are part of ‗course-names’. Here, ‗course-names’ becomes thedomain and CourseName is in the domain of ‗course-names’.Each row is unique  The sequence of columns (left to right) is insignificant. The benefit of this property is that columns can be retrieved in any order.  The sequence of rows (top to bottom) is insignificant. The benefit of this property is that rows can be retrieved in any order, that is, the third, fourth or fifth row of member details could be retrieved.  Each column must have a unique name. As mentioned above, the sequencing of columns being insignificant, columns must be referred by name and not by their position.NormalizationOne of the methods of designing a database is normalization of steps.What do you mean by normalization?Normalization can be defined as the technique implemented to remove redundancyfrom an existing set of tables.Normalization helps:  Reduce redundancy  Increase integrity  Stabilize design  Identify any missing dataA relational table is normalized if it satisfies a certain set of constraints, which arethat they should be free of data redundancy and that they can be modifiedconsistently and correctly. Therefore, normalization is the process of removingredundant data by splitting a table into smaller tables.The technique of normalization includes some rules, which when applied, changesun-normalized data to a structured and normalized state. The process of normalizingis implemented in levels called normal forms. There are three such stages, they are:  First normal form  Second normal form  Third normal form© SQL Star International Ltd. 16
  20. 20. First Normal Form (1NF)The first normal form can be defined as the level where the tables represent a set oftwo-dimensional structures and contain no repeating groups.You need to implement the following set of steps to convert your un-normalized datato its first normal form.  Identify the primary key  Remove all repeating columns  Create a new table to contain the repeating columns  Add a primary key column to the newly created table so as to ensure uniqueness  Add a foreign key column to the new table. It should be the same column at the primary key in the base table.To understand better, follow the example given.ExampleTo arrive at a functionally efficient library database schema, you would have tonormalize the tables of the library database. The main table used in the library iswhere the transaction details will be stored. You would require:  All information pertaining to the customers who borrow books  All information of the borrowed book, such as its author, its publisher‘s information and the dates of issue and return  The un-normalized table is as follows © SQL Star International Ltd. 17
  21. 21. © SQL Star International Ltd. 18
  22. 22. This table can be brought to the 1NF by removing all the repeating columns. Therepeating columns are put into separate tables in logical groups with a primary keyas a unique identifier for each table. The tables in the first normal form are:Second Normal Form (2NF)The second normal form can be defined as the level where tables are in the 1NF, andwhere for every table, all its non-primary key columns are dependent on the wholeprimary key. A column should not be partially dependent on the primary key. When acolumn depends on part of the primary key it is called partial dependency.To remove partial dependency: 1. Identify the non-primary key columns and remove them from the tables 2. Create another table to contain the removed columns, and the primary key column that they are dependent on.To bring a table to the 2NF, any of the following rules should be met:  The primary key column should not be a composite key. That is, it should be made up of only one column.  All the non-primary key columns are dependant only on the primary key.  There should be no non-primary key dependent columns in the table.To bring the tables to 2NF, remove all those columns that are partially dependent onthe whole primary key. For instance the book availability does not depend on thetransaction ID but only on the book ID. So that column can be removed into a newtable.Hence, the tables in the second normal form will be as follows:© SQL Star International Ltd. 19
  23. 23. Third Normal Form (3NF)The third normal form is defined as the level where the non-primary key columns in thetables are directly dependent on the primary key and are not dependent on any other non-primary key. If you remove the transitive dependencies from a table in 2NF, then it issaid that, “the non-primary key columns are dependent on the primary key, the whole keyand nothing but the key”.Steps to convert a table to the third normal form are: 1. Identify the non-primary key columns that depend on other non- primary key columns. 2. Remove the columns arrived at in the first step from the base table. 3. Create another table with the removed columns and include the non-primary key column that they are dependent on making it the primary key. 4. Create a foreign key in the base table linking it to the primary key in the new table.© SQL Star International Ltd. 20
  24. 24. To bring the tables to their third normal form remove the non-primary keys that aredependent on other non-primary keys and also remove the columns that arecalculated or derived columns. The membership fee a non-key column depends onthe age of a member, which is another non-key column. Tables in the third normalform are:The Entity Relationship ModelThe conceptual level model is a very important model in typical databasearchitecture. To represent or model data at this level, three major data modelsnamely, network, hierarchical and relational, have been proposed which you shallexamine later. Each of these models has its own pros and cons. The entityrelationship model is not a formal data model, unlike the three mentioned above.However, this model is a more natural view of the real world, which consists ofentities and relationships, as you shall see shortly. Therefore, this model is veryuseful for understanding the concept of data modeling. The three formal modelsemploy certain ways of representing data known as data structures; essentially torepresent the ―entity relationships‖ existing in the real world.The entity relationship model (E-R model) clarifies concepts regarding what entityrelationships are, and what modeling entity relationships existing in the real worldmeans. Therefore, a study of the E-R model should be an appropriate first steptowards understanding the three major data models.© SQL Star International Ltd. 21
  25. 25. EntitiesAn entity is a thing, which can be distinctly identified. What is important over here isthat it is individually distinct. Employees, a house, a supplier to an organization, areall entities. Identification of entities relevant to a database is extremely important,because, a database contains data about entities.All entities of the same type form an entity set. ―All Employees‖ form an entity setand so do ‗All Suppliers‘.Distinguishing EntitiesAs has been stated, an entity is a distinctly identifiable thing. To distinguish oneentity or one member of an entity set from another, one needs some means ofdistinction. This distinction is achieved through values of what is known as the ―KeyAttribute‖ of the entity.The database gives information about different entities contained in it. Thisinformation is about different properties of each entity. For example, a personaldatabase contains information about employees (here employee is the entity). Theproperties of an employee about which information is given, may typically be,employee number, name, date of birth, date of joining the organization, total jobexperience and educational qualifications. Each of these properties is called anattribute of the entity.Each of the attributes can take on a value from a range of possible values, which isknown as the domain of values for that attribute. The values need not be onlynumerical but may also be character strings.For each entity in an entity set, there is an attribute, which distinguishes the entityuniquely from the other members of the set. This attribute is the key attribute forthe entity-set. For example, the employee entity-set discussed about can have eitherthe employee number or the employee name (assuming no two names are identical)as the key attribute. In some cases, a combination of more than one attribute mayact as a key, instead of just one key attribute. Some times, an arbitrary serialnumber may have to be supplied as the key attribute.There are special cases where the members of an entity-set can be distinguishedfrom one another only by their relationship to entities of another type. The ‗is a‘relationship is one such relationship. These cases will be illustrated when we take upan actual example of an E-R model later.RelationshipsIn a real-world situation, certain entities are associated with each other. Forexample, referring to the employee entity-set will have a relationship with thedepartment entity-set signifying the department for which an employee works. Thisrelationship can be expressed as the ―works-for‖ relationship from ―employee‖ to―department‖.A relationship may exist amongst the members of the same entity-set. For example,in the employee entity-set, some employees may be seniors of certain otheremployees. Therefore a relationship ―senior-of‖ may exist between one member ofthe employee entity-set and a few other members of the same set.© SQL Star International Ltd. 22
  26. 26. A diagrammatic representation for the employee-department relationship may be asgiven below.A diagrammatic representation for the ―senior-of‖ relationship may be:It should be noted that relationships convey very important information regardingthe relevant real world situation just as entities do, and hence should be properlyrepresented.There may also be relationships involving more than two entity sets. For example,Prof. Smith teaching Economics to a student named Sam. This relationship containstwo relationships – (1) Prof. Smith teaches Economics and (2) Prof. Smith teachesSam. These two relationships cannot be combined to deduce the information givenby the original relationship.The same entity-sets may be also linked by more than one relationship. Forexample, the Professors and the Students entity-sets may be linked by the tworelationships, viz; (1) TEACHES and (2) ADVISOR-OTypes of RelationshipRelationships between the entity-sets can be classified according to how manymembers of one entity-sets are related to one member of the other entity-set andvice-versa. Accordingly, the following types of relationships can be identified.One-to-One RelationshipsIf a one-to-one relationship exists between two entity-sets A and B, it means thatwith each entity in A, at most one entity in B is associated and vice-versa. Strictone-to-one relationships are not very common in real world situations. Consider anentity set of traffic policemen and another entity-set of traffic control points in thecity and assume that only one policeman controls one traffic control point. Under thisassumption, the relationship CONTROLS between the entity sets POLICEMEN andCONTROL-SITES will be a one-to-one relationship.Many-to-one RelationshipsThis type of relationship is quite common in everyday life. If, with each entity in theentity-set B, zero or more entities in set A are associated, then we say that a© SQL Star International Ltd. 23
  27. 27. many-to-one relationship exists from set A to set B. In our earlier employeedatabase example, the WORKS-FOR relationship is a many-to-one relationship fromthe entity-set EMPLOYEES to the entity-set DEPARTMENTS (assuming that anemployee works for only one department at a time).Many-to-Many RelationshipsThis is yet another type of relationship which is quite common in real-life situations.In this case, associated with each entity in set A, there may be zero or more entitiesin set B and vice-versa. A very common example of this type would be therelationship between the entity-set SUPPLIERS and the entity-set PARTS. A suppliermay supply many parts, while a part may be supplied by many suppliers.Guidelines for Constructing the Entity-Relationship ModelHaving understood the basic components, you are now in a position to consider theconstruction of an E-R model. The principal steps involved in this exercise are: • Select relevant entity-sets for the real-life situation under consideration • Select relevant attributes for each entity-set • Identify the key-attribute for each entity-set • Determine the type of each of the relationships between the entity sets • Draw the E-R diagramConsider the situation in which the academic administration often finds itself. It hasto handle data regarding students, faculty, and the courses being offered, andpossible areas of specialization. It is worthwhile to consider the following pointsbefore you move to construct the model: • The students specialize in one or more areas • The students study a specific course • A course belongs to an area of specialization • A faculty member belongs to an area of specialization • A student can be either a doctoral student or a degree student • A faculty member guides a doctoral student • Certain courses have certain other courses as prerequisite • A faculty member offers a specific courseFrom the above, the desirable entity-sets, their relevant attributes and theappropriate key attributes can be determined. 1. Entity-set : Students Attributes : Roll No, Name, Date-of-birth, Basic Educational Qualification, No. of years of work experience© SQL Star International Ltd. 24
  28. 28. Key : Roll No. 2. Entity-set : Faculty-members Attributes : Name, Date-of-birth, Date of Joining, Educational Qualifications, Total No. of years of Teaching Experience Key : Name 3. Entity-set : Courses Attributes : Course-No, Course-Name Key : Course-No 4. Entity-Set : Areas (of specialization) Attributes : Name of the Area Key : Name of the Area 5. Entity-Set : Doctoral-students Attributes : NoneThis entity-set is needed to identify individual doctoral students. The reason forassigning a separate entity-set to doctoral students is to be able to establish therelationship between these students and their faculty guides, in the actual database.Now you are in a position to identify the different relationships amongst the aboveentities. These are: 1. SPECIALISES_IN: This is a many-to-many relationship between STUDENTS and AREAS 2. STUDIES: This is a many-to-many relationship between STUDENTS and COURSES 3. INCLUDED_IN: This is a many-to-one relationship from COURSES to AREAS 4. BELONGS_TO: This is a many-to-one relationship from FACULTIES to AREAS 5. GUIDES: This is a one-to-many relationship from FACULTIES to DOCTORAL- STUDENTS 6. OFFERS: This is a many-to-many relationship from FACULTIES to COURSES. The assumption here is that a course may be offered by more than one faculty-member 7. IS A: This relationship is one-to-one between STUDENTS & DOCTORAL-STUDENTS 8. PREREQUISITE_FOR: This is a many-to-many relationship from COURSES to COURSES because a course may be a prerequisite for more than one other course and may have more than one other course as prerequisites for itselfNow you are ready to draw the E-R diagram representing the E-R model. First let usdiscuss the relevant diagrammatic conventions and then actually draw the diagram© SQL Star International Ltd. 25
  29. 29. Conventions for Drawing E-R DiagramsFollowing are the conventions for drawing E-R diagrams: · Entity-sets are represented by rectangles. · Attributes are represented by circles. These are linked to the appropriate entity-sets by undirected edges. · Relationships are represented by diamond shaped boxes. These are linked to the appropriate entity-sets by directed edges.An E-R diagram for the Academic Administration database is:As already stated earlier, the E-R model brings out the essential features of datamodeling for databases. Data modeling in practice, is done according to the one ofthe three models, viz., hierarchical, network and relational. The three models too,establish relevant entities and the relationships amongst them; they differ in the waythey represent data about both entities and their relationships. The E-R model,however, is free from these relatively physical aspects of data representation andtherefore can be said to be a general view of the three models unifying them at arelatively abstract level.Case Study – Entity Relationship for a LibraryThe library needs to create a database to automate its data storage and processes.For this you first need to know how a library functions, what are its transactions andwhat data it needs to store for activities. To arrive at an ERD for a library, list theentities and its attributes you require before putting them into a diagram:  Member  Member ID  Name© SQL Star International Ltd. 26
  30. 30.  Address  Area  Zipcode  phone number  Age  Date of membership  Age group  Branch ID  Book  Book ID  Book name  Author name  Publisher  Published Year  Category  Branch  No of copies in store  Transaction  Transaction ID  Member ID  Book ID  Issue date  Return date  The actual return date  Fine to be paid by the member for default  Category (for books)  Category ID© SQL Star International Ltd. 27
  31. 31. Category description  MemberFee  Age group grade  Minimum value  Maximum value  Fee amount  Branch  Branch ID  Branch name  Address  Location  Phone number  Date of establishment  Availability  Book id  Available copies  Publisher  Publisher Id  Name  AddressThe list arrived at above can be depicted as an ERD in the following manner:© SQL Star International Ltd. 28
  32. 32. Communicating with RDBMSIn order to communicate with the RDBMS, that is, to access data, you have a querylanguage called a Structured Query Language (SQL). A query can be defined as arequest made to access data from the database. This definition refers not only todata retrieval, but also defining, manipulating and controlling data. The need toaccess data from the database on an ad-hoc basis led to the origin of SQL. The originof SQL can also be associated with one of Codd‘s Twelve Rules, where in he statesthat a relational database must have a high level language capable of handling allcommunication with the database. Although there are several languages that canaccess data from the database, SQL is the primary language for communicating withRDBMS. SQL can also operate on non-relational databases.© SQL Star International Ltd. 29
  33. 33. Features of SQLThe features of SQL are as follows: • SQL is a Declarative Language (non-procedural). You need not provide the Step wise procedure to be followed in order to access the data. Instead, it allows you to simply declare what data you want without having to provide details about where it is located or how to get it. It leaves it to the DBMS to determine the best way to get it. On the contrary, procedural languages such as C, or C++ provide a step-wise procedure telling the computer exactly what is to be done. The advantage being that these instructions given ahead of time can be compiled into machine language for fast execution. But these languages lack flexibility, that is, do not adapt to changes easily. • SQL is a set-based language. Since the relational model uses the concept of a mathematical relation that is, has its theoretical basis in set theory, SQL supports set operations and relational algebra operations.A set is an unordered collection of elements of the same type and structure. Tables(or relations) are called sets and rows (or records) are their elements. In a relationaldatabase the physical positioning of rows is not important, that is, they areunordered, so SQL being a set-based language can operate on an entire table, ormultiple tables at once. In contrast, a procedural language can operate on a singlerecord at a time as it uses ‗files‘ which are similar to tables, wherein records have aphysical ordering.Relational algebra operations can be divided into two groups: Set operations from mathematical set theories including Union, Intersection and Set Difference. Operations developed for relational databases, which include Select, Project and Join.Set OperationsSet operations include the following: Union Intersection© SQL Star International Ltd. 30
  34. 34.  Set DifferenceUnionTo understand the union operation look at the following two tables, States1 and States2:The above two tables contain names of US states. Some of the state names arecommon in both the tables.In order to return the state names that are in States1 or in States2 or in bothStates1 and States2, eliminating duplicate rows, you use the UNION operation.The notation for union of tables is:States1 UNION States2 = States3The result of the union operation is as follows: States 3 Hawaii New Jersey Indiana Florida Arizona Colorado California Alaska Texas Georgia Virginia Wisconsin Kansas Kentucky IowaThe resulting table contains the state names that are contained in both the tables,but displaying the common state names only once.© SQL Star International Ltd. 31
  35. 35. IntersectionThe intersection operation returns state names that are in both States1 andStates2, that is, it returns a third table that contains only common state names.The notation for intersection of tables is: States1 INTERSECTION States2 = States3The result of the intersection operation is as follows:Set DifferenceThe result of the set difference operation returns state names that occur in theStates1 table but not in the States2 table, or also vice versa. The result is asfollows:Relational OperationsIn addition to set operations, certain other operations were developed for relationaldatabases, which include:  Selection  Projection  JoinsSelectionThe selection operation enables you to retrieve only specific rows that match yourcriteria. For example, you have two tables TabA and TabB.© SQL Star International Ltd. 32
  36. 36. Using the selection capability of SQL, you can retrieve those rows from TabB tablewhere Col1 value is 2.The result set of rows would be:ProjectionThe projection operation enables you to retrieve only specific columns from the totalcolumns available. For instance, using the projection capability of SQL, you canretrieve only Col2 values from TabA table.The result set would be:JoinsThe join operation enables you to retrieve data from more than one table. Forinstance, using the joining capability of SQL, retrieve rows from both TabA andTabB by joining Col1 as they have equivalent values.The result set of joining the two tables would be:Why SQL is Preferred?SQL is favored due to the following reasons:© SQL Star International Ltd. 33
  37. 37.  A wide range of users, including those with little or no programming knowledge can use it.  It is an English-like language.  It is non procedural, that is, the user need not specify the method to be followed to arrive at the result, rather just specify the result that needs to be arrived at.  It allows defining, retrieving and manipulating data in the tables.Relational Data Model ConceptThis rule states that all data is represented as tables. Data can be viewed in no otherway.Codd’s RulesDr. E. F. Codd, was the creator of the relational data model. It was published as a two-part article in ComputerWorld (Codd, 1985). It contains a list of 12 rules that determinewhether a DBMS is relational and to what extent it is relational. These rules are a veryuseful yardstick for evaluating a relational system. In the article, Codd mentions thataccording to these rules, there is no database yet that is fully a relational system. He saysthat rules 6, 9, 10, 11 and 12 are difficult to satisfy. Each of the twelve rules is brieflydiscussed below.The Information RuleAll information in a relational database is represented explicitly at the logical level and inexactly one way through values in tables.Guaranteed Access RuleEach data item must be accessible by providing table name + primary key of the row+ column name.© SQL Star International Ltd. 34
  38. 38. Systematic Treatment of Null ValuesHandle missing or non-applicable data, that is, nulls, in a consistent manner. Nullsshould have no values and should simply be missing data. Treating Null as a zero formissing numeric data or as a blank for missing character data violates this rule.Vendors provide the ability to use default values for missing data, if so desired.Self-describing DatabaseIn addition to storing user data, a relational database must contain data about itself.There are two types of tables in RDBMS: user tables, which contain data required byusers, and system tables, which contain data about the database structure. The datathat describes the database structure is called meta-data. The collection of systemtables is called as the system catalog or data dictionary. Storing any part of the datadictionary in operating system files would violate this rule.Comprehensive Data SublanguageThe data access language (SQL) must be the only means of accessing data stored inthe database. The language must support relational operations and set operationswith regard to the following:  Data definition  Data manipulation  Integrity definition  Transaction control  Data controlAccessing data files (files that contain the actual data), through a utility other thanan SQL interface, violates this rule.View Updating RuleThere are situations where users may require only a part of the table information orinformation from a collection of tables. Such requirements can be met by creating‗Views‘. Views are virtual tables, which unlike a table contains no data, juststatements that return data in the form of tables.This rule states that views should allow updates in the underlying tables and viceversa.But SQL supports only updates of single tables at a time (see rule 7), therefore if,you join three tables to create a view, and try to update that view, then DBMS wouldfail to translate these updates to the underlying tables, thereby violating this rule.Also, a view not including the column that uniquely identifies each record in a tablecannot be updated, thus violating the rule.This rule will be dealt in depth in the chapter on ―Views‖.High-level Insert, Update and DeleteThis rule states that in a relational database, the query language (SQL) must becapable of performing manipulations (such as, inserting, updating or deleting data)© SQL Star International Ltd. 35
  39. 39. on sets of rows in a table. A database that supports only row-at-a-time manipulationcannot be considered as relational.Physical Data IndependenceThis rule states that in a relational database, any changes made in the way data isphysically stored (that is, data stored in file systems specific to the machinesoperating system) must not affect applications that access data. If a file supporting atable was moved from one disk to another or renamed, then this should have noimpact on the application.Logical Data IndependenceThis rule states that changes to the database design should be done in a way withoutthe users being aware of it. The change could be to expand the database (adding anew table) or to reduce it, but the application that refers to the data (logical) mustwork as before. If a single table were split into two, then a view would have to beprovided joining the two back together so that there would be no impact on theapplication.Integrity IndependenceIn order to be considered as a relational database, all data integrity, which aredefinable in the query language referred to in rule 5 must be stored in the databaseas data in tables, that is, in the catalog and not in the application programs.The data integrity rules that should apply to relational databases are: Entity integrity- the primary key column cannot have missing values Referential integrity- for every foreign key column value there must exist a matching primary key column value. Integrity rules are covered in depth in a later chapter.Distribution IndependenceIn a relational database, data can be stored centrally (on a single system) ordistributed (across a network of systems). The data in a centralized database shouldremain logically unaffected if they are distributed across systems. For example, auser should be able to retrieve data from two tables distributed across two terminals,the same way, as they would retrieve them if stored in the same terminal.Non-subversion RuleThis rule states that there should be no other access path to the database, otherthan SQL. Any other access language may bypass (or subvert) security or integrityrules, which otherwise would be obeyed by the regular data access language.© SQL Star International Ltd. 36
  40. 40. SummaryIn this chapter, you have learnt that: Files prove to be inefficient due to their redundant nature when the number of applications increase. This gave rise to the concept of Database. Database is a collection of logically related data stored on media. To handle and maintain this database, a software, Database Management System (DBMS) came into existence. They are of 4 types: 1. Hierarchical Database Management System 2. Network Database Management System 3. Relational Database Management System 4. Object Relational Database Management System  Out of these types, Relational Database Management System (RDBMS) was popularly used which enables to relate data in one table to the data in another. Normalization is the process to stabilize a database, by reducing data redundancy. Data can be stabilized through 3 stages: 1. First Normal Form (1NF)   2. Second Normal Form (2NF) 3. Third Normal Form (3NF) To access the stabilized data, Structured Query Language (SQL) is widely used.© SQL Star International Ltd. 37
  41. 41. Lab ExerciseIn the following questions, you are given the Universe of Discourse(UOD, that is, the general outline at the level a user would normallydescribe) of some typical enterprises. Please note that a UOD is nota smooth and structured description.Define:  Entity and associated attributes  Relationships between entities and type of relations  Draw the Entity-Relationship diagram1. LIBRARY SYSTEM:A library keeps records of current loans of books to borrowers. Each borrower isidentified by a borrower number and each copy of a book by an accession number.The name and address of each borrower is held so that overdue loan reminders etc.,can be sent whenever necessary. The information required about books is the title,authors, publishers, publication date, International Standard Book Number (ISBN),purchase and price and current price. There is a restriction on the number of booksa borrower may have on loan at any one time, the limit depending on whether aborrower is classified as having junior or adult status. Books out on loan may bereserved by other borrowers pending their return. The library stocks only thehardback version of the book. If a new edition of the book is published, all copies ofearlier editions are withdrawn from stock.2. A UNIVERSITY:A University has number of departments. Each department has its faculty.Departments enroll students.Each faculty member may conduct one or more courses and one or more studentsregister for a course. The courses are conducted in classrooms based on a preparedtime-table.Each subject has a prescribed text book and host of recommended reference books.A faculty member may guide more than one project and the same project may bedone by more than one student.3. DEPARTMENTAL STORE:The data in the database of a department store are defined as follows:  Each employee is represented. The data about an employee are his employee number, name, address and the department he works for.  Each department is represented. The data about departments are its employees, manager and items sold.  Each item sold is represented. The data about items are its name, manufacturer, price, model number (assigned by the manufacturer) and an internal item number (assigned by the store).© SQL Star International Ltd. 38
  42. 42.  Each manufacturer is represented. The data about a manufacturer are its name, address, items supplied to the store and their prices. Various employees work for a department and each department stores items supplied by various manufacturers.A MANUFACTURING ENTERPRISE:A manufacturing company consists of a number of divisions. Each division, in turn,consists of one or more departments. Each employee of the company belongs toonly one department at any point of time. Orders are executed at the divisional level.Any number of departments (as required) may execute an order. A department mayalso execute a number of orders. Employees work on various orders in theorganization.An order needs several parts. A part may be needed by several orders. A part itselfmay consist of sub parts. Alternatively, a part may be a support of a super part.Parts are housed in warehouses which are at specific locations. Suppliers supplyparts.AN AIRLINES ENTERPRISE:An Airlines company has a fleet of aircraft‘s which it employs to carry passengersfrom one airport to another.A flight (i.e. an aircraft assigned for trip from one airport to another) is manned by acrew. A time table is available for all the flights. At each airport, based on the flightschedules, service schedules are drawn up for the ground staff.At each airport, for each flight, caterer(s) provide the necessary food andrefreshments according to the catering schedule.The maintenance of aircraft‘s (that are not in operation and which have been taggedfor maintenance) is done by the maintenance staff according to the maintenanceschedule. Maintenance is conducted at the airports where hangar(s) are available forthe type of aircraft in question.© SQL Star International Ltd. 39
  43. 43. Chapter 2 Introduction to Oracle10g Key features of Oracle10g Components of Oracle10g© SQL Star International Ltd. 40
  44. 44. ObjectivesAt the end of the chapter, you will be able to:  Identify the different components of Oracle10g  Identify the enhanced features of Oracle10g© SQL Star International Ltd. 41
  45. 45. IntroductionThe traditional database systems such as relational, hierarchical and network havebeen successful in developing the database for traditional business applications suchas banking and railway reservations. But, when it comes to more complex businessapplications such as databases for scientific work, engineering designs,telecommunications, geographic information system and multimedia, the traditionaldatabase systems cannot handle them because the requirements and characteristicsof these applications are different from the traditional business applications. Theseapplications require more complex structures for:  Storing data related to real world objects such as engineering diagrams, molecular structures, or financial instruments  Transactions, which would be for longer durations  New data types required for storing complex multimedia data such as audio and video clips, images and maps.Oracle10g Database meets the above needs as it tightly incorporates ORDBMsconcepts.Object Relational Database Management System (ORDBMS) is a databasemanagement system that has evolved from the relational model and includes boththe relational and object-oriented technology. Oracle8.0 was the first version of theOracle database to incorporate object-oriented technology.In Oracle10g, ‗g‘ stands for GRID. This release is focused on efficient management ofinfrastructure based on its grid computing mechanism.Now, the question arises what is Grid Computing?The idea behind the grid computing is to utilize the resources available, to themaximum extent by dynamically pooling it based on the requirement of the end userduring the peak hours. In this case, the end user need not know the whereabouts ofthe resource.Infrastructure AdvantagesData AvailabilityInternet database availability is critical for any eBusiness application. Oracle10gfocuses on the following areas to achieve continuous data availability:  Zero data loss data protection environment  Support for online reorganization and redefinition architecture to reduce offline maintenance requirements  Provides more complete and precise database repair capabilities by ensuring better prevention and improved handling of disk corruption© SQL Star International Ltd. 42
  46. 46. Scalability and PerformanceOracle10g enables eBusiness to scale millions of users performing millions oftransactions per hour by focusing on the following key areas: Transparent cluster scalability and performance: Oracle10g along with itsgrid mechanism includes Real Application Clusters (RAC) that has been designed toprovide continuous data availability while increasing the scalability and performanceof the database infrastructure. RAC was introduced in Oracle9i, which is anarrangement, where a single database runs on a group of servers that are clusteredtogether. With Oracle9i RAC all servers in the cluster act as backup to each otherwhile at the same time increasing the overall computing power within the cluster. Scalable session state management: Oracle10g allows more users to behosted on the same or larger hardware platforms due to its new grid mechanismwhere in new nodes can be added to the cluster when the load increased. Optimized features critical for eBusiness: Oracle10g focuses on the followingperformance areas, critical for eBusiness: Support for large datafiles. Enterprises planning to setup Data Warehouse and transaction systems can extend their Oracle database upto 8 Exabytes, which is equivalent to 8 million terabytes.  Improving the performance of many of today‘s business applications by providing support for enhanced native compilation and improved optimization of PL/SQL.  Improving optimization plans and reducing resource usage by adding memory and CPU costs to the cost based optimizer cost calculation algorithm  Improving performance in Data Warehouse and Online Transaction Processing (OLTP) environments by general I/O improvements such as better sharing of run-time data structures, larger buffer caches and deferrable constraints.SecurityOracle10g provides secure application development and deploymentplatform by focusing on:A strong three-tier security, which ensures that a user can access the databaseonly through the middle tier. As a result user identities are maintained securelythrough all tiers of an application, with centralized user and privilege management inOracle Internet Directory.Deep data protection through enhancements in Virtual Private Database, fine-grainedauditing and Oracle Label SecurityDevelopment Platform for eBusiness ApplicationsOracle10g continues to provide the best development platform for both eBusinessand traditional application development by focusing on the following key area© SQL Star International Ltd. 43
  47. 47.  Enterprise Java Engine:Java support in Oracle10g focuses on improving the performance of the embeddedJava Virtual Machine, new JDBC and SQLJ functionalities, and enhancement to Javastored procedures. SQL and PL/SQL improvements:Oracle10g has introduced many enhancements in SQL and PL/SQL to meet moderndevelopment requirements. Oracle10g supports inheritance, type evolution, anddynamic method dispatch to increase the usefulness of objects. Along with theexisting datatypes, new datatypes have been introduced. It also supports CASEstatement, ANSI compliant joins and reserved naming conventions.  New Dataypes In addition to the existing datatypes, new datatypes have been introduced. They are BINARY FLOAT and BINARY DOUBLE. Bioinformatics and life science applications have benefited from these datatypes to solve complex computations.  Alternative Quote operator: Strings containing single code as literal, can be now be escaped using customized symbols using Q operator.  Environmental Scripts after each CONNECT: Previously glogin.sql and login.sql scripts were read at the startup of iSQL*Plus. Now, these scripts are automatically run after each user connects to the database.  Multiple Pages Output: Output spanning over multiple pages can now be viewed using NEXT button or can be viewed on a single page as in the previous version. SQLPlus Recycle Bin: SHOW RECYCLEBIN [original_name] command has been introduced to view the dropped database objects. Oracle Flashback Feature: This feature has helped a developer to reduce errors.  Oracle Flashback Table: FLASHBACK TABLE statement in SQL allows to recover the accidentally dropped table.  PURGE TABLE: This statement removes the database objects permanently from the Recycle Bin.© SQL Star International Ltd. 44
  48. 48. Oracle FlashbackVersion QueryChanges in the table data can be viewed using VERSION BETWEEN clause. Achanged transaction‟s undo records stored in the database must be available.Oracle Flashback Transaction Query Changes made to the tables can be viewed using FLASHBACK_TRANSACTION_QUERY view. This can be helpful for auditing, debugging and even performance analysis.Improved MERGE Functionality MERGE Statement has been improved by making WHEN MATCHED and WHEN NOT MATCHED clauses optional. Also, WHERE clause can now be used in this statement to restrict the values while inserting into target table. Regular Expression functions: Regular Expression functions have been introduced which works beyond the POSIX (Portable Operating System For UNIX) standard for matching ASCII characters.Improvements to PL/SQL:  Bulk Binding Enhancements: Performance related to BULK BINDING has been enhanced by introducing INDICES OF and VALUES OF clauses. INDICES OF clause permits sparse data in a collection. VALUES OF clause refers one array values based on another array values. Enhanced Native Compilation: The number of parameters to be set for Native Compilation has been reduced. A much more tight integration of SQL and PL/SQL runtime engines is made possible. New Packages: DBMS_WARNING: Warnings generated during compile time can be dynamically set using DBMS_WARNING package. UTL_MAIL: This is an enhancement to UTL_SMTP package. Using this, E- mails can be sent through a PL/SQL API. UTL_COMPRESS: This package compresses and uncompressed RAW Byte stream of Large Object (LOB) data. DBMS_METADATA: This package extracts the metadata of a database object, which can be obtained either in XML version or DDL.© SQL Star International Ltd. 45
  49. 49.  CLOB and NCLOB Implicit Conversions: You no longer need APIs to convert CLOB to NCLOB and vice versa. This release supports their implicit conversion.Oracle10g and the InternetOracle8i was the first internet-based database in the world. It recognized thatInternet provided the safest and efficient access to data to all users spread acrossthe globe.Oracle10g continues the Oracle9i focus on the Internet by providing a series ofenhancements targeted at eBusiness environments.To be able to allow commerce on the net, your system needs some importanthardware configuration so that it can support the transactions between the databaseand the Internet. One important step is to identify the kind of machines that youneed.Fat client or Thin clientThere are two kinds of client available, fat client and a thin client. Before debatingwhether everybody needs a fat client or a thin client, you need to understand whatthese terms mean.A fat client is a traditional PC system, which if purchased today would have 64MB ormore of memory, 6GB or more of disk space, a fast paced processor and/or a CD-ROM drive. A fat client would have all the codes locally within them.A thin client is a personal computer used mainly for functions like e-mail,presentation of information and word processing. It stores no code/programs locallyand only accesses them from the database.The reasons for shift from fat clients to thin clients are due to the followinglimitations:  Loss of critical pieces of information if they reside only on a disk drive in the event of a break down  The need for upgrading the software every time a new version comes into the market. This raises a lot of questions. Should the release of new versions force the end users to upgrade their software? Whether to assume that end- users have the necessary skills to upgrade their software? Should the support people go out to hundreds of PCs and upgrade them individually? Isn‘t this a waste of their time when these activities are only for someone who uses e-mail?The above complexities of fat client led to the development of a more maturenetwork known as the Network Computing Architecture (NCA) wherein the end userwould not be required to deal with issues like loss of data due to virus attacks or deal© SQL Star International Ltd. 46
  50. 50. with upgradations. Trained professionals would handle these at some centrallocation.Oracle Internet PlatformThe positioning of Oracle as an Internet solution company is due to the adoption ofNCA. This architecture enables the development, deployment and integration ofapplications within a networked computing environment. Oracle has developed NCA,which is based on the following three separate tiers:  A thin client tier, which is the layer responsible for the presentation of the information. It is the desktop PC running a web browser.   An application server tier (the middle tier), which is the layer wherein all the application codes are processed.   A database server tier, which is the layer where all the data is stored. A Three-tier ArchitectureThe NCA is designed such that the presentation layer is separated from theapplication layer. The application layer resides on a server separate from thedatabase server and it is assumed that the application server is the fat client. Theapplication server as well as the database server can be moved to a machine withmore resources, which could be placed in a central location and be managed bytrained professionals thereby keeping the end users away from all the complexities.Based on the above theoretical concepts, Oracle 10g release is broadly divided into: • Oracle Database 10g • Oracle Application Server 10g© SQL Star International Ltd. 47
  51. 51. • Oracle Enterprise Manager 10g Grid Control• Oracle Database 10gOracle10g database supports Grid Computing architecture. Here, multiple databaseservers are pooled together to form a cluster. It enhances utilization of resources. Itefficiently stores and manages the structured and unstructured data such as: • Spreadsheets • Word documents • PowerPoint presentations • XML • Multimedia data types like MP3, graphics, video and more.Oracle 10g facilitates two-tiered or multi-layered distributed database environmentslike client/server and Web-based applications. Large objects need be stored insideand outside the database. Oracle Database 10g has services which help to manageand retrieve data, located outside the database.• Oracle Application Server 10gA complete infrastructural platform is provided for developing and deployingenterprise applications, integrating many functions including a J2EE and Webservices run-time environment, an enterprise portal, an enterprise integrationbroker, business intelligence, Web caching, and identity management services. Theexisting 9iAS gets further enhanced with the introduction of new grid computingfeatures. It further integrates users, applications and data across your organization.• Oracle Enterprise Manager 10g Grid ControlIt is the consolidated, core management console that forms the basic framework toautomatically initiate administrative tasks across the networked environment. WithOracle Grid Control, multiple hardware nodes, databases, application servers andother targets can be brought together into single logical entities.Oracle10g continues Oracle Corporation’s lead on providing the best platform supportfor business intelligence by focusing on the challenges raised by large volume of dataand the need for real time complex analysis in an eBusiness environment. Oracle10gprovides the business intelligence platform by enhancing and extending databasesupport for Online Analytical Processing (OLAP), data mining and extraction.© SQL Star International Ltd. 48
  52. 52. SummaryIn this chapter, you have learnt that:  In Oracle10g, ‗g‘ stands for GRID. It is a technology, which groups similar resources into a cluster. This allows efficient utilization of resources. This helps us to design complex business applications.  Data availability, security and development for e-business applications are some of the advantages with Oracle10g.  Oracle10g structure is based on NCA (Networked Computing Architecture), which is developed to overcome the problems with fat client. It enables development of applications within networked computing environment.  Oracle10g has come up with new features in SQL* Plus environment, new commands in SQL language and improvements in PL/SQL, making it more user friendly.© SQL Star International Ltd. 49
  53. 53. Chapter 3 Data Retrieval iSQL*Plus Interface Logging into Database using iSQL*Plus Projection, Selection and Join Terminology Differences Between SQL and iSQL*Plus Review of Syntaxes for Basic SQL SELECT statements Arithmetic and Concatenation Operators in SQL statements Alternative Quote Operator Saving SQL Statements to Script Files© SQL Star International Ltd. 50
  54. 54. ObjectivesAt the end of this chapter, you will be able to:  Use the SELECT statement to extract data   Understand the various categories of SQL statements© SQL Star International Ltd. 51
  55. 55. Retrieving DataOracle uses the Structured Query Language (SQL) to communicate with thedatabase. The SQL statement used to extract data from the database is the SELECTstatement. The SELECT statement informs the database about the data you want toretrieve. SQL statements need to be executed in an environment where, they wouldbe interpreted and sent to database.iSQL*Plus EnvironmentiSQL*Plus introduced in Oracle9i is a browser environment in which SQL statementsare executed. SQL*Plus environment was the default environment in the priorreleases of Oracle. SQL*Plus is still available.Since the Oracle server understands only SQL worded statements, all Oracle toolssupport SQL syntax. Implementation of SQL through SQL*Plus environment oriSQL*Plus environment meets the ANSI (American National Standard Institute) andISO (International Standards Organization) standards.On issuing an SQL statement, the statement first gets stored in a part of thememory, which is called the SQL buffer. The SQL statements (stored in the buffer)are then recognized and submitted to the Oracle database for execution by theSQL*Plus or the iSQL*Plus environment.The iSQL*Plus environment helps to perform the following tasks:  Executing SQL statements to extract, add, change and remove data from the database  Formatting and performing calculations on query results so as to produce more meaningful reports  Storing SQL statements in files (called script files) so that they could be used later. These files have .sql file extension.How to log in to SQL*Plus and iSQL*Plus?The steps involved in logging into SQL*Plus and iSQL*Plus environments aredifferent.Logging in to SQL*Plus EnvironmentLogging in to SQL*Plus environment depends on the type of operating system youare working on.© SQL Star International Ltd. 52
  56. 56. Logging in through a Windows environment: 1.Click Start-> Programs-> Oracle – OraDb10g_home1 2. Select Application Development -> SQL Plus© SQL Star International Ltd. 53
  57. 57. 3. Enter username, password and the connect string.Logging in through a command-line environment:  Log on to the DOS promptEnter SQL*Plus command as follows: sqlplus [username[/password[@ ConnectString]]]Where,username is the database username assigned to each user.password is the password the user enters to gain access to the database. Thepassword is visible on entering it at the command line. Therefore, to ensure theintegrity of the password, do not enter it at the command line. Instead enter it at thepassword prompt.@ ConnectString is the alias through which the user has to access the database.Logging in to iSQL*Plus EnvironmentThe steps to log in to iSQL*Plus environment are as follows: 1. Initiate the browser and enter the URL address of the iSQL*Plus environment. iSQL*Plus browser window is displayed.© SQL Star International Ltd. 54
  58. 58. 2. Enter the username and password as shown in the following screen. Click the Login button.© SQL Star International Ltd. 55
  59. 59. After you log in to iSQL*Plus, you see the iSQL*Plus window as follows:Within the windows browser, the key areas of the iSQL*Plus window are the: Enter Statements field: The area to enter the SQL statements and iSQL*Plus commands. Execute button: Click to execute the statements entered in the Enter Statements field.  Load Script button: Click to access the area for entering the name and location of a file (containing the contents of the Enter Statements field, which has been saved) or the URL for the script you want to execute. Save Script button: Click to save the contents of the Enter Statements field to a file. It is suggested that you save these files with .sql extension. Cancel Button: Click to Cancel the query presently entered by the user. A confirmation is displayed at the end. Clear Screen button: Click to clear text from the Enter Statement field, output and stops any script running at that time. Help icon: Click to access iSQL*Plus help documentation.© SQL Star International Ltd. 56
  60. 60. iSQL*Plus CommandsiSQL*Plus has a set of commands, which are different from the SQL statements.These commands need to be entered one line at a time. In order to continue acommand on the next line, end the current line with a hyphen (-).iSQL*PLUS commands can be abbreviated. For instance, a command CLEAR BUFFERcould be written as CL BUFF. iSQL*Plus commands are not stored in the SQL buffer.The main categories into which iSQL*Plus commands have been divided are:  Environment – It affects the behavior of SQL statements for the session.  Formatting – It formats the query output.  File manipulation – It saves SQL statements into script files and, loads and runs them whenever needed.  Execution – It sends SQL statements from the browser to the Oracle server.  Editing – It modifies SQL statements in the Edit window.  Interaction – It allows you to pass values into the SQL statements and also print messages to the screen.SQL Vs iSQL*PlusSQL is the language used to communicate with the Oracle server from anytool or application. iSQL*Plus is the Oracle tool, which recognizes andsubmits the SQL statements to the Oracle server for execution, and basedon the query result, it produces formatted reports using its own commands.The following diagram depicts the SQL and iSQL*Plus interaction:© SQL Star International Ltd. 57

×