Basics of SQL: SQL, SQL Plus, PL/SQL: What's The Difference?
Basics of SQL: SQL, SQL Plus, PL/SQL: What's The Difference?
PL/SQL is a procedural language that Oracle developed as an extension to standard SQL to provide a
way to execute procedural logic on the database.
SQL
SQL stands for Structured Query Language. This has become the lingua franca of database access
languages. It has been adopted by the International Standards Organization (ISO) and has also been
adopted by the American National Standards Institute (ANSI). When you code statements such as
SELECT, INSERT, UPDATE, and DELETE, SQL is the language you are using. It is a declarative language
and is always executed on the database server. Often you will find yourself coding SQL statements in a
development tool, such as PowerBuilder or Visual Basic, but at runtime those statements are sent to
the server for execution.
PL/SQL
PL/SQL is Oracle's Procedural Language extension to SQL. It, too, usually runs on the database server,
but some Oracle products such as Developer/2000 also contain a PL/SQL engine that resides on the
client. Thus, you can run your PL/SQL code on either the client or the server depending on which is
more appropriate for the task at hand. Unlike SQL, PL/SQL is procedural, not declarative. This means
that your code specifies exactly how things get done. As in SQL, however, you need some way to send
your PL/SQL code up to the server for execution. PL/SQL also enables you to embed SQL statements
within its procedural code. This tight-knit relationship between PL/SQL, SQL, and SQL*Plus is the cause
for some of the confusion between the products.
SQL*Plus
SQL*Plus is an interactive program that allows you to type in and execute SQL statements. It also
enables you to type in PL/SQL code and send it to the server to be executed. SQL*Plus is one of the
most common front ends used to develop and create stored PL/SQL procedures and functions.
What happens when you run SQL*Plus and type in a SQL statement? Where does the processing take
place? What exactly does SQL*Plus do, and what does the database do? If you are in a Windows
environment and you have a database server somewhere on the network, the following things happen:
1. SQL*Plus transmits your SQL query over the network to the database server.
2. SQL*Plus waits for a reply from the database server.
3. The database server executes the query and transmits the results back to SQL*Plus.
4. SQL*Plus displays the query results on your computer screen.
Even if you're not running in a networked Windows environment, the same things happen. The only
difference might be that the database server and SQL*Plus are running on the same physical machine.
This would be true, for example, if you were running Personal Oracle on a single PC.
PL/SQL is executed in much the same manner. Type a PL/SQL block into SQL*Plus, and it is transmitted
to the database server for execution. If there are any SQL statements in the PL/SQL code, they are
sent to the server's SQL engine for execution, and the results are returned back to the PL/SQL
program.
SELECT Statement
Posted Tue, 03/03/2009 - 17:45 by Anonymous
The SELECT statement is used to query the database and retrieve selected data that match the criteria
that you specify.
The SELECT statement has five main clauses to choose from, although, FROM is the only required
clause. Each of the clauses have a vast selection of options, parameters, etc. The clauses will be listed
below, but each of them will be covered in more detail later in the tutorial.
SELECT column_name(s)
FROM table_name
and
DISTINCT Clause
The DISTINCT clause allows you to remove duplicates from the result set. The DISTINCT clause can
only be used with select statements.
The syntax for the DISTINCT clause is:
SELECT DISTINCT columns FROM tables WHERE predicates;
Example #1
Let's take a look at a very simple example.
SELECT DISTINCT city
FROM suppliers;
This SQL statement would return all unique cities from the suppliers table.
Example #2
The DISTINCT clause can be used with more than one field.
For example:
SELECT DISTINCT city, state
FROM suppliers;
This select statement would return each unique city and state combination. In this case, the distinct
applies to each field listed after the DISTINCT keyword.