Escolar Documentos
Profissional Documentos
Cultura Documentos
Online Help
Release 1.0 Early Adopter
December 2005
This is a single PDF document containing the online help
topics for Oracle Raptor. It is provided merely as a
convenience; you are still encouraged to use the help within
the Raptor user interface to obtain immediate and
context-relevant information.
Chuck Murray
The Programs (which include both the software and documentation) contain proprietary information; they
are provided under a license agreement containing restrictions on use and disclosure and are also protected
by copyright, patent, and other intellectual and industrial property laws. Reverse engineering, disassembly,
or decompilation of the Programs, except to the extent required to obtain interoperability with other
independently created software or as specified by law, is prohibited.
The information contained in this document is subject to change without notice. If you find any problems in
the documentation, please report them to us in writing. This document is not warranted to be error-free.
Except as may be expressly permitted in your license agreement for these Programs, no part of these
Programs may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose.
If the Programs are delivered to the United States Government or anyone licensing or using the Programs on
behalf of the United States Government, the following notice is applicable:
U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data
delivered to U.S. Government customers are "commercial computer software" or "commercial technical data"
pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As
such, use, duplication, disclosure, modification, and adaptation of the Programs, including documentation
and technical data, shall be subject to the licensing restrictions set forth in the applicable Oracle license
agreement, and, to the extent applicable, the additional rights set forth in FAR 52.227-19, Commercial
Computer SoftwareRestricted Rights (June 1987). Oracle Corporation, 500 Oracle Parkway, Redwood City,
CA 94065
The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently
dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup,
redundancy and other measures to ensure the safe use of such applications if the Programs are used for such
purposes, and we disclaim liability for any damages caused by such use of the Programs.
Oracle, JD Edwards, PeopleSoft, and Retek are registered trademarks of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective owners.
The Programs may provide links to Web sites and access to content, products, and services from third
parties. Oracle is not responsible for the availability of, or any content provided on, third-party Web sites.
You bear all risks associated with the use of such content. If you choose to purchase any products or services
from a third party, the relationship is directly between you and the third party. Oracle is not responsible for:
(a) the quality of third-party products or services; or (b) fulfilling any of the terms of the agreement with the
third party, including delivery of products or services and warranty obligations related to purchased
products or services. Oracle is not responsible for any loss or damage of any sort that you may incur from
dealing with any third party.
Contents
1
1.9.8
Streams reports .................................................................................................................
1.9.9
All Objects reports ............................................................................................................
1.9.10
Data Dictionary reports ...................................................................................................
1.9.11
User Defined reports ........................................................................................................
1.10
Raptor Preferences ...................................................................................................................
1.10.1
Environment ......................................................................................................................
1.10.2
Accelerators .......................................................................................................................
1.10.3
Code Editor........................................................................................................................
1.10.4
Database Connections ......................................................................................................
1.10.5
Debugger............................................................................................................................
1.10.6
Documentation..................................................................................................................
1.10.7
Extensions ..........................................................................................................................
1.10.8
File Types ...........................................................................................................................
1.10.9
Global Ignore List .............................................................................................................
1.10.10
SQL Formatter ...................................................................................................................
1.11
Using the Help..........................................................................................................................
1.12
Supplementary Oracle Database Information .....................................................................
iv
1-24
1-24
1-25
1-25
1-26
1-26
1-27
1-27
1-29
1-29
1-30
1-30
1-30
1-31
1-31
1-31
1-32
3-1
3-1
3-2
3-2
3-2
3-2
3-3
3-4
3-4
3-4
3-4
3-5
3-6
3-6
3-7
3-7
3-9
3.18
3.19
3.20
3.21
3.22
3.23
3.24
3.25
3.26
3.27
3.28
3.29
3.30
3.31
3.32
3.33
3.34
3.35
3.36
3.37
3.38
3.39
3-14
3-15
3-15
3-16
3-16
3-20
3-20
3-20
3-21
3-21
3-21
3-22
3-22
3-22
3-22
3-22
3-22
3-23
3-24
3-24
3-24
3-24
4.4
4.5
4.6
5-1
5-1
5-1
5-2
5-2
5-2
5-3
5-4
5-5
5-5
5-5
5-5
5-5
5-6
5-6
5-6
5-6
5-6
vi
6.5.4
6.5.5
6.5.6
6.5.7
6.6
6.6.1
6.6.2
6.6.3
6.6.4
6.6.5
6.6.6
6.6.7
6-12
6-12
6-13
6-14
6-15
6-15
6-16
6-16
6-17
6-17
6-17
6-18
vii
7.4.5
8-1
8-2
8-2
8-3
8-3
8-4
8-4
8-5
10
11
viii
10-1
10-1
10-2
10-2
10-2
10-3
10-3
10-3
10-4
10-4
10-4
10-5
11.2
Setting up the Globalization Support Environment ...........................................................
11.2.1
Setting NLS Parameters ...................................................................................................
11.2.2
Choosing a Locale with the NLS_LANG Environment Variable ..............................
11.2.3
Language and Territory Parameters ..............................................................................
11.2.3.1
NLS_LANGUAGE.....................................................................................................
11.2.3.2
NLS_TERRITORY......................................................................................................
11.2.4
Date and Time Parameters ..............................................................................................
11.2.4.1
Date Formats ..............................................................................................................
11.2.4.2
Time Formats .............................................................................................................
11.2.5
Calendar Definitions ......................................................................................................
11.2.5.1
Calendar Formats ....................................................................................................
11.2.5.2
NLS_CALENDAR ...................................................................................................
11.2.6
Numeric and List Parameters .......................................................................................
11.2.6.1
Numeric Formats.....................................................................................................
11.2.6.2
NLS_NUMERIC_CHARACTERS .........................................................................
11.2.7
Monetary Parameters .....................................................................................................
11.2.7.1
Currency Formats ....................................................................................................
11.2.7.2
NLS_CURRENCY....................................................................................................
11.2.7.3
NLS_ISO_CURRENCY ...........................................................................................
11.2.7.4
NLS_DUAL_CURRENCY......................................................................................
11.2.8
Linguistic Sorting and Searching..................................................................................
11.2.8.1
NLS_SORT................................................................................................................
11.2.8.2
NLS_COMP ..............................................................................................................
11.2.8.3
Case and Accent Insensitive Searching ................................................................
11.2.9
Length Semantics ............................................................................................................
11.2.9.1
NLS_LENGTH_SEMANTICS................................................................................
11.3
SQL and PL/SQL Programming with Unicode ................................................................
11.3.1
Overview of Unicode .....................................................................................................
11.3.2
SQL NCHAR Data Types ..............................................................................................
11.3.2.1
The NCHAR Data Type..........................................................................................
11.3.2.2
The NVARCHAR2 Data Type ...............................................................................
11.3.3
Unicode String Literals ..................................................................................................
11.4
Locale-Dependent SQL Functions with Optional NLS Parameters ...............................
11.4.1
Default Values for NLS Parameters in SQL Functions .............................................
11.4.2
Specifying NLS Parameters in SQL Functions ...........................................................
11.4.3
Unacceptable NLS Parameters in SQL Functions ......................................................
11-3
11-3
11-4
11-5
11-5
11-6
11-7
11-7
11-9
11-10
11-10
11-11
11-11
11-12
11-12
11-13
11-13
11-13
11-14
11-14
11-14
11-15
11-16
11-17
11-17
11-18
11-18
11-19
11-19
11-20
11-20
11-21
11-21
11-22
11-22
11-24
ix
1
Raptor Concepts and Usage
Oracle Raptor is a graphical version of SQL*Plus that gives database developers a
convenient way to perform basic tasks. You can browse, create, edit, and delete (drop)
database objects; run SQL statements and scripts; edit and debug PL/SQL code;
manipulate and export data; and view and create reports.
You can connect to any target Oracle database schema using standard Oracle database
authentication. Once connected, you can perform operations on objects in the
database.
See the Related Topics to learn about key features of Raptor.
Related Topics
Raptor User Interface
Database Objects
Database Connections
Entering and Modifying Data
Running and Debugging Functions and Procedures
Using the SQL Worksheet
Using SQL*Plus
Using Snippets to Insert Code Fragments
Reports
Raptor Preferences
Using the Help
Tutorial: Creating Objects for a Small Database
Supplementary Oracle Database Information
Note:
The menus at the top contain standard entries, plus entries for features specific to
Raptor (see Menus for Raptor), as shown in the following figure.
New creates a new a new database object (see Create/Edit New Object).
Open SQL Worksheet opens the SQL Worksheet (see Using the SQL Worksheet).
If you do not use the drop-down arrow to specify the database connection to use,
you are asked to select a connection.
Back moves to the pane that you most recently visited. (Or use the drop-down
arrow to specify a tab view.)
Forward moves to the pane after the current one in the list of visited panes. (Or
use the drop-down arrow to specify a tab view.)
The left side of the Raptor window has tabs and panes for the Connections and
Reports navigators, icons for performing actions, and a hierarchical tree display for the
currently selected navigator, as shown in the following figure.
The Connections navigator lists database connections that have been created. To
create a new database connection, import an XML file with connection definitions, or
export or edit current connections, right-click the Connections node and select the
appropriate menu item. (For more information, see Database Connections.)
The Reports navigator lists informative reports provided by Raptor, such as a list of
tables without primary keys for each database connection, as well as any user-defined
reports. (For more information, see Reports.)
Icons under the Connections tab (above the metadata tree) perform the following
actions on the currently selected object:
Refresh queries the database for the current details about the selected object (for
example, a connection or just a table).
Apply Filter restricts the display of objects using a filter that you specify. For
example, you can right-click the Tables node and specify a filter of EM% to see
only tables that start with EM.
The metadata tree in the Connections pane displays all the objects (categorized by
object type) accessible to the defined connections. To select an object, expand the
appropriate tree node or nodes, then click the object.
The right side of the Raptor window has tabs and panes for objects that you select or
open, as shown in the following figure, which displays information about a table
named BOOKS.
For objects other than subprograms, icons provide the following options:
Freeze View (the pin) keeps that objects tab and information in the window when
you click another object in the Connections navigator; a separate tab and display
are created for that other object. If you click the pin again, the objects display is
available for reuse.
Refresh updates the display by querying the database for the latest information.
Actions displays a a menu with actions appropriate for the object. The actions are
the same as when you right-click an object of that type in the Connections
navigator.
To switch among objects, click the desired tabs; to close a tab, click the X in the tab. If
you make changes to an object and click the X, you are asked if you want to save the
changes.
For tables and views, this information is grouped under tabs, which are labeled near
the top. For example, for tables the tabs are Columns, Data (for seeing and modifying
the data itself), Indexes, Constraints, and so on. For most objects, the tabs include SQL,
which displays the SQL statement for creating the object.
The Messages - Log area is used for feedback information as appropriate (for example,
results of an action, or error or warning messages). If this area is not already visible,
you can display is by clicking View and then Log.
Related Topics
Using the Help
Database Objects
Using the SQL Worksheet
Running and Debugging Functions and Procedures
Raptor Preferences
Raptor Concepts and Usage
Tutorial: Creating Objects for a Small Database
Database Objects
Debug menu
Contains options relevant when a function or procedure is selected.
Debug [name]: Starts execution of the specified function or procedure in debug mode.
The remaining items on the Debug menu match commands on the debugging toolbar,
which is described in Running and Debugging Functions and Procedures.
Source menu
Contains options for use when editing functions and procedures.
Completion Insight, Smart Completion Insight, and Parameter Insight: Display
pop-up windows that list item as you type and from which you can select an item for
auto-completion. (See also the code insight and completion options for Code Editor
under Raptor Preferences.)
Toggle Line Comments: Inserts and removes comment indicators at the start of
selected code lines.
Indent Block: Moves the selected statements to the right.
Unindent Block: Moves the selected statements to the left.
Tools menu
Invokes Raptor tools.
SQL*Plus: Displays a command-line window for entering SQL and SQL*Plus
statements (see Using SQL*Plus). If the location of the SQL*Plus executable is not
stored in your Raptor preferences, you are asked to specify its location.
Preferences: Enables you to customize the behavior of Raptor (see Raptor Preferences).
SQL Worksheet: Displays a worksheet in which you can create, execute, and debug
SQL and PL/SQL statements using a specified connection (see Using the SQL
Worksheet).
Note:
Related Topics
Raptor Concepts and Usage
Tutorial: Creating Objects for a Small Database
Supplementary Oracle Database Information
Database Objects
1.2.2 Functions
A function is a type of PL/SQL subprogram, which is a programming object that can
be stored and executed in the database server, and called from other programming
objects or applications. (Functions return a value; procedures do not return a value.)
For help with specific options in creating a PL/SQL subprogram, see Create PL/SQL
Function, Procedure, or Package.
You can perform the following operations on a function by right-clicking the function
name in the Connections navigator and selecting an item from the menu:
Open: Displays the function text so that you can view and edit it.
Run: Displays the Run/Debug PL/SQL dialog box, and then executes the function
in normal (not debug) mode.
Debug: Displays the Run/Debug PL/SQL dialog box, and then executes the
function in debug mode.
1.2.3 Indexes
An index is a database object that contains an entry for each value that appears in the
indexed column(s) of the table or cluster and provides direct, fast access to rows.
Indexes are automatically created on primary key columns; however, you must create
indexes on other columns to gain the benefits of indexing. For help with specific
options in creating an index, see Create/Edit Index.
You can perform the following operations on an index by right-clicking the index
name in the Connections navigator and selecting an item from the menu:
Database Objects
Unusable Index: Prevents the index from being used by Oracle in executing
queries. An unusable index must be rebuilt, or dropped and re-created, before it
can be used again.
Coalesce Index: Merges the contents of index blocks, where possible, to free blocks
for reuse.
1.2.6 Packages
A package is an object that contains subprograms, which are programming objects that
can be stored and executed in the database server, and called from other programming
objects or applications. A package can contain functions or procedures, or both. For
help with specific options in creating a package, see Create PL/SQL Function,
Procedure, or Package.
You can perform the following operations on a package by right-clicking the package
name in the Connections navigator and selecting an item from the menu:
New Package Body: Displays a pane in which you can enter text for the package
body.
Drop: Deletes the package.
1.2.7 Procedures
A procedure is a type of PL/SQL subprogram, which is a programming object that can
be stored and executed in the database server, and called from other programming
objects or applications. (Procedures do not return a value; functions return a value.)
For help with specific options in creating a PL/SQL subprogram, see Create PL/SQL
Function, Procedure, or Package.
You can perform the following operations on a procedure by right-clicking the
procedure name in the Connections navigator and selecting an item from the menu:
Open: Displays the procedure text so that you can view and edit it.
Run: Displays the Run/Debug PL/SQL dialog box, and then executes the
procedure in normal (not debug) mode.
Database Objects
Debug: Displays the Run/Debug PL/SQL dialog box, and then executes the
procedure in debug mode.
Purge: Removes the object from the Recycle bin and deletes it.
Undrop: Moves the object from the Recycle bin back to its appropriate place in the
Connections navigator display.
1.2.9 Sequences
Sequences are used to generate unique integers. You can use sequences to
automatically generate primary key values. For conceptual and usage information
about sequences, see Managing Sequences. For help with specific options in creating
and editing a sequence, see Create/Edit Sequence.
1.2.11 Tables
Tables are used to hold data. Each table typically has multiple columns that describe
attributes of the database entity associated with the table, and each column has an
associated data type. You have many table creation options and table organizations
(such as partitioned tables and index organized tables), to meet a variety of enterprise
needs. To create a table, you can do either of the following:
Create the table quickly by adding columns and specifying frequently used
features. To do this, do not check Show Advanced Options in the Create Table
dialog box. For help with options for creating a table using this quick approach,
see Create Table (quick creation).
Database Objects
Create the table by adding columns and selecting from a larger set of features. To
do this, check Show Advanced Options in the Create Table dialog box. For help
with options for creating a table with advanced features, see Create/Edit Table
(with advanced options).
You can perform the following operations on a table by right-clicking the table name in
the Connections navigator and selecting an item from the menu:
Edit: Displays the Create/Edit Table (with advanced options) dialog box.
Table: Table actions include Rename, Copy (create a copy using a different name),
Drop (delete the table), Truncate (delete existing data without affecting the table
definition), Lock (sets the table lock mode: row share, exclusive, and so on), and
Comment (descriptive comment explaining the use or purpose of the table).
Export: Enables you to export some or all of the table data to a file or to the system
clipboard, in any of the following formats: XML (XML tags and data), CSV
(comma-separated values including a header row for column identifiers), SQL
Insert (INSERT statements), SQL Loader (SQL*Loader control file), and DML.
After you select a format, the Export Table Data dialog box is displayed.
Column: Column actions include Comment (descriptive comment about a
column), Add, Drop, and Normalize.
Index: Options include Create (create an index on specified columns), Create Text
(create an Oracle Text index on a column), Create Text (create a function-based
index on a column), and Drop.
Storage: Options include Shrink Table (shrink space in a table, for segments in
tablespaces with automatic segment management) and Move Table (to another
tablespace). The Shrink Table options include Compact (only defragments the
segment space and compacts the table rows for subsequent release, but does not
readjust the high water mark and does not release the space immediately) and
Cascade (performs the same operations on all dependent objects of the table,
including secondary indexes on index-organized tables).
Analyze: Options include Compute Statistics (compute exact table and column
statistics and store them in the data dictionary), Estimate statistics (estimate table
and column statistics and store them in the data dictionary), and Validate
Structure (verifies the integrity of each data block and row, and for an
index-organized table also generates the optimal prefix compression count for the
primary key index on the table). Both computed and estimated statistics are used
by the Oracle Database optimizer to choose the execution plan for SQL statements
that access analyzed objects.
Constraint: Options include Enable or Disable Single, Drop (delete a constraint),
Add Check (add a check constraint), Add Foreign Key, and Add Unique.
Privileges: If you are connected as a database user with sufficient privileges, you
can Grant or Revoke privileges on the table to other users.
Trigger: Options include Create, Enable or Disable All, Enable or Disable Single,
and Drop (delete the trigger).
You can perform the following operations on a column in a table by right-clicking the
column name in the Connections navigator and selecting an item from the menu:
Drop: Deletes the column (including all data in that column) from the table.
Encrypt (for Oracle Database Release 10.2 and higher, and only if the Transparent
Data Encryption feature is enabled for the database): Displays a dialog box in
Raptor Concepts and Usage 1-9
Database Objects
which you specify a supported encryption algorithm to be used for encrypting all
data in the column. Current data and subsequently inserted data are encrypted.
Decrypt (for Oracle Database Release 10.2 and higher, and only if the Transparent
Data Encryption feature is enabled for the database): Decrypts data in the column
that had been encrypted, and causes data that is subsequently inserted not to be
encrypted.
For conceptual and usage information about tables, see Managing Tables.
1.2.12 Triggers
Triggers are stored PL/SQL blocks associated with a table, a schema, or the database,
or anonymous PL/SQL blocks or calls to a procedure implemented in PL/SQL or Java.
Oracle Database automatically executes a trigger when specified conditions occur. For
conceptual and usage information about sequences, see Triggers: Usage Information.
For help with specific options in creating a trigger, see Create/Edit Trigger.
1.2.13 Types
A data type associates a fixed set of properties with the values that can be used in a
column of a table or in an argument of a procedure or function. These properties cause
Oracle Database to treat values of one data type differently from values of another
data type. Most data types are supplied by Oracle, although users can create data
types.
For conceptual and usage information about data types, see Data Types: Usage
Information. For help with specific options in creating a user-defined type, see Create
Type (User-Defined).
1.2.15 Views
Views are virtual tables (analogous to queries in some database products) that select
data from one or more underlying tables. Oracle Database provides many view
creation options and specialized types of views (such as materialized views, described
in Materialized Views), to meet a variety of enterprise needs. For conceptual and usage
information about views, see Managing Views. For help with specific options in
creating and editing a view, see Create/Edit View.
You can perform the following operations on a view by right-clicking the view name
in the Connections navigator and selecting an item from the menu:
Compile: Recompiles the view, to enable you to locate possible errors before run
time. You may want to recompile a view after altering one of its base tables to
ensure that the change does not affect the view or other objects that depend on it.
Database Connections
1-11
Related Topics
Create/Edit/Select Database Connection
Export/Import Connection Descriptors
Raptor Concepts and Usage
Icons and other controls under the Data tab provide the following options:
Freeze View (the pin) keeps that objects tab and information in the window when
you click another object in the Connections navigator; a separate tab and display
are created for that other object. If you click the pin again, the objects display is
available for reuse.
Insert Row adds an empty row after the selected row, for you to enter new data.
Delete Selected Row(s) marks the selected rows for deletion. The actual deletion
does not occur until you commit changes.
Commit Changes ends the current transaction and makes permanent all changes
performed in the transaction.
Rollback Changes undoes any work done in the current transaction.
Sort displays a dialog box for selecting columns to sort by. For each column, you
can specify ascending or descending order, and you can specify that null values be
displayed first.
Filter enables you to enter a SQL predicate (WHERE clause text without the
WHERE keyword) for limiting the display of data. For example, to show only
rows where the RATING column value is equal to 10, specify: rating = 10
Refresh (to the right of the icons shown in the preceding figure) queries the
database to update the data display. If a filter is specified, the refresh operation
uses the filter.
Related Topics
Raptor User Interface
Raptor Concepts and Usage
In both cases, a code editing window is displayed. The following figure shows the
code editing window being used to debug a procedure named LIST_A_RATING2,
which is used for tutorial purposes in Debugging a PL/SQL Procedure.
The Source tab displays a toolbar and the text of the function or procedure, which
you can edit. You can set and unset breakpoints for debugging by clicking to the
left of the thin vertical line beside each statement with which you want to associate
a breakpoint. (When a breakpoint is set, a red circle is displayed.)
The Privileges tab displays, for each privilege associated with the function or
procedure, the grantor and grantee, the object name, and whether the grantee can
grant the privilege to other users.
The Dependencies tab shows any objects that this function or procedure
references, and any objects that reference this function or procedure.
1-13
The Source tab toolbar has the icons shown in the following figure.
The Debugging - Log tab under the code text area contains the debugging toolbar and
informational messages. The debugging toolbar has the icons shown in the following
figure.
Step Over bypasses the next method and goes to the next statement after the
method.
Step Out leaves the current method and goes to the next statement.
Step to End of Method goes to the last statement of the current method.
Pause halts execution but does not exit, thus allowing you to resume execution.
Terminate halts and exits the execution. You cannot resume execution from this
point; instead, to start running or debugging from the beginning of the function or
procedure, click the Run or Debug icon in the Source tab toolbar.
Garbage Collection removes invalid objects from the cache in favor of more
frequently accessed and more valid objects.
The Breakpoints tab under the code text area displays breakpoints, both
system-defined and user-defined.
The Smart Data tab under the code text area displays information about variables
associated with breakpoints.
The Data tab under the code text area displays information about all variables.
The Watches tab under the code text area displays information about watchpoints.
For more information about developing, compiling, and using PL/SQL functions and
procedures, see Subprograms and Packages: Usage Information.
Related Topics
Using Snippets to Insert Code Fragments
Run/Debug PL/SQL (dialog box)
Debugging a PL/SQL Procedure (tutorial)
Subprograms and Packages: Usage Information
Raptor Concepts and Usage
SQL Worksheet toolbar (under the SQL Worksheet tab): Contains icons for the
following operations:
Execute Statement executes the statement at the mouse pointer in the Enter SQL
Statement box. The SQL statements can include bind variables (but not
substitution variables) of type VARCHAR2, NUMBER, or DATE; a pop-up box is
displayed for entering bind variable values.
Run Script executes all statements in the Enter SQL Statement box using the Script
Runner. The SQL statements can include bind variables (but not substitution
variables) of type VARCHAR2, NUMBER, or DATE; a pop-up box is displayed for
entering bind variable values.
Cancel: Stops the execution of any statements currently being executed.
SQL History: Displays a dialog box with information about SQL statements that
you have executed. You can save statements to a file, or append to or overwrite
statements on the worksheet (see SQL History List).
1-15
Execute Explain Plan: Generates the execution plan for the statement (internally
executing the EXPLAIN PLAN statement). To see the execution plan, click the
Explain tab. For more information, see Execution Plan.
Clear: Erases the statement or statements in the Enter SQL Statement box.
Open File: Opens a SQL script file that you specify and displays it in the Enter
SQL Statement box.
Save File: Saves the contents of the Enter SQL Statement box to a SQL script file
that you specify.
Print File: Prints the contents of the Enter SQL Statement box.
To the right of these icons is a drop-down list for changing the database
connection to use with the worksheet.
Enter SQL Statement: The statement or statements that you intend to execute. (For a
single statement, the semicolon at the end is optional in the SQL Worksheet.) SQL
keywords are automatically highlighted. To format the statement (capitalizing the
names of statements, clauses, keywords, and so on), right-click in the statement area
and select Format SQL.
Tabs display panes with the following information:
Results: Displays the results of the most recent Execute Statement operation.
Explain: Displays the output if you clicked the Explain Execution Plan icon (see
Execution Plan).
Script Output: Displays the output if you clicked Run Script (see Script Runner).
DBMS Output: [TBS... Need explanations for the following: Includes a toolbar with
the following icons: Enable DBMS Output, Clear, Save, Print. Also: Buffer Size,
and a slider with the text Poll.]
OWA Output: [TBS... Need explanations for the following: Includes a toolbar with the
following icons: Enable OWA Output, Clear, Save, Print.]
Related Topics
SQL*Plus Statements Supported and Not Supported in SQL Worksheet
Script Runner
Execution Plan
Using Snippets to Insert Code Fragments
Using the SQL Worksheet for Queries (tutorial)
Raptor Concepts and Usage
def[ine]
desc[ribe]
doc[ument]
exec[ute]
exit (Stops execution and reinstates the specified connection)
pro[mpt]
quit (Stops execution and reinstates the specified connection)
rem[ark]
roll[back]
sta[rt]
undef[ine]
whenever
The following SQL*Plus statements are not supported by the SQL Worksheet:
a[ppend]
archive
attr[ibute]
bre[ak]
bti[tle]
c[hange]
cl[ear]
col[ulmn]
comp[ute]
copy
del
disc[onnect]
ed[it]
get
help
ho[st]
i[nput]
l[ist]
newpage
oradebug
passw[ord]
pau[se]
print
r[un]
recover
repf[ooter]
reph[eader]
sav[e]
sho[w]
shu[tdown]
spo[ol]
startup
store
timi[ng]
tti[tle]
var[iable]
Related Topics
Using the SQL Worksheet
1-17
Using SQL*Plus
execute them by clicking the drop-down next to the Execute Statement icon and
selecting Run Script. The Script Output pane displays the output.
The SQL*Plus features available in the script runner include @, @@, CONNECT, EXIT,
QUIT, UNDEFINE, WHENEVER, and substitution variables. For example, to run a
script named c:\myscripts\mytest.sql, type @c:\myscripts\mytest in the Enter SQL
Statement box, and click the drop-down next to the Execute Statement icon and select
Run Script.
The following considerations apply to using the Raptor script runner:
You cannot use bind variables. (The Execute SQL Statement feature does let you
use bind variables of type VARCHAR2, NUMBER, and DATE.)
For substitution variables, the syntax &&variable assigns a permanent variable
value, and the syntax &variable assigns a temporary (not stored) variable value.
For EXIT and QUIT, commit is the default behavior, but you can specify rollback.
In either case, the context is reset: for example, WHENEVER command
information and substitution variable values are cleared.
DESCRIBE works for tables, but not for all object types with which it is supported
in SQL*Plus.
For SQL*Plus commands that are not supported, a warning message is displayed.
If you have SQL*Plus available on your system, you may want to use it instead of the
script runner. To start SQL*Plus from Raptor, click Tools and then SQL*Plus. For
information about SQL*Plus, see Using SQL*Plus.
Related Topics
Using the SQL Worksheet
To use this feature, the system on which you are using Raptor must have an Oracle
Home directory or folder, with a SQL*Plus executable under that location. If the
location of the SQL*Plus executable is not already stored in your Raptor preferences,
you are asked to specify its location (see SQL*Plus Location).
If you do not have a SQL*Plus executable on your system, you can execute come
SQL*Plus statements using the SQL Worksheet (see SQL*Plus Statements Supported
and Not Supported in SQL Worksheet), and you can also use the Raptor script runner
feature to emulate a limited set of SQL*Plus features (see Script Runner).
For more information about using SQL*Plus, see SQL*Plus: Usage Information.
Related Topics
SQL*Plus Location (dialog box)
SQL*Plus: Usage Information
SQL*Plus Statements Supported and Not Supported in SQL Worksheet
Script Runner
Raptor Concepts and Usage
Related Topics
Running and Debugging Functions and Procedures
Using the SQL Worksheet
1-19
Reports
1.9 Reports
Raptor provides many reports about the database and its objects. You can also create
your own user-defined reports. To display reports, click the Reports tab on the left side
of the window (see Raptor User Interface). If this tab is not visible, select View and
then Reports.
Individual reports are displayed in tabbed panes on the right side of the window; and
for each report, you can select (in a drop-down control) the database connection for
which to display the report. For reports about objects, the objects shown are only those
visible to the database user associated with the selected database connection, and the
rows are usually ordered by Owner.
To see the SQL statement used to retrieve the information for a report, click the SQL
icon above the report and to the right of the database connection. Clicking this icon
displays the statement in the SQL Worksheet (see Using the SQL Worksheet).
The time required to display specific reports will vary, and may be affected by the
number and complexity of objects involved, and by the speed of the network
connection to the database.
Reports are grouped in the following categories:
About Your Database reports list release information about the database associated
with the connection.
Database Administration reports list usage information about system resources.
Table reports list information about tables owned by the user associated with the
specified connection. These reports can help you to better understand the metadata
and data. The table reports include Quality Assurance reports that indicate possible
logical design flaws and sources of run-time performance problems.
PL/SQL reports list information about your PL/SQL objects and allow you to search
the source of those objects.
Security reports list privilege-related information about the database.
XML reports list information about XML objects.
Jobs reports list information about jobs running on the database.
Streams reports list information about stream rules.
All Objects reports list information about all objects accessible to the user associated
with the specified database connection, not just objects owned by the user.
Data Dictionary reports list information about the data dictionary views that are
accessible in the database. Examples of data dictionary views are ALL_OBJECTS and
USER_TABLES.
User Defined reports are any customized reports that you have created.
Bind Variables for Reports
For some reports, you are prompted for bind variables before the report is generated.
These bind variables let you further restrict the output. The default value for all bind
variables is null, which implies no further restrictions. To specify a bind variable,
uncheck Null and type an entry in the Value field. Any bind variable values that you
enter are case insensitive, all matches are returned where the value string appears
anywhere in the name of the relevant object type.
Reports
Related Topics
Raptor Concepts and Usage
Raptor User Interface
Using the SQL Worksheet
Raptor Concepts and Usage
1-21
Reports
tables without comments. If database developers use the COMMENT statement when
creating or modifying tables, this report can provide useful information about the
purposes of tables and columns
Constraints: For each table, lists each associated constraint, including its type (unique
constraint, check constraint, primary key, foreign key) and status (enabled or
disabled).
Enabled Constraints and Disabled Constraints: For each constraint with a status of
enabled or disabled, lists the table name, constraint name, constraint type (unique
constraint, check constraint, primary key, foreign key), and status. A disabled
constraint is not enforced when rows are added or modified; to have a disabled
constraint enforced, you must edit the table and set the status of the constraint to
Enabled (see the appropriate tabs for Create/Edit Table (with advanced options)).
Primary Key Constraints: For primary key constraint, lists information that includes
the owner, the table name, the constraint name, the constraint status (enabled or
disabled), and the column name.
Unique Constraints: For each unique constraint, lists information that includes the
owner, the table name, the constraint name, the constraint status (enabled or disabled),
and the column name.
Foreign Key Constraints: For each foreign key constraint, lists information that
includes the owner, the table name, the constraint name, the column that the constraint
is against, the table that the constraint references, and the constraint in the table that is
referenced.
Check Constraints: For each check constraint, lists information that includes the
owner, the table name, the constraint name, the constraint status (enabled or disabled),
and the constraint specification.
Statistics: For each table, lists statistical information, including when it was last
analyzed, the total number of rows, the average row length, and the table type. In
addition, specialized reports order the results by most rows and largest average row
length.
Storage - Tables by Tablespace: For each tablespace, lists the number of tables and the
total number of megabytes currently allocated for the tables.
Storage - Tablespaces: For each table, lists the tablespace for the table and the number
of megabytes currently allocated for the table.
Organization: Specialized reports list information about partitioned tables, clustered
tables, and index organized tables.
Quality Assurance reports
Quality assurance reports identify conditions that are not technically errors, but that
usually indicate flaws in the database design. These flaws can result in various
problems, such as logic errors and the need for additional application coding to work
around the errors, as well as poor performance with queries at run time.
Tables without Primary Keys: Lists tables that do not have a primary key defined. A
primary key is a column (or set of columns) that uniquely identifies each row in the
table. Although tables are not required to have a primary key, it is strongly
recommended that you create or designate a primary key for each table. Primary key
columns are indexed, which enhances performance with queries, and they are
required to be unique and not null, providing some "automatic" validation of input
data. Primary keys can also be used with foreign keys to provide referential integrity.
Reports
Tables without Indexes: Lists tables that do not have any indexes. If a column in a
table has an index defined on it, queries that use the column are usually much faster
and more efficient than if there is no index on the column, especially if there are many
rows in the table and many different data values in the column.
Tables with Unindexed Foreign Keys: Lists any foreign keys that do not have an
associated index. A foreign key is a column (or set of columns) that references a
primary key: that is, each value in the foreign key must match a value in its associated
primary key. Foreign key columns are often joined in queries, and an index usually
improves performance significantly for queries that use a column. If an unindexed
foreign key is used in queries, you may be able to improve run-time performance by
creating an index on that foreign key.
Related Topics
Reports
1-23
Reports
System Privileges: For each privilege granted to the user associated with the database
connection, lists the privilege and whether it was granted with the ADMIN option.
Auditing: Lists information about audit policies.
Encryption: Lists information about encrypted columns.
Policies: Lists information about policies.
Related Topics
Reports
Reports
definition language (DDL) operation was performed on it. The Last DDL date can help
you to find if any changes to the object definitions have been made on or after a
specific time.
Invalid Objects: Lists all objects that have a status of invalid.
Object Count by Type: For each type of object associated with a specific owner, lists
the number of objects. This report might help you to identify users that have created
an especially large number of objects, particularly objects of a specific type.
Collection Types: Lists information about for each collection type. The information
includes the type owner, element type name and owner, and type-dependent specific
information.
Dependencies: For each object with references to it, lists information about references
to (uses of) that object.
Related Topics
Reports
1-25
Raptor Preferences
1.10.1 Environment
The Environment pane contains options that affect the startup and overall behavior
and appearance of Raptor. You can specify that certain operations be performed
automatically at specified times, with the trade-off usually being the extra time for the
operation as opposed to the possibility of problems if the operation is not performed
automatically (for example, if you forget to perform it when you should).
The undo level (number of previous operations that can be undone) and navigation
level (number of open files) values involve slight increases or decreases system
resource usage for higher or lower values.
Automatically Reload Externally Modified Files: If this option is checked, any files
open in Raptor that have been modified by an external application are updated when
you switch back to Raptor, overwriting any changes that you might have made. If this
option is not checked, changes that you make in Raptor overwrite any changes that
might have been made by external applications.
Silently Reload When File Is Unmodified: If this option is checked, you are not asked
if you want to reload files that have been modified externally but not in Raptor. If this
option is not checked, you are asked if you want to reload each file that has been
modified externally, regardless of whether it has been modified in Raptor,
Environment: Dockable Windows
The Dockable Windows pane configures the behavior of dockable windows and the
shapes of the four docking areas of Raptor: top, bottom, left, and right.
Dockable Windows Always on Top: If this option is checked, dockable windows
always remain visible in front of other windows.
Windows Layout: Click the corner arrows to lengthen or shorten the shape of each
docking area.
Environment: Local History
The Local History pane controls whether information about editing operations on files
opened within Raptor is kept. If local history is enabled, you can specify how long
information is retained and the maximum number of revisions for each file.
Environment: Log
The Log pane configures the colors of certain types of log messages and the saving of
log messages to log files.
Save Logs to File: If this option is checked, all output to the Messages - Log window is
saved to log files, where the file name reflects the operation and a timestamp. You are
also asked to specify a Log Directory; and if the specified directory does not already
Raptor Preferences
exist, it is created. Note that is you save log information to files, the number of these
files can become large.
Maximum Log Lines: The maximum number of lines to store in each log file.
Related Topics
Raptor Preferences
1.10.2 Accelerators
The Accelerators pane enables you to customize the accelerator key mappings for
Raptor.
Category: Select All or a specific category, to control which actions are displayed.
Actions: The actions for the selected category. When you select an action, any existing
accelerator key mappings are displayed.
Accelerators: Any existing key mappings for the selected action. To remove an existing
key mapping, select it and click Remove.
New Accelerator: The new accelerator key to be associated with the action. Press and
hold the desired modifier key, then press the other key. For example, to associate
Ctrl+J with an action, press and hold the Ctrl key, then press the j key. If any actions
are currently associated with that accelerator key, they are listed in the Current
Assignment field.
Load Preset: Enables you to load a set of predefined key mappings for certain systems
and external editing applications. If you load any preset key mappings that conflict
with changes that you have made, your changes are overwritten.
Related Topics
Raptor Preferences
1-27
Raptor Preferences
Raptor Preferences
checked, navigation actions cannot be undone, and only actual changes to the text can
be undone.
Related Topics
Raptor Preferences
1.10.5 Debugger
The Debugger pane contains general options for the Raptor debugger. Other panes
contain additional specific kinds of debugger options.
Debugger: Breakpoints
The Breakpoints tab sets the columns to appear in the Breakpoints pane and the scope
of each breakpoint.
Debugger: Breakpoints: Default Actions
The Breakpoints: Default Actions tab sets defaults for actions to occur at breakpoints.
These actions are the same as on the Actions tab in the Create/Edit Breakpoint dialog
box.
Debugger: Data
The Data tab pane enables you to control the columns to appear in the debugger Data
pane and aspects of how the data is displayed.
Debugger: Inspector
The Inspector tab enables you to control the columns to appear in the debugger
Inspector pane and aspects of how the data is displayed.
Debugger: Smart Data
The Smart Data tab enables you to control the columns to appear in the debugger
Smart Data pane and aspects of how the data is displayed.
1-29
Raptor Preferences
Debugger: Stack
The Stack tab enables you to control the columns to appear in the debugger Stack pane
and other options.
Debugger: Watches
The Watches tab enables you to control the columns to appear in the debugger
Watches pane and aspects of how the data is displayed.
Related Topics
Raptor Preferences
1.10.6 Documentation
The Documentation pane provides options for the display of Raptor online help.
Display in Window: If this option is checked, help is displayed in a separate window.
If this option is not checked, help is displayed in a pane in the Raptor User Interface.
Show Tabs: Controls which tabs appear in the Help Center pane (Table of Contents,
Index, Full Text Search).
Related Topics
Using the Help
Raptor Preferences
1.10.7 Extensions
The Extensions pane determines which extensions Raptor uses what it starts. If you
change any settings, you must exit Raptor and restart it for the new setting to take
effect.
Extensions to Use: Controls the specific extensions to use at startup.
Check for Updates: Checks for any updates to the selected extensions.
Automatically Check for Updates: If this option is checked, Raptor automatically
checks for any updates to the selected extensions at startup.
Related Topics
Raptor Preferences
To add a file extension, click Add and specify the file extension (including the period).
After adding the extension, you can modify its associated information by selecting it
and using the Details area.
Related Topics
Configure File Type Associations (dialog box)
Raptor Preferences
1-31
To print a single topic, display it in the Help Content area and click the Print icon, or
right-click its page icon in the Help contents hierarchy and select Print Topic Subtree.
The best way to become familiar with the help, and with Raptor itself, is simply to
experiment with the Help menu options and the Help button in some dialog boxes.
Related Topics
Raptor User Interface
Raptor Concepts and Usage
2
Tutorial: Creating Objects for a Small
Database
In this tutorial, you will use Raptor to create objects for a simplified library database,
which will include tables for books, patrons (people who have library cards), and
transactions (checking a book out, returning a book, and so on).
Tip: To print this tutorial, right-click its book icon in the Help
Contents display and select Print Topic Subtree.
The tables are deliberately oversimplified for this tutorial. They would not be adequate
for any actual public or organizational library. For example, this library contains only
books (not magazines, journals, or other document formats), and it can contain no
more than one copy of any book.
You will perform the following major steps:
Creating a Table (Books)
Creating a Table (Patrons)
Creating a Table (Transactions)
Creating a Sequence
Creating a View
Creating a PL/SQL Procedure
Debugging a PL/SQL Procedure (optional)
Using the SQL Worksheet for Queries (optional)
Related Topics
Script for Creating and Using the Library Tutorial Objects
Raptor Concepts and Usage
Raptor User Interface
Database Objects
the table that you create will be essentially the same as if you had entered the
following statement using the SQL Worksheet:
CREATE TABLE books (
book_id VARCHAR2(20) PRIMARY KEY,
title VARCHAR2(50)
CONSTRAINT title_not_null NOT NULL,
author_last_name VARCHAR2(30)
CONSTRAINT last_name_not_null NOT NULL,
author_first_name VARCHAR2(30),
rating NUMBER,
CONSTRAINT rating_1_to_10 CHECK (rating IS NULL OR
(rating >= 1 and rating <= 10)),
CONSTRAINT author_title_unique UNIQUE (author_last_name, title));
To create the Books table, connect to the database as the user in the schema you want
to use for this tutorial. Right-click the Tables node in the schema hierarchy on the left
side, select Create Table, and enter the following information. (If a tab or field is not
mentioned, do not enter anything for it.)
For detailed information about the table dialog box and its tabs, see Create Table
(quick creation) and Create/Edit Table (with advanced options).
Schema: Specify your current schema as the schema in which to create the table.
Name: Books
Create the table columns using the following information. After creating each column
except the last one (rating), click Add Column to add the next column. (If you
accidentally click OK instead of Add Column, right-click the BOOKS table in the
Connections navigator display, select Edit, and continue to add columns.)
Column Name
Type
Size
book_id
VARCHAR2 20
title
VARCHAR2 50
Not Null
author_last_name
VARCHAR2 30
Not Null
author_first_name
VARCHAR2 30
rating
NUMBER
After you have entered the last column (rating), check Show Advanced Options (next
to Schema). This displays additional tabs for more table options. For this table, you
will use the Unique Constraints and Check Constraints tabs.
Unique Constraints tab
Click Add to add a unique constraint for the table, namely, that the combination of
author_last_name and title must be unique within the table. (This is deliberately
oversimplified, since most major libraries will have allow more than one copy of a
book in their holdings. Also, the combination of last name and title is not always
"foolproof" check for uniqueness, but it is sufficient for this simple scenario.)
Name: author_title_unique
The use of single city_state_zip column for all that information is not good database
design; it is done here merely to simplify your work in the tutorial.
The location column (Oracle Spatial geometry representing the patrons geocoded
address) is merely to show the use of a complex (object) type.
To create the Patrons table, if you are not already connected, connect to the database as
the user for the schema you are using for this tutorial. Right-click the Tables node in
the schema hierarchy on the left side, select Create Table, and enter the following
information. (If a tab or field is not mentioned, do not enter anything for it.)
Schema: Specify your current schema as the schema in which to create the table.
Name: Patrons
Create most of the table columns using the following information. After creating each
column except the city_state_zip column, click Add Column to add the next column.
(If you accidentally click OK instead of Add Column, right-click the PATRONS table in
the Connections navigator display, select Edit, and continue to add columns.)
Size
patron_id
NUMBER
last_name
VARCHAR2
30
first_name
VARCHAR2
30
street_address
VARCHAR2
30
city_state_zip
VARCHAR2
30
The last column in the table (location) requires a complex data type, for which you
must use the Columns tab with advanced options. Check Show Advanced Options
(next to Schema). This displays additional tabs for more table options.
On the Columns tab, click the city_state_zip column name, and click the Add Column
(+) icon to add the following as the last column in the table.
Column Name Type
location
Complex type
Schema: MDSYS
Type: SDO_GEOMETRY
After you have entered the last column (location), click OK to finish creating the table.
Go to Creating a Table (Transactions) to create the next table.
Related Topics
Tutorial: Creating Objects for a Small Database
Raptor User Interface
To create the Transactions table, if you are not already connected, connect to the
database as the user for the schema you are using for this tutorial. Right-click the
Tables node in the schema hierarchy on the left side, select Create Table, and enter the
following information. (If a tab or field is not mentioned, do not enter anything for it.)
Schema: Specify your current schema as the schema in which to create the table.
Name: Transactions
Create the table columns using the following information. After creating each column
except the last one (transaction_type), click Add Column to add the next column. (If
you accidentally click OK instead of Add Column, right-click the TRANSACTIONS
table in the Connections navigator display, select Edit, and continue to add columns.)
Column Name
Type
transaction_id
NUMBER
patron_id
NUMBER
book_id
VARCHAR2 20
transaction_date
DATE
transaction_type NUMBER
Size
After you have entered the last column (transaction_type), check Show Advanced
Options (next to Schema). This displays additional tabs for more table options. For
this table, you will use the Primary Key and Foreign Keys tabs.
Primary Key tab
Because you have already specified the column for the primary key, you will use this
tab only to specify that the primary key column values are to be populated
automatically. This convenient approach uses a trigger and a sequence (both created
automatically by Raptor), and ensures that each transaction ID value is unique.
Populate Primary Key Column: TRANSACTION_ID
From: (Accept the defaults.)
Trigger Name: (Either accept the default or enter a name for the before-insert trigger
that will be created automatically.)
Foreign Keys tab
1. Click Add to create the first of the two foreign keys for the Transactions table.
Name: for_key_patron_id
Referenced Schema: Name of the schema containing the table with the primary key or
unique constraint to which this foreign key refers. Use the schema you have been
using for this tutorial.
Referenced Table: PATRONS
Referenced Constraint: Name (generated by Oracle) of the primary key constraint for
the Patrons table. (Might be a name with a format like PATRONS_PK.) Be sure that the
Referenced Column on PATRONS displayed value is PATRON_ID after you select the
Referenced Constraint.
Associations: Local Column: PATRON_ID
Associations: Referenced Column on PATRONS: PATRON_ID
2. Click Add to create the second of the two foreign keys for the Transactions table.
Creating a Sequence
Name: for_key_book_id
Referenced Schema: Name of the schema containing the table with the primary key or
unique constraint to which this foreign key refers. Use the schema you have been
using for this tutorial.
Referenced Table: BOOKS
Referenced Constraint: Name (generated by Oracle) of the primary key constraint for
the Books table. (Might be a name with a format like BOOKS_PK.) Be sure that the
Referenced Column on BOOKS displayed value is BOOK_ID after you select the
Referenced Constraint.
Associations: Local Column: BOOK_ID
Associations: Referenced Column on BOOKS: BOOK_ID
3. Click OK to finish creating the table.
You have finished creating all the tables. To create a sequence for use in generating
unique primary key values for the Patrons table, go to Creating a Sequence.
Related Topics
Tutorial: Creating Objects for a Small Database
Raptor User Interface
After creating the sequence, you can use it in INSERT statements to generate unique
numeric values. The following example uses the patron_id_seq sequence in creating a
row for a new patron (library user), assigning her a patron ID that is the next available
value of the patrons_id_seq sequence:
INSERT INTO patrons VALUES (patron_id_seq.nextval,
'Smith', 'Jane', '123 Main Street', 'Mytown, MA 01234', null);
To create the sequence, if you are not already connected, connect to the database as the
user for the schema you are using for this tutorial. Right-click the Sequences node in
the schema hierarchy on the left side, select Create Sequence, and enter information
using the Create Sequence dialog box.
Schema: Specify your current schema as the schema in which to create the sequence.
Name: patron_id_seq
Increment: 1
Start with: 100
Creating a View
To create the patrons_trans_view view, if you are not already connected, connect to the
database as the user for the schema you are using for this tutorial. Right-click the
Views node in the schema hierarchy on the left side, select Create View, and enter the
following information. (If a tab or field is not mentioned, do not enter anything for it.)
Schema: Specify your current schema as the schema in which to create the view.
Name: patrons_trans_view
Quick-Pick Objects tab
Schema: Specify your current schema.
Click Filter Types, be sure that only Tables is checked, and click OK. (This limits the
display of available objects to tales.)
Click Query to populate the Available display.
In the Available list, find and expand the PATRONS node, and double-click each of
the following columns to move it to Selected in the following order: PATRON_ID, LAST_
NAME, FIRST_NAME
In the Available list, find and expand the TRANSACTIONS node, and double-click
each of the following columns to move it to Selected in the following order: PATRON_
ID, TRANSACTION_TYPE, TRANSACTION_DATE
FROM Clause tab
In Selected, click on PATRONS; then in Alias, enter: p
In Selected, click on TRANSACTIONS; then in Alias, enter: t
SELECT Clause tab
SELECT List: Click to select the fourth item (PATRON_ID1 (t.PATRON_ID)); then
click the Delete (X) icon, which deletes that item from the SELECT clause of the query
used in the view definition. (That is, the patron_id value from the Transactions table is
not used for the view results, although it is needed for the WHERE clause.)
WHERE Clause
WHERE: Either type the following: p.patron_id = t.patron_id; or build the query using
the Expression Palette.
To use the Expression Palette, expand PATRONS, double-click PATRON_ID to move it
to the WHERE box; type an equal sign (=), optionally with a space before and after it;
click and expand TRANSACTIONS, double-click PATRON_ID to move it to the
WHERE box.
ORDER BY Clause
Click the Add (+) icon to add the first of two columns whose values will be used to
sort the results returned by the view.
In Expression Palette, expand PATRONS, double-click PATRON_ID to move it to the
Expression box.
Click the Add (+) icon to add the second of two columns whose values will be used to
sort the view results.
In Expression Palette, expand TRANSACTIONS, double-click TRANSACTION_TYPE
to move it to the Expression box.
DDL
Review the SQL statement that Raptor will use to create the view. If you want to make
any changes, go back to the relevant tabs and make the changes there.
If you want to save the CREATE VIEW statement to a SQL script file, click Save and
specify the location and file name.
When you are finished, click OK.
You have finished creating the view. To see the data returned by the view, in the
Connections navigator, expand Views, select PATRONS_TRANS_VIEW, and click the
Data tab.
Related Topics
Tutorial: Creating Objects for a Small Database
Raptor User Interface
matching_title VARCHAR2(50);
TYPE my_cursor IS REF CURSOR;
the_cursor my_cursor;
BEGIN
OPEN the_cursor FOR 'SELECT title FROM books WHERE
rating = :in_rating' USING in_rating;
DBMS_OUTPUT.PUT_LINE('All books with a rating of ' || in_rating || ':');
LOOP
FETCH the_cursor INTO matching_title;
EXIT WHEN the_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(matching_title);
END LOOP;
CLOSE the_cursor;
END;
This procedure uses a cursor (named the_cursor) to return only rows where the book
has the specified rating (in_rating parameter), and uses a loop to output the title of
each book with that rating.
Click the Save icon to save the procedure.
As a usage example, after creating the procedure named list_a_rating, you could use
the following statement to return all books with a rating of 10:
CALL list_a_rating(10);
Related Topics
Tutorial: Creating Objects for a Small Database
Script for Creating and Using the Library Tutorial Objects
Raptor User Interface
matching_rating NUMBER;
TYPE my_cursor IS REF CURSOR;
the_cursor my_cursor;
rating_cursor my_cursor;
BEGIN
OPEN the_cursor FOR 'SELECT title FROM books WHERE
rating <= :in_rating' USING in_rating;
OPEN rating_cursor FOR 'SELECT rating FROM books WHERE
rating <= :in_rating' USING in_rating;
DBMS_OUTPUT.PUT_LINE('All books with a rating of ' || in_rating || ':');
LOOP
FETCH the_cursor INTO matching_title;
FETCH rating_cursor INTO matching_rating;
EXIT WHEN the_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(matching_title);
END LOOP;
CLOSE the_cursor;
CLOSE rating_cursor;
END;
This procedure contains a logic error in the definition of the_cursor: it selects titles
where the rating is less than or equal to a specified rating, whereas it should select
titles only where the rating is equal to the specified rating.
Click the Save icon to save the procedure.
Assume that you wanted to run this procedure and list all books with a rating of 10.
Right-click LIST_A_RATING2 in the Connections navigator hierarchy display and
select Run. In the Run PL/SQL dialog box, change IN_RATING => IN_RATING to
IN_RATING => 10, and click OK. In the Log window, however, you see unexpected
output: many titles are listed, including some with ratings other than 10. So, you
decide to debug the procedure.
To debug the procedure, follow these steps:
1.
Set two breakpoints by clicking in the left margin (left of the thin vertical line)
beside each of these two lines: FETCH the_cursor INTO matching_title;
and FETCH rating_cursor INTO matching_rating;. (Clicking in the left
margin toggles the setting and unsetting of breakpoints.) This will enable you to
see the values of the matching_title and matching_rating variables as execution
proceeds in debug mode.
2.
3.
In the debugging toolbar, click the Resume icon to have execution proceed,
stopping at the next breakpoint; note the display in the Smart Data tab in the
lower right part of the window. Repeatedly click the Resume icon, noticing
especially the value of the rating variable as each row is processed. You will notice
the first incorrect result when you see that the title Get Rich Really Fast is included,
even though its rating is only 1 (obviously less than 10). (See the screen illustration
with debugging information in Running and Debugging Functions and
Procedures.)
4.
When you have enough information to fix the problem, you can click the
Terminate icon in the debugging toolbar.
From this debugging session, you know that to fix the logic error, you should change
rating <= :in_rating to rating = :in_rating in the definition of the_cursor.
Related Topics
Tutorial: Creating Objects for a Small Database
Running and Debugging Functions and Procedures
Run/Debug PL/SQL (dialog box)
Notice the automatic highlighting of SQL keywords (SELECT and FROM in this
example).
Click the Execute SQL Statement icon in the SQL Worksheet toolbar. The results of the
query are displayed on the Results tab under the area in which you entered the SQL
statement.
In the Enter SQL Statement box, enter (or copy and paste) the following statement,
which is the same as the SELECT statement in the view you created in Creating a
View:
SELECT p.patron_id, p.last_name, p.first_name,
t.transaction_type, t.transaction_date
FROM patrons p, transactions t
WHERE p.patron_id = t.patron_id
ORDER BY p.patron_id, t.transaction_type;
Click the Execute SQL Statement icon in the SQL Worksheet toolbar, and view the
results of the query.
Click the Explain tab to see the execution plan that Oracle Database follows to execute
the SQL statement. The information includes the optimizer strategy and the cost of
executing the statement. (For information about how to generate and interpret
execution plans, see Oracle Database Performance Tuning Guide.)
Related Topics
Tutorial: Creating Objects for a Small Database
Using the SQL Worksheet
2.9 Script for Creating and Using the Library Tutorial Objects
The following statements create and use the database objects that you have created (or
will create) in Tutorial: Creating Objects for a Small Database. You can view these
commands to help you understand the library database objects that are covered in the
tutorial.
-- Clean up from any previous running
DROP TABLE transactions;
DROP
DROP
DROP
DROP
DROP
TABLE books;
TABLE patrons;
SEQUENCE patron_id_seq;
SEQUENCE trans_id_seq;
VIEW patrons_trans_view;
set serveroutput on
-- Create objects
CREATE TABLE Books (
book_id VARCHAR2(20) PRIMARY KEY,
title VARCHAR2(50)
CONSTRAINT title_not_null NOT NULL,
author_last_name VARCHAR2(30)
CONSTRAINT last_name_not_null NOT NULL,
author_first_name VARCHAR2(30),
rating NUMBER,
CONSTRAINT rating_1_to_10 CHECK (rating IS NULL OR
(rating >= 1 and rating <= 10)),
CONSTRAINT author_title_unique UNIQUE (author_last_name, title));
CREATE TABLE Patrons (
patron_id NUMBER PRIMARY KEY,
last_name VARCHAR2(30)
CONSTRAINT patron_last_not_null NOT NULL,
first_name VARCHAR2(30),
street_address VARCHAR2(50),
city_state_zip VARCHAR2(50),
location MDSYS.SDO_GEOMETRY);
CREATE TABLE Transactions (
transaction_id NUMBER PRIMARY KEY,
patron_id CONSTRAINT for_key_patron_id
REFERENCES patrons(patron_id),
book_id CONSTRAINT for_key_book_id
REFERENCES books(book_id),
transaction_date DATE
CONSTRAINT tran_date_not_null NOT NULL,
transaction_type NUMBER
CONSTRAINT tran_type_not_null NOT NULL);
CREATE SEQUENCE patron_id_seq
START WITH 100
INCREMENT BY 1;
-- The actual sequence for the transaction_id
-- in the tutorial is created automatically,
-- and probably has a name in the form MDRS_xxx$.
CREATE SEQUENCE trans_id_seq
START WITH 1
INCREMENT BY 1;
CREATE OR REPLACE TRIGGER ins_transactions
BEFORE INSERT ON TRANSACTIONS
FOR EACH ROW
BEGIN
SELECT trans_id_seq.nextval INTO
:new.TRANSACTION_ID FROM dual;
END;
/
CREATE VIEW patrons_trans_view AS
SELECT p.patron_id, p.last_name, p.first_name,
t.transaction_type, t.transaction_date
FROM patrons p, transactions t
WHERE p.patron_id = t.patron_id
ORDER BY p.patron_id, t.transaction_type;
-- Procedure: List all books that have a specified rating.
CREATE OR REPLACE PROCEDURE list_a_rating(in_rating IN NUMBER) AS
matching_title VARCHAR2(50);
TYPE my_cursor IS REF CURSOR;
the_cursor my_cursor;
BEGIN
OPEN the_cursor FOR 'SELECT title FROM books WHERE
rating = :in_rating' USING in_rating;
DBMS_OUTPUT.PUT_LINE('All books with a rating of ' || in_rating || ':');
LOOP
FETCH the_cursor INTO matching_title;
EXIT WHEN the_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(matching_title);
END LOOP;
CLOSE the_cursor;
END;
/
show errors;
-- Insert and query data.
INSERT
INSERT
INSERT
null);
INSERT
5);
INSERT
transaction_date, transaction_type)
VALUES (102, 'A3333', SYSDATE, 1);
INSERT INTO transactions (patron_id, book_id,
transaction_date, transaction_type)
VALUES (103, 'A4444', SYSDATE, 2);
INSERT INTO transactions (patron_id, book_id,
transaction_date, transaction_type)
VALUES (100, 'A4444', SYSDATE, 1);
INSERT INTO transactions (patron_id, book_id,
transaction_date, transaction_type)
VALUES (102, 'A2222', SYSDATE, 2);
INSERT INTO transactions (patron_id, book_id,
transaction_date, transaction_type)
VALUES (102, 'A5555', SYSDATE, 1);
INSERT INTO transactions (patron_id, book_id,
transaction_date, transaction_type)
VALUES (101, 'A2222', SYSDATE, 1);
-- Test the view and the procedure.
SELECT * FROM patrons_trans_view;
CALL list_a_rating(10);
3
Dialog Boxes for Creating/Editing Objects
Raptor uses dialog boxes for creating and editing database connections and objects in
the database (tables, views, procedures, and so on). The dialog boxes sometimes have
multiple tabs, each reflecting a logical grouping of properties for that type of object.
For an explanation of any dialog box or tab, click the Help button or press the F1 key.
The dialog boxes are not presented here in any rigorous order, because the help for
each box is an independent piece of information and is normally seen when you click
Help or press F1 in that box.
For all Name fields, any name that you type is automatically
converted to and stored in the database metadata in uppercase, unless
you enclose the name in quotation marks (" "). (Names of database
objects in SQL and PL/SQL statements are not case-sensitive.)
Note:
Source: Select the source or sources to be checked for available updates: any or all
of some specified online update centers, or a local ZIP file containing an update
bundle.
2.
Update: If any updates are available from the selected source or sources, select
those that you want to download.
3.
Download: If you selected any updates to download, this page displays the
progress of the download operation.
Select Connection
Role: The set of privileges to be associated with the connection. For a user that has
been granted SYSOPER or SYSDBA system privilege, you can specify a connection
that includes the privilege.
Basic tab
Host Name: Host system for the Oracle database.
Port: Listener port.
SID: Database name.
Service Name: Network service name of the database (for a remote database
connection over a secure connection).
TNS tab
Network Alias: Oracle Net alias for the database. (The list for selecting a network alias
is initially filled from the tnsnames.ora file on your system, if that file exists.)
Connect Identifier: Oracle Net connect identifier.
Advanced tab
Custom JDBC URL: URL for connecting from Java to the database.
Creating and Editing Connections
To create a new connection when no connections exist, enter the connection information
and click Connect. To test the connection before you create it, click Test.
To create a new connection when one or more connections already exist, click New, enter the
connection information, and click Connect. To test the connection before you create it,
click Test.
To edit an existing connection, click in its entry in the Connection Name column, change
any property values on the left side, and click Connect. To test the connection before
you save changes to it, click Test.
Related Topics
Database Connections
Raptor User Interface
Select Library
Create/Edit Index
Fixed User: Creates a fixed user database link, for which you specify the user name
and password used to connect to the remote database.
Public: If this option is checked, the database link is public (available to all users). If
this option is not checked, the database link is private and is available only to you.
Shared: If this option is checked, a single network connection is used to create a public
database link that can be shared among multiple users. In this case, you must also
specify the Authentication information.
Authentication - User Name and Password: The user name and password on the
target instance. This information authenticates the user to the remote server and is
required for security. The specified user and password must be a valid user and
password on the remote instance.
DDL tab
You can review and save the SQL statement that Raptor will use to create a new
database link or that reflects any changes you have made to the database link
properties.
Related Topics
Database Objects
Raptor User Interface
Dialog Boxes for Creating/Editing Objects
The object is created and is displayed in the Editor window, where you can enter the
details.
For information about PL/SQL subprograms, see Subprograms and Packages: Usage
Information.
Related Topics
Database Objects
Raptor User Interface
Dialog Boxes for Creating/Editing Objects
Order: Indicates whether sequence numbers are generated in the order in which they
are requested. If no ordering is specified, sequence numbers are not guaranteed to be
in the order in which they were requested.
DDL tab
You can review the SQL statement that Raptor will use to create a new sequence or
that reflects any changes you have made to the sequence properties.
For information about sequences, see Managing Sequences.
Related Topics
Database Objects
Raptor User Interface
Dialog Boxes for Creating/Editing Objects
navigator and selecting Properties, which displays the Create/Edit Table (with
advanced options) dialog box.)
Show Advanced Options: If this option is checked, the dialog box changes to one with
multiple tabs, in which you can specify an extended set of features while creating the
table.
Schema: Database schema in which to create the table.
Name: Name of the table. Must be unique within a schema.
Columns tab (quick creation)
Specifies properties for each column in the table.
Columns: Lists the columns currently in the table.
To add a column after the currently selected column, click Add
Column; to delete a column, select it and click Remove Column.
Note:
Column Name: Name of the column. Must be unique within the table. Suggestion: For
a new column, replace any default name, such as COLUMN1.
Type: Data type for the column. The drop-down list includes only selected frequently
used data types. To specify any other type for the column, you must use the Columns
tab of the Create/Edit Table (with advanced options) dialog box.
Size: For VARCHAR2 data, the maximum size of the column data; for NUMBER data,
the maximum number of digits.
Not Null: If this option is checked, the column must contain data; you cannot specify
no value or an explicit null value for this column when you insert a row. If this option
is not checked, the column can contain either data or no data.
Primary Key: If this option is checked, the column is the primary key, or part of the
primary key, for the table. The primary key is the column, or set of columns, that
uniquely identifies each row in the table. A primary key column cannot be null.
If you want to have the primary key values automatically populated by a convenient
method that uses a before-insert trigger and a sequence, then before you finish
creating the table, you must check Show Advanced Options and use the Primary Key
tab, starting with the Populate Primary Key Column field.
To add another column, click Add Column. When you are finished adding columns,
either click OK or click the DDL tab to review the CREATE TABLE statement.
DDL tab (quick creation)
You can review and save the CREATE TABLE statement that Raptor will use to create
a new table or that reflects any changes you have made to the table properties. If you
want to make any changes, go back to the Columns tab and make the changes there.
When you are finished, click OK.
Related Topics
Create/Edit Table (with advanced options) (dialog box including advanced features)
Database Objects
Raptor User Interface
Tutorial: Creating Objects for a Small Database
3-8 Raptor Online Help
Note:
Name: Name of the column. Must be unique within the table. Suggestion: For a new
column, replace any default name, such as COLUMN1.
Datatype: Simple indicates a simple (non-object) data type; Complex indicates an
object type. For a complex type, you must specify the schema and the type name (for
example, MDSYS and SDO_GEOMETRY for the Oracle Spatial geometry type).
Type: Name of the data type. Most of the remaining information depends on the
specific type.
Precision: For numeric data, the precision (total number of significant digits that can
be represented) of the column data.
Scale: For numeric data, the scale (number of digits after the decimal point) of the
column data.
Size: For character data, the maximum size of the column data.
Units: For character data, the units represented by the Size: BYTE for bytes or CHAR
for characters. This attribute is important if the database can contain data in Unicode
format, with multiple bytes for each character.
Default: For relevant types, the default value inserted into the column if no value is
specified when a row is inserted.
Cannot be NULL: If this option is checked, the column must contain data; you cannot
specify no value or an explicit null value for this column when you insert a row. If this
option is not checked, the column can contain either data or no data. A primary key
column (see Primary Key tab) cannot be null.
Name: Name of the unique constraint. Must be unique within the database.
Enabled: If this option is checked, the unique constraint is enforced.
Available Columns: Lists the columns that are available to be added to the unique
constraint definition.
Selected Columns: Lists the columns that are included in the unique constraint
definition.
To add a column to the unique constraint definition, select it in Available Columns and
click the Add (>) icon; to remove a column from the unique constraint definition,
select it in Selected Columns and click the Remove (<) icon. To move all columns from
available to selected (or the reverse), use the Add All (>>) or Remove All (<<) icon. To
move a column up or down in the unique constraint definition, select it in Selected
Columns and use the arrow keys.
Foreign Keys tab
Specifies one or more foreign keys for the table. A foreign key specifies a column
("local column"), each of whose data values must match a value in the primary key or
unique constraint of another table.
Foreign Keys: Lists the foreign keys currently defined on the table. To add a foreign
key, click the Add button; to delete a foreign key, select it and click the Remove button.
Note: After you add a foreign key, to add another foreign key, click
the Add button.
Name: Name of the foreign key definition. Must be unique within the database.
Enabled: If this option is checked, the foreign key is enforced.
Referenced Schema: Name of the schema containing the table with the primary key or
unique constraint to which this foreign key refers.
Referenced Table: Name of the table with the primary key or unique constraint to
which this foreign key refers.
Referenced Constraint: Name of the primary key or unique constraint to which this
foreign key refers.
Associations: Local Column: Lists the column in the currently selected (local) table
that is included in the foreign key definition. For each local column in the foreign key
definition, select the name of a column in the local table.
Associations: Referenced Column on [table]: For each local column, identifies the
column in the other (foreign) table that must have a value matching the value in the
local column.
Check Constraints tab
Specifies one or more check constraints for the table. A check constraint specifies a
condition that must be met when a row is inserted into the table or when an existing
row is modified.
Check Constraints: Lists the check constraints currently defined on the table. To add a
check constraint, click the Add button; to delete a check constraint, select it and click
the Remove button.
After you add a check constraint, to add another check
constraint, click the Add button.
Note:
Name: Name of the check constraint definition. Must be unique within the database.
Enabled: If this option is checked, the check constraint is enforced.
Condition: Condition that must be met for a row. Can be any valid WHERE clause
(without the WHERE keyword) for a SELECT statement. For example, to indicate that
the value in a numeric column named RATING must be from 1 to 10, you can specify:
rating >=1 and rating <= 10
To add another check constraint, click the Add button.
Indexes tab
Specifies properties for each index on the table.
Indexes: Lists the indexes currently defined on the table. To add an index, click the
Add Index (+) icon; to delete an index, select it and click the Remove Index (X) icon.
After you add an index, to add another index, click the Add
Index (+) icon.
Note:
Extents - Next: Size of the next extent to be allocated to the table. Specify K (kilobytes)
or M (megabytes) for the unit associated with the number.
Extents - Min: Minimum number of extents allocated when the table is created.
Extents - Max: Maximum number of extents allocated when the table is created.
Unlimited (if checked) means that there is no maximum (and any specified maximum
is ignored).
Pct Increase: Percentage that each extent grows over the previous extent.
Ini Trans: Number of update transaction entries for which space is initially reserved in
the data block header.
Max Trans: Number of transaction entries that could concurrently use data in a data
block. This parameter has been deprecated. Oracle Database now automatically allows
up to 255 concurrent update transactions for any data block, depending on the
available space in the block.
Free Lists - Lists: Number of free lists for each of the free list groups for the table. The
default and minimum value for this parameter is 1, meaning that each free list group
contains one free list.
Free Lists - List Groups: Number of groups of free lists for the table. The default and
minimum value for this parameter is 1. Oracle uses the instance number of Real
Application Clusters instances to map each instance to one free list group.
Buffer Pool: <DEFAULT> means to use the Oracle Database default. KEEP means to
put blocks from the segment into the Keep buffer pool; maintaining an appropriately
sized Keep buffer pool lets Oracle retain the database object in memory to avoid I/O
operations. RECYCLE means to put blocks from the segment into the Recycle pool; an
appropriately sized Recycle pool reduces the number of objects whose default pool is
the Recycle pool from taking up unnecessary cache space.
Logging: <DEFAULT> means to use the Oracle Database default. ON means that the
table creation and any subsequent direct loader (SQL*Loader) and direct-path INSERT
operations against the table, partition, or LOB storage are logged in the redo log file.
OFF means that these operations are not logged in the redo log file.
DDL tab
You can review and save the CREATE TABLE statement that Raptor will use to create
a new table or that reflects any changes you have made to the table properties. If you
want to make any changes, go back to the relevant tabs and make the changes there.
To save the SQL statement to a script file, click Save and specify the location and file
name.
When you are finished, click OK.
Related Topics
Create Table (quick creation) (dialog box with limited features)
Database Objects
Raptor User Interface
Tutorial: Creating Objects for a Small Database
Create/Edit Trigger
Create/Edit View
Available: Lists the objects (typically, tables and views in a hierarchical display) from
which you can select objects to use in the SELECT, FROM, and WHERE clauses of the
view definition.
Selected: Lists the objects (typically, columns) that you can use in the SELECT, FROM,
and WHERE clauses of the view definition.
To add an object as selected, select it in Available and click the Add (>) icon; to remove
an object as selected, select it in Selected and click the Remove (<) icon. To move all
objects from selected to available, use the Remove All (<<) icon. To move an object up
or down in the selected list, select it in Selected and use the arrow keys.
For the example for the DDL tab, select the DEPTNO and SAL columns from the EMP
table.
View Information or Materialized View Information tab
Options for a standard view (View Information tab):
Restrict Query: If this option is checked, you can enable one of the following options
Read Only: Prevents the view from being used to add, delete, or change data in
the underlying table or tables.
Check Option: If this option is checked, it prohibits any changes to the underlying
table or tables that would produce rows that are not included in this view.
Force on create: If this option is checked, the view is created even if it has errors in its
definition. This option is useful if you want to create the view regardless of any errors,
and go back and correct the errors later. If this option is not checked, the view is not
created is its definition contains any errors.
Refresh properties for a materialized view (Materialized View Information tab):
Type: The type of refresh operation to be performed:
Complete Refresh: Executes the defining query of the materialized view, even if a
fast refresh is possible.
Fast Refresh: Uses the incremental refresh method, which performs the refresh
according to the changes that have occurred to the master tables. The changes for
conventional DML changes are stored in the materialized view log associated with
the master table.The changes for direct-path INSERT operations are stored in the
direct loader log.
Forced Refresh: Performs a fast refresh if one is possible; otherwise, performs a
complete refresh.
Primary Key: Creates a primary key materialized view, which allows materialized
view master tables to be reorganized without affecting the eligibility of the
materialized view for fast refresh.
Row ID: Creates a rowid materialized view, which is useful if the materialized
view does not include all primary key columns of the master tables.
Create/Edit View
time taken to complete the commit, because the database performs the refresh
operation as part of the commit process.
At: Starting date and time for the first automatic refresh operation. Must be in the
future.
Then Every: Interval for subsequent automatic refresh operations. If you do not
specify an value, the refresh operation is performed only once at the time specified for
At.
DDL tab
If you are editing an existing view or if you have only partially created a view, this tab
shows a SQL statement that reflects the current definition of the view.
To save the SQL statement to a script file, click Save and specify the location and file
name.
FROM Clause tab
Specifies the tables and views that you can use in the FROM clause of the view
definition.
Available: Lists the tables and views that are available to be selected for use in the
FROM clause of the view definition.
Selected: Lists the tables and views that you can use in the FROM clause of the view
definition.
To add an object as selected, select it in Available and click the Add (>) icon; to remove
an object as selected, select it in Selected and click the Remove (<) icon. To move all
objects from available to selected, use the Add All (<<) icon; to move all objects from
selected to available, use the Remove All (<<) icon.
Alias: Alias for the table or view.
For the example for the DDL tab, select the EMP table.
SELECT Clause tab
Specifies objects that you can use in the SELECT clause of the view definition.
SELECT List: Lists the objects (typically, columns) that you can currently use in the
SELECT clause. To add an object, click the Add (+) icon; to delete an object, select it
and click the Delete (X) icon; to move an object up or down in the view definition,
select it and use the up-arrow and down-arrow keys.
After you add an object, to add another object, click the Add
(+) icon.
Note:
Expression: Column name or an expression. For expressions, you can type them, or
you can use the Expression Palette to add object names and function names.
Validate: Checks the validity of the Expression entry.
For the example for the DDL tab, select DEPTNO column and the MIN(emp.sal) and
MAX(emp.sal) functions.
Create/Edit View
Note:
ORDER BY Expression Filter: For each column or column expression, you can type
the text completely into the Expression box; or you can type some of the text and use
the Expression Palette to add object names, function names, and operators.
Validate: Tests the validity of the syntax for the expression.
Order: ASC for ascending (expression values sorted in ascending order); DESC for
descending (expression values sorted in descending order).
Nulls Ordering: NULLS FIRST to have null expression values appear before non-null
values; NULLS LAST to have null expression values appear after non-null values.
("Before" and "after" positions are determined by the Order value.)
Entire SQL Query tab
Shows the entire SQL query for the view definition, and enables you to make changes
to the query.
Related Topics
Database Objects
Raptor User Interface
Dialog Boxes for Creating/Editing Objects
Find/Replace Text
Standard file extensions are .sql for Insert format, .xml for XML format, .ctl for SQL
LOADER format, and .csv for CSV format.
Columns tab
You can specify whether the output should include data from all columns or just from
the checked columns.
Where tab
You can restrict the output by entering a valid WHERE clause for a query on the table,
without the WHERE keyword. For example, to restrict the exported data to rows
where a column named RATING contains a value greater than 5, specify: rating >
5
Go to Line Number
Direction: Forward starts the search from the cursor in the direction of normal text
flow; Backward starts the search from the cursor in the opposite direction of normal
text flow.
Create/Edit Breakpoint
PL/SQL Block: A block of PL/SQL code created by Raptor. You should change the
formal IN and IN/OUT parameter specifications in this block to actual values that you
want to use for running or debugging the function or procedure.
For example, to specify 10 as the value for an input parameter named in_rating,
change IN_RATING => IN_RATING to IN_RATING => 10.
When you click OK, Raptor runs the function or procedure.
If you are debugging a function or procedure, the debugging toolbar and one or more
windows for debug-related information are displayed, as explained in Running and
Debugging Functions and Procedures.
Related Topics
Running and Debugging Functions and Procedures
Debugging a PL/SQL Procedure (tutorial)
Thread Options: You can specify whether the breakpoint occurs for all threads, or
only when the breakpoint is hit by threads that either do or do not have a specified
name.
Pass Count: The number of times the debugger should allow execution to pass over
the breakpoint before the breakpoint occurs.
Actions tab
Specify the actions to be taken when the breakpoint occurs. The options you specify
override any default values on the Debugger: Breakpoints: Default Actions pane of the
Raptor Preferences.
Halt Execution: Pauses execution when the breakpoint occurs.
Beep: Beeps when the breakpoint occurs.
Save/Save As
Log Breakpoint Occurrence: Sends a message to the log window when the breakpoint
occurs. You can also specify the following to be included in each display: a tag, and a
condition to be evaluated.
Enable/Disable a Group of Breakpoints: Enables or disables the specified breakpoint
group when this breakpoint occurs.
Related Topics
Running and Debugging Functions and Procedures
Debugging a PL/SQL Procedure (tutorial)
3.36 Save/Save As
This is a standard box for saving information to a file: use Location to navigate to
(double-clicking) the folder in which to save the file, then specify the file name
(including any extension) and, if necessary, the file type.
4
Database Objects: Usage Information
This topic discusses creating and managing database objects in your schema, plus
design considerations and indexing guidelines when developing applications with
Oracle Database. It contains the following topics:
Managing Tables
Managing Indexes
Managing Views
Managing Sequences
Managing Synonyms
See Also:
Managing Tables
Managing Tables
Managing Indexes
Managing Views
Managing Sequences
Managing Synonyms
Column Constraints
Table-Level Constraints
See Also:
Managing Tables
See Also:
In most cases, you should only need columns of NUMBER, VARCHAR2, and DATE data
types when creating a definition of a table.
When defining numeric data, you can use the precision option to set the maximum
number of digits in the number, and the scale option to define how many of the digits
are to the right of the decimal point. For example, a field to hold monetary values
might be defined as NUMBER(12,2), providing ten digits for the primary unit of
currency (dollars, pounds, marks, and so on) and two digits for the secondary unit
(cents, pennies, pfennigs, and so on).
To define a VARCHAR2 field for character data, you must include the size value. Set the
size to the maximum number of bytes (or, optionally, characters) to be stored in the
column. A column to hold postal codes for different countries, for example, might be
restricted to 12 bytes by defining it as VARCHAR2(12).
DATE columns are automatically formatted by Oracle to include a date and time
component. Although both the date and time are stored in a date column, by default,
the date portion is automatically displayed for you, when retrieving date data.
However, Oracle Database enables you great flexibility in how you can display your
dates and times.
Managing Tables
You can enforce rules by defining integrity constraints more reliably than by adding
logic to your application. Oracle Database can check that all the data in a table obeys
an integrity constraint faster than an application can.
Some constraints can be defined at the column level or at the table level. Column level
constraints are syntactically defined where the column to which the constraint applies
is defined. Table level constraints are syntactically defined at the end of the table
definition.
Primary Key
Unique Key
Check Constraint
Foreign Key
Constraints can be created and, in most cases, modified with a number of different
status values. The options include enabled or disabled, which determine if the
constraint is checked when rows are added, modified, or removed; and deferred or
immediate, which cause constraint validation to occur at the end of a transaction or at
the end of a statement, respectively.
See Also:
constraints.
4-4 Raptor Online Help
Managing Tables
An employee social security number where the primary key might be the
employee number
A truck license plate number where the primary key might be the truck number
A customer phone number, consisting of the two columns area_code and
local_phone where the primary key might be the customer number
A department name and location where the primary key might be the department
number
Managing Indexes
Use CHECK constraints when you need to enforce integrity rules based on logical
expressions, such as comparisons. Never use CHECK constraints when any of the other
types of integrity constraints can provide the necessary checking.
Examples of CHECK constraints include the following:
Managing Indexes
cause serious problems by increasing the processing overhead for statements that add,
modify, or delete rows. In some cases, a statement could use two or more indexes and
the optimizer picks just one of them. Unless other statements can take advantage of
the unused indexes, they are not providing any benefit. Therefore, you might find
yourself deleting indexes if you create too many.
This topic contains the following topics:
Index Types
Constraints use existing indexes where possible, rather than creating new ones.
Unique and primary keys can use non-unique as well as unique indexes. They can
even use just the first few columns of non-unique indexes.
At most one unique or primary key can use each non-unique index.
The column orders in the index and the constraint do not need to match.
You should almost always index foreign keys; the database does not do this for you
automatically.
4.3.2.1 Normal
A standard, B-tree index contains an entry for each value in the index key along with
an address to the row where the value is stored. A B-tree index is the default and most
common type of index in an Oracle database.
Managing Indexes
useful when all of the columns are likely to be included in the WHERE clause of
frequently executed SQL statements.
For concatenated indexes, you should define the columns used in the index carefully
so that the column with the fewest duplicate values is named first, the column with
next fewest duplicate values is second, and so on. Columns with many duplicate
values or many rows with NULL values should not be included or should be the
last-named columns in the index definition.
You can create an index on any column; however, if the column is not used in any of
these situations, creating an index on the column does not increase performance and
the index takes up resources unnecessarily.
Although the database creates an index for you on a column with an integrity
constraint, explicitly creating an index on such a column is recommended.
Create an index if you frequently want to retrieve less than about 15% of the rows
in a large table. This threshold percentage varies greatly, however, according to the
relative speed of a table scan and how clustered the row data is about the index
key. The faster the table scan, the lower the percentage; the more clustered the row
data, the higher the percentage.
Index columns that are used for joins to improve join performance.
Primary and unique keys automatically have indexes, but you might want to
create an index on a foreign key. See "Foreign Key" on page 4-6 for more
information.
Small tables do not require indexes; if a query is taking too long, then the table
might have grown from small to large.
Some columns are strong candidates for indexing. Columns with one or more of the
following characteristics are good candidates for indexing:
The column contains many nulls, but queries often select all rows having a value.
In this case, a comparison that matches all the non-null values, such as:
WHERE COL_X >= -9.99 *power(10,125)
is preferable to
WHERE COL_X IS NOT NULL
Managing Indexes
This is because the first uses an index on COL_X (assuming that COL_X is a
numeric column).
Columns with the following characteristics are less suitable for indexing:
There are many nulls in the column and you do not search on the non-null values.
The size of a single index entry cannot exceed roughly one-half (minus some
overhead) of the available space in the data block. Consult with the database
administrator for assistance in determining the space required by an index.
part_no
10-440
10-457
08-300
10-440
10-441
10-457
08-300
10-457
unit_cost
0.27
5.10
1.19
0.25
0.39
4.96
1.33
5.29
Assume that there are five vendors, and each vendor has about 1000 parts. Suppose
that the vendor_parts table is commonly queried by SQL statements such as the
following:
SELECT * FROM vendor_parts
WHERE part_no = 457 AND vendor_id = 1012;
To increase the performance of such queries, you might create a composite index
putting the most selective column first; that is, the column with the most values:
CREATE INDEX ind_vendor_id ON vendor_parts (part_no, vendor_id);
Composite indexes speed up queries that use the leading portion of the index. So in
this example, queries with WHERE clauses using only the part_no column also note a
performance gain. Because there are only five distinct values, placing a separate index
on vendor_id would serve no purpose.
Managing Views
It does not speed up queries. The table might be very small, or there might be
many rows in the table but very few index entries.
You cannot drop an index which is created through a constraint. You must drop the
constraint and then the index is dropped also.
If you drop a table, then all associated indexes are dropped.
To drop an index, the index must be contained in your schema or you must have the
DROP ANY INDEX system privilege.
You must qualify CURRVAL and NEXTVAL with the name of the sequence, such as
employees_seq.CURRVAL or employees_seq.NEXTVAL.
When you create a sequence, you can define its initial value and the increment
between its values. The first reference to NEXTVAL returns the initial value of the
sequence. Subsequent references to NEXTVAL increment the sequence value by the
defined increment and return the new value. Any reference to CURRVAL always
returns the current value of the sequence, which is the value returned by the last
reference to NEXTVAL.
Before you use CURRVAL for a sequence in your session, you must first initialize the
sequence with NEXTVAL.
Managing Synonyms
4-11
Managing Synonyms
5
Data Types: Usage Information
The topic discusses the data types used with Oracle Database. It contains the following
topics:
NCHAR and NVARCHAR2 data types store variable-length Unicode character data
only.
CHAR and NCHAR data types store fixed-length character literals.
See Also:
Space usage
To store data more efficiently, use the VARCHAR2 data type. The CHAR data type
blank-pads and stores trailing blanks up to a fixed column length for all column
values, whereas the VARCHAR2 data type does not add extra blanks.
Comparison semantics
Use the CHAR data type when you require ANSI compatibility in comparison
semantics (when trailing blanks are not important in string comparisons). Use the
VARCHAR2 when trailing blanks are important in string comparisons.
Future compatibility
The CHAR and VARCHAR2 data types are fully supported.
Oracle Database SQL Reference for more information on
comparison semantics for these data types
See Also:
NUMBER
BINARY_FLOAT
BINARY_DOUBLE
Use the NUMBER data type to store integers and real numbers in a fixed-point or
floating-point format. Numbers using this data type are guaranteed to be portable
among different Oracle Database platforms. For nearly all cases where you need to
store numeric data, you would use the NUMBER data type.
Oracle Database provides the numeric BINARY_FLOAT and BINARY_DOUBLE data
types exclusively for floating-point numbers. They support all of the basic
functionality provided by the NUMBER data type. However, while NUMBER uses
Precision is the total number of significant decimal digits, where the most
significant digit is the left-most nonzero digit, and the least significant digit is the
right-most known digit. For examples, see Table 51 on page 5-4.
Scale is the number of digits from the decimal point to the least significant digit.
The scale can range from -84 to 127. For examples, see Table 51 on page 5-4.
Positive scale is the number of significant digits to the right of the decimal
point to and including the least significant digit.
Negative scale is the number of significant digits to the left of the decimal
point, to but not including the least significant digit. For negative scale the
least significant digit is on the left side of the decimal point, because the actual
data is rounded to the specified number of places to the left of the decimal
point. For example, a specification of (10,-2) means to round to hundreds.
Scale can be greater than precision, most commonly when e notation is used. When
scale is greater than precision, the precision specifies the maximum number of
significant digits to the right of the decimal point. For example, a column defined as
NUMBER(4,5) requires a zero for the first digit after the decimal point and rounds all
values past the fifth digit after the decimal point.
It is good practice to specify the scale and precision of a fixed-point number column
for extra integrity checking on input. Specifying scale and precision does not force all
values to a fixed length. If a value exceeds the precision, then Oracle returns an error. If
a value exceeds the scale, then Oracle rounds it.
Specify an integer using the following form:
NUMBER(p)
This represents a fixed-point number with precision p and scale 0 and is equivalent to
NUMBER(p,0).
Specify a floating-point number using the following form:
NUMBER
The absence of precision and scale designators specifies the maximum range and
precision for an Oracle number.
Table 51 show how Oracle stores data using different values for precision and scale.
Table 51
Actual Data
Specified As
Stored As
123.89
NUMBER
123.89
123.89
NUMBER(3)
124
123.89
NUMBER(6,2)
123.89
123.89
NUMBER(6,1)
123.9
123.89
NUMBER(3)
exceeds precision
123.89
NUMBER(4,2)
exceeds precision
123.89
NUMBER(6,-2)
100
.01234
NUMBER(4,5)
.01234
.00012
NUMBER(4,5)
.00012
.000127
NUMBER(4,5)
.00013
.0000012
NUMBER(2,7)
.0000012
.00000123
NUMBER(2,7)
.0000012
1.2e-4
NUMBER(2,5)
0.00012
1.2e-5
NUMBER(2,5)
0.00001
5.3.3.1 BINARY_FLOAT
BINARY_FLOAT is a 32-bit, single-precision floating-point number data type. Each
BINARY_FLOAT value requires 5 bytes, including a length byte.
5.3.3.2 BINARY_DOUBLE
BINARY_DOUBLE is a 64-bit, double-precision floating-point number data type. Each
BINARY_DOUBLE value requires 9 bytes, including a length byte.
In a NUMBER column, floating point numbers have decimal precision. In a BINARY_
FLOAT or BINARY_DOUBLE column, floating-point numbers have binary precision.
The binary floating-point numbers support the special values infinity and NaN (not a
number).
You can specify floating-point numbers within the limits listed in Table 52 on
page 5-5.
Table 52
Value
Binary-Float
Binary-Double
3.40282E+38F
1.79769313486231E+308
1.17549E-38F
2.22507485850720E-308
DATE
TIMESTAMP
5.4.1.4 Using the TIMESTAMP WITH LOCAL TIME ZONE Data Type
Use TIMESTAMP WITH LOCAL TIME ZONE when the time zone is not significant. For
example, you might use it in an application that schedules teleconferences, where
participants each see the start and end times for their own time zone.
The TIMESTAMP WITH LOCAL TIME ZONE type is appropriate for two-tier
applications in which you want to display dates and times that use the time zone of
the client system. It is generally inappropriate in three-tier applications because data
displayed in a Web browser is formatted according to the time zone of the Web server,
not the time zone of the browser. The Web server is the database client, so its local time
is used.
Oracle Database provides various functions for calculating and converting datetime
data. For examples in SQL statements, see Using Date Functions.
Be careful when using a date format such as DD-MON-YY. The YY indicates the year in
the current century. For example, 31-DEC-92 is December 31, 2092, not 1992 as
you might expect. If you want to indicate years in any century other than the current
one, use a format mask such as the default RR.
You can use the following techniques to change the default date format on a more
global level:
Oracle Database SQL Reference for more information about date and
time formats
Oracle Database Concepts for information about Julian dates. Oracle
Database Julian dates might not be compatible with Julian dates
generated by other date algorithms.
6
SQL: Usage Information
This topic discusses how to use SQL with Oracle Database. It includes the following
topics:
Overview of SQL
Features of SQL
Format, perform calculations on, store, and print from query results
document the SQL statements. The comments (or remarks) in this example begin with
--, but you could also use rem or REM.
Example 61 Using SELECT to Retrieve Data
-- the following uses the wildcard * to retrieve all the columns of data in
-- all rows of the employees table
SELECT * FROM employees;
Example 62 shows how to use SELECT to retrieve the data for specific columns of the
employees table. In this example, you explicitly enter the column names in the
SELECT statement.
Example 62 Using SELECT to Retrieve Data From Specific Columns
-- the following retrieves the data in columns employee_id, last_name, first_name
SELECT employee_id, last_name, first_name FROM employees;
See Also:
See Also:
Comparison Operators
Operator
Definition
=, !=, <>
test greater than, greater than or equal to, less than, less than or
equal to
LIKE
IN ( )
Example 64 shows how to use SELECT with a WHERE clause and several comparison
operators to retrieve specific rows of data from the employees table.
Example 64 Using SELECT With a WHERE Clause
-- the following retrieves data where the manager_id equals 122
SELECT * FROM employees WHERE manager_id = 122;
-- this retrieves data where the manager_id equals 122 and job_id is ST_CLERK
SELECT * FROM employees WHERE manager_id = 122 AND job_id = 'ST_CLERK';
6-4 Raptor Online Help
-- this retrieves employees with managers with Ids between 122 and 125 inclusive
SELECT * FROM employees WHERE manager_id BETWEEN 122 AND 125;
-- this uses the wildcard % to retrieve employee data
-- where the last name contains mar somewhere in the name
SELECT employee_id, last_name FROM employees WHERE last_name LIKE '%mar%';
-- this retrieves employees where the last name starts with Mar
SELECT employee_id, last_name FROM employees WHERE last_name LIKE 'Mar%';
-- this retrieves employees where the commission percentage is not null
SELECT employee_id, last_name FROM employees WHERE commission_pct IS NOT NULL;
-- the following retrieves data where the employee_id equals 125, 130, or 135
SELECT employee_id, last_name, first_name FROM employees
WHERE employee_id IN (125, 130, 135);
See Also:
Numeric values are displayed with the lowest values first, such as 1 to 999.
Character values are displayed in alphabetical order, such as A first and Z last.
Date values are displayed with the earliest value first, such as 01-JUN-93 before
01-JUN-95.
Null (empty) values are displayed last for ascending sequences and first for
descending sequences.
Example 65 shows how to use SELECT with the ORDER BY clause to retrieve and
display rows from the employees table ordered (sorted) by specified columns.
Example 65 Using SELECT With ORDER BY
-- the following retrieves rows with manager_id = 122 ordered by employee_id
-- the order is the default ascending order, lowest employee_id displays first
SELECT * FROM employees WHERE manager_id = 122 ORDER BY employee_id;
-- the following retrieves rows ordered by manager_id
-- the order is specified as descending, highest manager_id displays first
SELECT employee_id, last_name, first_name, manager_id FROM employees
ORDER BY manager_id DESC;
See Example 620 on page 6-14 for the use of ORDER BY with the GROUP BY clause.
See Also:
See Also:
See Also:
See Also:
If you accidentally delete rows, you can restore the rows with the ROLLBACK
statement. See "Rolling Back a Transaction" on page 6-9.
See Also:
See Also:
See Also:
Using Sequences
Using Pseudocolumns
-- the following statement displays the SYSDATE, which is the current system date
-- NOW is a column alias for display purposes
-- DUAL is a dummy table with one row simply used to complete the SELECT statement
SELECT SYSDATE "NOW" FROM DUAL;
-- display the name of the current user, the user name should be HR
SELECT USER FROM DUAL;
-- using ROWNUM < 10 limits the number of rows returned to less than 10
SELECT employee_id, hire_date, SYSDATE FROM employees WHERE ROWNUM < 10;
See Example 618 on page 6-14 for another example of the use of SYSDATE.
Using Sequences
-- you can use the UPPER function to display uppercase data, LOWER for lowercase
SELECT employee_id, UPPER(last_name), LOWER(first_name) FROM employees;
-- you can use CONCAT function to concatenate character data
SELECT CONCAT('Last name: ', last_name) FROM employees;
-- you can use RTRIM and LTRIM to remove spaces from the beginning or end of
-- character data. Note the use of concatenation operator ||
SELECT employee_id, RTRIM(first_name) || ' ' || LTRIM(last_name) FROM employees;
-- you can TRIM to remove spaces from both the beginning and end
SELECT employee_id, TRIM(last_name) || ', ' || TRIM(first_name) FROM employees;
-- you can format the system date (SYSDATE) as a character string
-- with various format masks and then display
-- the following displays September 21 2005
+ for addition
- for subtraction
* for multiplication
/ for divide
-- you can use the ROUND function to round off numeric data, in this case to
-- two decimal places
SELECT employee_id, ROUND(salary/30, 2) "Salary per day" FROM employees;
-- you can use the TRUNC function to truncate numeric data, in this case to
-- 0 decimal places; 0 is the default so TRUNC(salary/30) would be same
SELECT employee_id, TRUNC(salary/30, 0) "Salary per day" FROM employees;
ADD_MONTHS function, which returns the date plus the specified number of
months.
MONTHS_BETWEEN function, which returns the number of months between two
dates.
SYSDATE function, which returns the current date and time set for the operating
system on which the database resides.
SYSTIMESTAMP function, which returns the system date, including fractional
seconds and time zone, of the system on which the database resides.
TRUNC function, which when applied to a DATE value, trims off the time portion
so that it represents the very beginning of the day (the stroke of midnight). By
truncating two DATE values and comparing them, you can determine whether
they refer to the same day. You can also use TRUNC along with a GROUP BY clause
to produce daily totals.
Arithmetic operators such as + and -. For example, SYSDATE-7 refers to 7 days
before the current system date.
INTERVAL data types, which enable you to represent constants when performing
date arithmetic rather than performing your own calculations. For example, you
can add or subtract INTERVAL constants from DATE values or subtract two DATE
values and compare the result to an INTERVAL.
Comparison operators such as >, <, =, and BETWEEN.
EXTRACT, which extracts and returns the value of a specified datetime field from a
datetime or interval value expression
NUMTODSINTERVAL, which converts a NUMBER or expression that can be implicitly
converted to a NUMBER value to an INTERVAL DAY TO SECOND literal
NUMTOYMINTERVAL, which converts a NUMBER or expression that can be implicitly
converted to a NUMBER value to an INTERVAL YEAR TO MONTH literal
Example 619 shows how to use date functions with format masks.
Example 619
-- use TO_DATE with a format mask to display or enter dates differently than the
-- current default date format
-- the following displays 1998 with the 'DD-MON-RR' format mask
SELECT TO_CHAR(TO_DATE('27-OCT-98', 'DD-MON-RR') ,'YYYY') "Year" FROM DUAL;
-- note that 'YY' in a format mask denotes the year in the current century
-- the following displays 2098 with the 'DD-MON-YY' format mask
SELECT TO_CHAR(TO_DATE('27-OCT-98', 'DD-MON-YY') ,'YYYY') "Year" FROM DUAL;
-- the following displays the date and time with a datetime format mask
SELECT TO_TIMESTAMP ('10-Sep-05 14:10:10.123000', 'DD-Mon-RR HH24:MI:SS.FF')
FROM DUAL;
-- the following displays the system date and time with a format mask
SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "Now" FROM DUAL;
-- you can use COUNT to count the employees with manager 122
-- note the use of a column alias Employee Count
SELECT COUNT(*) "Employee Count" FROM employees WHERE manager_id = 122;
-- count the employees grouped by manager, also sort the groups
SELECT COUNT(*) "Employee Count", manager_id FROM employees
GROUP BY manager_id ORDER BY manager_id;
-- you can use MIN to find the minimum salary for employees with manager 122
SELECT MIN(salary) FROM employees WHERE manager_id = 122;
-- this computes the minimum and maximum salary by job_id groups
-- the job_ids groups are sorted in alphabetical order
SELECT MIN(salary), MAX(salary), job_id FROM employees
GROUP BY job_id ORDER BY job_id;
Optionally, you can provide constraints as shown inExample 622. The use of
constrains is discussed in Ensuring Data Integrity With Constraints.
Example 622
hire_date
job_id
salary
commission_pct
manager_id
department_id
CONSTRAINT
CONSTRAINT
);
-- create a new index on the employees table using the email column
CREATE INDEX email_ix
ON employees (email);
-- disable the index
ALTER INDEX email_ix
RENAME TO my_email_ix;
-- drop the index
DROP INDEX my_email_ix;
-- create an index on a single column to make queries faster on that column
CREATE INDEX emp_last_name_ix ON employees (last_name);
DROP INDEX emp_last_name_ix;
-- create an index on two columns to make queries faster on the first column
-- or both columns
CREATE INDEX emp_mgr_id_ix ON employees (employee_id, manager_id);
DROP INDEX emp_mgr_id_ix;
-- a function-based index precalculates the result and speeds up queries that
-- use the function for searching or sorting, in this case UPPER(last_name)
CREATE INDEX emp_upper_last_name_ix ON employees (UPPER(last_name));
DROP INDEX emp_upper_last_name_ix;
Altering a Table
Dropping a Table
Creating a Sequence
Example 628
Dropping a Sequence
Creating a Synonym
Dropping a Synonym
7
PL/SQL: Usage Information
The topic discusses the development with PL/SQL. It includes the following topics:
You can nest blocks in the executable and exception-handling parts of a PL/SQL block
or subprogram, but not in the declarative part. You can define local subprograms in
the declarative part of any block. You can call local subprograms only from the block
in which they are defined.
Anonymous block
An anonymous block is a PL/SQL block that appears in your application and is
not named or stored in the database. In many applications, PL/SQL blocks can
appear wherever SQL statements can appear. A PL/SQL block groups related
declarations and statements.
Package
A package is a group of subprograms and variable definitions that Oracle stores in
the database. Subprograms and variables in packages can be called from other
packages or subprograms. See Subprograms and Packages: Usage Information.
Using Comments
Using Literals
END;
/
For another example of PL/SQL block structure, see Example 78 on page 7-9.
While testing or debugging a program, you might want to disable a line of code. The
following example shows how you can disable a single line by making it a comment:
-- pay_per_day := monthly_salary/number_of_days_worked;
You can use multi-line comment delimiters to comment-out large sections of code.
See Also: PL/SQL User's Guide and Reference for information on data
types used with PL/SQL, including the PL/SQL BOOLEAN and PLS_
INTEGER data types
Characters such as hyphens, slashes, and spaces are not allowed. For example the
following identifiers are not allowed:
mine&yours is not allowed because of the ampersand
debit-amount is not allowed because of the hyphen
on/off is not allowed because of the slash
user id is not allowed because of the space
You can use upper, lower, or mixed case to write identifiers. PL/SQL is not case
sensitive except within string and character literals. Every character, including dollar
signs, underscores, and number signs, is significant. If the only difference between
identifiers is the case of corresponding letters, PL/SQL considers them the same, as in
the following:
lastname is same as LASTNAME and LastName
LastName is the same as lastname and LASTNAME
LASTNAME is same as lastname and LastName
The size of an identifier cannot exceed 30 characters. Identifiers should be descriptive.
When possible, avoid obscure names such as cpm. Instead, use meaningful names such
as cost_per_thousand.
Some identifiers, called reserved words or keywords, have a special syntactic meaning
to PL/SQL. For example, the words BEGIN and END are reserved. Often, reserved
words and keywords are written in upper case for readability. Neither reserved words
or keywords should be used as identifiers and the use can cause compilation errors.
See Also: PL/SQL User's Guide and Reference for information on
PL/SQL reserved words and keywords
See Also:
NULL; -- NULL statement does nothing, allows this block to executed and tested
END;
/
Declaring variables with %ROWTYPE has several advantages. First, you do not need to
know the exact data type of the table columns. Second, if you change the database
definition of any of the table columns, the data types associated with the %ROWTYPE
declaration change accordingly at run time.
See Also: PL/SQL User's Guide and Reference for information on
%ROWTYPE
Declaring variables with %TYPE has two advantages. First, you need not know the
exact data type of the table columns. Second, if you change the database definition of
columns, such as employee_id or last_name, the data types of empid and
emplname in Example 711 change accordingly at run time.
See Also: PL/SQL User's Guide and Reference for information on
%TYPE
DECLARE
sales NUMBER(8,2) := 10100;
quota NUMBER(8,2) := 10000;
bonus NUMBER(6,2);
emp_id NUMBER(6) := 120; -- use employee 120 for testing
BEGIN
IF sales > (quota + 200) THEN
bonus := (sales - quota)/4;
UPDATE employees SET salary = salary + bonus WHERE employee_id = emp_id;
END IF;
END;
/
Example 713 shows the use of IF-THEN-ELSEIF-ELSE to determine the salary raise
an employee receives based on the hire date of the employee.
Example 713
DECLARE
bonus NUMBER(6,2);
emp_id NUMBER(6) := 120;
hire_date DATE;
BEGIN
SELECT hire_date INTO hire_date FROM employees WHERE employee_id = 120;
IF hire_date > TO_DATE('01-JAN-98') THEN
bonus := 500;
ELSIF hire_date > TO_DATE('01-JAN-96') THEN
bonus := 1000;
ELSE
bonus := 1500;
END IF;
UPDATE employees SET salary = salary + bonus WHERE employee_id = emp_id;
END;
/
DECLARE
grade CHAR(1);
BEGIN
grade := 'B';
CASE grade
WHEN 'A' THEN DBMS_OUTPUT.PUT_LINE('Excellent');
WHEN 'B' THEN DBMS_OUTPUT.PUT_LINE('Very Good');
WHEN 'C' THEN DBMS_OUTPUT.PUT_LINE('Good');
WHEN 'D' THEN DBMS_OUTPUT.PUT_LINE('Fair');
WHEN 'F' THEN DBMS_OUTPUT.PUT_LINE('Poor');
ELSE DBMS_OUTPUT.PUT_LINE('No such grade');
END CASE;
END;
/
Example 715 determines the salary raise an employee receives based on the current
salary of the employee and the job Id. This complex example combines the CASE
expression with IF-THEN-ELSE statements.
Example 715
empid
employees.employee_id%TYPE := 115;
sal
employees.salary%TYPE;
sal_raise NUMBER(3,2);
BEGIN
-- retrieve data from employees and assign to variables jobid and sal
SELECT job_id, salary INTO jobid, sal from employees WHERE employee_id = empid;
CASE -- check for conditions
WHEN jobid = 'PU_CLERK' THEN
IF sal < 3000 THEN sal_raise := .08;
ELSE sal_raise := .07;
END IF;
WHEN jobid = 'SH_CLERK' THEN
IF sal < 4000 THEN sal_raise := .06;
ELSE sal_raise := .05;
END IF;
WHEN jobid = 'ST_CLERK' THEN
IF sal < 3500 THEN sal_raise := .04;
ELSE sal_raise := .03;
END IF;
ELSE
BEGIN
-- if no conditions met, then the following
DBMS_OUTPUT.PUT_LINE('No raise for this job: ' || jobid);
END;
END CASE;
UPDATE employees SET salary = salary + salary * sal_raise
WHERE employee_id = empid; -- update a record in the employees table
COMMIT;
END;
/
BEGIN
-- use a FOR loop to process a series of numbers
FOR i in 1..10 LOOP
DBMS_OUTPUT.PUT_LINE('Number: ' || TO_CHAR(i) || ' Square: ' || TO_CHAR(i*i));
END LOOP;
END;
/
sequence of statements is executed, then control resumes at the top of the loop. If the
condition is false or null, the loop is bypassed and control passes to the next statement.
In Example 717, you find the first employee who has a salary over $15000 and is
higher in the chain of command than employee 120:
Example 717
The EXIT-WHEN statement lets you complete a loop if further processing is impossible
or undesirable. When the EXIT statement is encountered, the condition in the WHEN
clause is evaluated. If the condition is true, the loop completes and control passes to
the next statement. In Example 718, the loop completes when the value of total
exceeds 25,000:
Example 718
inside a subprogram. Any update to the value of the parameter inside the subprogram
is not accessible outside the subprogram.
Example 721
In Example 722, both a variable and a numeric literal are passed as a parameter to a
more complex procedure.
Example 722
Subprograms can also be declared in packages. You can create subprograms that are
stored in the database. These subprograms can be called from other subprograms,
packages, and SQL statements. See Subprograms and Packages: Usage Information.
7-16 Raptor Online Help
DECLARE -jobid
lastname
CURSOR c1
In Example 723, LIKE is used to specify the records to return with the query. For
information on LIKE, see Restricting Data Using the WHERE Clause.
See Also: PL/SQL User's Guide and Reference for information on
managing cursors with PL/SQL
determines its position in the collection. When declaring collections, you use a TYPE
definition.
To reference an element, use subscript notation with parentheses, as shown in
Example 724.
Example 724
You can use the %ROWTYPE attribute to declare a record that represents a row in a table
or a row from a query result set, without specifying the names and types for the fields.
When using %ROWTYPE, the record type definition is implied and the TYPE keyword is
not necessary, as shown in Example 726.
Example 726
See Also:
BEGIN
-- use values from SELECT for FOR LOOP processing
FOR someone IN (SELECT * FROM employees WHERE employee_id < 120 )
LOOP
DBMS_OUTPUT.PUT_LINE('First name = ' || someone.first_name ||
', Last name = ' || someone.last_name);
END LOOP;
END;
/
You can use a simple loop like the one shown here, or you can control the process
precisely by using individual statements to perform the query, retrieve data, and finish
processing.
To handle unexpected Oracle errors, you can use the OTHERS handler. Within this
handler, you can call the functions SQLCODE and SQLERRM to return the Oracle error
code and message text.
PL/SQL declares predefined exceptions globally in package STANDARD. You need not
declare them yourself. You can write handlers for predefined exceptions using the
names in Table 71.
Table 71
Exception
Description
ACCESS_INTO_NULL
CASE_NOT_FOUND
None of the choices in the WHEN clauses of a CASE statement is selected, and
there is no ELSE clause.
COLLECTION_IS_NULL
CURSOR_ALREADY_OPEN
DUP_VAL_ON_INDEX
INVALID_CURSOR
INVALID_NUMBER
LOGIN_DENIED
NO_DATA_FOUND
NOT_LOGGED_ON
PROGRAM_ERROR
ROWTYPE_MISMATCH
SELF_IS_NULL
A program attempts to call a MEMBER method, but the instance of the object
type has not been initialized. The built-in parameter SELF points to the object,
and is always the first parameter passed to a MEMBER method.
STORAGE_ERROR
SUBSCRIPT_BEYOND_COUNT
SUBSCRIPT_OUTSIDE_LIMIT A program references a nested table or varray element using an index number
(-1 for example) that is outside the legal range.
SYS_INVALID_ROWID
The conversion of a character string into a universal rowid fails because the
character string does not represent a valid rowid.
TIMEOUT_ON_RESOURCE
Description
TOO_MANY_ROWS
VALUE_ERROR
ZERO_DIVIDE
If you redeclare a global exception in a sub-block, the local declaration prevails. The
sub-block cannot reference the global exception, unless the exception is declared in a
labeled block and you qualify its name with the block label:
block_label.exception_name
Example 730 illustrates the scope rules:
Example 730
DECLARE
past_due EXCEPTION;
acct_num NUMBER;
BEGIN
DECLARE ---------- sub-block begins
past_due EXCEPTION; -- this declaration prevails
acct_num NUMBER;
due_date DATE := SYSDATE - 1; -- set on purpose to raise exception
todays_date DATE := SYSDATE;
BEGIN
IF due_date < todays_date THEN
RAISE past_due; -- this is not handled
END IF;
END; ------------- sub-block ends
EXCEPTION
WHEN past_due THEN -- does not handle raised exception
DBMS_OUTPUT.PUT_LINE('Handling PAST_DUE exception.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Could not recognize PAST_DUE_EXCEPTION in this scope.');
END;
/
The enclosing block does not handle the raised exception because the declaration of
past_due in the sub-block prevails. Though they share the same name, the two
past_due exceptions are different, just as the two acct_num variables share the same
name but are different variables. Thus, the RAISE statement and the WHEN clause refer
to different exceptions. To have the enclosing block handle the raised exception, you
must remove its declaration from the sub-block or define an OTHERS handler.
Example 731
In this example, if the SELECT INTO statement raises a ZERO_DIVIDE exception, the
local handler catches it and sets sal_calc to 2500. Execution of the handler is
complete, so the sub-block terminates, and execution continues with the INSERT
statement.
8
Subprograms and Packages: Usage
Information
The topic discusses the development of packages and subprograms with PL/SQL. It
includes the following topics:
Managing Subprograms
Managing Packages
Note:
Stored Subprograms
Packages
See Also: PL/SQL User's Guide and Reference to learn about PL/SQL
code and program units.
Subprograms are stored in a compact compiled form. When called, they are loaded
and processed immediately. Subprograms take advantage of shared memory, so that
only one copy of a subprogram is loaded into memory for execution by multiple users.
See Also: Oracle Database Express Edition 2 Day DBA Guide for
information on managing memory with Oracle Database
8.1.2 Packages
A package is a schema object that groups logically related PL/SQL types, variables,
and subprograms. Packages usually have two parts, a specification (spec) and a body;
sometimes the body is unnecessary. The specification is the interface to the package. It
declares the types, variables, constants, exceptions, cursors, and subprograms that can
be referenced from outside the package. The body defines the queries for the cursors
and the code for the subprograms.
Managing Packages
You can think of the spec as an interface and of the body as a black box. You can
debug, enhance, or replace a package body without changing the package spec.
The SQL CREATE PACKAGE statement is used to create package specification (specs).
The CREATE PACKAGE BODY statement is used to define the package body.
See Also:
The spec holds public declarations, which are visible to stored procedures and other
code outside the package. You must declare subprograms at the end of the spec after
all other items (except pragmas that name a specific function; such pragmas must
follow the function spec).
The body holds implementation details and private declarations, which are hidden
from code outside the package. Following the declarative part of the package body is
the optional initialization part, which holds statements that initialize package variables
and do any other one-time setup steps.
Managing Packages
my_pkg
NUMBER
NUMBER
NUMBER
AS
:= 3.14016408289008292431940027343666863227;
:= 2.71828182845904523536028747135266249775;
:= 0.0825
Package Name
Description
DBMS_ALERT
DBMS_APPLICATION_INFO
Description
DBMS_AQ
DBMS_AQADM
DBMS_AQELM
DBMS_AQIN
DBMS_CHANGE_NOTIFICATION
DBMS_CRYPTO
DBMS_DATAPUMP
DBMS_DB_VERSION
DBMS_DDL
DBMS_DEBUG
DBMS_DESCRIBE
DBMS_EPG
DBMS_ERRLOG
DMBS_FILE_TRANSFER
DMBS_FLASHBACK
DBMS_JOB
DBMS_LOB
DBMS_LOCK
Description
DBMS_METADATA
DBMS_OBFUSCATION_TOOLKIT
DBMS_OUTPUT
DBMS_PIPE
DBMS_RANDOM
DBMS_RESUMABLE
DBMS_ROWID
DBMS_SCHEDULER
DBMS_SERVER_ALERT
DBMS_SESSION
DBMS_SQL
DBMS_TDB
DBMS_TTS
DBMS_TYPES
DBMS_UTILITY
DBMS_WARNING
DBMS_XDB
DBMS_XDB_VERSION
DBMS_XDBT
DBMS_XDBZ
DBMS_XMLDOM
DBMS_XMLGEN
DBMS_XMLPARSER
DMBS_XMLQUERY
Description
DBMS_XMLSAVE
DBMS_XMLSCHEMA
DBMS_XMLSTORE
DBMS_XPLAN
DBMS_XSLPROCESSOR
HTF
HTMLDB_APPLICATION
HTMLDB_CUSTOM_AUTH
HTMLDB_ITEM
HTMLDB_UTIL
HTP
OWA_CACHE
OWA_COOKIE
OWA_CUSTOM
OWA_IMAGE
OWA_OPT_LOCK
OWA_PATTERN
OWA_SEC
OWA_TEXT
OWA_UTIL
UTL_COLL
UTL_COMPRESS
UTL_DBWS
Description
UTL_ENCODE
UTL_FILE
UTL_HTTP
UTL_I18N
UTL_INADDR
UTL_LMS
UTL_MAIL
UTL_RAW
UTL_RECOMP
UTL_REF
UTL_SMTP
UTL_TCP
UTL_URL
9
Triggers: Usage Information
This topic discusses the use of database triggers with Oracle Express. Triggers are
database objects that can be created with PL/SQL code. This topic includes the
following topics:
Overview of Triggers
Designing Triggers
See Also:
Types of Triggers
Naming Triggers
See Also:
Overview of Triggers
The SQL statement or the system event, database event, or DDL event that fires
the trigger body. The options include DELETE, INSERT, and UPDATE. One, two, or
all three of these options can be included in the triggering statement specification.
The table, view, DATABASE, or SCHEMA associated with the trigger.
Overview of Triggers
Use a BEFORE row trigger to modify the row before the row data is written to disk.
Use an AFTER row trigger to obtain, and perform operations, using the row Id.
BEFORE row triggers are slightly more efficient than AFTER
row triggers. With AFTER row triggers, affected data blocks must be
read (logical read, not physical read) once for the trigger and then
again for the triggering statement. Alternatively, with BEFORE row
triggers, the data blocks must be read only once for both the triggering
statement and the trigger.
Note:
Overview of Triggers
A trigger fired by an UPDATE statement has access to both old and new column
values for both BEFORE and AFTER row triggers.
A trigger fired by a DELETE statement has meaningful access to :OLD column
values only. Because the row no longer exists after the row is deleted, the :new
values are NULL and cannot be modified.
Old and new values are available in both BEFORE and AFTER row triggers. A new
column value can be assigned in a BEFORE row trigger, but not in an AFTER row
trigger (because the triggering statement takes effect before an AFTER row trigger is
fired). If a BEFORE row trigger changes the value of NEW.column, then an AFTER row
trigger fired by the same statement sees the change assigned by the BEFORE row
trigger.
Correlation names can also be used in the Boolean expression of a WHEN clause. A
colon (:) must precede the OLD and NEW qualifiers when they are used in a trigger
body, but a colon is not allowed when using the qualifiers in the WHEN clause.
Designing Triggers
Designing Triggers
Note:
Statements inside a trigger can reference remote schema objects. However, pay special
attention when calling remote procedures from within a local trigger. If a timestamp or
signature mismatch is found during execution of the trigger, then the remote
procedure is not run, and the trigger is invalidated.
Have the ALTER privilege for the table in the triggering statement, or
10
SQL*Plus: Usage Information
SQL*Plus is an interactive and batch command-line query tool that is installed with
Oracle Database. This topic includes the following topics:
Overview of SQL*Plus
Using SQL*Plus
See Also:
You can use SQL*Plus to generate reports interactively, to generate reports as batch
processes, and to output the results to text file, to screen, or to HTML file for browsing
on the Internet.
Using SQL*Plus
FIRST_NAME
-------------------David
Valli
Diana
Nancy
Daniel
LAST_NAME
----------------------Austin
Pataballa
Lorentz
Greenberg
Faviet
Using SQL*Plus
110 John
6 rows selected.
Chen
Note that a terminating semi-colon (;) is optional with SQL *Plus commands, but
required with SQL statements.
Null? Type
-------- -----------NOT NULL NUMBER(6)
VARCHAR2(20)
NOT NULL VARCHAR2(25)
NOT NULL VARCHAR2(25)
VARCHAR2(20)
NOT NULL DATE
NOT NULL VARCHAR2(10)
NUMBER(8,2)
NUMBER(2,2)
NUMBER(6)
NUMBER(4)
Using SQL*Plus
A SQL script file is executed with a START or @ command. For example, on a Windows
environment you could execute a SQL script as follows:
SQL> @c:\my_scripts\my_sql_script.sql
A SQL script file could be executed on a Linux environment as follows:
SQL> START /home/cjones/my_scripts/my_sql_script.sql
You can use SET ECHO ON to cause a script to echo each statement that is executed. You
can use SET TERMOUT OFF to prevent the script output from displaying on the screen.
When running a script, you should include the full path name unless the script is
located in the directory where SQL*Plus was launched.
For information on using bind variables in PL/SQL code, see Using Bind Variables.
Defining a Variable
-- prompt for employee_id in a query, you need to enter a valid Id such as 125
SELECT employee_id, last_name, job_id FROM employees WHERE employee_id = &emp_id;
When you run the previous SELECT statement, the output is similar to:
Enter value for emp_id: 125
...
EMPLOYEE_ID LAST_NAME
JOB_ID
Using SQL*Plus
Using SQL*Plus
11
Working in a Global Environment
This topic describes how to use Oracle's database access products with Unicode and
provides useful information for SQL and PL/SQL programming in a globalization
support environment. It includes the following topics:
Language Support
Working in a Global Environment 11-1
The database enables you to store, process, and retrieve data in native languages.
Through the use of Unicode databases and data types, the Oracle database
supports most contemporary languages.
See "Setting NLS Parameters".
Territory Support
The database supports cultural conventions that are specific to geographical
locations. The default local time format, date format, and numeric and monetary
conventions depend on the local territory setting.
See "Language and Territory Parameters".
Calendars Feature
Oracle supports seven different calendar systems in use around the world:
Gregorian, Japanese Imperial, ROC Official (Republic of China), Thai Buddha,
Persian, English Hijrah, and Arabic Hijrah.
See "Calendar Definitions".
Linguistic Sorting
Oracle provides linguistic definitions for culturally accurate sorting and case
conversion.
See "Linguistic Sorting and Searching".
Character Semantics
Oracle provides character semantics. It is useful for defining the storage
requirements for multibyte strings of varying widths in terms of characters instead
of bytes.
See "Length Semantics".
Unicode Support
Unicode is a universal encoded character set that enables you to store information
in any language, using a single character set. Oracle Database provides products
such as SQL and PL/SQL for inserting and retrieving Unicode data.
See "SQL and PL/SQL Programming with Unicode".
Calendar Definitions
Monetary Parameters
Length Semantics
Using NLS parameters within a SQL function to override the default values that
are set for the session in the initialization parameter file, set for the client with
environment variables, or set for the session by the ALTER SESSION statement.
For example:
TO_CHAR(hiredate,'DD/MON/YYYY','nls_date_language = FRENCH')
See Also:
Additional methods for setting the NLS parameters require that you shutdown and
restart the database. These techniques include the following:
Note:
The ALTER SESSION statement modifies only the session environment. The local
client NLS environment is not modified, unless the client explicitly retrieves the new
settings and modifies its local environment.
See Also:
NLS_LANGUAGE
NLS_TERRITORY
11.2.3.1 NLS_LANGUAGE
The NLS_LANGUAGE parameter can be set to any valid language name and the default
is derived from the NLS_LANG setting. NLS_LANGUAGE specifies the default
conventions for the following session characteristics:
Example 111 and Example 112 show the results from setting NLS_LANGUAGE to
different values. In Example 111, the ALTER SESSION statement is issued to set NLS_
LANGUAGE to Italian.
Example 111
NLS_LANGUAGE=ITALIAN
HIRE_DATE
SALARY
--------- ---------30-SET-97
962.5
07-MAR-98
975
07-DIC-99
862.5
Example 112
NLS_LANGUAGE=GERMAN
HIRE_DATE
SALARY
--------- ---------30-SEP-97
962.5
07-MRZ-98
975
07-DEZ-99
862.5
Note that the language of the month abbreviations has changed to German.
See Also:
11.2.3.2 NLS_TERRITORY
The NLS_TERRITORY parameter can be set to any valid territory name and the default
is derived from the NLS_LANG setting. NLS_TERRITORY specifies the conventions for
the following default date and numeric formatting characteristics:
Date format
The territory can be modified dynamically during the session by specifying the new
NLS_TERRITORY value in an ALTER SESSION statement. For example, to change the
territory to France during a session, issue the following ALTER SESSION statement:
ALTER SESSION SET NLS_TERRITORY = France;
Modifying NLS_TERRITORY resets all derived NLS session parameters to default
values for the new territory. Example 113 and Example 114 show behavior that
results from different settings of NLS_TERRITORY and NLS_LANGUAGE.
Example 113
NLS_LANGUAGE=AMERICAN, NLS_TERRITORY=AMERICA
-------------------$24,000.00
$17,000.00
$17,000.00
In Example 114 an ALTER SESSION statement is issued to change the territory to
Germany.
Example 114
NLS_LANGUAGE=AMERICAN, NLS_TERRITORY=GERMANY
Date Formats
Time Formats
Country
Description
Example
Estonia
dd.mm.yyyy
28.02.2005
Germany
dd.mm.rr
28.02.05
Description
Example
China
yyyy-mm-dd
2005-02-28
UK
dd/mm/yyyy
28/02/2005
US
mm/dd/yyyy
02/28/2005
NLS_DATE_FORMAT
NLS_DATE_LANGUAGE
The results of the query in Example 115 are similar to the following:
HIRE_DATE
--------30-SEP-97
07-MAR-98
07-DEC-99
Short
---------9/30/1997
3/7/1998
12/7/1999
Long
----------------------------Tuesday, September 30, 1997
Saturday, March 07, 1998
Tuesday, December 07, 1999
To add string literals to the date format, enclose the string literal with double quotes.
Note that when double quotes are included in the date format, the entire value must
be enclosed by single quotes. For example:
NLS_DATE_FORMAT = '"Date: "MM/DD/YYYY'
11.2.4.1.2 NLS_DATE_LANGUAGE The NLS_DATE_LANGUAGE parameter specifies the
language for the day and month names produced by the TO_CHAR and TO_DATE
functions. NLS_DATE_LANGUAGE overrides the language that is specified implicitly by
NLS_LANGUAGE. NLS_DATE_LANGUAGE has the same syntax as the NLS_LANGUAGE
parameter, and all supported languages are valid values.
NLS_DATE_LANGUAGE also determines the language used for:
Month and day abbreviations returned by the TO_CHAR and TO_DATE functions
Month and day abbreviations used by the default date format (NLS_DATE_
FORMAT)
Example 116 shows how to use NLS_DATE_LANGUAGE to set the date language to
French.
Example 116
You should see output similar to the following, depending on the current system date:
TO_CHAR(SYSDATE,'DAY:DDMON
-------------------------Jeudi
:06 Octobre
2005
The default date format uses the month abbreviations determined by NLS_DATE_
LANGUAGE. For example, if the default date format is DD-MON-YYYY and NLS_DATE_
LANGUAGE = FRENCH, then insert a date as follows:
INSERT INTO table_name VALUES ('12-Fvr.-1997');
Oracle Database SQL Reference for information on date
format models
See Also:
Country
Description
Example
Estonia
hh24:mi:ss
13:50:23
Germany
hh24:mi:ss
13:50:23
China
hh24:mi:ss
13:50:23
UK
hh24:mi:ss
13:50:23
US
hh:mi:ssxff am
1:50:23.555 PM
NLS_TIMESTAMP_FORMAT
NLS_TIMESTAMP_TZ_FORMAT
Setting NLS_TIMESTAMP_TZ_FORMAT
Calendar Formats
NLS_CALENDAR
11.2.5.1.1 First Day of the Week Some cultures consider Sunday to be the first day of the
week. Others consider Monday to be the first day of the week. A German calendar
starts with Monday.
The first day of the week is determined by the NLS_TERRITORY parameter.
11.2.5.1.2 First Calendar Week of the Year Some countries use week numbers for
scheduling, planning, and bookkeeping. Oracle supports this convention. In the ISO
standard, the week number can be different from the week number of the calendar
year. For example, 1st Jan 1988 is in ISO week number 53 of 1987. An ISO week
always starts on a Monday and ends on a Sunday.
To support the ISO standard, Oracle provides the IW date format element. It returns
the ISO week number.
The first calendar week of the year is determined by the NLS_TERRITORY parameter.
11-10 Raptor Online Help
11.2.5.1.3 Number of Days and Months in a Year Oracle supports six calendar systems in
addition to Gregorian, the default:
Japanese Imperialuses the same number of months and days as Gregorian, but
the year starts with the beginning of each Imperial Era
ROC Officialuses the same number of months and days as Gregorian, but the
year starts with the founding of the Republic of China
Persianhas 31 days for each of the first six months. The next five months have 30
days each. The last month has either 29 days or 30 days (leap year).
First Year of Era The Islamic calendar starts from the year of the Hegira.
The Japanese Imperial calendar starts from the beginning of an Emperor's reign. For
example, 1998 is the tenth year of the Heisei era.
11.2.5.2 NLS_CALENDAR
Many different calendar systems are in use throughout the world. NLS_CALENDAR
specifies which calendar system Oracle uses. The default value is Gregorian. The
value can be any valid calendar format name.
NLS_CALENDAR can have one of the following values:
Arabic Hijrah
English Hijrah
Gregorian
Japanese Imperial
Persian
Thai Buddha
NLS_CALENDAR='English Hijrah'
You should see output similar to the following, depending on the current system date:
SYSDATE
-------------------24 Ramadan
1422
Numeric Formats
NLS_NUMERIC_CHARACTERS
Country
Numeric Formats
Estonia
1 234 567,89
Germany
1.234.567,89
China
1,234,567.89
UK
1,234,567.89
US
1,234,567.89
Numeric formats are derived from the setting of the NLS_TERRITORY parameter, but
they can be overridden by the NLS_NUMERIC_CHARACTERS parameter.
11.2.6.2 NLS_NUMERIC_CHARACTERS
The NLS_NUMERIC_CHARACTERS parameter specifies the decimal character and
group separator. The group separator is the character that separates integer groups to
show thousands and millions, for example. The group separator is the character
returned by the G number format mask. The decimal character separates the integer
and decimal parts of a number. Setting NLS_NUMERIC_CHARACTERS overrides the
default values derived from the setting of NLS_TERRITORY. The value can be any two
valid numeric characters for the decimal character and group separator.
Any character can be the decimal character or group separator. The two characters
specified must be single-byte, and the characters must be different from each other.
The characters cannot be any numeric character or any of the following characters:
plus (+), hyphen (-), less than sign (<), greater than sign (>). Either character can be a
space.
To set the decimal character to a comma and the grouping separator to a period, define
NLS_NUMERIC_CHARACTERS as follows:
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ",.";
SQL statements can include numbers represented as numeric or text literals. Numeric
literals are not enclosed in quotes. They are part of the SQL language syntax and
always use a dot as the decimal character and never contain a group separator. Text
literals are enclosed in single quotes. They are implicitly or explicitly converted to
numbers, if required, according to the current NLS settings.
The following SELECT statement formats the number 4000 with the decimal character
and group separator specified in the ALTER SESSION statement:
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ",.";
SELECT TO_CHAR(4000, '9G999D99') FROM DUAL;
Currency Formats
NLS_CURRENCY
NLS_ISO_CURRENCY
NLS_DUAL_CURRENCY
Country
Example
Estonia
1 234,56 kr
Germany
1.234,56
China
1,234.56
UK
1,234.56
US
$1,234.56
11.2.7.2 NLS_CURRENCY
NLS_CURRENCY specifies the character string returned by the L number format mask,
the local currency symbol. Setting NLS_CURRENCY overrides the default setting
defined implicitly by NLS_TERRITORY. The value can be any valid currency symbol
string.
Example 119
$012,000.00
$014,000.00
$013,500.00
$012,000.00
$011,500.00
$013,000.00
$012,000.00
11.2.7.3 NLS_ISO_CURRENCY
NLS_ISO_CURRENCY specifies the character string returned by the C number format
mask, the ISO currency symbol. Setting NLS_ISO_CURRENCY overrides the default
value defined implicitly by NLS_TERRITORY. The value can be any valid string.
Local currency symbols can be ambiguous. For example, a dollar sign ($) can refer to
US dollars or Australian dollars. ISO specifications define unique currency symbols for
specific territories or countries. For example, the ISO currency symbol for the US
dollar is USD. The ISO currency symbol for the Australian dollar is AUD.
NLS_ISO_CURRENCY has the same syntax as the NLS_TERRITORY parameter, and all
supported territories are valid values.
To specify the ISO currency symbol for France, set NLS_ISO_CURRENCY as shown in
Example 1110.
Example 1110 Setting NLS_ISO_CURRENCY
-- set NLS_ISO_CURRENCY to France
ALTER SESSION SET NLS_ISO_CURRENCY = FRANCE;
-- display the salary of selected employees
SELECT TO_CHAR(salary, 'C099G999D99') "Salary" FROM employees
WHERE department_id = 60;
11.2.7.4 NLS_DUAL_CURRENCY
Use NLS_DUAL_CURRENCY to override the default dual currency symbol defined
implicitly by NLS_TERRITORY. The value can be any valid symbol.
NLS_DUAL_CURRENCY was introduced to support the euro currency symbol during
the euro transition period.
Treatment of letter accents also differs among languages. For example, in Danish, is
sorted after Z, while Y and are considered to be variants of the same letter.
You can define how to sort data by using linguistic sort parameters. The basic
linguistic definition treats strings as sequences of independent characters.
This topic includes the following topics:
NLS_SORT
NLS_COMP
11.2.8.1 NLS_SORT
The NLS_SORT parameter specifies the collating sequence for ORDER BY queries. It
overrides the default NLS_SORT value that is derived from NLS_LANGUAGE. The value
of NLS_SORT can be BINARY or any valid linguistic sort name:
NLS_SORT = BINARY | sort_name
If the value is BINARY, then the collating sequence is based on the numeric code of the
characters in the underlying encoding scheme. Depending on the data type, this will
either be in the binary sequence order of the database character set or the national
character set. If the value is a named linguistic sort, sorting is based on the order of the
defined sort. Most, but not all, languages supported by the NLS_LANGUAGE parameter
also support a linguistic sort with the same name.
You can set the NLS_SORT parameter to change the linguistic sorting behavior of the
your SQL session. Spain traditionally treats ch, ll as well as as letters of their own,
ordered after c, l and n respectively. Example 1111 and Example 1112 illustrate the
effect of using a Spanish sort against the employee names Chen and Chung. In
Example 1111, the NLS_SORT parameter is set to BINARY.
In Example 1111, LIKE is used to specify the records to return with the query. For
information on LIKE, see Restricting Data Using the WHERE Clause.
Example 1111 Setting NLS_SORT to BINARY
-- set the NLS_SORT for this user session
ALTER SESSION SET NLS_SORT=binary;
-- select the last name of those employees whose last name begin with C
SELECT last_name FROM employees
WHERE last_name LIKE 'C%' ORDER BY last_name;
-- select the last name of those employees whose last name begin with C
SELECT last_name FROM employees
WHERE last_name LIKE 'C%' ORDER BY last_name;
11.2.8.2 NLS_COMP
When using comparison operators, characters are compared according to their binary
codes in the designated encoding scheme. A character is greater than another if it has a
higher binary code. Because the binary sequence of characters may not match the
linguistic sequence for a particular language, such comparisons might not be
linguistically correct.
The value of the NLS_COMP parameter affects the comparison behavior of SQL
operations. The value can be BINARY (default) or LINGUISTIC. You can use NLS_
COMP to avoid the cumbersome process of using the NLSSORT function in SQL
statements when you want to perform a linguistic comparison instead of a binary
comparison. When NLS_COMP is set to LINGUISTIC, SQL operations perform a
linguistic comparison based on the value of NLS_SORT.
Example 1113 and Example 1114 illustrate the effect of performing a binary
comparison follow by a Spanish linguistic sensitive comparison against the employee
names. In Example 1113 the NLS_COMP parameter is set to BINARY while NLS_SORT
is set to Spanish.
Example 1113 Setting NLS_COMP to BINARY
-- set NLS_SORT and NLS_COMP for this user session
ALTER SESSION SET NLS_SORT=spanish_m NLS_COMP=binary;
-- select the last name of those employees whose last name begin with C
SELECT last_name FROM employees
WHERE last_name LIKE 'C%';
Chen
Chung
Colmenares
In Example 1114 the NLS_COMP parameter is set to LINGUISTIC while NLS_SORT is
set to Spanish.
Example 1114 Setting NLS_COMP to BINARY
-- set NLS_SORT and NLS_COMP for this user session
ALTER SESSION SET NLS_SORT=spanish_m NLS_COMP=linguistic;
-- select the last name of those employees whose last name begin with C
SELECT last_name FROM employees
WHERE last_name LIKE 'C%';
Append _CI to an Oracle sort name for a case-insensitive sort. For example:
BINARY_CI: accent sensitive and case insensitive binary sort
GENERIC_M_CI: accent sensitive and case insensitive GENERIC_M sort
Character semantics is useful for defining the storage requirements for multibyte
strings of varying widths. For example, in a Unicode database (AL32UTF8), suppose
that you need to define a VARCHAR2 column that can store up to five Chinese
characters together with five English characters. Using byte semantics, this column
requires 15 bytes for the Chinese characters, which are three bytes long, and 5 bytes for
the English characters, which are one byte long, for a total of 20 bytes. Using character
semantics, the column requires 10 characters.
The expressions in the following list use byte semantics. Note the BYTE qualifier in the
VARCHAR2 expression and the B suffix in the SQL function name.
VARCHAR2(20 BYTE)
SUBSTRB(string, 1, 20)
The expressions in the following list use character semantics. Note the CHAR qualifier
in the VARCHAR2 expression.
VARCHAR2(20 CHAR)
SUBSTR(string, 1, 20)
11.2.9.1 NLS_LENGTH_SEMANTICS
The NLS_LENGTH_SEMANTICS parameter specifies BYTE (default) or CHAR semantics.
By default, the character data types CHAR and VARCHAR2 are specified in bytes, not
characters. Hence, the specification CHAR(20) in a table definition allows 20 bytes for
storing character data.
NLS_LENGTH_SEMANTICS enables you to create CHAR, VARCHAR2, and LONG columns
using either byte or character length semantics. NCHAR, NVARCHAR2, CLOB, and NCLOB
columns are always character-based. Existing columns are not affected.
Example 1115 shows an example of creating a table. When the database character set
is WE8MSWIN1252, the last_name column of the table can hold up to 10 Western
European characters, occupying a maximum of 10 bytes. When the database character
set is Unicode (AL32UTF8), last_name can still hold up to 10 Unicode characters
regardless of the language; however, it can occupy a maximum of 40 bytes.
Example 1115 Length Semantics and CREATE TABLE
CREATE TABLE temp_employees_table
( employee_id NUMBER(4), last_name VARCHAR2(10 CHAR), job_id VARCHAR2(9),
manager_id NUMBER(4), hire_date DATE, salary NUMBER(7,2),
department_id NUMBER(2)) ;
See Also:
procedural languages. Both SQL and PL/SQL can be embedded in other programming
languages.
Oracle Express provides products such as SQL and PL/SQL for inserting and
retrieving Unicode data. Data is transparently converted between the database and
client programs, which ensures that client programs are independent of the database
character set and national character set. In addition, client programs are sometimes
even independent of the character data type, such as NCHAR or CHAR, used in the
database.
The PL/SQL and SQL engines process PL/SQL programs and SQL statements on
behalf of client-side programs such as server-side PL/SQL stored procedures. They
allow PL/SQL programs to declare CHAR, VARCHAR2, NCHAR, and NVARCHAR2
variables and to access SQL CHAR and NCHAR data types in the database.
This topic describes Unicode-related features in SQL and PL/SQL that you can deploy
for multilingual applications. It includes the following topics:
Overview of Unicode
You can create a Unicode database that enables you to store UTF-8 encoded
characters as SQL CHAR data types.
You can support multilingual data in specific columns by using Unicode data
types. You can store Unicode characters into columns of the SQL NCHAR data types
regardless of how the database character set has been defined. The NCHAR data
type is an exclusively Unicode data type.
Note:
Put a prefix N before a string literal that is enclosed with single quote marks. This
explicitly indicates that the following string literal is an NCHAR string literal. For
example, N'rsum' is an NCHAR string literal. This has the same limitation as
enclosing the string literal with single quote marks, where the data can be lost
during the conversion to the server's database character set. To avoid the potential
loss of data, you can set the environment variable ORA_NCHAR_LITERAL_
REPLACE to true. This will transparently replace the N' internally and preserve
the text literal for SQL processing. By default, this environment variable is set to
false to maintain backward compatibility.
Use the NCHR(n) SQL function, which returns a unit of character code in the
national character set, which is AL16UTF16 or UTF8. The result of concatenating
several NCHR(n) functions is NVARCHAR2 data. In this way, you can bypass the
client and server character set conversions and create an NVARCHAR2 string
directly. For example, NCHR(32) represents a blank character.
Because NCHR(n) is associated with the national character set, portability of the
resulting value is limited to applications that run with the same national character
set. If this is a concern, then use the UNISTR function to remove portability
limitations.
The last two methods can be used to encode any Unicode string literals.
Such a query can be made independent of the current date language by using a
statement similar to the following:
SELECT last_name FROM employees
WHERE hire_date > TO_DATE('01-JAN-1999','DD-MON-YYYY',
'NLS_DATE_LANGUAGE = AMERICAN');
In this way, SQL statements that are independent of the session language can be
defined where necessary. Such statements are necessary when string literals appear in
SQL statements in views, CHECK constraints, or triggers.
Only SQL statements that must be independent of the
session NLS parameter values should explicitly specify optional
NLS parameters in locale-dependent SQL functions. Using session
default values for NLS parameters in SQL functions usually results
in better performance.
Note:
All character functions support both single-byte and multibyte characters. Except
where explicitly stated, character functions operate character by character, rather than
byte by byte.
The rest of this topic includes the following topics:
SQL Function
TO_DATE
NLS_DATE_LANGUAGE,
NLS_CALENDAR
Table 115 (Cont.) SQL Functions and Their Valid NLS Parameters
SQL Function
TO_NUMBER
NLS_NUMERIC_CHARACTERS,
NLS_CURRENCY,
NLS_DUAL_CURRENCY,
NLS_ISO_CURRENCY,
TO_CHAR
NLS_DATE_LANGUAGE,
NLS_NUMERIC_CHARACTERS,
NLS_CURRENCY,
NLS_ISO_CURRENCY,
NLS_DUAL_CURRENCY,
NLS_CALENDAR
TO_NCHAR
NLS_DATE_LANGUAGE,
NLS_NUMERIC_CHARACTERS,
NLS_CURRENCY,
NLS_ISO_CURRENCY,
NLS_DUAL_CURRENCY,
NLS_CALENDAR
NLS_UPPER
NLS_SORT
NLS_LOWER
NLS_SORT
NLS_INITCAP
NLS_SORT
NLSSORT
NLS_SORT
Note:
NLS_LANGUAGE
NLS_TERRITORY
NLS_DATE_FORMAT
Index
Symbols
:= assignment operator,
7-6
A
ACCESS_INTO_NULL exception, 7-22
AFTER triggers
correlation names and, 9-4
specifying, 9-2
aliases
tables, 6-6
ALTER INDEX statement, 6-16
ALTER TABLE statement, 6-16, 6-17
analyzing tables, 1-9
anonymous PL/SQL blocks, 7-2
apostrophes, 7-7
arrays
PL/SQL, 7-17
assignment operator, 7-6
assignments
IN OUT parameters, 7-15
associations
file types, 3-20
attributes
%ROWTYPE, 7-10
%TYPE, 7-11
B
BEFORE triggers
correlation names and,
specifying, 9-2
BEGIN
block structure, 7-3
BINARY_DOUBLE
data types, 5-5
BINARY_FLOAT
data types, 5-5
bind variables
for reports, 1-20
PL/SQL, 7-21
blocks
anonymous, 7-2
BEGIN, 7-3
DECLARE, 7-3
9-4
END, 7-3
EXCEPTION, 7-3
nesting, 7-1, 7-2
structure, 7-3
BODY
CREATE PACKAGE SQL statement, 8-3
with SQL CREATE PACKAGE statement, 8-3
Boolean
literals, 7-7
breakpoints
creating and editing, 3-23
C
C number format mask, 11-14
calendars
parameter, 11-10
CASE expressions
overview, 7-12
case sensitivity
identifier, 7-6
string literal, 7-7
CASE_NOT_FOUND exception, 7-22
century
date format masks, 5-7
character data
storing, 5-1
character literals, 7-7
quoting, 6-3
using in SQL statements, 6-3
character set
national, 11-20
character sets
national, 11-20
check constraints, 3-11, 4-5
how to use, 4-6
Check for Updates feature, 3-2
coalescing an index, 1-6
code fragments, 1-19
COLLECTION_IS_NULL exception, 7-22
collections
PL/SQL, 7-17
column alias
using with SELECT, 6-4
column constraints, 4-4
columns
Index-1
Index-2
creating
functions, 8-2
packages, 8-3
procedures, 8-2
creating a constraint
using SQL statement, 6-16
creating a table
using SQL statement, 6-15
creating an index
SQL statement, 6-16
creating indexes for use with constraints, 4-7
currencies
formats, 11-13
CURSOR_ALREADY_OPEN exception, 7-22
cursors
definition, 7-17
explicit, 7-17
implicit, 7-17
customizing Raptor
setting preferences, 1-26
D
data
entering and modifying, 1-12
integrity checking on input, 5-3
data definition language (DDL)
SQL statements, 6-15
data integrity rules
as constraints, 4-4
data manipulation language
described, 6-7
data structures
PL/SQL, 7-17
data types
BINARY_DOUBLE, 5-5
BINARY_FLOAT, 5-5
CHAR, 5-1
character, 5-1
creating, 3-15
description, 4-2
floating-point number, 5-4
in table columns, 4-2
NCHAR, 5-1
NUMBER, 5-3
numeric, 5-2
NVARCHAR2, 5-1
overview, 5-1
VARCHAR2, 5-1
database connections
creating, editing, or selecting, 3-2
explanation, 1-11
database link
creating and editing, 3-4
database objects, 1-5
managing, 4-1
naming, 4-1
database resident program units, 8-1
database triggers, 9-1
date and time data
storing, 5-5
date and time parameters, 11-7
DATE data type, 5-5
date formats, 11-7, 11-8
dates
ISO standard, 11-10
NLS_DATE_LANGUAGE parameter, 11-9
datetime
literals, 7-7
days
format element, 11-9
DBMS_OUTPUT
procedures for displaying output in PL/SQL, 7-9
DBMS_OUTPUT package
displaying output, 7-9
displaying output from PL/SQL, 8-5
using PUT_LINE to display output, 7-9
debugging PL/SQL function or procedure, 1-13
dialog box, 3-22
declarations
constants, 7-4
exceptions in PL/SQL, 7-23
PL/SQL %ROWTYPE and %TYPE, 7-10
PL/SQL subprograms, 7-15
using NOT NULL constraint, 7-8
declarative part
of PL/SQL block, 7-3
DECLARE
block structure, 7-3
decryption
data in a table column, 1-10
DELETE statement, 6-7, 6-8
column values and triggers, 9-4
dependencies
schema objects
trigger management, 9-6
DESCRIBE command
SQL*Plus, 10-3
design considerations
Oracle Database, 4-1
dialog boxes and tabs, 3-1
disabled constraints, 1-22
disabled trigger
definition, 9-4
disabling
triggers, 9-4
displaying output
from PL/SQL, 7-9
setting SERVEROUTPUT, 7-9, 8-5
using DBMS_OUTPUT.PUT_LINE, 7-9
displaying PL/SQL output
with DBMS_OUTPUT, 7-9
distributed databases
triggers and, 9-6
dot notation, 7-11
DROP INDEX statement, 6-16
DROP SEQUENCE statement, 6-17
DROP SYNONYM statement, 6-18
DROP TABLE statement, 6-17
dropping
indexes, 4-10
dropping a sequence
using SQL statement, 6-17
dropping a synonym
using SQL statement, 6-18
dropping a table
using SQL statement, 6-17
DUAL
dummy table, 6-10
dummy table
DUAL, 6-10
DUP_VAL_ON_INDEX exception, 7-22
dynamic SQL, 7-19
E
enabled trigger
definition, 9-4
enabling
triggers, 9-4
encryption
data in a table column, 1-9
END
block structure, 7-3
ensuring data integrity
with constraints, 4-3
entering data in tables, 1-12
error handling
PL/SQL, 7-21
EXCEPTION
block structure, 7-3
exception handlers
PL/SQL, 7-21
exception-handling part
of PL/SQL block, 7-3
exceptions
advantages of PL/SQL, 7-23
declaring in PL/SQL, 7-23
during trigger execution, 9-4
list of predefined in PL/SQL, 7-22
predefined in PL/SQL, 7-21
scope rules in PL/SQL, 7-23
executable part
of PL/SQL block, 7-3
execution plan, 1-18
EXIT-WHEN statement
overview, 7-14
EXPLAIN PLAN
execution plan, 1-18
exporting
table data, 1-9, 3-20
extensions
Raptor, 1-30
F
FALSE value, 7-7
file I/O, 8-5
file types
associating with Raptor, 3-20
Index-3
floating-point number
data types, 5-4
floating-point numbers, 5-2
folders
for user-defined reports, 1-25, 3-16
FOR EACH ROW clause, 9-3
foreign key
referential integrity between tables, 4-6
foreign keys, 3-11
format elements
day, 11-9
month, 11-9
format masks, 11-12
TO_DATE function, 5-7
formats
currency, 11-13
date, 11-8
numeric, 11-12
time, 11-9
Freeze View
pinning an objects display, 1-3, 1-12
FROM clause, 3-18
FUNCTION
with CREATE statement, 8-2
functions
compiling, 1-6
creating, 8-2
creating and editing, 3-6
debugging, 3-22
execute, 8-3
managing, 8-3
overview, 8-1
running, 3-22
SQL aggregate, 6-14
SQL arithmetic operators, 6-12
SQL character, 6-11
SQL date, 6-13
SQL numeric, 6-12
G
globalization support
altering NLS parameter settings, 11-3
calendar definitions, 11-10
date and time parameter settings, 11-7
default values for NLS parameters in SQL
functions, 11-22
features, 11-1
language and territory parameter settings, 11-5
linguistic sorting and searching, 11-14
locale, 11-4
monetary parameter settings, 11-13
National Language Support (NLS) features, 11-1
NLS_LANG parameter setting, 11-4
numeric and list parameter settings, 11-11
overview, 11-1
programming with unicode, 11-18
setting up the environment, 11-3
specifying values for NLS parameters in SQL
functions, 11-22
Index-4
H
HAVING clause, 3-19
help
using the online help, 1-31
HELP command
SQL*Plus, 10-2
I
identifiers
maximum length, 7-6
IF-THEN-ELSE statement
overview, 7-11
indexes, 3-12
ascending, 4-7
choose the correct order of columns for
composites, 4-9
coalescing, 1-6
column, 4-7
concatenated, 4-7
creating and editing, 3-5
creating for use with constraints, 4-7
descending, 4-7
drop if not required, 4-10
dropping, 4-10
explanation, 1-6
function-based, 4-7
guidelines, 4-8
limit the number, 4-9
making unusable, 1-6
managing, 4-6
normal type, 4-7
order of columns, 4-9
rebuilding, 1-6
single column, 4-7
types, 4-7
initialization
using DEFAULT, 7-8
INSERT statement, 6-7
column values and triggers, 9-3
integrity constraints
CHECK, 4-6
triggers vs., 9-5
INTERVAL DAY TO SECOND data type, 5-5
INTERVAL YEAR TO MONTH data type, 5-5
introduction, 1-1, 4-1, 5-1, 6-1, 7-1, 8-1, 9-1, 10-1, 11-1
INVALID_CURSOR exception, 7-22
INVALID_NUMBER exception, 7-22
ISO standard date format, 11-10
J
joins
K
keywords
use in PL/SQL, 7-6
L
language support, 11-2
length semantics, 11-17
linguistic sorts
parameters, 11-14
link
database, 3-4
list parameter, 11-11
literals
Boolean, 7-7
character, 7-7
datetime, 7-7
numeric, 7-7
string, 7-7
types of PL/SQL, 7-7
local subprograms, 8-2
locale
globalization support, 11-4
locking a table, 1-9
LOGIN_DENIED exception, 7-22
LOOP statement
overview, 7-13
lowercase characters in object names
quotation marks required, 3-1
M
managing database objects
overview, 4-1
managing indexes, 4-6
managing tables, 4-2
materialized view logs, 1-7
materialized views, 1-7
maximum size
identifier, 7-6
modifying a constraint
using SQL statement, 6-16
modifying a table
using SQL statement, 6-17
modifying an index
SQL statement, 6-16
modifying data in tables, 1-12
modularity, 8-3
monetary parameters, 11-13
months
format element, 11-9
moving a table to another tablespace, 1-9
multi-line comments, 7-4
N
national character literals
quoting, 6-3
national character set, 11-20
National Language Support (NLS)
features, 11-1
globalization support, 11-1
NCHAR data type, 5-1, 11-20
NCHR SQL function, 11-21
nested tables
PL/SQL, 7-17
nesting
block, 7-1, 7-2
NEW correlation name, 9-3
NLS parameters
default values in SQL functions, 11-22
settings, 11-3
specifying in SQL functions, 11-22
unacceptable in SQL functions, 11-24
NLS_CALENDAR parameter, 11-11
NLS_COMP parameter, 11-16
NLS_CURRENCY parameter, 11-13
NLS_DATE_FORMAT parameter, 5-7, 11-8
NLS_DATE_LANGUAGE parameter, 11-8
NLS_DUAL_CURRENCY parameter, 11-14
NLS_INITCAP SQL function, 11-21
NLS_ISO_CURRENCY parameter, 11-14
NLS_LANG parameter, 11-4
choosing a locale, 11-4
NLS_LANGUAGE parameter, 11-5
NLS_LOWER SQL function, 11-21
NLS_NUMERIC_CHARACTERS parameter, 11-12
NLS_SORT parameter, 11-15
NLS_TERRITORY parameter, 11-6
NLS_TIMESTAMP_FORMAT parameter
parameters
NLS_TIMESTAMP_FORMAT, 11-9, 11-10
NLS_UPPER SQL function, 11-21
NLSSORT SQL function, 11-21
NO_DATA_FOUND exception, 7-22
NOT NULL constraint
using in variable declaration, 7-8
NOT_LOGGED_ON exception, 7-22
NUMBER data type, 5-3
numeric data types, 5-2
numeric formats, 11-12
numeric literals, 7-7
numeric parameters, 11-11
NVARCHAR2 data type, 5-1, 11-20
O
objects
database, 1-5
OLD correlation name, 9-3
online help
using, 1-31
Oracle Database
design considerations, 4-1
ORDER BY clause, 3-19
using with SELECT, 6-5
overview, 1-1, 4-1, 5-1, 6-1, 7-1, 8-1, 9-1, 10-1, 11-1
Index-5
P
PACKAGE
with SQL CREATE statement, 8-3
package
writing with PL/SQL, 8-3
PACKAGE BODY
with SQL CREATE statement, 8-3
packaged subprograms, 8-2
packages
accessing variables, 8-4
body, 8-2
creating, 8-3
creating and editing, 3-6
debugging, 3-22
guidelines for writing, 8-3
hidden declarations, 8-3
overview, 8-1
overview of Oracle supplied, 8-5
product-specific, 8-5
running, 3-22
specification, 8-2
understanding, 8-2
variables, 8-4
visibility of contents, 8-3
parameters
calendar, 11-10
linguistic sorts, 11-14
monetary, 11-13
NLS_CALENDAR, 11-11
NLS_COMP, 11-16
NLS_CURRENCY, 11-13
NLS_DATE_FORMAT, 11-8
NLS_DATE_LANGUAGE, 11-8
NLS_DUAL_CURRENCY, 11-14
NLS_ISO_CURRENCY, 11-14
NLS_LANG, 11-4
NLS_LANGUAGE, 11-5
NLS_NUMERIC_CHARACTERS, 11-12
NLS_SORT, 11-15
NLS_TERRITORY, 11-6
numeric, 11-11
setting, 11-4
time and date, 11-7
time zone, 11-9, 11-10
performance
index column order, 4-9
pinning an objects display, 1-3, 1-12
Index-6
PL/SQL, 7-1
%ROWTYPE attribute, 7-10
%TYPE attribute, 7-10
anonymous blocks, 7-2
arrays, 7-17
assigning values with SELECT INTO, 7-9
assignment operator, 7-6
bind variables, 7-21
block structure, 7-3
collections, 7-17
comments, 7-4
control structures, 7-11
cursor, 7-17
data structures, 7-17
declarations using DEFAULT, 7-8
declarations using NOT NULL, 7-8
declaring constants, 7-4
declaring variables, 7-4
DEFAULT keyword for assignments, 7-8
displaying output, 7-9, 8-5
entering and executing code, 7-2
error handling, 7-21
exception handling, 7-21
identifiers, 7-5
input data, 7-9
literals, 7-7
local subprograms, 7-15
nested tables, 7-17
output data, 7-9
overview of, 7-1
processing queries, 7-19
program units, 7-1
programming with unicode, 11-18
records, 7-18
SELECT INTO, 7-9
stored procedures, 7-2
trigger bodies, 9-3
using dynamic SQL, 7-19
using features, 7-2
variable assignments, 7-6
writing reusable code, 8-3
PL/SQL and SQL and Unicode, 11-19
PL/SQL subprograms
creating and editing, 3-6
debugging, 3-22
breakpoints, 3-23
running, 3-22
preferences
customizing Raptor, 1-26
primary key, 3-10
for a table, 4-5
PRIMARY KEY constraints
multiple columns in, 4-5
UNIQUE key constraint vs., 4-5
private synonyms, 3-7
privileges
needed on triggers, 9-6
triggers, 9-6
PROCEDURE
with CREATE statement, 8-2
procedures, 7-2
called by triggers, 9-6
compiling, 1-8
creating, 8-2
creating and editing, 3-6
execute, 8-3
managing, 8-3
overview, 8-1
stored procedures, 7-2
program units, 7-1, 8-3
PROGRAM_ERROR exception, 7-22
pseudocolumns
ROWNUM, 6-10
SYSDATE, 6-10
USER, 6-10
using in SQL statements, 6-10
public synonyms, 3-7
PUT_LINE
displaying output with, 7-9
Q
queries
in DML, 6-7
quotation marks
for name with lowercase characters, special
characters, or spaces, 3-1
quoting character literals, 6-3
R
raising exceptions
triggers, 9-4
Raptor preferences, 1-26
rebuilding an index, 1-6
recompiling
view, 1-10
records
definition, 7-10
PL/SQL, 7-18
Recycle bin, 1-8
report navigator, 1-20
reports, 1-20
bind variables for, 1-20
user-defined
creating and editing, 3-15
explanation, 1-25
folders for, 1-25, 3-16
reserved words
syntactic meaning in PL/SQL, 7-6
restrictions
system triggers, 9-6
ROLLBACK statement, 6-8, 6-9
row triggers
defining, 9-3
timing, 9-2
UPDATE statements and, 9-4
ROWNUM
pseudocolumn, 6-10
ROWTYPE attribute
declaring, 7-10
ROWTYPE_MISMATCH exception, 7-22
running PL/SQL function or procedure, 1-13
dialog box, 3-22
S
scale
greater than precision, 5-3
schema objects, 1-5
description, 4-1
tables, 4-2
schemas
description, 4-1
scientific notation, 7-7
scope
exceptions in PL/SQL, 7-23
script runner, 1-17
scripts
running, 1-17
SELECT clause, 3-18
SELECT INTO
PL/SQL, 7-9
SELECT statements, 6-2
SELF_IS_NULL exception, 7-22
sequences
creating and editing, 3-6
description, 4-10
managing, 4-10
using in SQL statements, 6-11
SERVEROUTPUT
displaying output from PL/SQL, 7-9
setting ON to display output, 8-5
SET command
for SQL*Plus settings, 10-3
shrinking a table, 1-9
single-line comments, 7-4
snippets, 1-19
sorting
specifying nondefault linguistic sorts, 11-15,
11-16
source types
description, 8-1
managing, 8-1
spaces in object names
quotation marks required, 3-1
special characters in object names
quotation marks required, 3-1
SPOOL command
SQL*Plus, 10-4
SQL
aggregate functions, 6-14
arithmetic operators, 6-12
character functions, 6-11
character literals in statements, 6-3
column alias, 6-4
committing changes with COMMIT, 6-9
comparison operators, 6-4
creating a constraint, 6-16
creating a table, 6-15
Index-7
Index-8
exiting, 10-2
HELP command, 10-2
location of executable, 3-24
overview, 10-1
prompting for a variable, 10-4
running SQL scripts, 10-3
SET command, 10-3
settings, 10-3
SPOOL command, 10-4
spooling output, 10-4
starting from the operating system command
prompt, 10-2
using, 1-18
using variables, 10-4
standalone subprograms, 8-2
execute, 8-3
managing, 8-3
statement triggers
conditional code for statements, 9-4
specifying SQL statement, 9-2
timing, 9-2
UPDATE statements and, 9-4
valid SQL statements, 9-5
statistics
computing table and column, 1-9
estimating table and column, 1-9
storage options, 3-12
STORAGE_ERROR exception, 7-22
stored procedures, 7-2
stored subprograms, 8-2
in Oracle database, 8-2
storing, 5-2
string literals, 7-7
Unicode, 11-21
Structured Query Language (SQL), 6-1
subprograms
creating and editing, 3-6
debugging, 3-22
declaring PL/SQL, 7-15
functions, 8-2
local, 8-2
managing, 8-3
overview, 8-1
packaged, 8-2
procedures, 8-2
running, 3-22
standalone, 8-2
stored, 8-2
SUBSCRIPT_BEYOND_COUNT exception, 7-22
SUBSCRIPT_OUTSIDE_LIMIT exception, 7-22
substitution variables, 1-18
synonyms
creating and editing, 3-7
description, 4-11
managing, 4-11
SYS_INVALID_ROWID exception, 7-22
SYSDATE
pseudocolumn, 6-10
T
table-level constraints, 4-4
tables
aliases, 6-6
analyzing, 1-9
compacting, 1-9
computing statistics, 1-9
creating and editing, 3-9
creating quickly, 3-7
decrypting column data, 1-10
encrypting column data, 1-9
entering and modifying data, 1-12
estimating statistics, 1-9
exporting data, 1-9, 3-20
locking, 1-9
managing, 4-2
moving to another tablespace, 1-9
primary key, 4-5
shrinking, 1-9
truncating, 1-9
territory definition, 11-6
territory support, 11-2
time and date data
storing, 5-5
time and date parameters, 11-7
time zone
parameters, 11-9, 11-10
TIMEOUT_ON_RESOURCE exception, 7-22
TIMESTAMP data type, 5-5
TIMESTAMP WITH LOCAL TIME ZONE data
type, 5-5
TIMESTAMP WITH TIME ZONE data type, 5-5
tnsnames.ora file, 1-11
TO_CHAR SQL function, 11-21
default date format, 11-8
group separator, 11-12
language for dates, 11-8
spelling of days and months, 11-9
TO_DATE function, 5-7
TO_DATE SQL function, 11-21
default date format, 11-8
language for dates, 11-8
spelling of days and months, 11-9
TO_NUMBER SQL function, 11-21
TOO_MANY_ROWS exception, 7-23
transaction control statements, 6-8
transactions
transaction control statements, 6-8
trigger
disabled
definition, 9-4
enabled
definition, 9-4
triggers
accessing column values, 9-3
AFTER, 9-2, 9-4
AFTER option, 9-2
as a stored PL/SQL subprogram, 9-1
BEFORE, 9-2, 9-4
BEFORE option, 9-2
body, 9-5
column list in UPDATE, 9-4
conditional predicates, 9-4
controlling when fired, 9-2
correlation names, 9-3
creating, 9-1, 9-5
creating and editing, 3-14
designing, 9-5
detecting the operation that fired a trigger, 9-4
disabling, 9-4
enabling, 9-4
error conditions and exceptions, 9-4
errors, 9-4
events, 9-2
exceptions, 9-4
fired multiple times with BEFORE option, 9-3
FOR EACH ROW clause, 9-3
FOR EACH ROW option, 9-3
guidelines for design, 9-5
illegal SQL statements, 9-5
integrity constraints vs., 9-5
naming, 9-2
NEW column value, 9-3
OLD column value, 9-3
overview, 9-1
privileges, 9-6
privileges needed, 9-6
procedures and, 9-6
remote dependencies and, 9-6
restrictions, 9-3, 9-5
row, 9-3
triggering statement, 9-2
types, 9-2
WHEN clause, 9-3
when fired, 9-2
TRUE value, 7-7
truncating a table, 1-9
tutorial
creating objects for a small database, 2-1
TYPE attribute
declaring, 7-11
types
creating, 3-15
U
Unicode
PL/SQL and SQL, 11-19
programming, 11-2
programming with SQL and PL/SQL,
string literals, 11-21
unique constraints, 3-10
unique key
on a column, 4-5
UNIQUE key constraints
PRIMARY KEY constraint vs., 4-5
UNISTR SQL function, 11-21
unusable indexes, 1-6
UPDATE statement, 6-7, 6-8
column values and triggers, 9-4
11-18
Index-9
V
VALUE_ERROR exception, 7-23
VARCHAR2 data type, 5-1
variables
accessing in packages, 8-4
bind, 7-21
declaring in PL/SQL, 7-4
passing as IN OUT parameter, 7-15
using with SQL*Plus, 10-4
views
compiling, 1-10
creating and editing, 3-16
description, 4-10
FROM clause, 3-18
GROUP BY clause, 3-19
HAVING clause, 3-19
managing, 4-10
ORDER BY clause, 3-19
recompiling, 1-10
SELECT clause, 3-18
WHERE clause, 3-19
visibility
of package contents, 8-3
W
WHEN clause, 9-3
cannot contain PL/SQL expressions,
correlation names, 9-4
WHERE clause, 3-19
using with SELECT, 6-4
WHILE-LOOP statement
overview, 7-13
Z
ZERO_DIVIDE exception, 7-23
Index-10
9-3