31

Click here to load reader

Oracle fundamentals and sql

Embed Size (px)

Citation preview

Page 1: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Introduction Describing the Life Cycle Development Phases Defining a Database Discussing the Theoretical, Conceptual, and Physical Aspects of a Relational Database Describing How a Relational Database Management System (RDBMS) Is Used to Manage a Relational Database Describing the Oracle Implementation of Both the RDBMS and the Object Relational Database Management System (ORDBMS) Describing How SQL Is Used in the Oracle Product Set

Writing a Basic SQL Statement Describing the SQL Select Capabilities Executing a Basic Select Statement with the Mandatory Clauses Differentiating Between SQL and iSQL*Plus Commands

Restricting and Sorting Data Limiting the Rows Retrieved by a Query Sorting the Rows Retrieved by a Query

1Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 2: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Suggested Study Material :

Oracle Database 10g SQLBy: Jason Price

› Publisher: McGraw-Hill/Osborne› ISBN: 9780070587557› Edition: 1 - Pub Date: 13-APR-04› www.tatamcgrawhill.com/html/9780070587557.html

2Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 3: Oracle fundamentals and sql

Oracle Fundamentals and SQLDBMS is the collection of interrelated data and a set of program to access the data. DBMS allows only one person to access the data at a given point time.

While the DBMS fulfilled the basic requirements of storing data,they were not a practical solution to efficiently storing,manipulating,and retrieving data quickly and easily.

So based on the theory of relational data modeling by Dr. Edgar Codd publishes in the year 1970 , In 1977 Software Development Laboratories (SDL) formed by Larry Ellison, Bob Miner, Ed Oates and Bruce Scott with $2,000 of startup cash. Larry and Bob were working on a CIA project code-named "Oracle."

In 1978 SDL changes its name to Relational Software Inc. (RSI) with CIA as the first customer.

In 1982 RSI changes its name to Oracle Systems Corporation (OSC) and then simplifies the name to Oracle Corporation.

3Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 4: Oracle fundamentals and sql

Oracle Fundamentals and SQL

RDBMS manages large volumes of data while supporting a large number of users simultaneously.

In a relational database,files do exist,but only as a medium to store data on disk.While a file processing system will only access a particular file when necessary toretrieve data,a relational database system will access all files simultaneously asone seamless system. The data that is stored in the database is completely independent of the files. The entire system is managed by a central database enginethat processes queries and manipulates data on demand. A single query can retrieve the data regardless of where it is stored.

Instead of merely acting as a journal of transactions,a relational database preservesthe natural relationships that exist between real world entities and stores the data in this manner. 4

Database Basic & Advance Courses by Dip Mail me at [email protected]

Page 5: Oracle fundamentals and sql

Oracle Fundamentals and SQL

For example,data for a company’s employees is stored in a structure,with each employee stored only once. Data for the employees’ dependents may also need to be stored in another structure Each record for a dependent will contain a pointer which references its related employee.

Figure in the next slide shows how the relational database preserves the relationships that occur naturally between employees and their dependents.

5Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 6: Oracle fundamentals and sql

Oracle Fundamentals and SQL

EMPLOYEE 1

EMPLOYEE 2

EMPLOYEE 3

Dependent 1

Dependent 2

Dependent 1

Dependent 2

Dependent 3

6Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 7: Oracle fundamentals and sql

Oracle Fundamentals and SQL

As shown in the Figure, more dependents can be added to a single employeewithout storing the employee’s information over and over again. Data can also bestored for an employee that has no dependents whatsoever. If an employee leavesthe company,deleting the employee would also automatically delete all data forthe employee’s dependents. Since data is stored only once,if an employee movesto a new address,updating the data is only a matter of changing a single record.

This configuration reduces data redundancy,which saves critical storage space,and still provides simplicity and ease in data management.

An additional benefit of the RDBMS is that it is self-describing. The database contains not only users’ data,but also a description of its own structure, which is commonly referred as metadata.

7Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 8: Oracle fundamentals and sql

Oracle Fundamentals and SQLEntity-Relationship Model

Entities

An entity is the person,place,thing,or abstract concept that you want to track inthe database. When building the data model,the first thing to do is identify allthe required entities based on the initial system requirements that were determined during the analysis phase. Each entity must be clearly defined to avoid ambiguity and design flaws.

You should first build a simple list of the entities, and then add each one to the data model. In the James Martin data model,entities are represented by squares with rounded corners and are labeled with their names.

8Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 9: Oracle fundamentals and sql

Oracle Fundamentals and SQLBelow Figure shows a data model with a few example of entities for a

student registration system for a college.

INSTRUCTORSTUDENT CLASS SUBJECT

Since each entity in a data model should only represent a single instance of theentity,the name of each entity should be listed in its singular form. The designshould only show how one single entity relates to another single entity.

The entities can be placed anywhere in the data model and can be adjusted for clarity as more entities and relationships are added. Once the set of entities has been identified and added to the model,you should review the model to make sure that the model will conform to the system requirements. Later,once the data model is complete,these entities will become tables that you will create in the database.

9Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 10: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Attributes

