My Cart (0)

Customer Service 1-800-221-5528

Murach’s Oracle SQL and PL/SQL for Developers (2nd Edition)

by Joel Murach
18 chapters, 648 pages, 272 illustrations
Published October 2014
ISBN 978-1-890774-80-6
Print: $54.50
eBook: $49.50
Print + eBook: $67.00

Over the years, Oracle Database has gained a reputation for being expensive and difficult to use. Today, however, you can download a free IDE called SQL Developer that makes it easy to enter, edit, and run SQL and PL/SQL statements. And this book makes it easier than ever to master the SQL and PL/SQL skills for working with an Oracle database.

College Instructors

Go to our instructor's site to learn more about this book and its instructor's materials.

 

This book is worth its cost just for its detailed and complete description of the SQL SELECT statement. The book takes 4 chapters (129 pages) to cover all aspects of it. I have not found any other book, including Oracle’s own documentation, which more completely describes how to use the SELECT statement."

Eric Mortensen, North East Ohio Oracle Users Group

  • About this Book
  • Table of Contents
  • FREE Downloads
  • Book FAQs
  • Corrections
  • Reviews

What you’ll learn in this book

Section 1: An introduction to SQL

In this section, you’ll learn the concepts and terms you need for working with any database. You’ll also learn how to use Oracle Database and Oracle SQL Developer to run SQL statements on your own computer.

Section 2: The essential SQL skills

In this section, you’ll learn all the SQL skills for retrieving data from a database and for adding, updating, and deleting that data. These skills move from the simple to the complex so you won’t have any trouble if you’re new to SQL. But these skills are also sure to raise your expertise even if you already have SQL experience.

Section 3: Database design and implementation

Here, you’ll learn how to design a database and how to implement that design by using the DDL (Data Definition Language) statements that are a part of SQL. When you’re done, you’ll be able to design and implement your own database. You’ll also gain valuable perspective that will make you a better SQL programmer, even if you never have to design a database.

Section 4: The essential PL/SQL skills

In this section, you’ll learn how to use Oracle’s procedure language, PL/SQL, to create stored procedures, functions, and triggers. You’ll also learn how to manage transactions and locking. That will give you a powerful set of PL/SQL skills.

Section 5: Advanced data types

Here, you’ll learn how to work with the timestamp, interval, and large object data types. These data types became available with releases 9i and 8, and they provide features that are critical for storing data in today’s global and digital world.

Why you’ll learn faster and better with this book

Like all of our books, you’ll find Murach features in this book that you won’t find in competing books. Here are just a few:

  • Unlike most Oracle books, this one starts by showing you how to query an existing database rather than how to create a new database. Why? Because that’s what you’re most likely to need to do first on the job. Once you master those skills, you can learn how to design and implement a database in section 3. Or, you can learn how to work with other database features like transactions or stored procedures in section 4 or advanced data types in section 5.
  • Unlike many Oracle books, this one shows how to use Oracle SQL Developer to enter and run your SQL statements. SQL Developer is a graphical tool that’s an intuitive and user-friendly replacement for SQL*Plus, an arcane command prompt tool that has been around since the early days of Oracle. As a result, using SQL Developer instead of SQL*Plus will help you learn more quickly.
  • Like all our books, this one includes hundreds of examples that range from the simple to the complex. That way, you can quickly get the idea of how a feature works from the simple examples, but you’ll also see how the feature is used in the real world from the complex examples.

Who this book is for

Application developers

I think it’s fair to say that most developers don’t know enough about SQL and the database management system they’re using. As one customer put it, "I know just enough about SQL to be a little bit dangerous!"

That’s why developers often code SQL statements that don’t perform as efficiently as they ought to. That’s why they aren’t able to code some of the queries that they need for their applications. And that’s why they don’t take advantage of all the power that Oracle Database has to offer.

That’s also why our Oracle SQL book should be required reading for every application programmer who uses Oracle Database. It shows you how to code the SQL and PL/SQL statements that you need for your applications. It shows you how to code these statements so they run efficiently. And it introduces you to many of the most useful advanced features that Oracle has to offer.

Anyone who wants to become a database administrator

This book is also the right first book for anyone who wants to become a database administrator. Although this book doesn’t present all of the advanced skills that are needed by a DBA, it will get you started. Once you’ve finished it, you’ll be prepared for more advanced books on the subject.

