Oracle Tutorials For Beginners

This series of Oracle tutorials provides an introduction to Oracle for beginners. This first tutorial explains relational theory, on which all relational databases are built, and provides some examples so you can see how it works in practice. Object-oriented design as it applies to databases is also discussed briefly.

Other articles in this series of Oracle tutorials expand on these concepts, discuss the factors that affect SQL (and therefore database) performance and examine the Oracle database from the point of view of the dba.

What is an Oracle database?

Oracle is an object-relational hybrid database - a relational database with added object-oriented features - and, since Oracle 10g, a grid-enabled database - the ability to scale across multiple inexpensive servers to provide more processing resources.

Each release of the Oracle database brings new features to improve scalability, reliability, performance and availability. We'll be examining some of these new features in later Oracle tutorials.

Oracle Tips & Tricks to SKYROCKET Your Career!

If you're not already a subscriber to Oracle Tips and Tricks, you're  missing out on a myriad of tips and techniques to help you become a better, faster, smarter developer. Subscribe now and ignite your career.

What is a relational database?

Lets' start by defining a relational database.

A British engineer working for IBM named Ted Codd elucidated the theory of relational databases in his paper "A Relational Model of Data for Large Shared Data Banks" in the 1970s. At the core of this relational model is the concept of the separation of the logical and physical data models which enables you to "see" the database in a completely different way to its underlying structure.

The importance of this separation is that it makes relational databases extremely flexible by enabling each model to be changed without affecting the other. With  earlier database technologies, such as hierarchical databases, changes in business requirements requiring new data structures necessitated the complete re-design of the database. With relational databases, new data structures can be added without having to perform a complete re-design.

A relational database can be regarded as containing a set of 2-dimensional tables ("relations") with each table comprising rows ("tuples") and columns ("domains"). Relationships between database tables are created when one table has a column with the same meaning as a column in another table. The names and values of the two columns are irrelevant but they must refer to/mean the same thing.

Let's take the example of a very simple database with just 2 tables (relations):

  • employees
  • departments

the employees table has just three columns  :

  • employee_id
  • employee_ name
  • department_id

the department table has just two columns :

  • department_id
  • department_name

There is a relationship between these two tables via the department_id column in each table. The department_id column in the employees table  relates to the department_id column in the departments table. This enables you to assign employees to a department and determine which employees work for which department.

Now that we can say that these two tables are related, the other part of relational database model - relational calculus (which is essentially set theory) enables relations (i.e. database tables) to be combined in various ways:

  • the union of 2 relations results in a set of data containing those elements that exist in one or other relation (or both relations);
  • the result of the join (i.e. the intersection) of 2 relations is the set of  elements that exist in both relations;
  • the exclusive "OR" of 2 relations produces the set of items that are in either of the relations but not both
  • an outer-join is the same as the join but also includes elements from one or both relations that are not in the other (depending on whether a full outer-join or a left or right outer join is performed)
  • relations can also be subtracted from each other leaving the set of   elements that were in the first relation but not the 2nd

Let's move on from definitions to look at a few examples in the rest of this Oracle tutorial.

The use of the following data will help to make the examples more concrete:


Id Name Price
1 Oracle tutorials 3
2 SQL tutorial 22
3 PL/SQL tutorial 43
4 UNIX tutorial 24
5 Oracle fundamentals 160
6 Advanced Oracle SQL tutorial 43


Id Prod_id
1 1
2 4
3 6

The join of Product and Order on the product id would produce the following result:

Prod_Id Name Price Ord_Id
1 Oracle tutorials 3 1
4 UNIX tutorial 24 2
6 Advanced Oracle SQL tutorial 43 3

To achieve the union of Ord and Prod we have to cheat a little because the number and data types of the columns must be  the same.

For this reason, "union" is not normally used to combine different tables in their entirety but instead to combine sub selections from one or more tables.

The following query:

SELECT prod_id,'dummy',ord_id FROM ord
SELECT prod_id,name,price FROM prod

would produce the following results:

1 dummy 1
2 dummy 4
3 dummy 6
1 Oracle tutorial 3
2 SQL tutorial 22
3 PL/SQL tutorial 43
4 UNIX tutorial 24
5 Oracle fundamentals 160
6 Advanced Oracle SQL tutorial 43

The result of that query may not be particularly useful but it does show how the UNION command works. There are of course other operators and variations which we will be looking at in later Oracle tutorials.

Continue this tutorial with a look at basic sql commands, built-in Oracle data typesuser-defined types and sql aggregate functions.

Return from Oracle Tutorials to home page