Once the entities have been identified and added to the data model,you candecide on the exact details for each entity that should be stored. At a minimum,these details should fully support the initial system requirements,but you can alsoinclude any additional details that you feel would contribute to the overall qualityof the system. Perhaps you see the opportunity to provide additional functionalitythat might prove useful later on,such as a timestamp to store the most recenttime each customer signed onto the system.

First,you should build a list of attributes per entity using words that are simple,but fully explain the exact purpose of the attribute. The attributes you decide onwill become the columns of the tables. If the columns are named properly earlyin the design process,later users will not have to guess what a column is for.Once clear attribute names have been identified,some people choose to convertthese names into appropriate column names.

10Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 11: Oracle fundamentals and sql

Oracle Fundamentals and SQL

STUDENT

STUD_IDL_NAMEF_NAME

ADDR_LINECITYPIN

STATEPHONE_NO

CLASS

CLASS_IDSEMESTER

CLASS_NAMESUBJECTLOCATIONDURATION

GRADE_LEVEL

SUBJECT

SUBJECT_IDSUBJECT_NAMEDEGREE_PROG

INSTRUCTOR

INTRUC_IDL_NAMEFNAME

Following Figure shows the college student registration system with attributes.

11Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 12: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Entities and Their Relationships

The relationships between entities is the focal point for the relational databasemanagement system. Therefore,it is critical to understand how entity relationshipsare defined and how these relationships are treated to preserve data integrity.

In a data model,to represent a relationship,you would simply draw a line connecting two entities.

This indicates that in some way, shape or form, one or both entities influences the other. However,this notation is simply not enough to provide a clear picture of the implications of the relationship. You must also include the entities’ cardinality.

12Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 13: Oracle fundamentals and sql

Oracle Fundamentals and SQLCardinalityCardinality refers to the quantity of entity instances that are allowed on eitherside of the relationship and is represented by making certain notations directly onthe relationship lines between the entities.

Types of Relationships

There are three main types of relationships,depending on the cardinality of theentities involved. These are:• One-to-one (1:1)—Indicates that one instance of an entity must be associatedwith exactly one instance of another entity.• One-to-many (1:M)—Indicates that one instance of an entity may be associatedwith one or more instances of another entity.• Many-to-many (M:N)—Indicates that one or more instances of an entity maybe associated with one or more instances of another entity.

13Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 14: Oracle fundamentals and sql

Oracle Fundamentals and SQL

CUSTOMER ORDER ITEM

The relationship between CUSTOMER and ORDER in Figure is a one-to- manyrelationship; a single customer may have one or more orders. The relationship between ORDER and ITEM is a many-to-many relationship; a single order may contain multiple items,and a single item may be found on multiple orders. One-to-one relationships are very rare, because such a relationship is simple one. If a one-to-one relationship is found in a data model, the two entities can usually be combined into a single entity without losing the meaningful value of the data.

Cardinality Notations

14Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 15: Oracle fundamentals and sql

Oracle Fundamentals and SQLNormalization

The theoretical concepts of Mathematical Set Theory and Relational Algebra allowed a database designer to organize data in a systematic fashion by simply defining how each piece of data related to another through a process called data normalization.

The purpose of normalization is to build a data model according to system requirements and to make adjustments to the model to remove as many design flaws as possible. The ultimate data model would provide manageability so that a single piece of data can be updated in a single location,and it would clearly show the relationships without ambiguity. All design flaws and anomalies would be worked out of the design to allow the most flexible database system without a single incident of redundancy. As you can imagine, eliminating all anomalies is somewhat of a lofty goal and is not often reached. As your data model moves closer to this goal,many design anomalies and data management problems disappear.

15Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 16: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Strategy and

Analysis

Design

Build andDocument

Transition Production

Software development Life cycle

16Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 17: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Oracle10g offers a comprehensive high performance infrastructure needed to develop, deploy, and manage Internet applications or e-business solutions as follows

• GRID COMPUTING, AUTOMATION, SELF-MANAGEMENT• Scalability from departments to enterprise e-business sites Robust, reliable, available, secure architecture One development model, easy deployment options Leverage an organization’s current skill set throughout the Oracle platform (including SQL,PL/SQL, Java, and XML) One management interface for all applications Industry standard technologies, no proprietary lock-in

17Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 18: Oracle fundamentals and sql

Oracle Fundamentals and SQLStructured Query Language (SQL)

The SQL in PL/SQL stands for structured query language. We use SQL to SELECT,

INSERT, UPDATE, or DELETE data. We use it to create and maintain objects and

users, and to control access rights to our instances.

SQL (pronounced as sequel or by its letter abbreviation) is the entrance, or window, to the database. It is a fourth-generation language (4GL) that is

intendedto be easy to use and quick to learn. The basic SQL syntax is not the

creation ofOracle. It actually grew out of the work done by Dr. E.F. Codd and IBM in theearly 1970s. The American National Standards Institute (ANSI) recognizes

SQLand publishes standards for the language.

Oracle supports ANSI-standard SQL but also adds its own twist in its SQL*Plus