Anyone who wants to learn standard SQL

This book is also a good choice for anyone who wants to learn standard SQL. Since SQL is a standard language for accessing database data, most of the SQL code in this book will work with any database management system. As a result, once you use this book to learn how to use SQL to work with an Oracle database, you can transfer most of what you have learned to another DBMS such as MySQL, DB2, or Microsoft SQL Server.

What the prerequisites are

Although you will progress through this book more quickly if you have some development experience, everything you need to know about databases and SQL is presented in this book. As a result, you don’t need to have any programming background to use this book.

What's new for this edition

Since our customers loved the first edition of this book, we added just a few Oracle 12c features to the new edition:

  • Top-N queries and pagination, which let you use the FETCH and OFFSET clauses to limit the number of rows returned by a query and to return a specified range of rows
  • Automatic ID generation, which lets you define a primary key column so its ID is automatically generated instead of having to use triggers to do that

Maybe more important, though, we now include the solutions to the exercises as a download from our website. That’s because the only customer complaints we received for this book were that we didn’t provide the solutions to the exercises.

What software you need for this book

To run SQL statements with an Oracle database using the techniques in this book, we recommend that you use:

  • The Express Edition of Oracle Database 11g
  • Oracle SQL Developer

Both of these products can be downloaded for free from Oracle’s website. And appendix A of this book provides complete instructions for installing them.

If you want to use another edition of Oracle Database, like the Personal Edition of 12c, you can still use the techniques described in this book. However, you may need to install that edition, and you may need to use a different procedure to connect SQL Developer to it. That’s why appendix B shows you how to do both.

Unfortunately, you can’t use SQL Developer to connect to versions of Oracle Database that are prior to version 9.2.0.1. So if your company is using an earlier version, one alternative is to use SQL*Plus to work with it as described in chapter 2. A better training alternative, though, is to download and install the Express Edition of Oracle Database and SQL Developer as described in appendix A. Then, when you’re through training, you can use SQL*Plus or a commercial product like Toad to work with the version of Oracle Database that your company uses.

What people say about this book

"If you use Oracle as a backend database to your VB, C#, or ASP.NET database applications, then Murach’s Oracle SQL and PL/SQL should be the next addition to your developer library."
- Jeff Manley, a1vbcode.com

"This book is worth its cost just for its detailed and complete description of the SQL SELECT statement. The book takes 4 chapters (129 pages) to cover all aspects of it. I have not found any other book, including Oracle’s own documentation, which more completely describes how to use the SELECT statement."
- Eric Mortensen, North East Ohio Oracle Users Group

"A lifesaver! Got stuck on one of my Oracle 9i assignments and it took just one look in this book and I was all set and ready to take on other assignments. It is really a reliable reference book."
- Posted at an online bookseller

"Although I am primarily a SQL Server programmer, this book explained many of the ‘Oracle’ ways to do the stuff I already do with SQL Server in a manner that I could understand and relate to. I found lots of examples of stuff that I was struggling with in entering into my first large, full-scale Oracle programming projects. It is open daily when I work on Oracle code now."
- Posted at an online bookseller

"Murach books have a reputation for accessibility to the novice user. Murach’s Oracle SQL and PL/SQL is just as accessible to the novice, but also contains plenty to assist other Oracle users.... The result is a book that is great for Oracle novices, but also great for casual intermediate users like myself."
- David O’Meara, JavaRanch.com

"I bought this book to take my SQL skills up a notch or more. This book really does that. It moves from the basics to advanced queries. The advanced queries are very well explained and you get useful skills and understand how to extend this to other queries."
- Posted at an online bookseller

“This book is a must-have for programmers looking to get into data management. It is clear and simple and the examples are easy to understand. All programmers that deal with databases should have this book in their library.”
- Posted at an online bookseller

“Loved the layout. Not long winded; just the facts. The page on the left gives a more indepth explanation. The page on the right gives you the nitty-gritty of what you need to know. I highly recommend the book and will look for Murach's books in the future.”
- Posted at an online bookseller

View the table of contents for this book in a PDF: Table of Contents (PDF)

Click on any chapter title to display or hide its content.

Section 1 An introduction to SQL

Chapter 1 An introduction to relational databases and SQL

An introduction to client/server systems

The hardware components of a client/server system

The software components of a client/server system

Other client/server architectures

