What Is SQLplus
What Is SQLplus
While these operations may not seem significant, they are the building blocks
you can use to perform various useful functions.
Combine this capability with SQL*Plus’s formatting abilities and you can
turn these results into a credible-looking report, such as that shown
in Example 1-2, complete with page titles, page numbers, column titles, and
nicely formatted output.
Billing
Emp ID Name Rate
---------- ------------------- --------
101 Marusia Churai $169.00
102 Mykhailo Hrushevsky $135.00
104 Pavlo Virsky $99.00
105 Mykola Leontovych $121.00
107 Lesia Ukrainka $45.00
108 Pavlo Chubynsky $220.00
110 Ivan Mazepa $84.00
111 Taras Shevchenko $100.00
112 Igor Sikorsky $70.00
113 Mykhailo Verbytsky $300.00
Another twist on the same theme is to format the output as a list of comma-
separated values, such as that shown in Example 1-3.
101,"Marusia Churai",169
102,"Mykhailo Hrushevsky",135
104,"Pavlo Virsky",99
105,"Mykola Leontovych",121
107,"Lesia Ukrainka",45
108,"Pavlo Chubynsky",220
110,"Ivan Mazepa",84
111,"Taras Shevchenko",100
112,"Igor Sikorsky",70
113,"Mykhailo Verbytsky",300
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=US-ASCII">
<meta name="generator" content="SQL*Plus 10.1.0">
<style type='text/css'> body {font:10pt Arial,Helvetica,
sans-serif; color:black; background:White;}
...
<tr>
<td align="right">
101
</td>
<td>
Marusia Churai
</td>
<td align="right">
$169.00
</td>
</tr>
<tr>
<td align="right">
102
</td>
<td>
Mykhailo Hrushevsky
</td>
...
By writing such HTML output to a file, you can easily generate ad hoc
reports for users to view from a corporate intranet. One DBA whom I spoke
with regularly refreshes the phone list on his departmental intranet using this
mechanism. Figure 1-1 shows the output in Example 1-4 as you would see it
rendered in a browser.
Figure 1-1. A SQL*Plus-generated HTML report rendered in a browser
It’s a small leap from executing only queries to executing any other SQL
statement. In fact, SQL*Plus will let you execute any valid SQL statement
and is frequently used during database maintenance tasks. For example, you
can create a new user with the following statement:
Of course, it’s rare that you would issue such a simple statement, or just one
statement, when you add a new user. Usually, you also want to assign a
default tablespace and often a quota on that tablespace. You may also want to
grant the privilege needed to connect to the database. Whenever you have a
task that requires a sequence of statements to be executed, you can simplify
things by taking advantage of SQL*Plus’s scripting capabilities. The
statements in Example 1-5, when placed in a script file, allow you to add a
new user with just one command.
User created.
Grant succeeded.
The output you see is SQL*Plus showing you the before and after version of
each line containing a SQL*Plus user variable. You will read more about user
variables and the subject of scripting in Chapter 8.
You’ve just seen several examples of what can be done using SQL*Plus to
generate simple text reports, perform database administration tasks, extract
data, generate HTML reports, run automated scripts, and otherwise make
your life easier. Subsequent chapters delve deeply into each of these areas
and more.
Product Description
three products.
Because these three products all have “SQL” as part of their names, people
occasionally get confused about the relationships among them and about
which statements get executed where. SQL*Plus does have its own set of
commands that it recognizes and executes (for example, SET
SERVEROUTPUT ON from Example 1-7), but any SQL statements and
PL/SQL blocks are sent to the database server for execution. Figure 1-
2 illustrates this relationship.