utility. Through SQL*Plus, Oracle supports additional commands and capabilities

that are not part of the standard. SQL*Plus is a utility available in multiple forms: 18

Database Basic & Advance Courses by Dip Mail me at [email protected]

Page 19: Oracle fundamentals and sql

Oracle Fundamentals and SQLSQL*Plus in Oracle accepts literally dozens of commands and has even more environmental settings. Many of the commands accept arguments that control the effects of the command. Some of the more commonly used commands are listed below.

CLEARCOLUMNCONNECT

DELDESCRIBE

DISCONNECTEDIT

EXECUTEEXITGET

HOSTLIST RUNSAVESET

SHOWSHUTDOWN

SPOOLSTART/STARTUP

SHOW ALL

19Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 20: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Data Types DescriptionVARCHAR2 (SIZE) Variable-length character dataCHAR (Size) Fixed-length character dataNUMBER (p,s) Variable-length numeric dataDATE Date and Time ValuesLONG Variable-length character data

Up to 2 gigabytesCLOB Character data up to 4 gigabytesRAW and LONG RAW Raw Binary DataBLOB Binary Data up to 4 gigabytesBFILE Binary Data stored in an external file

Up to 4 gigabytesROWID A 64 base number system representing

the unique address of a row in its table

20Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 21: Oracle fundamentals and sql

Oracle Fundamentals and SQLDatabase Objects Description

Table Basic Unit of Storage, Composed of Rows and Columns

View Logically represents subset of date from one or more tables

Sequence Numeric Value Generator

Index Improves the performance of some queries

Synonym Give alternative names of objects

21Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 22: Oracle fundamentals and sql

Oracle Fundamentals and SQLSelect Data RetrievalInsertUpdate Data Manipulation Language (DML)Delete Merge

CreateAlter Drop Data Definition Language (DDL)RenameTruncate

CommitRollback Transaction ControlSavepoint

Grant Revoke Data Control Language (DCL)

Types of SQL Statements and their Representations

22Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 23: Oracle fundamentals and sql

Oracle Fundamentals and SQL

The Basic CommandSELECT column_listFROM table_name;

Filtering the Result SetSELECT column_listFROM table_nameWHERE conditions;

23Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 24: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Operator Description+ Add- Subtract* Multiply/ Divide

Using Arithmetic Operators with SQL Statements

Example :

Select last_name, salary, salary + 300From employees;

24Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 25: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Oracle’s comparison operators are broken down into the following groups:

Simple comparison operatorsRange comparison operatorsExistence comparison operatorSimilarity comparison operatorNull comparison operator

Regardless of the type of comparison operator that is used, the values that arebeing compared must be of the same data type or an error will be returned. Forexample,you cannot directly compare a NUMBER datatype to a DATE datatype.

Simple comparison operators test the condition of one value compared to another. The Next Slide lists the comparison operators that are supported by Oracle.

25Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 26: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Simple Comparison OperatorsA = B

A != B, A <> B, A ^= B

A > B

A < B

A >= B

A <= B

26Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 27: Oracle fundamentals and sql

Oracle Fundamentals and SQL

Range Comparison OperatorsIN

ANY, SOME

ALL

BETWEEN a AND b

27Database Basic & Advance Courses by Dip Mail me at

[email protected]

Page 28: Oracle fundamentals and sql

Oracle Fundamentals and SQL

28Database Basic & Advance Courses by Dip Mail me at

[email protected]

Operator MeaningBETWEEN … AND …. Between Two Values

(Inclusive)IN (SET) Match any of a list of ValuesLIKE Match a Character PatternIS NULL Is a null Value

Existence Comparison Operators

Page 29: Oracle fundamentals and sql

Oracle Fundamentals and SQL

29Database Basic & Advance Courses by Dip Mail me at

[email protected]

Operator Meaning AND Return TRUE if both components

Conditions are trueOR Return TRUE if either components

Condition is trueNOT Return TRUE if the following

Condition is false

Similarity Comparison Operators

Page 30: Oracle fundamentals and sql

Oracle Fundamentals and SQL

30Database Basic & Advance Courses by Dip Mail me at

[email protected]

You can write the join condition in the where clause, by prefixing the column name with the table name when the same column name appears in more than one table

Syntax is :

SELECT table1.column, table2.column From table1, table2Where table1.column1 = table2.column2;

Obtaining Data from Multiple table using Join Conditions and the Filter Clause

Page 31: Oracle fundamentals and sql

Thank You

Database Basic & Advance Courses by Dip Mail me at [email protected] 31

We are into training business since 10+ years and have trained more than 1000+ candidates in the field of Database, Some of them have given their valued opinion which can be looked into http://www.plentynum.com/testimonials_academy.html

If you like us to contact you then fill up the form at http://plentynum.com/enquiry.html

In case of any clarification / requirements you can mail the undersigned or call us at +91.99713 65346 (Delhi) / +91.99032 69302 (Kolkata).

Disclaimer : Oracle and other product are registered trademark of their respective owners, this slide only is for help to an individual and we are nowhere responsible for any error/fault coming from the said materials/slides