An introduction to the relational database model

How a table is organized

How tables are related

How columns in a table are defined

An introduction to SQL and SQL-based systems

A brief history of SQL

A comparison of Oracle, DB2, and Microsoft SQL Server

The SQL statements

An introduction to the SQL statements

How to work with database objects

How to query a single table

How to join data from two or more tables

How to add, update, and delete data in a table

How to work with views

SQL coding guidelines

An introduction to PL/SQL

How to work with stored procedures

How to work with user-defined functions

How to work with triggers

How to use SQL from an application program

Three data access models

Java code that retrieves data from an Oracle database

Chapter 2 How to use Oracle SQL Developer and other tools

How to work with an Oracle database

How to start and stop the database service

How to use the Database Home Page

How to use SQL*Plus

How to use SQL Developer to work with a database

How to create a database connection

How to export or import database connections

How to navigate through the database objects

How to view the column definitions for a table

How to view the data for a table

How to edit the column definitions

How to use SQL Developer to run SQL statements

How to enter and execute a SQL statement

How to work with the Snippets window

How to handle syntax errors

How to open and save SQL statements

How to enter and execute a SQL script

How to use the SQL Reference manual

How to view the manual

How to look up information

Section 2 The essential SQL skills

Chapter 3 How to retrieve data from a single table

An introduction to the SELECT statement

The basic syntax of the SELECT statement

SELECT statement examples

How to code the SELECT clause

How to code column specifications

How to name the columns in a result set

How to code string expressions

How to code arithmetic expressions

How to use scalar functions

How to use the Dual table

How to use the DISTINCT keyword to eliminate duplicate rows

How to use the ROWNUM pseudo column to limit the number of rows

How to code the WHERE clause

How to use the comparison operators

How to use the AND, OR, and NOT logical operators

How to use the IN operator

How to use the BETWEEN operator

How to use the LIKE operator

How to use the IS NULL condition

How to code the ORDER BY clause

How to sort a result set by a column name

How to sort a result set by an alias, an expression, or a column number

How to code the row limiting clause

How to limit the number of rows

How to return a range of rows

Chapter 4 How to retrieve data from two or more tables

How to work with inner joins

How to code an inner join

When and how to use table aliases

How to work with tables from different schemas

How to use compound join conditions

How to use a self-join

Inner joins that join more than two tables

How to use the implicit inner join syntax

How to work with outer joins

How to code an outer join

Outer join examples

Outer joins that join more than two tables

How to use the implicit outer join syntax

Other skills for working with joins

How to combine inner and outer joins

How to join tables with the USING keyword

How to join tables with the NATURAL keyword

How to use cross joins

How to work with unions

The syntax of a union

Unions that combine data from different tables

Unions that combine data from the same table

How to use the MINUS and INTERSECT operators

Chapter 5 How to code summary queries

How to work with aggregate functions

How to code aggregate functions

Queries that use aggregate functions

How to group and summarize data

How to code the GROUP BY and HAVING clauses

Queries that use the GROUP BY and HAVING clauses

How the HAVING clause compares to the WHERE clause

How to code complex search conditions

How to summarize data using Oracle extensions

How to use the ROLLUP operator

How to use the CUBE operator

Chapter 6 How to code subqueries

An introduction to subqueries

How to use subqueries

How subqueries compare to joins

How to code subqueries in search conditions

How to use subqueries with the IN operator

How to compare the result of a subquery with an expression

How to use the ALL keyword

How to use the ANY and SOME keywords

How to code correlated subqueries

How to use the EXISTS operator

Other ways to use subqueries

How to code subqueries in the FROM clause

How to code subqueries in the SELECT clause

Guidelines for working with complex queries

A complex query that uses subqueries

A procedure for building complex queries

Two more skills for working with subqueries

How to code a subquery factoring clause

How to code a hierarchical query

Chapter 7 How to insert, update, and delete data

How to create test tables

How to create the tables for this book

How to create a copy of a table

How to commit and rollback changes

How to commit changes

How to rollback changes

How to insert new rows

How to insert a single row

How to insert default values and null values

How to use a subquery to insert multiple rows

How to update existing rows

How to update rows

How to use a subquery in an UPDATE statement

How to delete existing rows

How to delete rows

How to use a subquery in a DELETE statement

Chapter 8 How to work with data types and functions

The built-in data types

Data type overview

The character data types

The numeric data types

The temporal data types

The large object data types

How to convert data from one type to another

How to convert characters, numbers, and dates

Common number format elements

Common date/time format elements

How to convert characters to and from their numeric codes

How to work with character data

How to use the common character functions

How to parse a string

How to sort a string in numerical sequence

How to sort mixed-case columns in alphabetical sequence

How to work with numeric data

How to use the common numeric functions

How to search for floating-point numbers

How to work with date/time data

How to use the common date/time functions

How to parse dates and times

How to perform a date search

How to perform a time search

Other functions you should know about

How to use the CASE function

How to use the COALESCE, NVL, and NVL2 functions

How to use the GROUPING function

How to use the ranking functions

Section 3 Database design and implementation

Chapter 9 How to design a database

How to design a data structure

The basic steps for designing a data structure

How to identify the data elements

How to subdivide the data elements

How to identify the tables and assign columns

How to identify the primary and foreign keys

How to enforce the relationships between tables

How normalization works

How to identify the columns to be indexed

How to normalize a data structure

The seven normal forms

How to apply the first normal form

How to apply the second normal form

How to apply the third normal form

When and how to denormalize a data structure

Chapter 10 How to create tables, indexes, and sequences

How to work with tables

How to create a table

How to code a primary key constraint

How to code a foreign key constraint

How to code a check constraint

How to alter the columns of a table

How to alter the constraints of a table

How to rename, truncate, and drop a table

How to work with indexes

How to create an index

How to drop an index

How to work with sequences

How to create a sequence

How to use a sequence

How to alter a sequence

How to drop a sequence

The script used to create the AP tables

An introduction to scripts

How the DDL statements work

How to automatically generate ID values

How to use a sequence as a default

How to use the GENERATED clause

How to use SQL Developer

How to work with the columns of a table

How to work with the data of a table

How to work with the constraints of a table

How to work with indexes

How to work with sequences

Chapter 11 How to create views

An introduction to views

How views work

Benefits of using views

How to work with views

How to create a view

How to create an updatable view

How to create a read-only view

How to use the WITH CHECK OPTION clause

How to insert or delete rows through a view

How to alter or drop a view

How to use SQL Developer

How to get information about a view

How to drop a view

How to alter or create a view

Chapter 12 How to manage database security

An introduction to database security

How to create an admin user

How to use SQL Developer to view database objects for a schema

How to create end users

How to use SQL*Plus to test end users

System privileges and object privileges

How to manage database security

How to create, alter, and drop users

How to create and drop roles

How to grant privileges

How to revoke privileges

How to work with private synonyms

How to work with public synonyms

A script that creates roles and users

How to view the privileges for users and roles

How to use SQL Developer

How to work with users

How to grant and revoke roles

How to grant and revoke system privileges

Section 4 The essential PL/SQL skills

Chapter 13 How to write PL/SQL code

An introduction to PL/SQL

An anonymous PL/SQL block in a script

A summary of statements for working with PL/SQL and scripts

How to code the basic PL/SQL statements

How to print data to an output window

How to declare and use variables

How to code IF statements

How to code CASE statements

How to code loops

How to use a cursor

How to use collections

How to handle exceptions

A list of predefined exceptions

Other scripting and PL/SQL skills

How to drop database objects without displaying errors

How to use bind variables

How to use substitution variables

How to use dynamic SQL

How to run a script from a command line

Chapter 14 How to manage transactions and locking

How to work with transactions

How to commit and rollback transactions

How to work with save points

How to work with concurrency and locking

How concurrency and locking are related

The four concurrency problems that locks can prevent

How to set the transaction isolation level

How to prevent deadlocks

Chapter 15 How to create stored procedures

How to code stored procedures

How to create and call a stored procedure

How to code input and output parameters

How to code optional parameters

How to raise errors

A stored procedure that inserts a row

A stored procedure that drops a table

How to drop a stored procedure

How to code user-defined functions

How to create and call a function

A function that calculates balance due

How to drop a function

How to work with packages

How to create a package

How to drop a package

Advantages of packages

How to use SQL Developer

How to view and drop procedures, functions, and packages

How to edit and compile procedures and functions

How to grant and revoke privileges

How to debug procedures and functions

Chapter 16 How to create triggers

How to work with triggers

How to create a BEFORE trigger for a table

How to use a trigger to enforce data consistency

How to use a trigger to work with a sequence

How to create an AFTER trigger for a table

How to use an INSTEAD OF trigger for a view

How to use a trigger to work with DDL statements

How to use a trigger to work with database events

How to enable, disable, rename, or drop a trigger

Other skills for working with triggers

How to code a compound trigger

A trigger that causes the mutating-table error

How to solve the mutating-table problem

How to use SQL Developer

How to view, rename, or drop a trigger

How to enable or disable a trigger

How to edit a trigger

How to debug a trigger

Section 5 Advanced data types

Chapter 17 How to work with timestamps and intervals

An introduction to time zones

Database time zone vs. session time zone

How to change the default date format

How to change the default time zone

Session settings vs. database settings

How to use functions to work with time zones

How to work with timestamps

An introduction to the TIMESTAMP types

How to work with the TIMESTAMP type

How to work with the TIMESTAMP WITH LOCAL TIME ZONE type

How to work with the TIMESTAMP WITH TIME ZONE type

Common format elements for timestamps

How to use functions to work with timestamps

How to work with intervals

An introduction to the INTERVAL types

How to work with the INTERVAL YEAR TO MONTH type

How to work with the INTERVAL DAY TO SECOND type

How to use functions to work with intervals

Chapter 18 How to work with large objects

An introduction to large objects

The LOB types

APIs for working with LOBs

How to use SQL to work with large objects

How to work with CLOBs

How to work with NCLOBs

How to work with BLOBs

How to work with BFILEs

How to specify LOB storage options

How to migrate to the new LOB types

How to use Java to work with large objects

The main method for the sample application

How to write an image to a table

How to read an image from a table

A utility class for working with databases

How to use PL/SQL to work with large objects

The methods of the DBMS_LOB package

An example that uses the DBMS_LOB package

Appendixes

Appendix A How to install the software and source code for this book

How to install the software from oracle.com

How to install the Oracle Database Express Edition

How to install Oracle SQL Developer

How to install the SQL documentation

How to install the PL/SQL documentation

How to install the software from murach.com

How to install the source files for this book

How to create the tables and users for this book

How to restore the tables and users

Appendix B How to install the Standard or Enterprise Edition of Oracle Database

How to install the Personal Edition of Oracle Database

How to create the tables and users for this book for Oracle 12c and later

How to restore the tables and users

How to connect to Oracle 12c and later

How to start and stop database services

Sample chapters

Chapter 2: How to use Oracle SQL Developer and other tools

Oracle SQL Developer is a free, graphical tool that makes it so much easier to work with Oracle databases that we think you should use it right from the start. So this chapter shows you how to use SQL Developer to work with database objects and to build and run SQL statements.

Chapter 3: How to retrieve data from a single table

Once you have SQL Developer installed on your system, chapter 3 shows how to use SQL SELECT statements to retrieve data from a single table. Our hope is that this will give you a better idea of how well our book works and how much there is to learn about SQL.

Chapter 2 PDF (572Kb) Download Now

Chapter 3 PDF (271Kb) Download Now

Book examples and exercise solutions

This download includes:

  • The scripts for all the SQL statements presented in the book examples
  • The scripts for creating the users, schemas, and tables that are used in the database for the book examples and exercises
  • The scripts for the solutions to the exercises in the book

Appendix A in the book describes how to install and use these files.

Exe file for Windows (4.9 Mb) Download Now

Zip file for any system (4.8 Mb) Download Now

To view the "Frequently Asked Questions" for this book in a PDF, just click on this link: View the questions

Then, if you have any questions that aren't answered here, please email us. Thanks!

There are no book corrections that we know of at this time. But if you find any, please email us so we can post any corrections that affect the technical accuracy of the book right here. Thank you!

There are no reviews for this product yet.

To leave a review, please log in to your account.     Log In Here

Our Ironclad Guarantee

You must be satisfied. Try our print books for 30 days or our eBooks for 14 days. If they aren't the best you've ever used, you can return the books or cancel the eBooks for a prompt refund. No questions asked!

Contact Murach Books

For orders and customer service:

1-800-221-5528

Weekdays, 8 to 4 Pacific Time

College Instructors

If you're a college instructor who would like to consider a book for a course, please visit our website for instructors to learn how to get a complimentary review copy and the full set of instructional materials.