SQL - 92 Guide and Reference
SQL - 92 Guide and Reference
Progress® software products are copyrighted and all rights are reserved by Progress Software Corporation.
This manual is also copyrighted and all rights are reserved. This manual may not, in whole or in part, be
copied, photocopied, translated, or reduced to any electronic medium or machine-readable form without
prior consent, in writing, from Progress Software Corporation.
The information in this manual is subject to change without notice, and Progress Software Corporation
assumes no responsibility for any errors that may appear in this document.
The references in this manual to specific platforms supported are subject to change.
Progress®, Progress Results®, and WebSpeed® are registered trademarks of Progress Software Corporation.
Apptivity™, AppServer™, ProVision™, ProVision™ Plus, SmartObjects™, SonicMQ™, and all other
Progress product names are trademarks of Progress Software Corporation.
Progress® SonicMQ™ contains the IBM® XML Parser for Java Edition and the IBM® Runtime
Environment for Windows®, Java™ Technology Edition Version 1.1.8 Runtime Modules.
©
Copyright IBM Corporation 1998-1999. All rights reserved. U.S. Government Users Restricted Rights —
Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
IBM® is a registered trademark of IBM Corporation. Java™ is a trademark of Sun Microsystems Inc.
Windows® is a registered trademark of Microsoft Corp.
Progress® is a trademark of Progress Software Corporation and is used by IBM Corporation in the mark
Progress/400 under license. Progress/400 AND 400® are trademarks of IBM Corporation and are used by
Progress Software Corporation under license.
All other company and product names are the trademarks or registered trademarks of their respective
companies.
February 2000
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Organization of This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
How to Use This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Other Useful Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Development Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
SQL-92 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
SQL-92 Reference. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
iv
Contents
v
Contents
vi
Contents
vii
Contents
viii
Contents
ix
Contents
SQLCursor.registerOutParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–21
SQLCursor.rowCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–22
SQLCursor.setParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–23
SQLCursor.wasNULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–25
SQLIStatement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–26
SQLIStatement.execute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–26
SQLIStatement.makeNULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–27
SQLIStatement.rowCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–28
SQLIStatement.setParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–29
SQLPStatement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–31
SQLPStatement.execute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–31
SQLPStatement.makeNULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–32
SQLPStatement.rowCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–33
SQLPStatement.setParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6–34
x
Contents
D. Progress SQL-92 Elements and Statements in Backus Naur Form (BNF) . . D–1
Data Types Syntax in BNF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–2
DATA TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–2
Expressions Syntax in BNF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–4
EXPRESSION (expr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–4
CONDITIONAL EXPRESSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–5
Literals Syntax in BNF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–6
DATE-TIME LITERAL Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–6
Query Expressions Syntax in BNF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–7
QUERY EXPRESSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–7
Search Conditions Syntax in BNF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–10
Statements, DDL and DML Syntax in BNF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D–12
xi
Contents
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Glossary–1
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Index–1
xii
Contents
Figures
Figure 4–1: ROUND Function Digit Positions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–86
Figure 5–1: Creating Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–4
Figure 5–2: Executing Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–6
xiii
Contents
Tables
Table 1–1: Components of a Relational Database . . . . . . . . . . . . . . . . . . . . . . . . . 1–3
Table 1–2: Language Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–4
Table 1–3: Sample SQL-92 Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–19
Table 2–1: Specification Formats for Binary Values . . . . . . . . . . . . . . . . . . . . . . . . 2–12
Table 2–2: Relational Operators and Resulting Predicates . . . . . . . . . . . . . . . . . . 2–31
Table 2–3: Date-format Strings and Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . 2–51
Table 2–4: Time-format Strings and Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . 2–53
Table 3–1: Progress SQL-92 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3–2
Table 4–1: Progress SQL-92 Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . 4–2
Table 4–2: Progress SQL-92 Scalar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4–2
Table 5–1: Summary of Progress SQL-92 Java Classes . . . . . . . . . . . . . . . . . . . . 5–7
Table 5–2: Mapping Between SQL-92 and Java Data Types . . . . . . . . . . . . . . . . . 5–20
Table 5–3: Executable SQL-92 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–21
Table 5–4: getDiagnostics Error Handling Options . . . . . . . . . . . . . . . . . . . . . . . . . 5–30
Table 6–1: Argument Values for DhSQLException.getDiagnostics . . . . . . . . . . . . 6–7
Table 6–2: Allowable Values for fieldType in getParam . . . . . . . . . . . . . . . . . . . . . 6–17
Table 6–3: Allowable Values for fieldType in getValue . . . . . . . . . . . . . . . . . . . . . . 6–18
Table 6–4: Allowable Values for fieldType in registerOutParam . . . . . . . . . . . . . . . 6–22
Table A–1: Progress SQL-92 Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . A–2
Table A–2: Progress SQL-92 System Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A–6
Table A–3: Progress SQL-92 Error Codes and Messages . . . . . . . . . . . . . . . . . . . A–8
Table B–1: System Tables and Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–2
Table B–2: SYSTABLES Core System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–6
Table B–3: SYSCOLUMNS Core System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . B–7
Table B–4: SYSINDEXES Core System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–8
Table B–5: SYSCALCTABLE System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–9
Table B–6: SYSCHARSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–10
Table B–7: SYSCOLAUTH System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–11
Table B–8: SYSCOLSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–12
Table B–9: SYSCOLUMNS_FULL System Table . . . . . . . . . . . . . . . . . . . . . . . . . . B–13
Table B–10: SYSDATATYPES System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–15
Table B–11: SYSDATESTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–16
Table B–12: SYSDBAUTH System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–17
Table B–13: SYSFLOATSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–18
Table B–14: SYSIDXSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–19
Table B–15: SYSINTSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–20
Table B–16: SYSNUMSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–21
Table B–17: SYSPROCBIN System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–22
Table B–18: SYSPROCCOLUMNS System Table . . . . . . . . . . . . . . . . . . . . . . . . . . B–23
Table B–19: SYSPROCEDURES System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–24
Table B–20: SYSPROCTEXT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–25
Table B–21: SYSREALSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–26
Table B–22: SYSSMINTSTAT System Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B–27
xiv
Contents
xv
Contents
Procedures
Team_cre.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–20
Team_upd.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–21
Team_que.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–22
Team_xit.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1–23
TeamProc.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5–22
xvi
Preface
Purpose
The manual describes the syntax and semantics of Progress SQL-92 language statements and
elements.
Audience
This manual is intended for application programmers writing database applications using the
Progress SQL-92 environment.
Introduces the application developer to the SQL-92 environment, including the interactive
user interface tool SQL Explorer. Provides an overview of related documentation and
resources.
Provides detailed reference information on each SQL statement. The statements are
presented in alphabetical order.
Progress SQL-92 Guide and Reference
Provides detailed reference information on SQL functions. The functions are presented in
alphabetical order.
Describes the Java stored procedures and triggers that SQL Server processes execute.
Lists column names, column data types, and column lengths for system tables in the
Progress SQL-92 system catalog.
Lists Progress supported data types and corresponding Progress SQL-92 data types.
Describes support for the ARRAY data type.
Appendix D, “Progress SQL-92 Elements and Statements in Backus Naur Form (BNF)”
Presents SQL-92 language elements and SQL-92 syntax in Backus Naur Form.
Glossary
xviii
Preface
Typographical Conventions
This manual uses the following typographical conventions:
– New terms
– Code examples
– System output
• Small capitals are used for Progress key functions and generic keyboard keys.
END-ERROR, GET, GO
ALT, CTRL, SPACEBAR, TAB
• When you have to press a combination of keys, they are joined by a dash. You press and
hold down the first key, then press the second key.
CTRL-X
• When you have to press and release one key, then press another key, the key names are
separated with a space.
ESCAPE H
ESCAPE CURSOR-LEFT
xix
Progress SQL-92 Guide and Reference
Syntax Notation
The syntax for each SQL-92 component follows a set of conventions:
• Uppercase words are keywords. Although they are always shown in uppercase, you can
use either uppercase or lowercase when using them in an expression or a statement.
SYNTAX
• Italics identify options or arguments that you must supply. These options can be defined
as part of the syntax or in a separate syntax identified by the name in italics. In the GRANT
statement you must supply at least one user_name.
• Square brackets ([ ] ) around an item indicate that the item, or a choice of one of the
enclosed items, is optional.
In this syntax example the first user_name is required, and additional user_name
specifications are optional:
SYNTAX
• Braces ({ }) around an item indicate that the item, or a choice of one of the enclosed
items, is required.
In the GRANT example, you must specify either RESOURCE or DBA or both, and at least
one user_name. Any user_name specifications after the first are optional:
SYNTAX
In some cases, braces are not a syntax notation, but part of the language.
xx
Preface
For example, this excerpt from an ODBC application invokes a stored procedure using the
ODBC syntax { call procedure_name ( param ) }, where braces and parentheses are part
of the language:
SYNTAX
• A vertical bar (|) indicates a choice. In the CREATE SYNONYM example you must
specify a table_name, view_name, or synonym but you can only choose one. Note that in
all SQL-92 syntax, if you specify the optional owner_name qualifier, there must not be a
blank between the period separator and the table_name or view_name or synonym:
SYNTAX
In the DELETE FROM example, you must specify one of table_name or view_name:
SYNTAX
• Ellipses (...) indicate that you can choose one or more of the preceding items. If a group
of items is enclosed in braces and followed by ellipses, you must choose one or more of
those items. If a group of items is enclosed in brackets and followed by ellipses, you can
optionally choose one or more of those items.
xxi
Progress SQL-92 Guide and Reference
In the ORDER BY example, you must include one expression (expr) or column position
(posn), and you can optionally specify the sort order as ascending (ASC) or descending
(DESC). You can specify additional expressions or column positions for sorting within a
sorted result set. The SQL-92 engine orders the rows on the basis of the first expr or posn.
If the values are the same, the second expr or posn is used in the ordering:
SYNTAX
In the GRANT example, you must include one user_name, but you can optionally include
more. Note that each subsequent user_name must be preceded by a comma:
SYNTAX
• In many examples, the syntax is too long to place in one horizontal row. In such cases,
optional items appear individually bracketed in multiple rows in order, left-to-right and
top-to-bottom. This order generally applies, unless otherwise specified. Required items
also appear on multiple rows in the required order, left-to-right and top-to-bottom. In cases
where grouping and order might otherwise be ambiguous, braced (required) or bracketed
(optional) groups clarify the groupings.
SYNTAX
xxii
Preface
Getting Started
Progress Electronic Documentation Installation and Configuration Guide (Hard copy only)
A booklet that describes how to install the Progress EDOC viewer and collection on UNIX
and Windows.
A manual that describes how to install and set up Progress Version 9.1 for the UNIX
operating system.
A manual that describes how to install and set up Progress Version 9.1 for all supported
Windows and Citrix MetaFrame operating systems.
xxiii
Progress SQL-92 Guide and Reference
A guide that provides a brief description of each new feature of the release. The booklet
also explains where to find more detailed information in the documentation set about each
new feature.
Progress Master Glossary for Windows and Progress Master Glossary for Character (EDOC
only)
Platform-specific master glossaries for the Progress documentation set. These books are
in electronic format only.
Progress Master Index and Glossary for Windows and Progress Master Index and Glossary for
Character (Hard copy only)
Platform-specific master indexes and glossaries for the Progress hard-copy documentation
set.
A booklet that explains how Progress software and media are packaged. An icon-based
map groups the documentation by functionality, providing an overall view of the
documentation set. Welcome to Progress also provides descriptions of the various services
Progress Software Corporation offers.
Development Tools
Progress Basic Database Tools (Character only; information for Windows is in online help)
A guide for the Progress Database Administration tools, such as the Data Dictionary.
Database
Progress Database Design Guide
A guide that uses a sample database and the Progress Data Dictionary to illustrate the
fundamental principles of relational database design. Topics include relationships,
normalization, indexing, and database triggers.
This guide describes Progress database administration concepts and procedures. The
procedures allow you to create and maintain your Progress databases and manage their
performance.
xxiv
Preface
SQL-92
Progress Embedded SQL-92 Guide and Reference
A guide to the Java Database Connectivity (JDBC) interface and the Progress SQL-92
JDBC driver. It describes how to set up and use the driver and details the driver’s support
for the JDBC interface.
A guide to the ODBC interface and the Progress SQL-92 ODBC driver. It describes how
to set up and use the driver and details the driver’s support for the ODBC interface.
Reference
Pocket Progress (Hard copy only)
A reference that lets you quickly look up information about the Progress language or
programming environment.
SQL-92 Reference
These are non-Progress resources available from your technical bookseller.
A Guide to the SQL Standard
Date, C.J., with Hugh Darwen. 1997. Reading, MA: Addison Wesley.
Melton, Jim (Digital Equipment Corporation) and Alan R. Simon. 1993. San Francisco:
Morgan Kaufmann Publishers.
xxv
Progress SQL-92 Guide and Reference
xxvi
1
Getting Started with SQL-92
• Description of SQL concepts and Progress support for the SQL-92 standard
What is SQL?
SQL is an industry-standard language specifically designed to enable people to define database
structure, add and maintain data, and query data. SQL has become the standard way to represent
and maintain data in a relational database.
RDBMS Architecture
4GL Client JDBC
WebSpeed Open AppServer ODBC ESQL/C
4GL SQL-92
Database Database
Server Server
SQL-92 supports a completely separate interface from the 4GL, but both interfaces use a Shared
Database Storage Engine that handles low-level database functions. By sharing this Storage
Engine, memory is saved and efficiency is gained regarding key database processing. This
architecture also provides SQL-92 and 4GL clients concurrent access to data.
1–2
Getting Started with SQL-92
Element Description
Column Each column characterizes one attribute of a row of data. Each column has
a data type such as character, integer or decimal associated with it.
NOTE: A View is a subset of a database that an application can process. It may contain parts
of one or more tables. Views have no independent existence. They are a way of
looking at the data.
1–3
Progress SQL-92 Guide and Reference
Element Description
1–4
Getting Started with SQL-92
Element Description
Date-time format strings Date-time formation strings control the output of date and time
values.
1–5
Progress SQL-92 Guide and Reference
• A File menu containing an option for each action you can perform
– Setting Connection options, Reporting options, Logging options, and Font options
1–6
Getting Started with SQL-92
• Buttons that allow you to run or delete from history the statements that you have entered
in the top pane, as well as buttons that allow you to scroll backward and forward through
statements
• A bottom pane that displays the output or results of statements you execute
SYNTAX
SQLEXP [-char]
{ -S { service_name | port_number }
[ -H host_name ] [ -db ] database_name } | { -url dbURL }
[ -command command_string ]
[ -infile input_file ] [ -outfile output_file ]
[ -user username ] [ -password password ]
[ -sqlverbose ] [ -help ]
-char
Starts the character version. The default mode for SQL Explorer is GUI on Windows. On
UNIX platforms, the -char option is the default.
-S service_name | port_number
The port number or service name to use for a network connection to a database server on
the same machine or on a remote host.
-H host_name
Specifies the name of the remote host on which the database server is running. The default
value is “localhost.”
1–7
Progress SQL-92 Guide and Reference
-db database_name
Specifies the physical file name of the database to which you want to connect. The -db
argument is optional; you can specify the database name without the argument.
-url dbURL
Identifies the database to which you want to connect. The URL string has the following
components:
SYNTAX
jdbc:jdbcprogress:T:host_name:service_name | port_number:database_name
jdbc:jdbcprogress:T
host_name
The name of the system where the Progress SQL-92 JDBC data source resides.
service_name | port_number
database_name
-command command_string
Specifies a SQL command to execute after startup and before displaying an interactive
prompt.
-infile input_file
Specifies a file that contains SQL statements to be executed in batch mode after startup.
-outfile output_file
Specifies a file where SQL Explorer is to write SQL-92 statement output. When this option
is omitted SQL-92 statement output is sent to standard output.
1–8
Getting Started with SQL-92
-user username
Specifies a username other than the current user login for connecting to the database.
-password password
Specifies the password for connecting to the database when password protection has been
established. By default, no password is required.
-sqlverbose
-help
Character Mode
Use the following syntax to start SQL Explorer in character mode and connect to a database:
SYNTAX
OR:
1–9
Progress SQL-92 Guide and Reference
EXAMPLE
After starting a database server for the “y2ksports” database on port 2000 of the same machine
(the local host), you can start SQL Explorer in character mode and connect to the y2ksports
database with the following command:
Notice that in this example no username or password is specified. The connect request is made
using the current user login as the username. Once you are connected, the connection URL
appears in the title of the Command Prompt window and the SQL Explorer prompt is ready to
accept SQL-92 statements.
Windows
Follow these steps to connect to a database from the SQL Explorer window:
1 ♦ Choose Connect from the SQL Explorer File menu. The Connect Database dialog box
appears.
2 ♦ In the Connect Database dialog box, choose “basic” or “url” tab to enter the information
required by the database to which you want to connect:
• To make a network connection to a database on a remote host enter the host name in
the Host field, enter the service name or port number in the Service or Port field, and
enter the physical filename of the database in the Database field.
3 ♦ If password protection has been established for the database enter your User ID and
Password, then click Connect. Otherwise, just click Connect.
Once you are connected the connection URL appears in the title of the SQL Explorer window.
You can change the SQL Explorer properties so the Connect Database dialog box prompts the
user for the URL information. For more information, see “Modifying SQL Explorer
Properties,” later in this chapter.
To disconnect choose Disconnect from the File menu.
1–10
Getting Started with SQL-92
EXAMPLE
After starting a database server for the “y2ksports” database on port 2000 of the same machine
(the local host), you can use SQL Explorer to connect to the y2ksports database. Use an
authorized username, to connect to the database.
To connect to the database using the “basic tab”, enter the following information in the Connect
Database dialog box, then click Connect.
• Host: localhost
• Database: y2ksports
• User: username
The ’sysprogress’ username is the owner of the system tables, and is the initial DBA for the
Progress SQL-92 sample databases. For information on authentication, see the Progress
Database Administration Guide and Reference.
CAUTION: When a user connects to a database using the SQL Explorer, a share lock is
automatically placed on the database’s schema. If multiple users connect to the
same database using the SQL Explorer, and one user attempts to create a table or
modify the database schema, the user will not be able to complete the modification
because an exclusive lock on the schema could not be acquired.
Comment Lines
SQL Explorer recognizes the pound sign ( # ) or double dashes ( -- ) as comment lines in input
files, as well as interactively. For a line to be treated as a comment line, one of these comment
identifiers must be the first text in the line. The identifier can be in any column. SQL Explorer
treats all text in the line after the comment identifier as a comment.
Character Mode
A semicolon ( ; ) is required to indicate the end of a statement, and signal SQL Explorer to
execute a single SQL-92 statement. When you execute a SQL statement the output displays to
standard output. You can use the -outfile startup parameter to redirect the output to a file that
you specify.
1–11
Progress SQL-92 Guide and Reference
Use the following syntax to execute a SQL-92 statement from the SQL Explorer command
prompt:
SYNTAX
SQLExplorer> SQL_92_statement ;
To query the y2ksports database for the contents of the item table with owner PUB, enter this
statement at the SQL Explorer command prompt:
-- Selecting all rows from the item table, with owner pub
Windows
When you run a single SQL-92 statement the output is displayed in table format in the bottom
pane. You can use the File→ Toggle Table Format option or the CTRL-T accelerator key to
disable the table format.
Follow these steps to execute a SQL-92 statement from the SQL Explorer window:
2 ♦ Click the Execute button. The output displays in the bottom pane.
NOTE: When executing a single statement in the Windows version the semicolon ( ; ) is
optional. Clicking the Execute button signals SQL Explorer to execute the statement.
EXAMPLE
To query the y2ksports database for all columns in the customer table with owner PUB, type the
following SQL-92 statement in the top pane of the SQL Explorer window, then click Run:
-- Selecting all rows from the customer table with owner pub.
1–12
Getting Started with SQL-92
2 ♦ Navigate to the directory where you want to save the file, then type in the name of an .sql
file and click OK.
Character Mode
Executes the file in batch mode. SQL Explorer terminates after executing all the commands in
the file. When you run SQL-92 statements from an input file the output displays to standard
output. Use the -outfile startup parameter to redirect the output to a named file.
Use the following syntax to connect to a database and execute SQL-92 statements from an input
file:
SYNTAX
1–13
Progress SQL-92 Guide and Reference
Windows
Follow the steps to execute SQL statement from an input file:
1 ♦ Choose File→ Run File from the SQL Explorer menu. The Windows Open File dialog box
appears.
2 ♦ Navigate to the directory containing the input file, select the file and click OK. The
statement and its results are displayed in the bottom pane.
2 ♦ Use the Windows Open File dialog box to select the .sql file you want as input, then click
OK. Each statement in the file is loaded into the history of the top pane.
Each property is available for both the character interface and the graphical interface, unless
noted otherwise.
AutoCommit
Automatically commits all changes to the database when set to true. False is the default.
ColumnWidthLimit
Truncates the output column width when set less than the SQL column width. Default
value is 25 characters. Increase the value to prevent truncating an output column that is
greater than 25 characters.
1–14
Getting Started with SQL-92
ColumnWidthMin
Controls the minimum width of columns output to the bottom pane or standard output.
Default value is 1.
ConnectTimeout
Allows you to specify the maximum number of seconds the SQL Explorer should wait
when attempting to establish a connection, before terminating the connection request. The
default value is 180 seconds.
DisableWarnings
Allows the SQL Explorer to send warning messages to the output screen. To enable the
display of warning messages, change DisableWarnings from the default value of true to
the override setting of false.
Echo
Prohibits Windows SQL Explorer from displaying output to the bottom pane when set to
false. Default is true.
FetchLimit
Specifies the maximum number of records to be retrieved from the database when the
default value of 101 is increased or decreased. To disable the FetchLimit completely, set
the HasFetchLimit property to false.
HasFetchLimit
The HasFetchLimit property allows you to change the default value of true to the
override setting of false. This property is related to the FetchLimit property. Setting
HasFetchLimit to false allows you to disable the fetch limit completely, without
requiring you to set an artificially high FetchLimit.
NOTE: Earlier releases of SQL Explorer enforced a fetch limit. The default for the
FetchLimit property remains at 101 records. Setting HasFetchLimit to false
allows you to disable the FetchLimit completely, without requiring you to set an
artificially high FetchLimit.
Logfile
Allows you to change the name and/or location of the Logfile by setting the Logfile
property to the full path and filename of an alternate log file. The default Logfile,
SQLExplorer.log is located in the current working directory.
1–15
Progress SQL-92 Guide and Reference
Logging
Logs all SQL statements and their output to the specified log file when set to true. Default
value is false.
Pager
Allows you to change the default setting of false to the override value of true. When
Pager is set to false, all of the output data is returned to the screen. When you choose
true, SQL Explorer returns the number of lines specified in PagerLimit, which has a
default value of 22 lines. You can then page up and down to review the output.
The Pager and PagerLimit properties are available in the character interface only. The
graphical interface does not require these properties.
PagerLimit
Allows you specify how many lines SQL Explorer displays on your screen. You can set
this value to the maximum available display area on your screen, or to the number of lines
you choose to use for output display. A typical setting is twenty-two lines. For PagerLimit
to take effect, you must first set the Pager property to true. If the Pager property is set to
the default value of false, SQL Explorer ignores the PagerLimit property setting.
ReportFormat
Allows you to override the standard format display for output data. Setting this property
to by label directs SQL Explorer to return data in an alternative format. A single output
line in the by label format returns the record id, column name, and column value for one
column in the result set.
Resets the property settings to their original values. Enter @reset to reset all property
values. You can also reset one or more specified properties by supplying the property
name and the new property value.
Run filename
Executes the specified file named. The file itself contains SQL-92 statements and SQL
Explorer command statements ( @ and ! ). Different applications may have different
requirements for database operations, such as transaction isolation level or automatic
commit operations. You can create a custom file for each application.
1–16
Getting Started with SQL-92
Transaction
Sets the transaction isolation level to COMMITTED READ. The isolation levels specify the
degree to which one transaction can modify data or database objects being used by a
concurrent transaction. See the SET TRANSACTION ISOLATION LEVEL Statement
and LOCK TABLE Statement in Chapter 3, “SQL-92 Statements,” for complete
information on isolation levels. You can set the default to any of these values:
• UNCOMMITTED READ
• REPEATABLE READ
• SERIALIZABLE
useurl
Controls the format in which the Connect dialog box prompts users for database
connection information in Windows SQL Explorer.
EXAMPLES
The following example displays current property settings, for both character and Windows SQL
Explorer:
SQLExplorer> @show ;
1–17
Progress SQL-92 Guide and Reference
This example displays the available options for setting properties, for both character and
Windows SQL Explorer:
SQLExplorer> @help ;
This is syntax for changing the value for a specific property, both in character and Windows
SQL Explorer:
SYNTAX
Windows Only
Follow these steps to change property settings for Windows SQL Explorer only:
2 ♦ Change any properties you want, then click OK. Any changes you make are applied
immediately.
1–18
Getting Started with SQL-92
1 ♦ Choose File→ Log. The Log Session Options dialog box appears.
2 ♦ Type the full path and filename of the file where the session is to be logged or click
Browse to open the Windows Save As dialog box and select a file.
3 ♦ Once the filename is present, click OK. SQL Explorer will now log all SQL-92 statements
and their output to the specified file.
SQL Explorer logs all SQL statements and resulting output to the specified log file.
You can submit these scripts sequentially to SQL Explorer. If you are using character mode,
submit a script as an input file by using the -infile parameter. If you are using the graphical
interface, choose File→ Run File from the SQL Explorer menu and select the script to run.
1–19
Progress SQL-92 Guide and Reference
Team_cre.sql
-------------------------------------------------------------------------
-- File Name: Team_cre.sql
--
-- Purpose: Creates the team table in the y2ksports database, a copy of
-- the sports2000 database.
--
-- Requirements:
-- (1) Create the database by copying SPORTS2000.
-- Example: prodb y2ksports sports2000
-- (2) Start the database.
-- Example: proserve y2ksports -S 800
-- (3) Submit this script to SQL Explorer as an input file
-- (character mode) or as a run file (GUI mode).
--
-- Revision History:
--
-- Date Author Change
-- ----- -------- --------
--
-- 11/99 DB-DOC Created, V9.1A
-----------------------------------------------------------------------
1–20
Getting Started with SQL-92
Team_upd.sql
---------------------------------------------------------------------
-- File Name: Team_upd.sql
-- Purpose: Populates the team table in a copy of the
-- sports2000 database.
-- Requirements:
-- (1) Database must be running.
-- (2) Team table must exist -- see Team_cre.sql
-- (3) Submit this script to SQL Explorer as an input file
-- (character mode) or as a run file (GUI mode)
-- Revision History:
-- Date Author Change
-- ---- ------ -------
-- 11/99 DB-DOC Created
-----------------------------------------------------------------------
1–21
Progress SQL-92 Guide and Reference
Team_que.sql
-------------------------------------------------------------------------
-- File Name: Team_que.sql
--
-- Purpose: Queries the team table in the y2ksports database, a copy of
-- the sports2000 database.
--
-- Requirements:
-- (1) Database must be running.
-- (2) Team table must exist -- see Team_cre.sql
-- (3) For rows to be returned you must first populate
-- the table. See Team_upd.sql.
-- (4) Submit this script to SQL Explorer as an input file
-- (character mode) or as a run file (GUI mode).
--
-- Revision History:
--
-- Date Author Change
-- ---- ------ ------
--
-- 11/99 DB-DOC Created, V9.1A
-------------------------------------------------------------------------
commit work ;
1–22
Getting Started with SQL-92
Team_xit.sql
• Authentication
• SQLDUMP utility for dumping application data from database tables to files
• SQLLOAD utility for loading application data from files to database tables
1–23
Progress SQL-92 Guide and Reference
1–24
2
SQL-92 Language Elements
This chapter describes language elements that are common to many Progress SQL-92
statements. Syntax diagrams in other chapters often refer to these language elements without
detailed explanations. The language elements are described in the following sections:
• Identifiers
• Data types
• Query expressions
• Search conditions
• Expressions
• Literals
2.1 Overview
• Data types control how SQL stores column values. CREATE TABLE statements specify
data types for columns.
• Query expressions retrieve values from tables. Query expressions form the basis of other
SQL statements and syntax elements.
• Search conditions specify a condition about a given row or group of rows that is true or
false. Query expressions and UPDATE statements specify search conditions to restrict the
number of rows in the result table.
• Expressions are symbols or strings of symbols used to represent or calculate a single value
in a SQL statement. When SQL encounters an expression, it retrieves or calculates the
value represented by the expression and uses that value when it executes the statement.
• Literals are a type of SQL expression that specify a constant value. Some SQL constructs
allow literals but prohibit other forms of expressions.
• Date-time format strings control the output of date and time values. SQL interprets format
strings and replaces them with formatted values.
2–2
SQL-92 Language Elements
• Conventional identifiers
SQL does not distinguish between uppercase and lowercase letters in SQL identifiers. It
converts all names specified as conventional identifiers to uppercase, but statements can refer
to the names in mixed case.
2–3
Progress SQL-92 Guide and Reference
EXAMPLE
The following commands show some of the characteristics of conventional identifiers:
-- Conventional Identifiers
-- Names are case-insensitive
CREATE TABLE ShOwCaSe (CoLuMn1 character(5));
Update count = 0.
Commit work;
COLUMN1
----------------
99
-- Conventional Identifiers
-- Cannot use reserved words in identifiers
-- Examples: ’table’ and ’column’ cannot be used as identifiers
CREATE TABLE TABLE (column1 character);
2–4
SQL-92 Language Elements
NOTE: Although delimited identifiers preserve case for display purposes, case is still
ignored for name matching. All of the following would refer to the same table:
“Order”, “order”, Order, order. However, if the table were created using “Order”, it
would display as written. With conventional identifiers, a table created as Order
would display as ORDER.
NOTE: This behavior differs from the SQL-92 standard, which requires delimited identifiers
to be case-sensitive.
The following SQL example shows some ways to create and refer to delimited identifiers:
COMMIT WORK;
2–5
Progress SQL-92 Guide and Reference
• Character
• Exact numeric
• Approximate numeric
• Date-time
• Bit String
NOTE: All the data types can store null values. A null value indicates that the value is not
known and is distinct from all non-null values.
This is the syntax for a data type:
SYNTAX
SYNTAX
CHARACTER [ ( length ) ]
CHARACTER (alias CHAR) corresponds to a null-terminated character string with the length
specified. Values are padded with blanks to the specified length. The default length is 1.
The maximum length is 2000 characters.
2–6
SQL-92 Language Elements
NOTES
• For data types CHARACTER( length ) and VARCHAR( length ) the value of
length specifies the number of characters.
• The maximum length can be as large as 31995. The sum of all the column lengths of
a table row must not exceed 31960.
• Due to index size limitations, only the narrower VARCHAR columns can be
indexed.
• 31995 characters for single-column tables converted from Version 8 to Version 9 and not
updated in Version 9.
• The number of columns in a table — more columns in a table further limits the length of
VARCHAR data
• When a table was created — tables created earlier can support longer VARCHAR data
than tables created later
See the “Character-String Literals” section for details on specifying values to be stored in
CHARACTER columns.
2–7
Progress SQL-92 Guide and Reference
a variable width character set, you will be able to hold between 10660 and 31982 characters
depending on the actual mix of characters you use.
SYNTAX
TINYINT
SMALLINT
INTEGER
The range of values for a NUMERIC type column is -n to +n where n is the largest number
that can be represented with the specified precision and scale. If a value exceeds the
precision of a NUMERIC column, SQL generates an overflow error. If a value exceeds the
scale of a NUMERIC column, SQL rounds the value.
NUMERIC type columns cannot specify a negative scale or specify a scale larger than the
precision.
2–8
SQL-92 Language Elements
EXAMPLE
The following example shows what values can be inserted into a column created with a
precision of 3 and scale of 2:
ErrorCode=-20052
Error in executeDirect:Overflow error;Rolledback Xn
ErrorCode=-20052
Error in executeDirect:Overflow error;Rolledback Xn
ErrorCode=-20052
Error in executeDirect:Overflow error;Rolledback Xn
COL1
----------------
3.33
3.36
3.3
3.33
2–9
Progress SQL-92 Guide and Reference
SYNTAX
REAL
DOUBLE PRECISION
FLOAT [ ( precision ) ]
Corresponds to a double precision floating-point number of the given precision, in bytes.
By default, FLOAT columns have a precision of 8. The REAL data type is same as a FLOAT(4)
and double-precision is the same as a FLOAT(8).
SYNTAX
DATE
Stores a date value as three parts: year, month, and day. The ranges for the parts are:
• Year: 1 to 9999
2–10
SQL-92 Language Elements
• Month: 1 to 12
• Day: Lower limit is 1; the upper limit depends on the month and the year.
TIME
Stores a time value as four parts: hours, minutes, seconds, and milliseconds. The range for
the parts is:
• Hours: 0 to 23
• Minutes: 0 to 59
• Seconds: 0 to 59
• Milliseconds: 0 to 999
TIMESTAMP
SYNTAX
BIT
SQL statements can assign and compare values in BIT columns to and from columns of
types CHAR, VARCHAR, BINARY, VARBINARY, TINYINT, SMALLINT, and INTEGER. However,
in assignments from BINARY and VARBINARY, the value of the first four bits must be 0001
or 0000.
BINARY [ ( length ) ]
Corresponds to a bit field of the specified length of bytes. The default length is 1 byte. The
maximum length is 2000 bytes.
2–11
Progress SQL-92 Guide and Reference
In interactive SQL, INSERT statements must use a special format to store values in BINARY
columns. They can specify the binary values as a bit string, hexadecimal string, or
character string. INSERT statements must enclose binary values in single-quote marks,
preceded by b for a bit string and x for a hexadecimal string.
If the data inserted into a BINARY column is less than the length specified, SQL pads it with
zeros.
BINARY data can be assigned and compared to and from columns of type BIT, CHAR, and
VARBINARY. Arithmetic operations are not allowed.
VARBINARY ( length )
Corresponds to a variable-length bit field of the specified length in bytes. The default
length is 1 byte. The maximum length is 31995 byte. The default length is 1.
NOTE: Due to index limitations, only the narrower VARBINARY columns can be indexed.
LVARBINARY ( length )
Corresponds to an arbitrarily long byte array with the maximum length defined by the
amount of available disk storage up to 2,000,000,000. A BLOB is an object of data type
LVARBINARY.
2–12
SQL-92 Language Elements
• 31995 bytes for single-column tables converted from Version 8 to Version 9 and not
updated in Version 9.
• 31982 bytes for single-column tables originally created in Version 9 or updated in Version
9.
• The number of columns in a table — more columns in a table further limits the length of
VARBINARY data
• When a table was created — tables created earlier can support longer VARBINARY data
than tables created later
LVARBINARY Limitations
Current limitations for LVARBINARY support are listed below:
• LVARBINARY data type will only be accessible from the SQL Engine. LVARBINARY
data columns added to tables created by the 4GL are not visible to the 4GL. ESQLC does
not support this data type.
• Conversion, aggregate, and scalar functions are disallowed on this data type.
• A column of data type LVARBINARY is not a valid column name in a CREATE INDEX
statement.
2–13
Progress SQL-92 Guide and Reference
• When issuing a CREATE TABLE statement, a valid data type for the column definitions
is LVARBINARY. However, LVARBINARY do not allow the column constraints of
PRIMARY KEY, FOREIGN KEY, UNIQUE, REFERENCES, and CHECK.
NOTE: When creating a table with a column of data type LVARBINARY, place the table in
a new AREA.
• The VALUES option on the INSERT statement is not valid for the LVARBINARY data
type.
• Use BINARY DUMP/LOAD to dump and load data that contains the LVARBINARY
data type.
NOTE: SQLDUMP and SQLLOAD do not support tables with LVARBINARY column
data.
• SELECT statements are query expressions with optional ORDER BY and FOR UPDATE
clauses.
• INSERT statements can specify a query expression to add the rows of the result table to a
table.
2–14
SQL-92 Language Elements
• UPDATE statements can specify a query expression that returns a single row to modify
columns of a row.
• Some search conditions can specify query expressions. In basic predicates, the result table
can contain only a single value. In a quantified_predicate and an in_predicate, the result
table can contain only a single column.
• The FROM clause of a query expression can specify another query expression, called a
derived table.
SYNTAX
query_specification
| query_expression set_operator query_expression
| ( query_expression )
SYNTAX
2–15
Progress SQL-92 Guide and Reference
Specifies that the result table includes all columns from all tables named in the FROM
clause.
The optional ‘column_title argument specifies a new heading for the associated column
in the result table. You can also use the column_title in an ORDER BY clause.
• A joined table that combines rows and columns from multiple tables.
The usage notes specific to each form of table reference are below.
If there are multiple table references, SQL joins the tables to form an intermediate result
table that is used as the basis for evaluating all other clauses in the query expression. That
intermediate result table is the Cartesian product of rows in the tables in the FROM clause,
formed by concatenating every row of every table with all other rows in all tables.
table_ref
SYNTAX
2–16
SQL-92 Language Elements
An alias is a name you use to qualify column names in other parts of the query
expression. Aliases are also called correlation names.
If you specify an alias, you must use it, and not the table name, to qualify column
names that refer to the table. Query expressions that join a table with itself must use
aliases to distinguish between references to column names.
For example, the following query expression joins the table customer with itself. It
uses the aliases x and y and returns information on customers in the same city as
customer SMITH:
Derived tables can also specify column aliases. Column aliases provide alternative
names to use in column references elsewhere in the query expression. If you specify
column aliases, you must specify them for all the columns in the result table of the
query expression. Also, if you specify column aliases in the FROM clause, you must
use them, and not the column names, in references to the columns.
FROM [ ( ] joined_table [ ) ]
Combines data from two table references by specifying a join condition. The syntax
currently allowed in the FROM clause supports only a CROSS JOIN, INNER JOIN, or
LEFT OUTER JOIN.
CROSS JOIN specifies a Cartesian product of rows in the two tables. Every row in
one table is joined to every row in the other table.
INNER JOIN specifies an inner join using the supplied search condition.
LEFT OUTER JOIN specifies a left outer join using the supplied search condition.
2–17
Progress SQL-92 Guide and Reference
You can also specify these and other join conditions in the WHERE clause of a query
expression. See the “Outer Joins” section for more information on both ways of
specifying outer joins.
joined_table
SYNTAX
See the section on “Inner Joins”, Cross Joins, and “Outer Joins” for more details.
WHERE search_condition
The search_condition is applied to each row of the result table set of the FROM
clause. Only rows that satisfy the conditions become part of the result table. If the
result of the search_condition is NULL for a row, the row is not selected. Search
conditions can specify different conditions for joining two or more tables. See the
“Outer Joins” section for more information.
The search_condition is applied to each row of the result table set of the FROM
clause. Only rows that satisfy the conditions become part of the result table. If the
result of the search_condition is NULL for a row, the row is not selected.
Search conditions can specify different conditions for joining two or more tables. See
the “Outer Joins” and “Search Conditions” sections for information on the different
kinds of search conditions.
For the first column specified in the GROUP BY clause, SQL arranges rows of the result
table into groups whose rows all have the same values for the specified column.
2–18
SQL-92 Language Elements
If you specify a second GROUP BY column, SQL groups rows in each main group by
values of the second column.
SQL groups rows for values in additional GROUP BY columns in a similar fashion.
All columns named in the GROUP BY clause must also be in the select list of the query
expression. Conversely, columns in the select list must also be in the GROUP BY clause
or be part of an aggregate function.
HAVING search_condition
Allows you to set conditions on the groups returned by the GROUP BY clause. If the
HAVING clause is used without the GROUP BY clause, the implicit group against which
the search condition is evaluated is all the rows returned by the WHERE clause.
A condition of the HAVING clause can compare one aggregate function value with
another aggregate function value or a constant.
SYNTAX
UNION [ ALL ]
Appends the result table from one query expression to the result table from another.
The two query expressions must have the same number of columns in their result tables,
and those columns must have the same or compatible data types.
The final result table contains the rows from the second query expression appended to the
rows from the first. By default, the result table does not contain any duplicate rows from
the second query expression. Specify UNION ALL to include duplicate rows in the result
table.
The two query expressions must have the same number of columns in their result tables,
and those columns must have the same or compatible data types.
2–19
Progress SQL-92 Guide and Reference
INTERSECT
Limits rows in the final result table to those that exist in the result tables from both query
expressions.
The two query expressions must have the same number of columns in their result tables,
and those columns must have the same or compatible data types:
MINUS
Limits rows in the final result table to those that exist in the result table from the first query
expression minus those that exist in the second. In other words, the MINUS operator returns
rows that exist in the result table from the first query expression but that do not exist in the
second.
The two query expressions must have the same number of columns in their result tables,
and those columns must have the same or compatible data types.
EXAMPLES
The following example specifies all columns in the customer table:
The table_name.* syntax is useful when the select list refers to columns in multiple tables and
you want to specify all the columns in one of those tables:
You can qualify a column name with the name of the table it belongs to. The following
examples illustrate column names qualified by table name:
2–20
SQL-92 Language Elements
The following example illustrates specifying a new column heading for an associated column.
Enclose the new title in single or double quotation marks if it contains a space or other special
characters:
You must qualify a column name if it occurs in more than one table specified in the FROM clause:
select
Customer.custnum,
Customer.city as "Customer City",
Customer.State as ’Customer State’,
Billto.City as "Bill City",
Billto.State as ’Bill State’
from Customer, Billto
where Customer.City = ’Clinton’;
2–21
Progress SQL-92 Guide and Reference
The following example selects only the customers whose name is ’SMITH’:
SELECT *
FROM customer
WHERE name = ’SMITH’ ;
The following example finds all customers whose city is the same as the customer ’SMITH’.
SELECT *
FROM customer
WHERE city IN (
SELECT city
FROM customer
WHERE name = ’SMITH’) ;
The following example retrieves the customer and order information for customers with orders:
The HAVING clause in the following example compares the value of an aggregate function
( COUNT (*) ) to a constant ( 10 ). The query returns the customer number and number of orders
for all customers who had more than 10 orders before March 31st, 1999.
2–22
SQL-92 Language Elements
The following examples show merging a list of customers and suppliers without and with
duplicate entries:
AUTHORIZATION
• DBA privilege OR
SQL COMPLIANCE
2–23
Progress SQL-92 Guide and Reference
ENVIRONMENT
RELATED STATEMENTS
2.5 Joins
The following sections describe the supported joins.
SYNTAX
Explicitly specifies that the join generates the Cartesian product of rows in the two table
references. This syntax is equivalent to omitting the WHERE clause and a search condition.
2–24
SQL-92 Language Elements
Specify search_condition for restricting rows that will be in the result table generated by
the join. In the first format, INNER is optional and has no effect. There is no difference
between the WHERE form of inner joins and the JOIN ON form.
SYNTAX
Equi-joins
Specifies that values in one table equal the corresponding column values in the other.
Self joins
Joins a table with itself. If a WHERE clause specifies a self join, the FROM clause must use aliases
to allow two different references to the same table. Also called an auto join.
2–25
Progress SQL-92 Guide and Reference
EXAMPLE
The following queries illustrate the results of a simple CROSS JOIN operation and an
equivalent formulation that does not use the CROSS JOIN syntax:
For customers with orders, retrieve their names and order info:
2–26
SQL-92 Language Elements
-- Retrieve all the customers from the same city as customer SMITH:
SELECT y.cust_no, y.name
FROM customer AS x INNER JOIN customer AS y
ON x.name = ’SMITH’ AND y.city = x.city ;
• In the WHERE clause of a query expression, specify the outer join operator ( + ) after the
column name of the table for which rows will not be preserved in the result table. Both
sides of an outer join search condition in a WHERE clause must be simple column
references. This syntax allows both left and right outer joins.
• For left outer joins only, in the FROM clause, specify the LEFT OUTER JOIN clause
between two table names, followed by a search condition. The search condition can
contain only the join condition between the specified tables.
• Right outer joins are only supported using the outer join operator in the WHERE clause.
The keywords RIGHT OUTER JOIN are not supported currently.
2–27
Progress SQL-92 Guide and Reference
SYNTAX
SYNTAX
EXAMPLE
The following example shows a left outer join. The query requests information about all the
customers and their orders. Even if there is not a corresponding row in the orders table for each
row in the customer table, NULL values are displayed for the order.order_no and
order.order_date columns:
2–28
SQL-92 Language Elements
2–29
Progress SQL-92 Guide and Reference
SYNTAX
[ NOT ] predicate
[ { AND | OR }{ predicate | ( search_condition ) } ]
predicate:
SYNTAX
basic_predicate
| quantified_predicate
| between_predicate
| null_predicate
| like_predicate
| exists_predicate
| in_predicate
| outer_join_predicate
2–30
SQL-92 Language Elements
EXAMPLE
The following example illustrates the use of logical operators:
SYNTAX
=
| <> | != | ^=
| <
| <=
| >
| >=
Table 2–2 lists the relational operators and the resulting predicate for each operator.
See the “Basic Predicate” section for more information.
Relational
Predicate for this Relational Operator
Operator
<> | != | ^= True if the two expressions are not equal. The operators != and ^= are
equivalent to <>.
< True if the first expression is less than the second expression.
2–31
Progress SQL-92 Guide and Reference
Relational
Predicate for this Relational Operator
Operator
<= True if the first expression is less than or equal to the second
expression.
> True if the first expression is greater than the second expression.
>= True if the first expression is greater than or equal to the second
expression.
NOTE: For data sorting and comparison of character data, the SQL server uses a Progress
collation table. The result of comparison is based on the sort weight of each character
in the collation table, for these relational operators:
SYNTAX
2–32
SQL-92 Language Elements
SYNTAX
EXAMPLE
SYNTAX
2–33
Progress SQL-92 Guide and Reference
EXAMPLE
SYNTAX
EXAMPLE
SYNTAX
NOTES
• The column name specified in the LIKE predicate must refer to a character string column.
• A percent sign ( % ) in the pattern matches zero or more characters of the column string.
• A underscore symbol ( _ ) in the pattern matches any single character of the column string.
2–34
SQL-92 Language Elements
EXAMPLE
This example illustrates three ways to use the LIKE predicate:
In the first LIKE clause, for all strings with the substring ’Computer’ the predicate evaluates to
true. In the second LIKE clause, for all strings which are exactly three characters long the
predicate evaluates to true. In the third LIKE clause the backslash character ( \ ) is specified as
the escape character, which means that the special interpretation given to the underscore
character ( _ ) is disabled. The pattern evaluates to TRUE if the item_name column has
embedded underscore characters.
SYNTAX
EXISTS (query_expression)
EXAMPLE
In this example, the predicate evaluates to true if the specified customer has any orders:
2–35
Progress SQL-92 Guide and Reference
2.6.9 IN Predicate
The IN predicate can be used to compare a value with a set of values. If an IN predicate specifies
a query expression, then the result table it returns can contain only a single column.
This is the syntax for an in_predicate:
SYNTAX
expression [ NOT ] IN
{ (query_expression) | (constant , constant [ , ... ] ) }
EXAMPLE
SYNTAX
2–36
SQL-92 Language Elements
2.7 Expressions
An expression is a symbol or string of symbols used to represent or calculate a single value in
a SQL statement. When you specify an expression in a statement, SQL retrieves or calculates
the value represented by the expression and uses that value when it executes the statement.
Expressions are also called scalar expressions or value expressions.
This is the syntax for an expression (expression):
SYNTAX
[ table_name. | alias.]column_name
Specifies a column in a table. You can qualify a column name with the name of the table
or the alias it belongs to.
Specify constant values. See the “Literals” section for information on specifying literals.
aggregate_function | scalar_function
SQL functions. See Chapter 4, “SQL-92 Functions” for more information on “Aggregate
Functions” and “Scalar Functions.”
numeric_arith_expr
Computes a value from numeric values. See “Numeric Arithmetic Expressions” for more
information.
2–37
Progress SQL-92 Guide and Reference
date_arith_expr
Computes a value from date-time values. See “Date Arithmetic Expressions” for more
information.
conditional_expr
Evaluates a search condition or expression and returns one of multiple possible results
depending on that evaluation.
(expression)
EXAMPLES
The following example illustrates specifying a table name for the customer_id field:
You must qualify a column name if it occurs in more than one table specified in the FROM
clause:
NOTES
• Qualified column names are always permitted, even when they are not required.
• You can also qualify column names with an alias. An alias is also called a correlation
name.
• The FROM clause of a query expression can specify an optional alias after the table name
See the “Query Expressions” section for details on query expressions. If you specify an
alias, you must use it, and not the table name, to qualify column names that refer to the
table. Query expressions that join a table with itself must use aliases to distinguish between
references to column names.
2–38
SQL-92 Language Elements
The following example shows a query expression that joins the table customer with itself. It uses
the aliases x and y and returns information on customers in the same city as customer SMITH:
SYNTAX
[ + | - ] { numeric_literal | numeric_expr }
[ { + | - | * | / } numeric_arith_expr ]
+ | -
Unary operators.
numeric_literal
See the “Numeric Literals” section for details on specifying numeric literals.
numeric_expr
Evaluates to a numeric data type. See the “Data Types” section for information about
expressions that can evaluate to numeric data types, including:
• Column name
• Aggregate functions
2–39
Progress SQL-92 Guide and Reference
+ | - | * | /
Operators for addition, subtraction, multiplication, and division. SQL evaluates numeric
arithmetic expressions in the following order:
• Expressions in parentheses
SYNTAX
date_time_expr { + | - } int_expr
| date_time_expr - date_time_expr
date_time_expr
Date-time expressions can contain date-time literals, but they must be converted to DATE
or TIME using the CAST, CONVERT, or TO_DATE functions. See the following
examples: CAST Function (SQL-92 Compatible) and CONVERT Function (Progress
Extension).
2–40
SQL-92 Language Elements
int_expr
Returns an integer value. SQL interprets the integer differently depending on the data type
of the date-time expression:
EXAMPLES
The following example manipulates DATE values using date arithmetic. SQL interprets
integers as days and returns date differences in units of days:
select sysdate,
sysdate - 3 ,
sysdate - cast (’9/29/52’ as date)
from dtest;
The following example manipulates TIME values using date arithmetic. SQL interprets integers
as milliseconds and returns time differences in milliseconds:
select systime,
systime - 3000,
systime - cast (’15:28:01’ as time)
from dtest;
2–41
Progress SQL-92 Guide and Reference
CASE
CASE is the most general conditional expression. It specifies a series of search conditions
and associated expressions. SQL returns the value specified by the first expression whose
associated search condition evaluates as true. If none of the expressions evaluate as true,
the CASE expression returns a null value, or the value of some other default expression if
the CASE expression includes the ELSE clause.
All the other conditional expressions can also be expressed as CASE expressions.
DECODE
NULLIF
COALESCE
COALESCE specifies a series of expressions. SQL returns the first expression whose
value is not null. If all the expressions evaluate as null, COALESCE returns a null value.
IFNULL
2–42
SQL-92 Language Elements
2.8 Literals
A literal is a type of expression that specifies a constant value. Literals are also called constants.
Generally, you can specify a literal wherever SQL syntax allows an expression. Some SQL
constructs allow literals but disallow other forms of expressions.
There are three types of literals:
• Numeric
• Character string
• Date-time
SYNTAX
EXAMPLE
The following numeric strings are all valid:
123
123.456
-123.456
12.34E-04
2–43
Progress SQL-92 Guide and Reference
EXAMPLE
The INSERT statements in the following example show embedding quotation marks in
character-string literals:
c1
--
unquoted literal
’single-quoted literal’
"double-quoted literal"
O’Hare
4 records selected
NOTE
• A character string literal may contain multi-byte characters in the character set used by the
SQL client. Only single-byte ASCII-encoded quote marks are valid in the syntax.
NOTES
• All text (names of days, months, ordinal number endings) in all date-format literals must
be in the English Language. The default date format is American. You can explicitly
request another date format by using a format string.
2–44
SQL-92 Language Elements
Date Literals
A date literal specifies a day, month, and year using any of the following formats, enclosed in
single quotation marks ( ’ ’ ).
This is the syntax for a date_literal:
SYNTAX
{ d ’yyyy-mm-dd’ }
| mm-dd-yyyy
| mm/dd/yyyy
| mm-dd-yy
| mm/dd/yy
| yyyy-mm-dd
| yyyy/mm/dd
| dd-mon-yyyy
| dd/mon/yyyy
| dd-mon-yy
| dd/mon/yy
{ d ’yyyy-mm-dd’ }
A date literal enclosed in an escape clause is compatible with ODBC. Precede the literal
string with an open brace ( { ) and a lowercase d. End the literal with a close brace.
NOTE: If you use the ODBC escape clause, you must specify the date using the format
yyyy-mm-dd.
dd
Specifies the day of month as a one or two digit number in the range 01-31.
mm
Specifies the month value as a one or two digit number in the range 01-12.
mon
Specifies the first 3 characters of the name of the month in the range ’JAN’ to ’DEC’.
2–45
Progress SQL-92 Guide and Reference
yy
yyyy
EXAMPLES
The following example illustrates using the date literal format with an INSERT statement:
The INSERT and SELECT statements in the following example show some of the supported
formats for date literals:
--------------
c1
1956-05-07
1956-05-07
1956-05-07
1956-05-07
1952-09-29
2–46
SQL-92 Language Elements
Time Literals
Time literals specify an hour, minute, second, and millisecond, using the following format,
enclosed in single quotation marks ( ’ ’ ).
This is the syntax for a time_literal:
SYNTAX
{ t ’hh:mi:ss’ } | hh:mi:ss[:mls ]
{ t ’hh:mi:ss’ }
A time literal enclosed in an escape clause is compatible with ODBC. Precede the literal
string with an open brace ( { ) and a lowercase t. End the literal with a close brace ( } ).
NOTE: If you use the ODBC escape clause, you must specify the time using the format
hh:mi:ss.
hh
Specifies the hour value as a two-digit number (in the range 00 to 23).
mi
Specifies the minute value as a two-digit number (in the range 00 to 59).
ss
Specifies the seconds value as a two-digit number (in the range 00 to 59).
mls
Specifies the milliseconds value as a two-digit number (in the range 000 to 999).
2–47
Progress SQL-92 Guide and Reference
EXAMPLES
The following example illustrates using the time literal format with an INSERT statement:
The INSERT statements in the following example show some of the formats SQL will and will
not accept for time literals:
This SELECT statement illustrates which INSERT statements successfully inserted a row:
c2
--
08:30:01
08:30:00
08:30:01
08:30:01
2–48
SQL-92 Language Elements
Timestamp Literals
Timestamp literals specify a date and a time separated by a space, enclosed in single quotation
marks ( ’ ’ ).
This is the syntax for a timestamp_literal:
SYNTAX
{ ts ’yyyy-mm-dd hh:mi:ss’ }
A timestamp literal enclosed in an escape clause is compatible with ODBC. Precede the
literal string with an open brace ( { ) and a lowercase ts. End the literal with a close brace
( } ). Note that braces are part of the syntax.
NOTE: If you use the ODBC escape clause, you must specify the timestamp using the format
yyyy-mm-dd hh:mi:ss.
date_literal
A date literal.
time_literal
A time literal.
EXAMPLES
This example illustrates how to INSERT a time-stamp literal into a column:
This example illustrates a time-stamp literal with the ODBC escape clause:
2–49
Progress SQL-92 Guide and Reference
EXAMPLE
2–50
SQL-92 Language Elements
Date-
format Description
String
Y,YYY The year as a four-digit number with a comma after the first digit.
MON The first three characters of the name of the month (in the range ’JAN’ to
’DEC’).
WW The week of the year as a two-digit number (in the range 01-53).
W The week of the month as a one-digit number (in the range 1-5).
DDD The day of the year as a three-digit number (in the range 001-366).
D The day of the week as a one-digit number (in the range 1-7, 1 for Sunday and
7 for Saturday).
2–51
Progress SQL-92 Guide and Reference
Date-
format Description
String
DAY The day of the week as a character string of nine characters (in the range
’SUNDAY’ to ’SATURDAY ’).
DY The day of the week as a character string of three characters (in the range
’SUN’ to ’SAT’).
J The Julian day (number of days since DEC 31, 1899) as an eight-digit number.
TH When added to a format keyword that results in a number, this format keyword
(’TH’) is replaced by the string ’ST’, ’ND’, ’RD’, or ’TH’ depending on the
last digit of the number.
EXAMPLE
The following example illustrates the use of the DAY, MONTH, DD, and TH format strings:
C1
--
09/29/1952
1 record selected
1 record selected
2–52
SQL-92 Language Elements
Time-
format Description
String
HH12 The hour value as a two-digit number (in the range 00 to 11).
SSSSS The seconds from midnight as a five-digit number (in the range 00000 to
86399).
MLS The milliseconds value as a three-digit number (in the range 000 to 999).
2–53
Progress SQL-92 Guide and Reference
EXAMPLE
The following example illustrates the TO_CHAR function, and the Day, Month, dd, and HH12
format strings:
C1
--
09/29/1952
1 record selected
2–54
3
SQL-92 Statements
This chapter describes the function and syntax for each of these SQL-92 statements as shown
in Table 3–1.
SQL-92 Statements
SQL-92 Statements
3–2
ALTER USER Statement
SYNTAX
EXAMPLE
In this example username 'Jasper' changes the 'Jasper' account password from 'normandy' to
'brittany':
NOTES
• Used in conjunction with CREATE USER and DROP USER, the ALTER USER
statement provides a way to change a user password through SQL-92. This SQL-only
solution does not require the Progress dictionary.
• The old_password specification must match the current password for username.
AUTHORIZATION
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
3–3
BEGIN-END DECLARE SECTION
SYNTAX
host_lang_type variable_name ;
SYNTAX
EXAMPLE
This example is a code fragment from the StatSel function in the sample program
2StatSel.pc. The complete source for sample program, 2StatSel.pc, is listed in Appendix A
of the Progress Embedded SQL-92 Guide and Reference.
3–4
BEGIN-END DECLARE SECTION
NOTES
• The C Language type int is not supported by ESQLC. Type int maps to 16 or 32 bits
depending on the machine architecture. This can create rounding errors at runtime as
values are passed across different machine architectures.
• The scope of variables follows host language scoping rules. The ESQLC variables are not
visible outside the file in which they are declared.
• DECLARE sections are permissible only where host language declarations are
permissible in the host language syntax. This restriction is due to how DECLARE
SECTION blocks are translated into the main body of host language declarations.
• Avoid DECLARE sections in header files that are included by more than one source file.
This can cause duplicate variables with the same name.
• The form of the variable created by ESQLC for each type is specified so that it can be
manipulated from host language statements. Declaring variables allows you to use the
variables in both host language and embedded SQL-92 statements.
AUTHORIZATION
None
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
Static Array Types (Chapter 14 in the Progress Embedded SQL-92 Guide and Reference)
3–5
CALL Statement
CALL Statement
Invokes a stored procedure.
SYNTAX
proc_name
parameter
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–6
CLOSE Statement
CLOSE Statement
Closing a cursor changes the state of the cursor from open to closed.
SYNTAX
cursor_name
An identifier named earlier in a DECLARE CURSOR statement and an OPEN CURSOR statement.
EXAMPLE
This example is a code fragment from the seldone routine in the sample program 4DynSel.pc.
The complete source for sample program, 4DynSel.pc, is listed in Appendix A of the Progress
Embedded SQL-92 Guide and Reference.
NOTES
• Only a cursor in the open state can be set to the closed state.
• When a transaction ends, any cursors in the open state are automatically set to the closed
state.
• When a cursor is in the closed state, you cannot perform FETCH, DELETE, or UPDATE
operations using that cursor.
3–7
CLOSE Statement
AUTHORIZATION
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–8
Column Constraints
Column Constraints
Specifies a constraint for a column that restricts the values that the column can store. INSERT,
UPDATE, or DELETE statements that violate the constraint fail. The database returns a
constraint violation error with SQLCODE of -20116.
Column constraints are similar to table constraints, but their definitions are associated with a
single column rather than the entire table.
SYNTAX
CONSTRAINT constraint_name
NOT NULL [ PRIMARY KEY | UNIQUE ]
| REFERENCES [ owner_name.]table_name [ ( column_name ) ]
| CHECK ( search_condition )
CONSTRAINT constraint_name
Allows you to assign a name that you choose to the column constraint. While this
specification is optional, this facilitates making changes to the column definition. If you
do not specify a constraint_name, the database assigns a name. These names can be long
and unwieldy, and you must query system tables to retrieve the name.
NOT NULL
Defines the column as the primary key for the table. There can be at most one primary key
for a table. A column with the NOT NULL PRIMARY KEY constraint should not contain null
or duplicate values. See the NOTE below.
Other tables can name primary keys as foreign keys in their REFERENCES clauses. If they
do, SQL restricts operations on the table containing the primary key in the following ways:
• DELETE and UPDATE statements that modify values in the column that match a foreign
key's value also fail.
3–9
Column Constraints
Defines the column as a unique key that cannot contain null or duplicate values. Columns
with NOT NULL UNIQUE constraints defined for them are also called candidate keys.
Other tables can name unique keys in their REFERENCES clauses. If they do, SQL restricts
operations on the table containing the unique key in the following ways:
A foreign key and its matching primary or unique key specify a referential constraint. A
value stored in the foreign key must either be null or be equal to some value in the
matching unique or primary key.
You can omit the column_name argument if the table specified in the REFERENCES clause
has a primary key and you want the primary key to be the matching key for the constraint.
CHECK ( search_condition )
Specifies a column-level check constraint. SQL restricts the form of the search condition.
The search condition must not:
• Refer to any column other than the one with which it is defined
EXAMPLES
The following example shows the creation of a primary key column on the supplier table:
3–10
Column Constraints
The following example creates a NOT NULL UNIQUE constraint to define the column ss_no as a
unique key for the employee table.
NOTE: The second CREATE TABLE statement in the previous example could have omitted the
column name order_no in the REFERENCES clause, since it refers to the primary key
of table orders.
The following example creates a check constraint:
NOTE: If a column is defined with a UNIQUE column constraints, no error results if more
than one row has a NULL value for the column. This is in compliance with the
SQL-92 standard.
3–11
COMMIT Statement
COMMIT Statement
Commits a transaction explicitly after executing one or more SQL statements. Committing a
transaction makes permanent any changes made by the SQL statements.
SYNTAX
COMMIT [ WORK ] ;
NOTES
• The SQL statements executed prior to executing the COMMIT statement are executed as
one atomic transaction that is recoverable and durable. The transaction is serializable if
you specify this isolation level.
• On a system failure and or the execution of the ROLLBACK, the transaction is rolled back
to its initial state. Any changes made by the transaction are undone, restoring the database
to its initial state. In the event of a system failure, the transaction will be rolled back during
crash recovery when the database is restarted.
• Once a COMMIT operation is executed the database modifications cannot be rolled back.
• The atomicity applies only to the database modification and not to any direct I/O
performed to devices such as the terminal, printer, and OS files by the application code.
3–12
COMMIT Statement
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
ROLLBACK Statement
3–13
CONNECT Statement
CONNECT Statement
Establishes a connection to a database. Optionally, the CONNECT statement can also specify
a name for the connection and a username and password for authentication.
SYNTAX
CONNECT TO connect_string
[ AS connection_name ]
[ USER username ]
[ USING password ] ;
connect_string
SYNTAX
NOTE: Arguments to CONNECT must be either string literals enclosed in quotation marks
or character-string host variables.
connect_string
Specifies to which database to connect. If the CONNECT statement specifies DEFAULT, SQL
tries to connect to the environment-defined database, if any. The value of the DB_NAME
environment variable specifies the default connect string.
3–14
CONNECT Statement
connection_name
The name of the connection as either a character literal or host variable. If the CONNECT
statement omits a connection name, the default is the name of the database. Connection
names must be unique.
username
User name for authentication of the connection. SQL verifies the user name against a
corresponding password before it connects to the database. The value of the DH_USER
environment variable specifies the default user name. If DH_USER is not set, the value of
the USER environment variable specifies the default user name.
password
Password for authentication of the connection. SQL verifies the password against a
corresponding user name before it connects to the database.
The value of the DH_PASSWD environment variable determines the default password.
3–15
CONNECT Statement
NOTES
• An application can connect to more than one database at a time, with a maximum of 10
connections. However, the application can actually gain access to only one database at a
time. The database name specified in the CONNECT statement becomes the active one.
EXAMPLES
The following examples illustrate the CONNECT statement:
• The first statement shown connects to the salesdb database on the local system.
• The second statement connects to the custdb database on the local system.
See also the last example for the DISCONNECT Statement which illustrates the CONNECT,
SET CONNECTION, and DISCONNECT statements in combination.
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–16
CREATE INDEX Statement
SYNTAX
UNIQUE
Does not allow the table to contain any rows with duplicate column values for the set of
columns specified for that index.
index_name
table_name
column_name [ , ... ]
The columns on which searches and retrievals will be ordered. These columns are called
the index key. When more than one column is specified in the CREATE INDEX statement, a
concatenated index is created.
area_name
The name of the storage area where the index and its entries are stored.
ASC | DESC
Allows the index to be ordered as either ascending (ASC) or descending (DESC) on each
column of the concatenated index. The default is ASC.
3–17
CREATE INDEX Statement
NOTES
• The first index you create on a table should be the most fundamental key of the table. This
index (the first one created on a table) cannot be dropped except by dropping the table.
EXAMPLE
This example illustrates how to create a UNIQUE INDEX on a table:
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–18
CREATE PROCEDURE Statement
SYNTAX
parameter_decl
SYNTAX
owner_name
Specifies the owner of the procedure. If the name is different from the user name of the
user executing the statement, then the user must have DBA privileges.
procname
Names the stored procedure. DROP PROCEDURE statements specify the procedure name
defined here. SQL also uses procname in the name of the Java class that it creates from the
Java snippet.
IN | OUT | INOUT
Calling applications pass values for input parameters in the CALL statement or CALL escape
sequence.
3–19
CREATE PROCEDURE Statement
INOUT parameters have both a value passed in and receive a new value during procedure
processing.
parameter_name data_type
Names a parameter and associates an SQL data type with it. The data_type must be one
of the supported data types described in the “Data Types” section in Chapter 2, “SQL-92
Language Elements.”
Specifies columns in the result set the procedure returns. If the CREATE PROCEDURE
statement includes this clause, the Java snippet must explicitly insert rows into the result
set using the Java class SQLResultSet.
Note that the column_name argument is not used in the body of the stored procedure.
Instead, methods of the Java classes refer to columns in the result set by ordinal number,
not by name.
IMPORT
java_import_clause
Specifies standard Java classes to import. The IMPORT keyword must be uppercase and on
a separate line.
BEGIN
java_snippet
END
The body of the stored procedure. The body is a sequence of Java statements between the
BEGIN and END keywords. The Java statements become a method in a class that SQL
creates and submits to the Java compiler.
NOTE: The BEGIN and END keywords must be uppercase and on separate lines.
3–20
CREATE PROCEDURE Statement
EXAMPLE
empcursor.close () ;
END
3–21
CREATE PROCEDURE Statement
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–22
CREATE SYNONYM Statement
SYNTAX
PUBLIC
Specifies that the synonym is public: all users can refer to the name without qualifying it.
By default, the synonym is private: other users must qualify the synonym by preceding it
with the user name of the user who created it.
SYNONYM synonym
EXAMPLE
3–23
CREATE SYNONYM Statement
AUTHORIZATION
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
3–24
CREATE TABLE Statement
SYNTAX
owner_name
Specifies the owner of the table. If the name is different from the user name of the user
executing the statement, then the user must have DBA privileges.
table_name
column_definition:
SYNTAX
column_name data_type
[ DEFAULT { literal | NULL | SYSDATE } ]
[ column_constraint [ column_constraint , ... ] ]
3–25
CREATE TABLE Statement
column_name data_type
Names a column and associates a data type with it. The column names specified must
be different from other column names in the table definition. The data_type must be
one of the supported data types described in the “Data Types” section in Chapter 2,
“SQL-92 Language Elements.”
Note that when a table contains more than one column, a comma separator is required
after each column_definition except for the final column_definition.
DEFAULT
Specifies an explicit default value for a column. The column takes on the value if an
INSERT statement does not include a value for the column. If a column definition
omits the DEFAULT clause, the default value is NULL.
SYSDATE The current date. Valid only for columns defined with
DATE data types. SYSDATE is equivalent to the Progress
default keyword TODAY.
column_constraint
Specifies a constraint that will be applied while inserting or updating a value in the
associated column. For more information, see the "Column Constraints" section.
table_constraint
Specifies a constraint that will be applied while inserting or updating a row in the
table. For more information, see the Table Constraints section.
AREA area_name
Specifies the name of the storage area where data stored in the table is to be stored.
If the specified area does not exist, the database returns an error. If you do not specify
an area, the default area is used.
3–26
CREATE TABLE Statement
AS query_expression
Specifies a query expression to use for the data types and data values of the table's
columns. The types and lengths of the columns of the query expression result become
the types and lengths of the respective columns in the table created. The rows in the
resultant set of the query expression are inserted into the table after creating the table.
In this form of the CREATE TABLE statement, column names are optional. If omitted,
the names of the table's columns are taken from the column names of the query
expression.
EXAMPLES
In the following CREATE TABLE supplier_item example, the user issuing the CREATE
TABLE statement must have REFERENCES privilege on the itemno column of the table
john.item:
The following CREATE TABLE statement explicitly specifies a table owner, gus:
The following example shows the AS query_expression form of CREATE TABLE to create and
load a table with a subset of the data in the customer table:
3–27
CREATE TABLE Statement
The following example includes a NOT NULL column constraint and DEFAULT clauses for
column definitions:
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–28
CREATE TRIGGER Statement
SYNTAX
owner_name
Specifies the owner of the trigger. If the name is different from the user name of the user
executing the statement, then the user must have DBA privileges.
trigname
Names the trigger. DROP TRIGGER statements specify the trigger name defined here. SQL
also uses trigname in the name of the Java class that it creates from the Java snippet.
BEFORE | AFTER
Denotes the trigger action time. The trigger action time specifies whether the triggered
action, implemented by java_snippet, executes BEFORE or AFTER the invoking INSERT,
UPDATE, or DELETE statement.
3–29
CREATE TRIGGER Statement
If UPDATE is the triggering statement, this clause can include an optional column list. Only
updates to any of the specified columns will activate the trigger. If UPDATE is the triggering
statement and does not include the optional column list, then any UPDATE on the table will
activate the trigger.
ON table_name
Identifies the name of the table where the trigger is defined. A triggering statement that
specifies table_name causes the trigger to execute. table_name cannot be the name of a
view.
The meaning of the OLDROW and NEWROW arguments of the REFERENCING clause depends on
whether the trigger event is INSERT, UPDATE, or DELETE:
• UPDATE...REFERENCING OLDROW means the triggered action can access the values of
columns, before they are changed, of each row updated. SQL passes the column
values of the row as it exists in the database before the update operation.
3–30
CREATE TRIGGER Statement
• UPDATE is the only triggering statement that allows both NEWROW and OLDROW in the
REFERENCING clause.
• UPDATE...REFERENCING NEWROW means the triggered action can access the values of
columns, after they are changed, of each row updated. SQL passes the column values
specified by the UPDATE statement.
NOTES
• The trigger action time (BEFORE or AFTER) does not affect the meaning of the REFERENCING
clause. For instance, BEFORE UPDATE...REFERENCING NEWROW still means the values of
columns after they are updated will be available to the triggered action.
• The REFERENCING clause generates an error if the trigger does not include the FOR EACH ROW
clause.
FOR EACH ROW means the triggered action executes once for each row being updated by the
triggering statement. CREATE TRIGGER must include the FOR EACH ROW clause if it also
includes a REFERENCING clause.
FOR EACH STATEMENT means the triggered action executes only once for the whole
triggering statement. FOR EACH STATEMENT is the default.
IMPORT java_import_clause
Specifies standard Java classes to import. The IMPORT keyword must be uppercase and on
a separate line.
BEGIN
java_snippet
END
Denotes the body of the trigger or the triggered action. The body contains the Java source
code that implements the actions to be completed when a triggering statement specifies the
target table. The Java statements become a method in a class that SQL creates and submits
to the Java compiler.
The BEGIN and END keywords must be uppercase and on separate lines.
3–31
CREATE TRIGGER Statement
NOTES
• Triggers can take action on their own table so that they invoke themselves. SQL limits
such recursion to five levels.
• You can you have multiple triggers on the same table. Multiple UPDATE triggers on the
same table must specify different columns. SQL-92 executes all triggers applicable to a
given combination of table, trigger event, and action time.
• The actions carried out by a trigger can fire another trigger. When this happens, the other
trigger's actions execute before the rest of the first trigger finishes executing.
• If a constraint and trigger are both invoked by a particular SQL statement, SQL checks
constraints first, so any data modification that violates a constraint does not also fire a
trigger.
• To modify an existing trigger, you must delete it and issue another CREATE TRIGGER
statement. You can query the systrigger system table for information about the trigger
before you delete it.
EXAMPLE
This example illustrates an UPDATE trigger on a table called BUG_INFO. If the STATUS or
PRIORITY fields are modified, the trigger modifies the BUG_SUMMARY and
BUG_STATUS tables appropriately, based on defined conditions:
(1 of 3)
IMPORT
import java.sql.* ;
3–32
CREATE TRIGGER Statement
(2 of 3)
BEGIN
try
{
// column number of STATUS is 10
String old_status, new_status;
if ((old_status.CompareTo("OPEN") == 0) &&
(new_status.CompareTo("FIXED") == 0))
{
// If STATUS has changed from OPEN to FIXED
// increment the bugs_fixed_cnt by 1 in the
// row corresponding to current month
// and current year
SQLIStatement update_stmt (
" update BUG_STATUS set bugs_fixed_cnt = bugs_fixed_cnt + 1 "
" where month = ? and year = ?"
);
update_stmt.SetParam(1, current_month);
update_stmt.SetParam(2, current_year);
update_stmt.Execute();
SQLIStatement insert_stmt (
" insert into BUG_SUMMARY values (?,?,?)"
);
3–33
CREATE TRIGGER Statement
(3 of 3)
insert_stmt.SetParam(1, bug_id);
insert_stmt.SetParam(2, priority);
insert_stmt.SetParam(3, turn_around_time);
insert_stmt.Execute();
}
if ((new_priority.CompareTo("URGENT")==0) &&
(old_priority.CompareTo("URGENT") != 0))
{
// If PRIORITY has changed to URGENT increment the
// bugs_escalated by 1 in the row corresponding to
// current month and current year
SQLIStatement update_stmt (
" update BUG_STATUS
set bugs_escalated_cnt = bugs_escalated_cnt + 1 "
" where month = ? and year = ?"
);
update_stmt.SetParam(1, current_month);
update_stmt.SetParam(2, current_year);
update_stmt.Execute();
}
}
catch (SQLException e)
{
// Log the exception message from e.
SQLException sqle = new SQLException("UPDATE_BUG_TRIGGER failed");
throw sqle;
}
END
3–34
CREATE TRIGGER Statement
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–35
CREATE USER Statement
SYNTAX
EXAMPLE
In this example an account with DBA privileges creates the 'username' 'Jasper' with 'password'
'spaniel':
NOTES
• Used in conjunction with ALTER USER Statement and DROP USER Statement, the
CREATE USER statement provides a way to manage user records through SQL. This
SQL_only solution does not require the Progress dictionary.
• Before issuing the CREATE USER statement, there are no users defined in the user table
and any user may log into the database.
• After issuing the CREATE USER statement, only users defined in the user table may log
into the database.
3–36
CREATE USER Statement
AUTHORIZATION
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
3–37
CREATE VIEW Statement
SYNTAX
owner_name
( column_name, column_name,... )
Specifies column names for the view. These names provide an alias for the columns
selected by the query specification. If the column names are not specified, then the view
is created with the same column names as the tables or views on which it is based.
Checks that the updated or inserted row satisfies the view definition. The row must be
selectable using the view. The WITH CHECK OPTION clause is only allowed on an updatable
view.
NOTES
• A view is deletable if deleting rows from that view is allowed. For a view to be deletable,
the view definition has to satisfy the following conditions:
– The first FROM clause contains only one table reference or one view reference.
– If the first FROM clause contains a view reference, then the view referred to is
deletable.
3–38
CREATE VIEW Statement
• A view is updatable if updating rows from that view is allowed. For a view to be
updatable, the view has to satisfy the following conditions:
– The view is deletable (it satisfies all the conditions specified above for deletability).
– All the select expressions in the first SELECT clause of the view definition are
simple column references.
– If the first FROM clause contains a view reference, then the view referred to is
updatable.
• A view is insertable if inserting rows into that view is allowed. For a view to be insertable,
the view has to satisfy the following conditions:
– The view is updatable (it satisfies all the conditions specified above for updatability).
– If the first FROM clause contains a table reference, then all NOT NULL columns of
the table are selected in the first SELECT clause of the view definition.
– If the first FROM clause contains a view reference, then the view referred to is
insertable.
EXAMPLE
3–39
CREATE VIEW Statement
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–40
DECLARE CURSOR Statement
SYNTAX
cursor_name
A name you assign to the cursor. The name must meet the requirements for an identifier.
prepared_statement_name
EXAMPLES
This example illustrates static processing of a SELECT statement. This is a code fragment from
the StatSel function in sample program 2StatSel.pc. The complete source for this sample
program is in Appendix A of the Progress Embedded SQL-92 Guide and Reference.
3–41
DECLARE CURSOR Statement
This example is a code fragment from the DynSel function in sample program 4DynSel.pc,
which illustrates dynamic processing of a SELECT statement. The complete source for this
sample program is in Appendix A of the Progress Embedded SQL-92 Guide and Reference.
NOTES
• You must declare a cursor before any OPEN Statement, FETCH Statement, or CLOSE
Statement.
• The scope of the cursor declaration is the entire source file in which it is declared. The
operations on the cursor such as OPEN Statement, CLOSE Statement, and FETCH
Statement can occur only within the same compilation unit as the cursor declaration.
• The use of a cursor allows the execution of the positioned forms of the UPDATE and
DELETE statements.
– The DECLARE statement and the OPEN statement that follows must occur within
the same transaction within the same task.
• See the "SELECT a Single Row" reference entry for descriptions of the ORDER BY
Clause and FOR UPDATE Clause.
3–42
DECLARE CURSOR Statement
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–43
DELETE Statement
DELETE Statement
Deletes zero, one, or more rows from the specified table that satisfy the search condition
specified in the WHERE clause. If the optional WHERE clause is not specified, then the
DELETE statement deletes all rows of the specified table.
SYNTAX
EXAMPLE
NOTE
• If the table has primary or candidate keys and there are references from other tables to the
rows to be deleted, the statement is rejected.
AUTHORIZATION
Must have DBA privilege, ownership of the table, of DELETE permission of the table.
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–44
DESCRIBE Statement
DESCRIBE Statement
Writes information about a prepared statement to the SQL Descriptor Area (SQLDA). You use
a DESCRIBE statement in a series of steps that allows a program to accept SQL-92 statements
at run time. Dynamically generated statements are not part of a program's source code; they are
generated at run time.
There are two forms of the DESCRIBE statement:
• The DESCRIBE BIND VARIABLES Statement writes information about input variables
in an expression to an SQLDA. These variables can be substitution variable names or
parameter markers.
• The DESCRIBE SELECT LIST Statement writes information about select list items in a
prepared SELECT statement to an SQLDA.
SYNTAX
The SQLDA is a host language data structure used in dynamic SQL-92 processing. DESCRIBE
statements write information about the number, data types, and sizes of input variables or select
list items to SQLDA structures. Program logic then processes that information to allocate
storage. OPEN, EXECUTE, and FETCH statements read the SQLDA structures for the
addresses of the allocated storage.
For more information see the DESCRIBE BIND VARIABLES Statement and the DESCRIBE
SELECT LIST Statement.
3–45
DESCRIBE BIND VARIABLES Statement
SYNTAX
statement_name
The name of an input SQL-92 statement to be processed using dynamic SQL-92 steps.
Typically, this is the same statement_name used in the PREPARE statement.
input_sqlda_name
The name of the SQLDA structure to which DESCRIBE will write information about input
variables. Input variables represent values supplied to INSERT and UPDATE statements at
run time, and to predicates in DELETE, UPDATE, and SELECT statements at run time.
To utilize the DESCRIBE BIND VARIABLES statement in your application, issue statements
in the following order:
1. PREPARE
The DESCRIBE BIND VARIABLES statement writes the number of input variables to the
sqld_nvars field of the SQLDA. If the sqld_size field of the SQLDA is not equal to or greater
than this number, DESCRIBE writes the value as a negative number to sqld_nvars. Design
your application to check sqld_nvars for a negative number to determine if a particular
SQLDA is large enough to process the current input statement.
Input variables in dynamic SQL-92 statements are identified by parameter markers or as
substitution names. See the PREPARE Statement for more information.
3–46
DESCRIBE BIND VARIABLES Statement
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–47
DESCRIBE SELECT LIST Statement
SYNTAX
statement_name
The name of a SELECT statement to be processed using dynamic SQL-92 steps. Typically,
this is the same statement_name as in the PREPARE Statement.
output_sqlda_name
The name of the SQLDA structure to which DESCRIBE will write information about select
list items.
NOTE: Select list items are column names and expressions in a SELECT Statement. A
FETCH Statement writes the values returned by a SELECT Statement to the
addresses stored in an output SQLDA.
To utilize the DESCRIBE SELECT LIST statement in your application, issue statements in the
following order:
1. DECLARE CURSOR
2. PREPARE
3. OPEN
5. FETCH
A DESCRIBE SELECT LIST statement writes the number of select list items to the
sqld_nvars field of an output SQLDA. If the sqld_size field of the SQLDA is not equal to or
greater than this number, DESCRIBE writes the value as a negative number to sqld_nvars.
Design your application to check sqld_nvars for a negative number to determine if a particular
output SQLDA is large enough to process the current SELECT Statement.
3–48
DESCRIBE SELECT LIST Statement
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–49
DISCONNECT Statement
DISCONNECT Statement
Terminates the connection between an application and the database to which it is connected.
SYNTAX
connection_name
The name of the connection as either a character literal or host variable. See the
CONNECT Statement for more information on the connection_name.
CURRENT
ALL
DEFAULT
EXAMPLES
The first example illustrates CONNECT TO AS 'connection_name' and DISCONNECT
'connection_name'.
EXEC SQL
CONNECT TO 'progress:T:localhost:6745:salesdb' AS 'conn_1' ;
/*
** C Language and embedded SQL-92 application processing against the
** database in the connect_string
*/
.
.
.
EXEC SQL
DISCONNECT 'conn_1' ;
3–50
DISCONNECT Statement
EXEC SQL
CONNECT TO DEFAULT ;
/*
** C Language and embedded SQL-92 application processing against the
** database in the connect_string
*/
.
.
.
EXEC SQL
DISCONNECT DEFAULT ;
This example disconnects all database connections. After you issue DISCONNECT ALL there
is no current connection.
EXEC SQL
DISCONNECT ALL;
The following example illustrates the CONNECT, SET CONNECTION, and DISCONNECT
statements in combination using these steps:
3–51
DISCONNECT Statement
/*
** 1. CONNECT TO 'connect_string'
*/
EXEC SQL
CONNECT TO 'progress:T:localhost:6745:salesdb' AS 'conn_1' ;
/*
** 2. CONNECT TO DEFAULT. This suspends the conn_1 connection
** and sets the DEFAULT connection current
*/
EXEC SQL
CONNECT TO DEFAULT ;
/*
** Application processing against the DEFAULT database
*/
.
.
.
/*
** 3. DISCONNECT DEFAULT
*/
EXEC SQL
DISCONNECT DEFAULT ;
/*
** 4. Set the first connection, conn_1, current
*/
EXEC SQL
SET CONNECTION conn_1 ;
/*
** Application processing against the database in the connect_string
*/
.
.
.
/*
** 5. DISCONNECT the conn_1 connection, which is the current connection.
*/
EXEC SQL
DISCONNECT CURRENT ;
3–52
DISCONNECT Statement
NOTES
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–53
DROP INDEX Statement
SYNTAX
index_owner_name
Specifies the name of the index owner. If index_owner_name is specified and is different
from the name of the user executing the statement, then the user must have DBA
privileges.
table_name
NOTE: You cannot drop the first index created on a table, except by dropping the table.
EXAMPLE
3–54
DROP INDEX Statement
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–55
DROP PROCEDURE Statement
SYNTAX
owner_name
procedure_name
EXAMPLE
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–56
DROP SYNONYM Statement
SYNTAX
PUBLIC
Specifies that the synonym was created with the PUBLIC argument.
SYNONYM synonym
EXAMPLE
NOTES
• If DROP SYNONYM specifies PUBLIC and the synonym was not a public synonym, SQL
generates the base table not found error.
• If DROP SYNONYM does not specify public and the synonym was created with the PUBLIC
argument, SQL generates the base table not found error.
3–57
DROP SYNONYM Statement
AUTHORIZATION
Must have DBA privilege or ownership of the synonym (for DROP SYNONYM).
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
3–58
DROP TABLE Statement
SYNTAX
owner_name
table_name
EXAMPLE
NOTES
• If owner_name is specified and is different from the name of the user executing the
statement, then the user must have DBA privileges.
• When a table is dropped, the indexes on the table and the privileges associated with the
table are dropped automatically.
• Views dependent on the dropped table are not automatically dropped, but become invalid.
• If the table is part of another table's referential constraint (if the table is named in another
table's REFERENCES clause), the DROP TABLE statement fails. You must DROP the
referring table first.
3–59
DROP TABLE Statement
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–60
DROP TRIGGER Statement
SYNTAX
owner_name
trigger_name
EXAMPLE
AUTHORIZATION
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
3–61
DROP USER Statement
SYNTAX
'username'
Specifies the user name to delete. The 'username' must be enclosed in quotes.
EXAMPLE
In this example, an account with DBA privileges drops the 'username' 'Jasper':
NOTES
• Used in conjunction with CREATE USER Statement and ALTER USER Statement, the
DROP USER statement provides a way to manage user records through SQL. This
SQL-only solution does not require the Progress dictionary.
AUTHORIZATION
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
3–62
DROP VIEW Statement
SYNTAX
owner_name
view_name
EXAMPLE
NOTES
• If owner_name is specified and is different from the name of the user executing the
statement, then the user must have DBA privileges.
• When a view is dropped, other views that are dependent on this view are not dropped. The
dependent views become invalid.
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–63
EXEC SQL Delimiter
SYNTAX
sql_statement
EXAMPLE
This example is a code fragment from the DynSel function in sample program 4DynSel.pc,
which illustrates dynamic processing of a SELECT statement. The complete source for sample
program, 2StatSel.pc, is listed in Appendix A of the Progress Embedded SQL-92 Guide and
Reference.
NOTE
• In general, the ESQLC precompiler does not parse host language statements and therefore
does not detect any syntax or semantic errors in host language statements. The exceptions
to this rule are:
3–64
EXEC SQL Delimiter
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
None
3–65
EXECUTE Statement
EXECUTE Statement
Executes the statement specified in statement_name. This is the syntax for an EXECUTE
statement:
SYNTAX
EXECUTE statement_name
[ USING
{ [ SQL ] DESCRIPTOR structure_name
| :host_variable [ [ INDICATOR ] :ind_variable ] , ... }
] ;
statement_name
structure_name
EXAMPLE
This example is a code fragment from the DynUpd function in sample program 3DynUpd.pc,
which illustrates dynamic processing of an UPDATE statement. The complete source for
sample program, 2StatSel.pc, is listed in Appendix A of the Progress Embedded SQL-92
Guide and Reference.
/*
** Process the non-SELECT input statement
** PREPARE the statement
** EXECUTE the prepared statement
** COMMIT WORK
*/
3–66
EXECUTE Statement
NOTES
• A prepared statement can be executed multiple times in the same transaction. Typically
each call to the EXECUTE statement supplies a different set of host variables.
• If there is a DESCRIPTOR in the USING clause, the program can allocate space for the
input host variables at runtime.
AUTHORIZATION
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–67
EXECUTE IMMEDIATE Statement
SYNTAX
statement_name
structure_name
NOTES
• A statement string must not contain host variable references or parameter markers.
• A statement string must not begin with EXEC SQL Delimiter and must not end with a
semicolon.
• When an EXECUTE IMMEDIATE statement is executed, the SQL engine parses the
statement and checks it for errors. Any error in the execution of the statement is reported
in the SQLCA.
• If the same SQL-92 statement is to be executed multiple times, it is more efficient to use
PREPARE and EXECUTE statements, rather than an EXECUTE IMMEDIATE
statement.
3–68
EXECUTE IMMEDIATE Statement
AUTHORIZATION
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–69
FETCH Statement
FETCH Statement
Moves the position of the cursor to the next row of the active set and fetches the column values
of the current row into the specified host variables.
SYNTAX
FETCH cursor_name
{ USING SQL DESCRIPTOR structure_name
| INTO :host_var_ref [[ INDICATOR ] :ind_var_ref ] , ...
} ;
cursor_name
A name identified in an earlier DECLARE CURSOR statement and an OPEN CURSOR statement.
Directs the SQL engine to FETCH data into storage addressed by an SQLDA structure.
3–70
FETCH Statement
EXAMPLE
The complete source for sample program 4DynSel.pc is listed in Appendix A of the Progress
Embedded SQL-92 Guide and Reference. This example is a code fragment from the dynsel
function in that sample program:
/*
** One way to limit the number of rows returned is to
** set a new value for "j" here. As supplied in the SPORTS200 database,
** the PUB.InventoryTrans table contains 75 rows.
*/
j = 100;
for (i = 0; i < j; i++)
{
EXEC SQL FETCH dyncur INTO
:int_p1_v, :int_p2_v, :char_p_v ;
if (i == 0)
{
printf (" 1st col 2nd col 3rd col");
printf (" ------- ------- --------");
}
printf (" %d %d %s ",
int_p1_v, int_p2_v, char_p_v) ;
}
NOTES
– The first time you execute a FETCH statement after opening the cursor, the cursor is
positioned to the first row of the active set.
– Subsequent FETCH operations advance the cursor position in the active set. The next
row becomes the current row.
– When the current row is deleted using a positioned DELETE statement, the cursor is
positioned before the row after the deleted row in the active set.
• The cursor can only be moved forward in the active set by executing FETCH statements.
To move the cursor to the beginning of the active set, you must CLOSE the cursor and
OPEN it again.
3–71
FETCH Statement
• If the cursor is positioned on the last row of the active set or if the active set does not
contain any rows, executing a FETCH will return the status code SQL_NOT_FOUND in
the SQLCA.
• After a successful FETCH, the total row count fetched so far for this cursor is returned in
sqlca.sqlerrd[2]. The count is set to zero after an OPEN cursor operation.
• You can FETCH multiple rows in one FETCH operation by using array variables in the
INTO clause. The SQL_NOT_FOUND status code is returned in the SQLCA when the
end of the active set is reached, even if the current FETCH statement returns one or more
rows.
• If you use array variables in a FETCH Statement, the array sizes are set to the number of
rows fetched after the FETCH statement is executed.
AUTHORIZATION
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–72
GET DIAGNOSTICS Statement
SYNTAX
GET DIAGNOSTICS
:param = header_info_item
[ , :param = header_info_item ] , ... ;
:param
header_info_item
One of the following keywords, which returns associated information about the
diagnostics area or the SQL statement:
SYNTAX
NUMBER
The number of detail areas in the diagnostics area. Currently, NUMBER is always 1.
NUMBER is type NUMERIC with a scale of 0.
MORE
A one-character string with a value of Y (all conditions are detailed in the diagnostics
area) or N (all conditions are not detailed) that tells whether the diagnostics area
contains information on all the conditions resulting from the statement.
3–73
GET DIAGNOSTICS Statement
COMMAND_FUNCTION
Contains the character-string code for the statement (as specified in the SQL-92
standard), if the statements was a static SQL statement. If the statement was a
dynamic statement, contains either the character string 'EXECUTE' or 'EXECUTE
IMMEDIATE'.
DYNAMIC_FUNCTION
Contains the character-string code for the statement (as specified in the SQL-92
standard). For dynamic SQL statements only (as indicated by 'EXECUTE' or 'EXECUTE
IMMEDIATE' in the COMMAND_FUNCTION item).
ROW_COUNT
EXAMPLE
The GET DIAGNOSTICS example extracts header information about the last SQL statement
executed. The information is assigned to host variables that are defined in the DECLARE
SECTION of an embedded SQL program:
For information on defining and using host variables, see Chapter 7, "Query Statements," in the
Progress Embedded SQL-92 Guide and Reference.
NOTE: The GET DIAGNOSTICS statement itself does not affect the contents of the
diagnostics area. This means applications can issue multiple GET DIAGNOSTICS
statements to retrieve different items of information about the same SQL statement.
SQL COMPLIANCE
SQL-92
ENVIRONMENT
Embedded SQL
RELATED STATEMENTS
3–74
GET DIAGNOSTICS EXCEPTION Statement
SYNTAX
EXCEPTION number
Specifies that GET DIAGNOSTICS EXCEPTION extracts detail information. number specifies
which of multiple detail areas GET DIAGNOSTICS extracts. Currently, number must be the
integer 1.
:param
Receives the information returned by the GET DIAGNOSTICS EXCEPTION statement. The
host-language program must declare a param compatible with the SQL data type of the
information item.
3–75
GET DIAGNOSTICS EXCEPTION Statement
detail_info_item
One of the following keywords, which returns associated information about the particular
error condition:
SYNTAX
CONDITION_NUMBER
| RETURNED_SQLSTATE
| CLASS_ORIGIN
| SUBCLASS_ORIGIN
| ENVIRONMENT_NAME
| CONNECTION_NAME
| CONSTRAINT_CATALOG
| CONSTRAINT_SCHEMA
| CONSTRAINT_NAME
| CATALOG_NAME
| SCHEMA_NAME
| TABLE_NAME
| COLUMN_NAME
| CURSOR_NAME
| MESSAGE_TEXT
| MESSAGE_LENGTH
| MESSAGE_OCTET_LENGTH
CONDITION_NUMBER
RETURNED_SQLSTATE
CLASS_ORIGIN
The general type of error. For example, 'connection exception,' or 'data exception.'
SUBCLASS_ORIGIN
3–76
GET DIAGNOSTICS EXCEPTION Statement
ENVIRONMENT_NAME
CONNECTION_NAME
CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
CATALOG_NAME
SCHEMA_NAME
TABLE_NAME
COLUMN_NAME
The name of the affected columns, if the error condition involves a column.
CURSOR_NAME
MESSAGE_TEXT
MESSAGE_LENGTH
3–77
GET DIAGNOSTICS EXCEPTION Statement
MESSAGE_OCTET_LENGTH
EXAMPLE
THE GET DIAGNOSTICS EXCEPTION example extracts detail information into host
variables that are defined in the DECLARE SECTION of an embedded SQL program:
For information on defining and using host variables, see Chapter 7, "Query Statements," in the
Progress Embedded SQL-92 Guide and Reference.
NOTE: The GET DIAGNOSTICS statement itself does not affect the contents of the
diagnostics area. This means applications can issue multiple GET DIAGNOSTICS
statements to retrieve different items of information about the same SQL statement.
SQL COMPLIANCE
SQL-92
ENVIRONMENT
Embedded SQL
RELATED STATEMENTS
3–78
GRANT Statement
GRANT Statement
Grants various privileges to the specified users of the database. There are two forms of the
GRANT statement:
• Grant various privileges on specific tables and views. Privilege definitions are stored in
the system tables SYSDBAUTH, SYSTABAUTH, and SYSCOLAUTH for the database,
tables, and columns, respectively.
SYNTAX
SYNTAX
privilege:
SYNTAX
RESOURCE
3–79
GRANT Statement
DBA
Allows the specified users to create, access, modify, or delete any database object, and to
grant other users any privileges.
SELECT
Allows the specified users to read data from the table or view.
INSERT
Allows the specified users to add new rows to the table or view.
DELETE
Allows the specified users to delete rows from the table or view.
INDEX
ALL
TO PUBLIC
Grants the specified privileges on the table or view to any user with access to the system.
3–80
GRANT Statement
Allows the specified users to grant their privileges or a subset of their privileges to other
users.
EXAMPLE
NOTE: If the username specified in a RESOURCE or DBA GRANT operation does not
already exist, the GRANT statement creates a row in the SYSDBAUTH system table
for the new username. This row is not deleted by a subsequent REVOKE operation.
AUTHORIZATION
Must have the DBA privilege, ownership of the table, or all the specified privileges on the
table (granted with the WITH GRANT OPTION clause).
SQL COMPLIANCE
SQL-92, ODBC Core SQL grammar. Extensions: INDEX, RESOURCE, DBA privileges
ENVIRONMENT
RELATED STATEMENTS
REVOKE Statement
3–81
INSERT Statement
INSERT Statement
Inserts new rows into the specified table or view that will contain either the explicitly specified
values or the values returned by the query expression.
SYNTAX
EXAMPLES
NOTES
• If the optional list of column names is specified, then only the values for those columns
are required. The rest of the columns of the inserted row will contain NULL values,
provided that the table definition allows NULL values and there is no DEFAULT clause
for the columns. If a DEFAULT clause is specified for a column and the column name is
not present in the optional column list, then the column is given the default value.
• If the optional list is not specified, then all the column values must be either explicitly
specified or returned by the query expression. The order of the values should be the same
as the order in which the columns are declared in the declaration of the table or view.
• The VALUES ( ... ) form for specifying the column values inserts one row into the
table. The query expression form inserts all the rows from the query results.
• If the table contains a foreign key and there is no corresponding primary key that matches
the values of the foreign key in the record being inserted, the insert operation is rejected.
3–82
INSERT Statement
AUTHORIZATION
Must have DBA privilege, ownership of the table, INSERT privilege on the table, or
SELECT privilege on all the tables or views referred to in the query_expression, if a
query_expression is specified.
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–83
LOCK TABLE Statement
SYNTAX
table_name
The table in the database that you want to lock explicitly. You can specify one table or a
comma-separated list of tables.
SHARE MODE
Allows all transactions to read the table(s). Prohibits all other transactions from
modifying the table(s). After you acquire an explicit lock on a table in SHARE MODE, any
SELECT statements in your transaction can read rows and do not implicitly acquire
individual record locks. Any INSERT, UPDATE, and DELETE statements do acquire record
locks.
EXCLUSIVE MODE
Allows the current transaction to read and modify the table(s), and prohibits any other
transactions from reading or modifying the table(s). After you acquire an explicit lock on
a table in EXCLUSIVE MODE, you can SELECT, INSERT, UPDATE, and DELETE rows and your
transaction does not implicitly acquire individual record locks for these operations.
EXAMPLES
Unless another transaction holds an EXCLUSIVE lock on the teratab and megatab tables, the
SHARE MODE example explicitly locks the tables. The shared lock allows all transactions to
read the tables. Only the current transaction can modify the tables:
3–84
LOCK TABLE Statement
Unless another transaction holds a lock on the teratab table, the EXCLUSIVE MODE example
locks the teratab table for exclusive use by the current transaction. No other transactions can
read or modify the teratab table:
Without a table lock, the first SELECT statement in this example could exceed the limits of the
record lock table. The LOCK TABLE statement prevents the subsequent SELECT statement
from consuming the record lock table:
NOTES
• The LOCK TABLE statement may encounter a locking conflict with another transaction.
– Locked the table in EXCLUSIVE MODE and has not issued a COMMIT or
ROLLBACK
– Inserted, updated, or deleted rows in the table and has not issued a COMMIT or
ROLLBACK
– Locked the table in SHARE MODE or EXCLUSIVE MODE and has not issued a
COMMIT or ROLLBACK
– Read from, inserted, updated, or deleted rows and has not issued a COMMIT or
ROLLBACK
• When there is a locking conflict, the transaction is suspended for up to five seconds until
the requested lock can be acquired. If after five seconds the lock is still not available, the
database returns an error.
3–85
LOCK TABLE Statement
• You can use explicit table locking to improve the performance of a single transaction, at
the cost of decreasing the concurrency of the system and potentially blocking other
transactions. It is more efficient to lock a table explicitly if you know that the transaction
will be updating a substantial part of a table. You gain efficiency by decreasing the
overhead of the implicit locking mechanism, and by decreasing any potential wait time for
acquiring individual record locks on the table.
• You can use explicit table locking to minimize potential deadlocks in situations where a
transaction is modifying a substantial part of a table. Before making a choice between
explicit or implicit locking, compare the benefits of table locking with the disadvantages
of losing concurrency.
• The database releases explicit and implicit locks only when the transaction ends with a
COMMIT or ROLLBACK operation.
– READ UNCOMMITTED ensures that when a record is read, no record locks are
acquired.
– READ COMMITTED ensures that when a record is read a share lock is acquired on
that record; the duration of the lock varies.
– REPEATABLE READ ensures that when a record is read, a share lock is acquired
on that record and held until the end of the current transaction.
– SERIALIZABLE ensures that when a table is accessed the entire table is locked with
a lock of appropriate strength; the lock is held until the end of the transaction.
• With READ COMMITTED, the intent is to hold the share lock on a record until the
application reads the next record. This behavior is not always achieved.
Under specific conditions, the server might release a share record lock before the record
is returned to the client. This can lead to unreliable results when the application intends to
update the rows being fetched. To prevent early release of the share lock when READ
COMMITTED is in effect the following must be true:
3–86
LOCK TABLE Statement
If an application requires a query that does not satisfy the conditions listed and the intent
is to update the fetched rows, the application should set the isolation level to
REPEATABLE READ.
• To achieve better performance, some client configurations prefetch records from the
server. With isolation level READ COMMITTED, it is possible for the server to release a
share lock on a record that an application is processing. When prefetching is in effect, a
user application should not assume that the current row is locked. If a Progress C
Language embedded SQL-92 application uses the array fetch feature, prefetching is
enabled.
• If an application employs prefetching and has a requirement for updating the fetched rows,
the application should set the transaction isolation level to REPEATABLE READ.
• As illustrated in the third example, some SELECT statements place an entry in the record
lock table for every row in a table. For these queries, consider issuing a LOCK TABLE
SHARE MODE before the SELECT statement.
AUTHORIZATION
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
3–87
OPEN Statement
OPEN Statement
Executes a prepared SQL-92 query associated with a cursor and creates a result set composed
of the rows that satisfy the query. This set of rows is called the active set.
SYNTAX
OPEN cursor_name
[ USING { [ SQL ] DESCRIPTOR structure_name
| :host_variable [[ INDICATOR ] :ind_variable ] , ... } ] ;
cursor_name
Directs the SQL engine to create the result set in storage addressed by the identified
SQLDA structure.
3–88
OPEN Statement
EXAMPLE
This example is a code fragment from the StatSel function in sample program 2StatSel.pc,
which illustrates static processing of a SELECT statement. The complete source for sample
program, 2StatSel.pc, is listed in Appendix A of the Progress Embedded SQL-92 Guide and
Reference.
/*
** 5. Name WHENEVER routine to handle SQLERROR.
**
** 6. DECLARE cursor for the SELECT statement.
** NOTE: You must set input parameter values before OPEN CURSOR.
** The static query in this program does not have input parameters.
**
** 7. OPEN the cursor.
** NOTE: For static statements, if a DECLARE CURSOR
** statement contains references to automatic variables,
** the OPEN CURSOR statement must be in the same C function.
**
** 8. Name WHENEVER routine to handle NOT FOUND condition.
*/
NOTES
• Executing an OPEN cursor statement sets the cursor to the open state.
• After the OPEN cursor statement is executed, the cursor is positioned just before the first
row of the active set.
• For a single execution of an OPEN cursor statement, the active set does not change and
the host variables are not re_examined.
• If you elect to retrieve a new active set and a host variable value has changed, you must
CLOSE the cursor and OPEN it again.
3–89
OPEN Statement
• When a cursor is in the open state, executing an OPEN statement on that cursor results in
an error.
– You must execute the DECLARE statement before executing the OPEN statement
for that cursor.
– The DECLARE cursor statement and the OPEN statement for the same cursor must
occur in the same transaction.
– If the statement contains parameter markers for stack variables, the DECLARE
cursor statement and the following OPEN statement for the same cursor must occur
in the same C Language function.
AUTHORIZATION
Must have DBA privilege of SELECT privilege on all the tables and views referenced in
the SELECT statement associated with the cursor.
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
3–90
PREPARE Statement
PREPARE Statement
Parses and assigns a name to an ad hoc or dynamically generated SQL-92 statement for
execution. You use a PREPARE statement in a series of steps that allows a program to accept
or generate SQL-92 statements at run time.
SYNTAX
statement_name
A name for the dynamically generated statement. DESCRIBE, EXECUTE, and DECLARE
CURSOR statements refer to this statement_name. A statement_name must be unique in a
program.
statement_string
Specifies the SQL-92 statement to be prepared for dynamic execution. You can use either
the name of a C Language string variable containing the SQL-92 statement, or you can
specify the SQL-92 statement as a quoted literal. If there is an SQL-92 syntax error, the
PREPARE statement returns an error in the SQLCA.
SYNTAX
{ :host_variable | quoted_literal }
EXAMPLES
The first example is a code fragment from the DynUpd function in sample program 3DynUpd.pc,
which illustrates dynamic processing of an UPDATE statement:
/*
** Process a dynamic non-SELECT input statement
** PREPARE the statement
** EXECUTE the prepared statement
** COMMIT WORK
*/
3–91
PREPARE Statement
This example is a code fragment from the DynSel function in sample program 4DynSel.pc,
which illustrates dynamic processing of a SELECT statement:
/*
** PREPARE a the dynamic SELECT statement.
** DECLARE cursor for the prepared SELECT statement.
** NOTE: You must set input parameter values before OPEN CURSOR.
** If your query has input parameters, you must define them in
** the DECLARE SECTION.
** OPEN the declared cursor.
** NOTE: For static statements, if a DECLARE CURSOR
** statement contains references to automatic variables,
** the OPEN CURSOR statement must be in the same C function.
**
** Name WHENEVER routine for NOT FOUND condition.
** FETCH a row and print results until no more rows.
*/
The complete source for four sample programs are listed in Appendix A of the Progress
Embedded SQL-92 Guide and Reference.
NOTES
• A statement string can have one or more references to input variables. These variables
represent values supplied at run time to:
3–92
PREPARE Statement
• The USING clauses of EXECUTE and OPEN statements identify host language storage.
The values in this storage expand a statement string, replacing a substitution name or a
parameter marker. You can design your program to execute the same prepared statement
many times in a transaction, supplying different values for input variables for each
execution. If you COMMIT or ROLLBACK the transaction, you must PREPARE the
statement string again.
AUTHORIZATION
Must have DBA privilege or Authorization for SQL-92 statement being prepared (See the
AUTHORIZATION section for the relevant statement).
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–93
REVOKE Statement
REVOKE Statement
Revokes various privileges from the specified users of the database. There are two forms of the
REVOKE statement.
SYNTAX
RESOURCE
Revokes from the specified users the privilege to issue CREATE statements.
DBA
Revokes from the specified users the privilege to create, access, modify, or delete any
database object, and revokes the privilege to grant other users any privileges.
SYNTAX
3–94
REVOKE Statement
Revokes the GRANT option for the privilege from the specified users. The actual privilege
itself is not revoked. If specified with RESTRICT, and the privilege is passed on to other
users, the REVOKE statement fails and generates an error. Otherwise, GRANT OPTION FOR
implicitly revokes any privilege the user might have given to other users.
privilege
SYNTAX
If more than one user grants access to the same table to a user, then all the grantors must
perform a revoke for the user to lose access to the table.
Using the keyword ALL revokes all the privileges granted on the table or view.
FROM PUBLIC
Revokes the specified privileges on the table or view from any user with access to the
system.
RESTRICT | CASCADE
Prompts SQL to check to see if the privilege being revoked was passed on to other users.
This is possible only if the original privilege included the WITH GRANT OPTION clause.
If so, the REVOKE statement fails and generates an error. If the privilege was not passed on,
the REVOKE statement succeeds.
If the REVOKE statement specifies CASCADE, revoking the access privileges from a user also
revokes the privileges from all users who received the privilege from that user.
If the REVOKE statement specifies neither RESTRICT nor CASCADE, the behavior is the same
as for CASCADE.
3–95
REVOKE Statement
EXAMPLE
AUTHORIZATION
Must have the DBA privilege (to revoke DBA or RESOURCE privileges), ownership of
the table (to revoke privileges on a table),
SQL COMPLIANCE
SQL-92, ODBC Core SQL grammar. Progress Extensions: INDEX, RESOURCE, DBA
privileges
ENVIRONMENT
RELATED STATEMENTS
GRANT Statement
3–96
ROLLBACK Statement
ROLLBACK Statement
Ends the current transaction and undoes any database changes performed during the transaction.
SYNTAX
ROLLBACK [ WORK ] ;
NOTES
• Under certain circumstances, SQL marks a transaction for abort but does not actually roll
it back immediately. Without an explicit ROLLBACK, any subsequent updates do not
take effect. A COMMIT statement causes SQL to recognize the transaction as marked for
abort and instead implicitly rolls back the transaction.
• SQL marks a transaction for abort in the event of a hardware or software system failure.
This transaction is rolled back during recovery.
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
COMMIT Statement
3–97
SELECT Statement
SELECT Statement
Selects the specified column values from one or more rows contained in the tables or views
specified in the query expression. The selection of rows is restricted by the WHERE clause. The
temporary table derived through the clauses of a select statement is called a result table.
SYNTAX
SELECT column_list
FROM table_list
[ WHERE search_condition ]
[ GROUP BY grouping_condition ]
[ HAVING search_condition ]
[ORDER BY ordering_condition ]
[FOR UPDATE update_condition ]
;
column_list
FROM table_list
WHERE search_condition
GROUP BY grouping_condition
HAVING search_condition
ORDER BY ordering_condition
3–98
SELECT Statement
AUTHORIZATION
Must have DBA privilege or SELECT permission on all the tables or views referred to in
the query_expression.
SQL COMPLIANCE
SQL-92. Progress Extensions: FOR UPDATE clause, ODBC Extended SQL grammar
ENVIRONMENT
RELATED STATEMENTS
3–99
COLUMN_LIST Clause
COLUMN_LIST Clause
Specifies which columns to retrieve by the SELECT statement.
SYNTAX
[ ALL | DISTINCT ]
{ * | { table_name | alias.}* [ , { table_name.| alias.} * ] ...
| expr [ [ AS ] [ ' ] column_title [ ' ] ]
[, expr [ [ AS ] [ ' ] column_title [ ' ] ] ] ...
| [ table| alias.]column_name , ... ]
}
[ ALL | DISTINCT ]
Indicates whether a result table omits duplicate rows. ALL is the default and specifies
that the result table includes all rows. DISTINCT specifies taht a table omits duplicate
rows.
* | { table_name. | alias. } *
Specifies that the result table includes all columns from all tables named in the FROM
clause.
The optional ’column_title’ argument specifies a new heading for the associated
column in the result table. You can also use the column_title in an ORDER BY clause.
Enclose the new title in single or double quotation marks if it contains spaces or other
special characters.
3–100
COLUMN_LIST Clause
EXAMPLES
Both these statement return all the columns in the customer table to the select list.
The table_name.* syntax is useful when the select list refers to columns in multiple tables and
you want to specify all the columns in one of those tables:
The following example illustrates using the column_title option to change the name of the
column.
3–101
COLUMN_LIST Clause
You must qualify a column name if it occurs in more than one table specified in the FROM clause:
select
Customer.custnum,
Customer.city as "Customer City",
Customer.State as 'Customer State',
Billto.City as "Bill City",
Billto.State as 'Bill State'
from Customer, Billto
where Customer.City = 'Clinton';
3–102
FROM Clause
FROM Clause
Specifies one or more table references. Each table reference resolves to one table (either a
table stored in the database or a virtual table resulting from processing the table reference)
whose rows the query expression uses to create the result table.
SYNTAX
table_ref
• A joined table that combines rows and columns from multiple tables.
If there are multiple table references, SQL joins the tables to form an intermediate result
table that is used as the basis for evaluating all other clauses in the query expression. That
intermediate result table is the Cartesian product of rows in the tables in the FROM clause,
formed by concatenating every row of every table with all other rows in all tables.
SYNTAX
alias
A name used to qualify column names in other parts of the query expression. Aliases are
also called correlation names.
3–103
FROM Clause
If you specify an alias, you must use it, and not the table name, to qualify column names
that refer to the table. Query expressions that join a table with itself must use aliases to
distinguish between references to column names.
Similar to table aliases, the column_alias provides an alternative name to use in column
references elsewhere in the query expression. If you specify column aliases, you must
specify them for all the columns in table_name. Also, if you specify column aliases in the
FROM clause, you must use them, and not the column names, in references to the columns.
Derived tables can also specify column aliases. Column aliases provide alternative names
to use in column references elsewhere in the query expression. If you specify column
aliases, you must specify them for all the columns in the result table of the query
expression. Also, if you specify column aliases in the FROM clause, you must use them, and
not the column names, in references to the columns.
FROM [ ( ] joined_table [ ) ]
Combines data from two table references by specifying a join condition.
SYNTAX
The syntax currently allowed in the FROM clause supports only a subset of possible join
conditions:
• CROSS JOIN specifies a Cartesian product of rows in the two tables. Every row in one
table is joined to every row in the other table.
• INNER JOIN specifies an inner join using the supplied search condition.
• LEFT OUTER JOIN specifies a left outer join using the supplied search condition.
3–104
FROM Clause
You can also specify these and other join conditions in the WHERE clause of a query
expression. See the “Outer Joins” section in Chapter 2, “SQL-92 Language Elements” for
more information on both ways of specifying outer joins.
{ NO REORDER }
Disables join order optimization for the FROM clause. Use NO REORDER when you choose to
override the join order chosen by the optimizer. The braces are part of the syntax for this
optional clause.
EXAMPLE
For customers with orders, retrieve their names and order info:
3–105
WHERE Clause
WHERE Clause
Specifies a search_condition that applies conditions to restrict the number of rows in the result
table. If the query expression does not specify a WHERE clause, the result table includes all the
rows of the specified table reference in the FROM clause.
SYNTAX
WHERE search_condition
search_condition
Applied to each row of the result table set of the FROM clause. Only rows that satisfy the
conditions become part of the result table. If the result of the search_condition is NULL
for a row, the row is not selected.
Search conditions can specify different conditions for joining two or more tables. See the
“Outer Joins” and “Search Conditions” sections in Chapter 2, “SQL-92 Language
Elements” for information on the different kinds of search conditions.
3–106
GROUP BY CLAUSE
GROUP BY CLAUSE
Specifies grouping of rows in the result table.
SYNTAX
NOTES
• For the first column specified in the GROUP BY clause, SQL arranges rows of the result table
into groups whose rows all have the same values for the specified column.
• If you specify a second GROUP BY column, SQL groups rows in each main group by values
of the second column.
• SQL groups rows for values in additional GROUP BY columns in a similar fashion.
• All columns named in the GROUP BY clause must also be in the select list of the query
expression. Conversely, columns in the select list must also be in the GROUP BY clause or
be part of an aggregate function.
3–107
HAVING CLAUSE
HAVING CLAUSE
Allows you to set conditions on the groups returned by the GROUP BY clause. If the HAVING
clause is used without the GROUP BY clause, the implicit group against which the search
condition is evaluated is all the rows returned by the WHERE clause.
SYNTAX
HAVING search_condition
NOTE: A condition of the HAVING clause can compare one aggregate function value with
another aggregate function value or a constant.
EXAMPLE
The HAVING clause in the following example compares the value of an aggregate function
( COUNT (*) ) to a constant ( 10 ). The query returns the customer number and number of orders
for all customers who had more than 10 orders before March 31st, 1999.
3–108
ORDER BY Clause
ORDER BY Clause
Allows ordering of the rows selected by the SELECT statement. Unless an ORDER BY clause
is specified, the rows of the result set might be returned in an unpredictable order as determined
by the access paths chosen and other decisions made by the query optimizer. The decisions
made will be affected by the statistics generated from table and index data examined by the
UPDATE STATISTICS command.
SYNTAX
expr
Expression of one or more columns of the tables specified in the FROM clause of the
SELECT statement.
posn
ASC | DESC
Indicates whether to order by ascending order (ASC) or descending order. The default is
ASC.
EXAMPLES
3–109
ORDER BY Clause
NOTES
• The ORDER BY clause, if specified, should follow all other clauses of the SELECT
statement.
• The selected rows are ordered on the basis of the first expr or posn. If the values are the
same, then the second expr or posn is used in the ordering.
3–110
FOR UPDATE Clause
SYNTAX
OF [ table.]column_name , ...
Specifies the table's column name to be updated.
NOWAIT
Causes the SELECT statement to return immediately with an error if a lock cannot be
acquired on a row in the selection set because of the lock held by some other transaction.
The default behavior is for the transaction to wait until it gets the required lock or until it
times out waiting for the lock.
NOTE: If you specify FOR UPDATE, the database acquires exclusive locks on all the rows
satisfying the SELECT statement. The database does not acquire row level locks if
there is an exclusive lock on the table. See the LOCK TABLE Statement for
information on table locking.
3–111
SET CONNECTION Statement
SYNTAX
connection_name
The name of the connection as either a character literal or host variable. If the SET
CONNECTION statement omits a connection name, the default is the name of the database.
Connection names must be unique.
DEFAULT
EXAMPLES
The first example shows how to establish a database as the current database. The SET
CONNECTION command sets the database associated with the connection named conn_1 to
the status of current database. The connection named conn_1 must be associated with an
established connection:
EXEC SQL
SET CONNECTION 'conn_1' ;
Use SET CONNECTION DEFAULT to set current the database associated with the
DEFAULT connection. This statement suspends the conn_1 connection, which had been
current.
EXEC SQL
SET CONNECTION DEFAULT ;
See also the last example for the DISCONNECT Statement, which illustrates the CONNECT,
SET CONNECTION, and DISCONNECT statements in combination.
3–112
SET CONNECTION Statement
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
3–113
SET SCHEMA Statement
SYNTAX
'string_literal'
Specifies the name for the default owner as a string literal, enclosed in single or double
quotes.
Indicates a parameter marker to contain the default owner. The actual replacement value
for the owner name is supplied in a subsequent SQL-92 operation.
:host_var
Host variable reference declared in a DECLARE SECTION. The SET SCHEMA :host_var option
is valid only in an embedded SQL-92 program.
USER
Directs the database to set the default owner back to the username that established the
session.
EXAMPLE
This example sets the default schema name to 'White'. Subsequent SQL-92 statements with
unqualified table references will use the owner name 'White'. The SELECT statement in this
example returns all rows in the 'White.customer' table. The username establishing the original
session is still the current user.
3–114
SET SCHEMA Statement
NOTES
• For authorization purposes, invoking SET SCHEMA does not change the username
associated with the current session.
• You can set the default schema name to the username associated with the session by using
a SET SCHEMA USER statement.
AUTHORIZATION
None
SQL COMPLIANCE
SQL-92
ENVIRONMENT
RELATED STATEMENTS
None
3–115
SET TRANSACTION ISOLATION LEVEL Statement
SYNTAX
isolation_level_name:
SYNTAX
READ UNCOMMITTED
Allows dirty reads, nonrepeatable reads, and phantoms. When a record is read, no
record locks are aquired. This forces read-only use. Allows a user application to read
records that were modified by other applications but have not yet been committed.
READ COMMITTED
Prohibits dirty reads; allows nonrepeatable reads and phantoms. Whenever a record
is read, a share lock is acquired on that record. The duration of the lock varies.
Disallows the reading of uncommitted modified records. However, if a record is read
multiple times in the same transaction, the state of the record can be different each
time.
REPEATABLE READ
Prohibits dirty reads and nonrepeatable reads; allows phantoms. Whenever a record
is read, a share lock is acquired on that record and held until the end of the current
transaction. Disallows the reading of uncommitted modified records. If a record is
read multiple times in the same transaction, the state of the record remains the same.
SERIALIZABLE
3–116
SET TRANSACTION ISOLATION LEVEL Statement
affect each other, and that they will behave as if they were executing serially, not
concurrently.
Whenever a table is accessed, the entire table is locked with an appropriate lock. The
table lock is held until the end of the current transaction.
NOTES
• Progress Software recommends that you specify the transaction isolation level number by
isolation_level_name.
• See the LOCK TABLE Statement for information on record locking schemes used by each
isolation level.
3–117
SET TRANSACTION ISOLATION LEVEL Statement
AUTHORIZATION
None
SQL COMPLIANCE
The isolation level SERIALIZABLE guarantees the highest consistency. The isolation
level READ UNCOMMITTED guarantees the least consistency. The default isolation
level is REPEATABLE READ, which prohibits non-repeatable read operations. The
ANSI/ISO SQL standard defines isolation levels in terms of the inconsistencies they
allow:
Dirty read
Allows the transaction to read a row that has been inserted or modified by another
transaction, but not committed. If the other transaction rolls back its changes, the
transaction will read a row that never existed because it never committed.
Nonrepeatable read
Allows the transaction to read a row that another transaction modifies or deletes
before the next read operation. If the other transaction commits the change, the
transaction receives modified values or discovers the row is deleted on subsequent
read operations.
Phantom
Allows the transaction to read a range of rows that satisfies a given search condition,
but to which another transaction adds rows before another read operation using the
same search condition. The transaction receives a different collection of rows with
the same search condition.
ENVIRONMENT
RELATED STATEMENTS
3–118
Table Constraints
Table Constraints
Specifies a constraint for a table that restricts the values that the table can store. INSERT,
UPDATE, or DELETE statements that violate the constraint fail. SQL returns a constraint
violation error.
Table constraints have syntax and behavior similar to Column Constraints. Note the following
differences:
• The definitions of the table constraints are separated from the column definitions by
commas.
• Table constraint definitions can include more than one column, and SQL evaluates the
constraint based on the combination of values stored in all the columns.
SYNTAX
CONSTRAINT constraint_name
PRIMARY KEY ( column [ , ... ] )
| UNIQUE ( column [ , ... ] )
| FOREIGN KEY ( column [, ... ] )
REFERENCES [ owner_name.]table_name [ ( column [ , ... ] ) ]
| CHECK ( search_condition )
CONSTRAINT constraint_name
Allows you to assign a name that you choose to the table constraint. While this
specification is optional, this facilitates making changes to the table definition, since the
name you specify is in your source CREATE TABLE statement. If you do not specify a
constraint_name, the database assigns a name. These names can be long and unwieldy,
and you must query system tables to determine the name.
Defines the column list as the primary key for the table. There can be at most one primary
key for a table.
All the columns that make up a table level primary key must be defined as NOT NULL, or the
CREATE TABLE statement fails. The combination of values in the columns that make up the
primary key must be unique for each row in the table.
3–119
Table Constraints
Other tables can name primary keys in their REFERENCES clauses. If they do, SQL restricts
operations on the table containing the primary key in the following ways:
• DELETE and UPDATE statements that modify values in the combination of columns that
match a foreign key's value also fail.
Defines the column list as a unique, or candidate, key for the table. Unique key table-level
constraints have the same rules as primary key table-level constraints, except that you can
specify more than one UNIQUE table-level constraint in a table definition.
A foreign key and its matching primary or unique key specify a referential constraint. The
combination of values stored in the columns that make up a foreign key must either:
You can omit the column list in the REFERENCES clause if the table specified in the
REFERENCES clause has a primary key and you want the primary key to be the matching
key for the constraint.
CHECK (search_condition)
Specifies a table level check constraint. The syntax for table level and column level check
constraints is identical. Table level check constraints must be separated by commas from
surrounding column definitions.
SQL restricts the form of the search condition. The search condition must not:
• Refer to any column other than columns that precede it in the table definition.
3–120
Table Constraints
EXAMPLES
The following example shows creation of a table level primary key. Note that its definition is
separated from the column definitions by a comma:
The following example shows how to create a table with two UNIQUE table level constraints:
3–121
Table Constraints
SQL evaluates the referential constraint to see if it satisfies the following search condition:
(student_courses.teacher IS NULL
OR student_courses.course_title IS NULL)
OR EXISTS (SELECT * FROM student_courses WHERE
(student_courses.teacher = courses.teacher AND
student_courses.course_title = courses.course_title)
)
NOTE: INSERT, UPDATE, or DELETE statements that cause the search condition to be
false violate the constraint, fail, and generate an error.
The following example creates a table with two column level check constraints and one table
level check constraint. Each constraint is defined with a name.
3–122
UPDATE Statement
UPDATE Statement
Updates the rows and columns of the specified table with the given values for rows that satisfy
the search_condition. This is the syntax for the UPDATE statement:
SYNTAX
UPDATE table_name
SET assignment [, assignment ] , ...
[ WHERE search_condition ] ;
assignment:
SYNTAX
NOTES
• If you specify the optional WHERE clause, only rows that satisfy the search_condition are
updated. If you do not specify a WHERE clause all rows of the table are updated.
• If the expressions in the SET clause are dependent on the columns of the target table, the
expressions are evaluated for each row of the table.
• If a table has check constraints and if the columns to be updated are part of a check
expression, then the check expression is evaluated. If the result of the evaluation is
FALSE, the UPDATE statement fails.
• If a table has primary or candidate keys and if the columns to be updated are part of the
primary or candidate key, SQL checks to determine if there is a corresponding row in the
referencing table. If there is a corresponding row the UPDATE operation fails.
3–123
UPDATE Statement
EXAMPLES
UPDATE orders
SET qty = 12000
WHERE order_no = 1001 ;
UPDATE orders
SET (product) =
(SELECT item_name
FROM items
WHERE item_no = 2401 )
WHERE order_no = 1002 ;
UPDATE orders
SET (amount) = (2000 * 30)
WHERE order_no = 1004 ;
UPDATE orders
SET (product, amount) =
(SELECT item_name, price * 30
FROM items
WHERE item_no = 2401 )
WHERE order_no = 1002 ;
AUTHORIZATION
Must have DBA privilege or UPDATE privileges on all the specified columns of the target
table, and SELECT privilege on all the other tables referred to in the statement.
SQL COMPLIANCE
SQL-92. ODBC Extended SQL grammar. Progress Extensions: assignments of the form
( column , column , ... ) = ( expr , expr , ... )
ENVIRONMENT
RELATED STATEMENTS
3–124
UPDATE STATISTICS Statement
• The value ranges corresponding to 10% of the rows of a table, for each indexed column.
The UPDATE STATISTICS operation produces a 10-step histogram of the column
values.
SYNTAX
table_name
Specifies a single table on which to update statistics. If you do not specify a table_name,
the UPDATE STATISTICS statement updates statistics on all tables in the database.
NOTES
• The time required to gather the statistics is highly dependent on the number of tables
specified and on the number of rows in those tables.
• The optimizer uses the information from UPDATE STATISTICS to make decisions about
the best query strategy to use when executing a particular SQL-92 statement.
3–125
UPDATE STATISTICS Statement
AUTHORIZATION
Must have DBA privilege, SELECT privilege, or ownership of table (to issue UPDATE
STATISTICS statement for a specific table).
SQL COMPLIANCE
Progress Extension
ENVIRONMENT
RELATED STATEMENTS
None
3–126
WHENEVER Statement
WHENEVER Statement
Specifies actions for three SQL-92 run-time exceptions. This is the syntax for a WHENEVER
statement:
SYNTAX
WHENEVER
{ NOT FOUND | SQLERROR | SQLWARNING }
{ STOP | CONTINUE |{ GOTO | GO TO } host_lang_label } ;
• The CONTINUE exception results in the ESQLC program continuing execution. The
default exception is to CONTINUE.
EXAMPLES
The first example is a code fragment from the main function in sample program 1StatUpd.pc.
The complete source for sample program, 1StatUpd.pc, is listed in Appendix A of the Progress
Embedded SQL-92 Guide and Reference.
/*
** Name WHENEVER routine to handle SQLERROR condition.
*/
EXEC SQL WHENEVER SQLERROR GOTO mainerr ;
3–127
WHENEVER Statement
This example is a code fragment from the dynupd function in sample program 3DynUpd.pc,
which illustrates dynamic processing of an UPDATE statement. The complete source for
sample program, 3DynUpd.pc, is listed in Appendix A of the Progress Embedded SQL-92 Guide
and Reference.
/*
** Name WHENEVER routines to handle NOT FOUND and SQLERROR
*/
NOTES
• You can place multiple WHENEVER statements for the same exception in a source file.
Each WHENEVER statement overrides the previous WHENEVER statement specified
for the same exception.
AUTHORIZATION
None
SQL COMPLIANCE
ENVIRONMENT
RELATED STATEMENTS
FETCH Statement
3–128
4
SQL-92 Functions
A function is a type of SQL expression that returns a value based on the arguments supplied to
the function. Progress SQL-92 supports two types of functions:
• Aggregate Functions — Calculate a single value for a collection of rows in a result table.
If the function is in a statement with a GROUP BY clause, it returns a value for each group
in the result table. Aggregate functions are also called set or statistical functions.
Aggregate functions cannot be nested. This chapter describes the Aggregate Functions
listed in Table 4–1.
• Scalar Functions — Calculate a value based on another single value. Scalar functions are
also called value functions. Scalar functions can be nested. This chapter describes the
Scalar Functions listed in Table 4–2.
SQL-92 Functions
SQL-92 Functions
4–2
SQL-92 Functions
4–3
AVG Function
AVG Function
Computes the average of a collection of values. The keyword DISTINCT specifies that the
duplicate values are to be eliminated before computing the average.
SYNTAX
EXAMPLE
This example illustrates the AVG function:
NOTES
• Null values are eliminated before the average value is computed. If all the values are null,
the result is null.
4–4
COUNT Function
COUNT Function
Computes either the number of rows in a group of rows or the number of non-null values in a
group of values.
SYNTAX
EXAMPLE
This example illustrates the COUNT function:
NOTES
• The keyword DISTINCT specifies that the duplicate values are to be eliminated before
computing the count.
• If the argument to COUNT function is ’*’, then the function computes the count of the
number of rows in a group.
• If the argument to COUNT function is not ’*’, then null values are eliminated before the
number of rows is computed.
• The result of the function is of integer type. The result is never null.
4–5
MAX Function
MAX Function
Returns the maximum value in a group of values.
SYNTAX
EXAMPLE
This example illustrates the MAX function:
NOTES
• The result of the function is of the same data type as that of the argument.
• The result is null if the result set is empty or contains only null values.
4–6
MIN Function
MIN Function
Returns the minimum value in a group of values.
SYNTAX
EXAMPLE
This example illustrates the MIN function:
NOTES
• The result of the function is of the same data type as that of the argument.
• The result is null if the result set is empty or contains only null values.
4–7
SUM Function
SUM Function
Returns the sum of the values in a group. The keyword DISTINCT specifies that the duplicate
values are to be eliminated before computing the sum.
SYNTAX
EXAMPLE
This example illustrates the SUM function:
NOTES
• The result of the function is of the same data type as that of the argument except that the
result is of type INTEGER when the argument is of type SMALLINT or TINYINT.
4–8
ABS Function
ABS Function
Computes the absolute value of expression.
SYNTAX
ABS ( expression )
EXAMPLE
This example illustrates the ABS function:
NOTES
COMPATIBILITY
ODBC Compatible
4–9
ACOS Function
ACOS Function
Returns the arccosine of expression.
SYNTAX
ACOS ( expression )
EXAMPLE
This example illustrates two ways to use the acos function. The first SELECT statement returns
the arcosine in radians, and the second returns the arcosine in degrees.
ARCCOSINE IN RADIANS
--------------------
1.047197551196598
1 record selected
ARCCOSINE IN DEGREES
--------------------
59.999999999999993
1 record selected
4–10
ACOS Function
NOTES
• ACOS takes the ratio (expression) of two sides of a right triangle and returns the
corresponding angle. The ratio is the length of the side adjacent to the angle divided by the
length of the hypotenuse.
• The result is expressed in radians and is in the range -Pi/2 to Pi/2 radians. To convert
degrees to radians, multiply degrees by Pi/180. To convert radians to degrees, multiply
radians by 180/Pi.
COMPATIBILITY
ODBC Compatible
4–11
ADD_MONTHS Function
ADD_MONTHS Function
Adds to the date value specified by the date_expression, the given number of months specified
by integer_expression, and returns the resultant date value.
SYNTAX
EXAMPLE
This example illustrates the ADD_MONTHS function:
SELECT *
FROM customer
WHERE ADD_MONTHS (start_date, 6) > SYSDATE ;
NOTES
COMPATIBILITY
Progress Extension
4–12
ASCII Function
ASCII Function
Returns the ASCII value of the first character of the given character expression.
SYNTAX
ASCII ( char_expression )
EXAMPLE
The following example shows how to use the ASCII function:
NOTES
• The ASCII function is character-set dependent, and supports multi-byte characters. The
function returns the character encoding integer value of the first character of
char_expression in the current character set. If char_expression is a literal string, the
result is determined by the character set of the SQL client. If char_expression is a
column in the database, the character set of the database determines the result.
COMPATIBILITY
ODBC Compatible
4–13
ASIN Function
ASIN Function
Returns the arcsine of expression.
SYNTAX
ASIN ( expression )
EXAMPLE
The following example shows how to use the ASIN function. The first SELECT statement
returns the arcsine in degrees, and the second returns the arcsine in radians.
ARCSINE IN DEGREES
-------------------
90.000000000000000
1 record selected
ARCSINE IN RADIANS
------------------
1.570796326794897
1 record selected
ASIN takes the ratio (expression) of two sides of a right triangle and returns the corresponding
angle. The ratio is the length of the side opposite the angle divided by the length of the
hypotenuse.
The result is expressed in radians and is in the range -pi/2 to pi/2 radians. To convert degrees to
radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.
4–14
ASIN Function
NOTES
COMPATIBILITY
ODBC Compatible
4–15
ATAN Function
ATAN Function
Returns the arctangent of expression.
SYNTAX
ATAN ( expression )
EXAMPLE
The following example illustrates two ways to use the ATAN function:
ARCTANGENT IN DEGREES
-----------------------
45.000000000000000
1 record selected
ARCTANGENT IN RADIANS
-----------------------
0.785398163397448
1 record selected
ATAN takes the ratio (expression) of two sides of a right triangle and returns the
corresponding angle. The ratio is the length of the side opposite the angle divided by the length
of the side adjacent to the angle.
The result is expressed in radians and is in the range -Pi/2 to Pi/2 radians. To convert degrees to
radians, multiply degrees by Pi/180. To convert radians to degrees, multiply radians by 180/Pi.
NOTES
COMPATIBILITY
ODBC Compatible
4–16
ATAN2 Function
ATAN2 Function
Returns the arctangent of the x and y coordinates specified by expression1 and expression2.
SYNTAX
EXAMPLE
The following example illustrates two ways to use the ATAN2 function:
ARCTANGENT IN DEGREES
-----------------------
45.000000000000000
1 record selected
ARCTANGENT IN RADIANS
-----------------------
0.785398163397448
1 record selected
4–17
ATAN2 Function
NOTES
• ATAN2 takes the ratio of two sides of a right triangle and returns the corresponding angle.
The ratio is the length of the side opposite the angle divided by the length of the side
adjacent to the angle.
• expression1 and expression2 specify the x and y coordinates of the end of the
hypotenuse opposite the angle.
• The result is expressed in radians and is in the range -pi/2 to pi/2 radians. To convert
degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply
radians by 180/pi.
• Both expression1 and expression2 must evaluate to approximate numeric data types.
COMPATIBILITY
ODBC Compatible
4–18
CASE Function
CASE Function
Specifies a series of search conditions and associated result expressions. The general form is
called a searched case expression. SQL returns the value specified by the first result expression
whose associated search condition evaluates as true. If none of the search conditions evaluates
as true, the CASE expression returns a null value, or the value of some other default expression
if the CASE expression includes the ELSE clause.
CASE also supports syntax for a shorthand notation, called a simple case expression, for
evaluating whether one expression is equal to a series of other expressions.
SYNTAX
searched_case_expr | simple_case_expr
searched_case_expr
SYNTAX
CASE
WHEN search_condition THEN { result_expr | NULL }
[ ... ]
[ ELSE expr | NULL ]
END
simple_case_expr
SYNTAX
CASE primary_expr
WHEN expr THEN { result_expr | NULL }
[ ... ]
[ ELSE expr | NULL ]
CASE
4–19
CASE Function
If search_condition evaluates as false, SQL evaluates the next WHEN-THEN clause, if any,
or the ELSE clause, if it is specified.
CASE primary_expr
Specifies a simple case expression. In a simple case expression, one or more WHEN-THEN
clauses specify two expressions.
If expr is not equal to primary_expr, SQL evaluates the next WHEN-THEN clause, if any,
or the ELSE clause, if it is specified.
EXAMPLES
A simple case expression can always be expressed as a searched case expression. This example
illustrates a simple case expression:
CASE primary_expr
WHEN expr1 THEN result_expr1
WHEN expr2 THEN result_expr2
ELSE expr3
END
4–20
CASE Function
The simple case expression in the preceding CASE example is equivalent to the following
searched case expression:
CASE
WHEN primary_expr = expr1 THEN result_expr1
WHEN primary_expr = expr2 THEN result_expr2
ELSE expr3
END
The following example shows a searched case expression that assigns a label denoting suppliers
as ’In Mass’ if the state column value is ’MA’:
4–21
CASE Function
NOTES
COMPATIBILITY
SQL-92 Compatible
4–22
CAST Function
CAST Function
Converts an expression to another data type. The first argument is the expression to be
converted. The second argument is the target data type.
The length option for the data_type argument specifies the length for conversions to CHAR and
VARCHAR data types. If omitted, the default is 1 byte.
If the expression evaluates to null, the result of the function is null. Specifying NULL with the
CAST function is useful for set operations, such as UNION, that require two tables to have the
same structure. CAST NULL allows you to specify a column of the correct data type, so a table
with a similar structure to another, but with fewer columns, can be in a union operation with the
other table.
The CAST function provides a data-type-conversion mechanism compatible with the SQL-92
standard.
Use the CONVERT function, enclosed in the ODBC escape clause { fn }, to specify
ODBC-compliant syntax for data type conversion. See the ODBC compatible CONVERT
function for more information.
SYNTAX
EXAMPLE
The following SQL example uses CAST to convert an integer field from a catalog table to a
CHARACTER data type:
CONVERT(CHARACTER(25),FLD) FLD
-------------------------- ---
100 100
1 record selected
COMPATIBILITY
SQL-92 Compatible
4–23
CEILING Function
CEILING Function
Returns the smallest integer greater than or equal to expression.
SYNTAX
CEILING ( expression )
EXAMPLE
This example illustrates the CEILING function:
NOTE
COMPATIBILITY
ODBC Compatible
4–24
CHAR Function
CHAR Function
Returns a character string with the first character having an ASCII value equal to the argument
expression. CHAR is identical to CHR but provides ODBC-compatible syntax.
SYNTAX
CHAR ( integer_expression )
EXAMPLE
This example illustrates the CHAR function:
SELECT *
FROM customer
WHERE SUBSTR (zip, 1, 1) = CHAR (53) ;
NOTES
• The CHAR and CHR functions are character-set dependent, and support single-byte and
multi-byte characters. If integer_expression is a valid character encoding integer value
in the current SQL server character set, the function returns the correct character. If it is
not a valid character the function returns a NULL value.
COMPATIBILITY
ODBC Compatible
4–25
CHR Function
CHR Function
Returns a character string with the first character having an ASCII value equal to the argument
expression.
SYNTAX
CHR ( integer_expression )
EXAMPLE
This example illustrates the CHR function and the SUBSTR (substring) function:
SELECT *
FROM customer
WHERE SUBSTR (zip, 1, 1) = CHR (53) ;
NOTES
• The CHR and CHAR functions are character-set dependent, and support multi-byte
characters. If integer_expression is a valid character encoding integer value in the
current SQL server character set, the function returns the correct character. If it is not a
valid character the function returns a NULL value.
COMPATIBILITY
Progress Extension
4–26
COALESCE Function
COALESCE Function
Specifies a series of expressions, and returns the first expression whose value is not null. If all
the expressions evaluate as null, COALESCE returns a null value.
SYNTAX
NOTE: The COALESCE syntax is shorthand notation for a common case that can also be
represented in a CASE expression. The following two formulations are equivalent:
CASE
WHEN expression1 IS NOT NULL THEN expression1
WHEN expression2 IS NOT NULL THEN expression2
ELSE expression3
END
EXAMPLE
This example illustrates the COALESCE function:
NOTES
COMPATIBILITY
SQL-92 Compatible
4–27
CONCAT Function
CONCAT Function
Returns a concatenated character string formed by concatenating argument one with argument
two.
SYNTAX
EXAMPLE
This example illustrates the CONCAT function:
NOTES
• The two char_expression expressions and the result of the CONCAT function may
contain multi-byte characters.
COMPATIBILITY
ODBC Compatible
4–28
CONVERT Function (ODBC Compatible)
SYNTAX
data_type
SYNTAX
COMPATIBILITY
ODBC Compatible
4–29
CONVERT Function (Progress Extension)
SYNTAX
EXAMPLE
The following SQL example uses the CONVERT function to convert an INTEGER field from
a system table to a character string:
CONVERT(CHAR,FLD) FLD
----------------- ---
100 100
1 record selected
CONVERT(CHAR(35),FLD) FLD
--------------------- ---
100 100
1 record selected
4–30
CONVERT Function (Progress Extension)
NOTE
COMPATIBILITY
Progress Extension
4–31
COS Function
COS Function
Returns the cosine of expression.
SYNTAX
COS ( expression )
EXAMPLE
This example illustrates the COS function:
COSINE OF 45 DEG
----------------
0.707106781186548
1 record selected
NOTES
• COS takes an angle expression and returns the ratio of two sides of a right triangle. The
ratio is the length of the side adjacent to the angle divided by the length of the hypotenuse.
COMPATIBILITY
ODBC Compatible
4–32
CURDATE Function
CURDATE Function
Returns the current date as a DATE value. This function takes no arguments.
SYNTAX
CURDATE ( )
NOTE: SQL statements can refer to CURDATE anywhere they can refer to a DATE
expression.
EXAMPLE
The following example shows how to use the CURDATE function:
COMPATIBILITY
ODBC Compatible
4–33
CURTIME Function
CURTIME Function
Returns the current time as a TIME value. This function takes no arguments.
SYNTAX
CURTIME ( )
NOTE: SQL statements can refer to CURTIME anywhere they can refer to a TIME
expression.
EXAMPLE
This example illustrates how to use the CURTIME function to INSERT the current time into
the create_time column of the objects table:
COMPATIBILITY
ODBC Compatible
4–34
DATABASE Function
DATABASE Function
Returns the name of the database corresponding to the current connection name. This function
takes no arguments, and the trailing parentheses are optional.
SYNTAX
DATABASE [ ( ) ]
EXAMPLE
The following example shows how to use the DATABASE function:
DATABASE
--------
steel
1 record selected
COMPATIBILITY
ODBC Compatible
4–35
DAYNAME Function
DAYNAME Function
Returns a character string containing the name of the day (for example, Sunday through
Saturday) for the day portion of date_expression. The argument date_expression can be the
name of a column, the result of another scalar function, or a date or timestamp literal.
SYNTAX
DAYNAME ( date_expression )
EXAMPLE
This example illustrates the DAYNAME function:
SELECT *
FROM orders
WHERE order_no = 342 and DAYNAME(order_date)=’SATURDAY’;
1 record selected
COMPATIBILITY
ODBC Compatible
4–36
DAYOFMONTH Function
DAYOFMONTH Function
Returns the day of the month in the argument as a short integer value in the range of 1-31. The
argument date_expression can be the name of a column, the result of another scalar function,
or a date or timestamp literal.
SYNTAX
DAYOFMONTH ( date_expression )
EXAMPLE
This example illustrates the DAYOFMONTH function:
SELECT *
FROM orders
WHERE DAYOFMONTH (order_date) = 14 ;
NOTES
COMPATIBILITY
ODBC Compatible
4–37
DAYOFWEEK Function
DAYOFWEEK Function
Returns the day of the week in the argument as a short integer value in the range of 1-7.
The argument date_expression can be the name of a column, the result of another scalar
function, or a date or timestamp literal.
SYNTAX
DAYOFWEEK ( date_expression )
EXAMPLE
The following example shows how to use the DAYOFWEEK function:
SELECT *
FROM orders
WHERE DAYOFWEEK (order_date) = 2 ;
NOTES
COMPATIBILITY
ODBC Compatible
4–38
DAYOFYEAR Function
DAYOFYEAR Function
Returns the day of the year in the argument as a short integer value in the range of 1-366. The
argument date_expression can be the name of a column, the result of another scalar function,
or a date or timestamp literal.
SYNTAX
DAYOFYEAR ( date_expression )
EXAMPLE
This example illustrates the DAYOFYEAR function:
SELECT *
FROM orders
WHERE DAYOFYEAR (order_date) = 300 ;
NOTES
COMPATIBILITY
ODBC Compatible
4–39
DB_NAME Function
DB_NAME Function
Returns the name of the database corresponding to the current connection name. It provides
compatibility with the Sybase SQL Server function db_name.
SYNTAX
DB_NAME ( )
EXAMPLE
This example illustrates the DB_NAME function:
DB_NAME
-------
demo
1 record selected
COMPATIBILITY
Progress Extension
4–40
DECODE Function
DECODE Function
Compares the value of the first argument expression with each search_expression and, if a
match is found, returns the corresponding match_expression. If no match is found, then the
function returns the default_expression. If a default_expression is not specified and no match is
found, the function returns a null value.
SYNTAX
EXAMPLE
This example illustrates one way to use the DECODE function:
NOTES
• The first argument expression can be of any type. The types of all search_expressions
must be compatible with the type of the first argument.
• The match_expressions can be of any type. The types of all match_expressions must be
compatible with the type of the first match_expression.
• The type of the default_expression must be compatible with the type of the first
match_expression.
4–41
DECODE Function
• The type of the result is the same as that of the first match_expression.
• If the first argument expression is null, then the value of the default_expression is
returned, if it is specified. Otherwise null is returned.
COMPATIBILITY
Progress Extension
4–42
DEGREES Function
DEGREES Function
Returns the number of degrees in an angle specified in radians by expression.
SYNTAX
DEGREES ( expression )
EXAMPLE
This example illustrates the DEGREES function:
NOTES
COMPATIBILITY
ODBC Compatible
4–43
EXP Function
EXP Function
Returns the exponential value of expression (e raised to the power of expression).
SYNTAX
EXP ( expression )
EXAMPLE
This example illustrates the EXP function:
NOTE
COMPATIBILITY
ODBC Compatible
4–44
FLOOR Function
FLOOR Function
Returns the largest integer less than or equal to expression.
SYNTAX
FLOOR ( expression )
EXAMPLE
This example illustrates the FLOOR function:
NOTE
COMPATIBILITY
ODBC Compatible
4–45
GREATEST Function
GREATEST Function
Returns the greatest value among the values of the given expressions.
SYNTAX
EXAMPLE
This example illustrates the GREATEST function:
NOTES
• The first argument to the function can be of any type. However, the types of the subsequent
arguments must be compatible with that of the first argument.
• The type of the result is the same as that of the first argument.
COMPATIBILITY
Progress Extension
4–46
HOUR FUNCTION
HOUR FUNCTION
Returns the hour in the argument as a short integer value in the range of 0-23.
SYNTAX
HOUR ( time_expression )
EXAMPLE
This example illustrates the HOUR function:
SELECT *
FROM arrivals
WHERE HOUR (in_time) < 12 ;
NOTES
COMPATIBILITY
ODBC Compatible
4–47
IFNULL Function
IFNULL Function
Returns value if expr is null. If expr is not null, IFNULL returns expr.
SYNTAX
EXAMPLE
This example illustrates the IFNULL function. The SELECT statement returns three rows with
a NULL value in column C1, and two non-NULL values:
C1 IFNULL(C1,9999)
-- ----------------
9999
9999
9999
1 1
3 3
NOTE
• The data type of value must be compatible with the data type of expr.
COMPATIBILITY
ODBC Compatible
4–48
INITCAP Function
INITCAP Function
Returns the result of the argument character expression after converting the first character to
uppercase and the subsequent characters to lowercase.
SYNTAX
INITCAP ( char_expression )
EXAMPLE
The following example shows how to use the INITCAP function:
NOTES
• A char_expression and the result may contain multi-byte characters. The uppercase
conversion for the first character and the lowercase conversion for the rest of the
characters is based on the case table in the convmap file. The default case table is BASIC.
COMPATIBILITY
Progress Extension
4–49
INSERT Function
INSERT Function
Returns a character string where length number of characters have been deleted from
string_exp1 beginning at start_pos, and string_exp2 has been inserted into string_exp1,
beginning at start_pos.
SYNTAX
EXAMPLE
This example illustrates the INSERT function. The two letters ’o’ and ’l’ are deleted from the
name ’Goldman’ in the last_name column, and the letters ’xx’ are inserted into the last_name
column, beginning at the fourth character, overlaying the letters ’d’ and ’m’:
SELECT INSERT(last_name,2,4,’xx’)
FROM customer
WHERE last_name = ’Goldman’;
INSERT LAST_NAME,2,4,XX)
------------------------
Gxxan
1 record selected
NOTES
• The start_pos and length can be of data type INTEGER, SMALLINT, or TINYINT.
4–50
INSERT Function
• string_exp1 and string_exp2 and the result may contain multi-byte characters. This is
determined by the character set of the SQL server. The length argument specifies a
number of characters.
COMPATIBILITY
ODBC Compatible
4–51
INSTR Function
INSTR Function
Searches character string char_expression1 for the character string char_expression2. The
search begins at start_pos of char_expression1. If occurrence is specified, then INSTR searches
for the nth occurrence, where n is the value of the fourth argument.
The position (with respect to the start of char_expression1) is returned if a search is successful.
Zero is returned if no match can be found.
SYNTAX
EXAMPLE
This example illustrates the INSTR function:
NOTES
• The third and fourth arguments, if specified, must be SMALLINT or TINYINT data type.
• The value for start position in a character string is the ordinal number of the character in
the string. The very first character in a string is at position 1, the second character is at
position 2, the nth character is at position n.
4–52
INSTR Function
COMPATIBILITY
Progress Extension
4–53
LAST_DAY Function
LAST_DAY Function
Returns the date corresponding to the last day of the month containing the argument date.
SYNTAX
LAST_DAY ( date_expression )
EXAMPLE
This example illustrates the LAST_DAY function:
SELECT *
FROM orders
WHERE LAST_DAY (order_date) + 1 = ’08/01/1999’ ;
NOTES
COMPATIBILITY
Progress Extension
4–54
LCASE Function
LCASE Function
Returns the result of the argument character expression after converting all the characters to
lowercase. LCASE is the same as LOWER but provides ODBC-compatible syntax.
SYNTAX
LCASE ( char_expression )
EXAMPLE
This example illustrates the LCASE function:
SELECT *
FROM customer
WHERE LCASE (last_name) = ’smith’ ;
NOTES
• A char_expression and the result may contain multi-byte characters. The lowercase
conversion is determined by the case table in the convmap file. The default case table is
BASIC.
COMPATIBILITY
ODBC Compatible
4–55
LEAST Function
LEAST Function
Returns the lowest value among the values of the given expressions.
SYNTAX
EXAMPLE
This example illustrates the LEAST function:
NOTES
• The first argument to the function can be of any type. However, the types of the subsequent
arguments must be compatible with that of the first argument.
• The type of the result is the same as that of the first argument.
COMPATIBILITY
Progress Extension
4–56
LEFT Function
LEFT Function
Returns the leftmost count of characters of string_exp.
SYNTAX
EXAMPLE
The following example shows how to use the LEFT function:
LEFT(LAST_NAME),4)
------------------
Gold
1 record selected
NOTES
• If any of the arguments of the expression evaluate to null, the result is null.
• The string_exp and the result may contain multi-byte characters. The function returns the
number of characters.
COMPATIBILITY
ODBC Compatible
4–57
LENGTH Function
LENGTH Function
Returns the string length of the value of the given character expression.
SYNTAX
LENGTH ( char_expression )
EXAMPLE
This example illustrates the LENGTH function:
NOTES
COMPATIBILITY
ODBC Compatible
4–58
LOCATE Function
LOCATE Function
Returns the location of the first occurrence of char_expr1 in char_expr2. If the function
includes the optional integer argument start_pos, LOCATE begins searching char_expr2 at that
position. If the function omits the start_pos argument, LOCATE begins its search at the
beginning of char_expr2.
LOCATE denotes the first character position of a character expression as 1. If the search fails,
LOCATE returns 0. If either character expression is null, LOCATE returns a null value.
SYNTAX
EXAMPLE
The following example uses two string literals as character expressions. LOCATE returns a
value of 6:
LOCATE(THIS,
------------
6
1 record selected
NOTE
COMPATIBILITY
ODBC Compatible
4–59
LOG10 Function
LOG10 Function
Returns the base 10 logarithm of expression.
SYNTAX
LOG10 ( expression )
EXAMPLE
This example illustrates the LOG10 function:
NOTE
COMPATIBILITY
ODBC Compatible
4–60
LOWER Function
LOWER Function
Returns the result of the argument char_expression after converting all the characters to
lowercase.
SYNTAX
LOWER ( char_expression )
EXAMPLE
This example illustrates the LOWER function:
SELECT *
FROM customer
WHERE LOWER (last_name) = ’smith’ ;
NOTES
COMPATIBILITY
SQL-92 Compatible
4–61
LPAD Function
LPAD Function
Pads the character string corresponding to the first argument on the left with the character string
corresponding to the third argument. After the padding, the length of the result is length.
SYNTAX
EXAMPLE
This example illustrates two ways to use the LPAD function:
NOTES
• The first argument to the function must be of type CHARACTER. The second argument
to the function must be of type INTEGER. The third argument, if specified, must be of
type CHARACTER. If the third argument is not specified, the default value is a string of
length 1 containing one blank.
• If L1 is the length of the first argument and L2 is the value of the second argument:
– If L1 is less than L2, the number of characters padded is equal to L2 minus L1.
– If L1 is equal to L2, no characters are padded and the result string is the same as the
first argument.
– If L1 is greater than L2, the result string is equal to the first argument truncated to the
first L2 characters.
4–62
LPAD Function
COMPATIBILITY
Progress Extension
4–63
LTRIM Function
LTRIM Function
Removes all the leading characters in char_expression that are present in char_set and returns
the resulting string. The first character in the result is guaranteed not to be in char_set. If you
do not specify the char_set argument, leading blanks are removed.
SYNTAX
EXAMPLE
This example illustrates the LTRIM function:
NOTES
• The char_expression, the character set specified by char_set, and the result may contain
multi-byte characters. Character comparisons are case-sensitive and are determined by the
collation table in the database.
COMPATIBILITY
ODBC Compatible
4–64
MINUTE Function
MINUTE Function
Returns the minute value in the argument as a short integer in the range of 0-59.
SYNTAX
MINUTE ( time_expression )
EXAMPLE
This example illustrates the MINUTE function:
SELECT *
FROM arrivals
WHERE MINUTE (in_time) > 10 ;
NOTES
COMPATIBILITY
ODBC Compatible
4–65
MOD Function
MOD Function
Returns the remainder of expression1 divided by expression2.
SYNTAX
EXAMPLE
This example illustrates the MOD function:
NOTES
• Both expression1 and expression2 must evaluate to exact numeric data types.
COMPATIBILITY
ODBC Compatible
4–66
MONTH Function
MONTH Function
Returns the month in the year specified by the argument as a short integer value in the range of
1-12.
SYNTAX
MONTH ( date_expression )
EXAMPLE
This example illustrates the MONTH function:
NOTES
COMPATIBILITY
ODBC Compatible
4–67
MONTHNAME Function
MONTHNAME Function
Returns a character string containing the name of the month (for example, January through
December) for the month portion of date_expression. Argument date_expression can be the
name of a column, the result of another scalar function, or a date or timestamp literal.
SYNTAX
MONTHNAME ( date_expression )
EXAMPLE
This example illustrates the MONTHNAME function. The query returns all rows where the
name of the month in the order_date column is equal to ’June’:
SELECT *
FROM orders
WHERE order_no =346 and MONTHNAME(order_date)=’JUNE’;
1 record selected
COMPATIBILITY
ODBC Compatible
4–68
MONTHS_BETWEEN Function
MONTHS_BETWEEN Function
Computes the number of months between two date values corresponding to the first and second
arguments.
SYNTAX
EXAMPLE
This example illustrates the MONTHS_BETWEEN function:
NOTES
• The first and second arguments to the function must be of type DATE.
• The result is negative if the date corresponding to the second argument is greater than that
corresponding to the first argument.
COMPATIBILITY
Progress Extension
4–69
NEXT_DAY Function
NEXT_DAY Function
Returns the minimum date that is greater than the date corresponding to the first argument where
the day of the week is the same as that specified by the second argument.
SYNTAX
EXAMPLE
This example illustrates the NEXT_DAY function:
NOTES
• The second argument to the function must be of type CHARACTER. The result of the
second argument must be a valid day of the week (’SUNDAY’, ’MONDAY’ etc.).
COMPATIBILITY
Progress Extension
4–70
NOW Function
NOW Function
Returns the current date and time as a TIMESTAMP value. This function takes no arguments.
SYNTAX
NOW ( )
COMPATIBILITY
ODBC Compatible
4–71
NULLIF Function
NULLIF Function
Returns a null value for expression1 if it is equal to expression2. It is useful for converting
values to null from applications that use some other representation for missing or unknown data.
The NULLIF scalar function is a type of conditional expression.
SYNTAX
EXAMPLE
This example uses the NULLIF scalar function to insert a null value into an address column if
the host-language variable contains a single space character:
NOTES
• The NULLIF expression is shorthand notation for a common case that can also be
represented in a CASE expression, as follows:
CASE
WHEN expression1 = expression2 THEN NULL
ELSE expression1
END
COMPATIBILITY
SQL-92 Compatible
4–72
NVL Function
NVL Function
Returns the value of the first expression if the first expression value is not null. If the first
expression value is null, the value of the second expression is returned.
SYNTAX
NOTE: The NVL function is not ODBC compatible. Use the IFNULL function when
ODBC-compatible syntax is required.
EXAMPLE
This example illustrates the NVL function:
NOTES
• The type of the second argument must be compatible with that of the first argument.
COMPATIBILITY
Progress Extension
4–73
PI Function
PI Function
Returns the constant value of pi as a floating-point value.
SYNTAX
PI ( )
EXAMPLE
This example illustrates the PI function:
COMPATIBILITY
ODBC Compatible
4–74
POWER Function
POWER Function
Returns expression1 raised to the power of expression2.
SYNTAX
EXAMPLE
This example illustrates the POWER function, raising ’3’ to the second power:
NOTES
4–75
PREFIX Function
PREFIX Function
Returns the substring of a character string, starting from the position specified by start_pos and
ending before the specified character.
SYNTAX
char_expression
start_pos
Evaluates to an integer value. PREFIX searches the string specified in the first argument
starting at that position. A value of 1 indicates the first character of the string.
char_expression
Evaluates to a single character. PREFIX returns the substring that ends before that
character. If PREFIX does not find the character, it returns the substring beginning at
start_pos, to the end of the string. If the expression evaluates to more than one character,
PREFIX ignores all but the first character.
4–76
PREFIX Function
EXAMPLE
The following example shows one way to use the PREFIX function:
NOTE
• Each char_expression and the result may contain multi-byte characters. The start_pos
argument specifies the character position, not a byte position. Character comparisons are
case-sensitive and are determined by sort weights in the collation table in the database.
COMPATIBILITY
Progress Extension
4–77
PRO_* Functions
PRO_* Functions
Provide limited support for the ARRAY data type. The PRO_ELEMENT,
PRO_ARR_ESCAPE, and PRO_ARR_DESCAPE functions are documented in Appendix C,
“Data Type Compatibility Issues with Previous Versions of Progress.”
NOTE: For a specific example on how to have separate elements in an array field, see the
Technical Support Kbase solution #19061.
4–78
QUARTER Function
QUARTER Function
Returns the quarter in the year specified by the argument as a short integer value in the range of
1-4.
SYNTAX
QUARTER ( date_expression )
EXAMPLE
This example illustrates the QUARTER function. The query requests all rows in the orders table
where the order_date is in the third quarter of the year:
SELECT *
FROM orders
WHERE QUARTER (order_date) = 3 ;
NOTES
COMPATIBILITY
ODBC Compatible
4–79
RADIANS Function
RADIANS Function
Returns the number of radians in an angle specified in degrees by expression.
SYNTAX
RADIANS ( expression )
EXAMPLE
This example illustrates the RADIANS function:
NOTES
COMPATIBILITY
ODBC Compatible
4–80
RAND Function
RAND Function
Returns a randomly generated number, using expression as an optional seed value.
SYNTAX
RAND ( [ expression ] )
EXAMPLE
This example illustrates the RAND function, supplying an optional seed value of ’3’:
NOTE
COMPATIBILITY
ODBC Compatible
4–81
REPEAT Function
REPEAT Function
Returns a character string composed of string_exp repeated count times.
SYNTAX
EXAMPLE
The following example shows how to use the REPEAT function:
REPEAT(FLD1,3)
-----------------
AfghanistanAfghanistanAfghanistan
1 record selected
NOTES
• The string_exp can be of the type fixed length or variable length CHARACTER .
• If any of the arguments of the expression evaluates to a null, the result is null.
COMPATIBILITY
ODBC Compatible
4–82
REPLACE Function
REPLACE Function
Replaces all occurrences of string_exp2 in string_exp1 with string_exp3.
SYNTAX
EXAMPLE
This example illustrates the REPLACE function, replacing the letters ’mi’ in the last_name
’Smith’ with the letters ’moo’:
REPLACE(LAST_NAME,MI,MOO)
-------------------------
Smooth
1 record selected
NOTES
• If any of the arguments of the expression evaluates to null, the result is null.
• If the replacement string is not found in the search string, it returns the original string.
• Each occurrence of string_exp and the result may contain multi-byte characters.
Character comparisons are case-sensitive and are determined by sort weights in the
collation table in the database.
COMPATIBILITY
ODBC Compatible
4–83
RIGHT Function
RIGHT Function
Returns the rightmost count of characters of string_exp.
SYNTAX
EXAMPLE
This example illustrates the RIGHT function, selecting the rightmost six letters from the string
’Afghanistan’:
RIGHT(FLD1,6)
---------------
nistan
1 record selected
NOTES
• If any of the arguments of the expression evaluate to null, the result is null.
• string_exp and the result may contain multi-byte characters. count represents the number
of characters.
COMPATIBILITY
ODBC Compatible
4–84
ROUND Function
ROUND Function
Returns the rounded value of a numeric expression.
SYNTAX
EXAMPLE
This example illustrates four calls to the ROUND function. In each case the num_expression is
2953861.8320. In the first call the rounding_factor is 2, in the second call the
rounding_factor is -2, in the third call the rounding_factor is 0, and in the fourth call no
rounding_factor is specified.
NOTES
– INTEGER
– TINYINT
– SMALLINT
– NUMBER
4–85
ROUND Function
– FLOAT
– DOUBLE PRECISION
• If the data type of num_expression is not a supported type, ROUND returns an error
message.
• rounding_factor is an integer between -32 and +32 inclusive, and indicates the digit
position to which you want to round num_expression. Figure 4–1 illustrates how the digit
positions are numbered. In the figure, the num_expression is 2953861.8320.
2953861.8320
Position -2
Position 0
Position 2
4–86
ROUND Function
COMPATIBILITY
Progress Extension
4–87
ROWID Function
ROWID Function
Returns the row identifier of the current row in a table. This function takes no arguments. The
ROWID of a row is determined when the row is inserted into the table. Once assigned, the
ROWID remains the same for the row until the row is deleted. At any given time, each row in
a table is uniquely identified by its ROWID.
NOTE: Using its ROWID is the most efficient way of selecting the row.
SYNTAX
ROWID
EXAMPLE
This example illustrates the ROWID function, returning all columns from the row in the
customers table where the rowid = ’10’:
SELECT *
FROM customers
WHERE ROWID = ’10’;
COMPATIBILITY
Progress Extension
4–88
RPAD Function
RPAD Function
Pads the character string corresponding to the first argument on the right with the character
string corresponding to the third argument. After the padding, the length of the result is equal to
the value of the second argument length.
SYNTAX
EXAMPLE
This example illustrates two ways to use the RPAD function:
NOTES
• The first argument to the function must be of type CHARACTER. The second argument
to the function must be of type INTEGER. The third argument, if specified, must be of
type CHARACTER. If the third argument is not specified, the default value is a string of
length 1 containing one blank.
• If L1 is the length of the first argument and L2 is the value of the second argument:
– If L1 is less than L2, the number of characters padded is equal to L2 minus L1.
– If L1 is equal to L2, no characters are padded and the result string is the same as the
first argument.
– If L1 is greater than L2, the result string is equal to the first argument truncated to the
first L2 characters.
4–89
RPAD Function
COMPATIBILITY
Progress Extension
4–90
RTRIM Function
RTRIM Function
Removes all the trailing characters in char_expression that are present in char_set and returns
the resultant string. The last character in the result is guaranteed not to be in char_set. If you do
not specify a char_set, trailing blanks are removed.
SYNTAX
EXAMPLE
This example illustrates the RTRIM function:
NOTES
• The char_expression, the character set specified by char_set, and the result may contain
multi-byte characters. Character comparisons are case-sensitive and are determined by the
collation table in the database.
COMPATIBILITY
ODBC Compatible
4–91
SECOND Function
SECOND Function
Returns the seconds in the argument as a short integer value in the range of 0-59.
SYNTAX
SECOND ( time_expression )
EXAMPLE
This example illustrates the SECOND function, requesting all columns from rows in the arrivals
table where the in_time column is less than or equal to ’40’:
NOTES
COMPATIBILITY
ODBC Compatible
4–92
SIGN Function
SIGN Function
Returns 1 if expression is positive, -1 if expression is negative, or zero if expression is zero.
SYNTAX
SIGN ( expression )
EXAMPLE
This example illustrates the SIGN function:
NOTE
COMPATIBILITY
ODBC Compatible
4–93
SIN Function
SIN Function
Returns the sine of expression.
SYNTAX
SIN ( expression )
EXAMPLE
This example illustrates the SIN trigonometric function:
SINE OF 45 DEGREES
------------------
0.707106781186547
1 record selected
NOTES
• SIN takes an angle (expression) and returns the ratio of two sides of a right triangle. The
ratio is the length of the side opposite the angle divided by the length of the hypotenuse.
COMPATIBILITY
ODBC Compatible
4–94
SQRT Function
SQRT Function
Returns the square root of expression.
SYNTAX
SQRT ( expression )
EXAMPLE
This example illustrates the SQRT function, requesting the square root of the value ’28’:
NOTES
COMPATIBILITY
ODBC Compatible
4–95
SUBSTR Function
SUBSTR Function
Returns the substring of the character string corresponding to the first argument starting at
start_pos and length characters long. If the third argument length is not specified, the substring
starting at start_pos up to the end of char_expression is returned.
SYNTAX
EXAMPLE
This example illustrates the SUBSTR function:
NOTES
• The values for specifying position in the character string start from 1. The first character
in a string is at position 1, the second character is at position 2, and so on.
• char_expression and the result may contain multi-byte characters. length specifies a
number of characters. Character comparisons are case-sensitive and are determined by sort
weights in the collation table in the database.
COMPATIBILITY
Progress Extension
4–96
SUBSTRING Function (ODBC Compatible)
SYNTAX
EXAMPLE
This example illustrates the SUBSTRING function:
NOTES
• The values for specifying position in the character string start from 1. The very first
character in a string is at position 1, the second character is at position 2, and so on.
• char_expression and the result may contain multi-byte characters. start_pos is the
character position, and length specifies a number of characters.
COMPATIBILITY
ODBC Compatible
4–97
SUFFIX Function
SUFFIX Function
Returns the substring of a character string starting after the position specified by start_pos and
the second char_expression, to the end of the string.
SYNTAX
char_expression
start_pos
Evaluates to an integer value. SUFFIX searches the string specified in the first argument
starting at that position. A value of 1 indicates the first character of the string.
char_expression
Evaluates to a single character. SUFFIX returns the substring that begins with that
character. If SUFFIX does not find the character after start_pos, it returns null. If the
expression evaluates to more than one character, SUFFIX ignores all but the first character.
4–98
SUFFIX Function
EXAMPLE
This example illustrates two ways to use the SUFFIX function:
2 records selected
C1 C2 SUFFIX(C1,1,C
-- -- -------------
test.pref . pref
pref.test s t
2 records selected
NOTE
• Each char_expression and the result may contain multi-byte characters. The start_pos
argument specifies the character position, not a byte position. Character comparisons are
case-sensitive and are determined by sort weights in the collation table in the database.
COMPATIBILITY
Progress Extension
4–99
SYSDATE Function
SYSDATE Function
Returns the current date as a DATE value. This function takes no arguments, and the trailing
parentheses are optional.
SYNTAX
SYSDATE [ ( ) ]
EXAMPLE
This example illustrates the SYSDATE function, inserting a new row into the objects table,
setting the create_date column to the value of the current date:
COMPATIBILITY
Progress Extension
4–100
SYSTIME Function
SYSTIME Function
Returns the current time as a TIME value to the nearest second. This function takes no
arguments, and the trailing parentheses are optional.
NOTE: SQL statements can refer to SYSTIME anywhere they can refer to a TIME
expression.
SYNTAX
SYSTIME [ ( ) ]
EXAMPLE
This example illustrates the SYSTIME function, inserting a new row into the objects table,
setting the create_time column to the value of the current time:
COMPATIBILITY
Progress Extension
4–101
SYSTIMESTAMP Function
SYSTIMESTAMP Function
Returns the current date and time as a TIMESTAMP value. This function takes no arguments,
and the trailing parentheses are optional.
SYNTAX
SYSTIMESTAMP [ ( ) ]
EXAMPLE
This example illustrates different formats for SYSDATE, SYSTIME, and SYSTIMESTAMP:
SYSDATE
-------
09/13/1994
1 record selected
SYSTIME
-------
14:44:07:000
1 record selected
SYSTIMESTAMP
------------
1994-09-13 14:44:15:000
1 record selected
COMPATIBILITY
Progress Extension
4–102
TAN Function
TAN Function
Returns the tangent of expression.
SYNTAX
TAN ( expression )
EXAMPLE
The following example shows how to use the TAN function:
TANGENT OF 45 DEGREES
---------------------
1.000000000000000
1 record selected
NOTES
• TAN takes an angle (expression) and returns the ratio of two sides of a right triangle. The
ratio is the length of the side opposite the angle divided by the length of the side adjacent
to the angle.
COMPATIBILITY
ODBC Compatible
4–103
TO_CHAR Function
TO_CHAR Function
Converts the given expression to character form and returns the result. The primary use for
TO_CHAR is to format the output of date-time expressions through the format_string
argument.
SYNTAX
expression
Converts to character form. It must evaluate to a value of the date or time data type to use
the format_string.
format_string
Specifies the format of the output. See the “Date-format Strings” section and the
“Time-format Strings” section in Chapter 2, “SQL-92 Language Elements” for more
information on format strings.
SQL ignores the format string if the expression argument does not evaluate to a date or
time.
NOTES
• The format argument can be used only when the type of the first argument is DATE.
COMPATIBILITY
Progress Extension
4–104
TO_DATE
TO_DATE
Converts the given date literal to a date value.
SYNTAX
TO_DATE ( date_literal )
EXAMPLE
This example illustrates the TO_DATE function, returning all columns from rows in the orders
table where the order_date column is earlier or equal to the date ’12/31/1999’:
SELECT *
FROM orders
WHERE order_date <= TO_DATE (’12/31/1999’) ;
NOTES
COMPATIBILITY
Progress Extension
4–105
TO_NUMBER Function
TO_NUMBER Function
Converts the given character expression to a number value.
SYNTAX
TO_NUMBER ( char_expression )
EXAMPLE
This example illustrates the TO_NUMBER function and the SUBSTR function:
SELECT *
FROM customer
WHERE TO_NUMBER (SUBSTR (phone, 1, 3)) = 603 ;
NOTES
COMPATIBILITY
Progress Extension
4–106
TO_TIME Function
TO_TIME Function
Converts the given time literal to a time value.
SYNTAX
TO_TIME ( time_literal )
EXAMPLE
The following example shows how to use the TO_DATE and the TO_TIME functions:
NOTES
COMPATIBILITY
Progress Extension
4–107
TO_TIMESTAMP Function
TO_TIMESTAMP Function
Converts the given timestamp literal to a timestamp value.
SYNTAX
TO_TIMESTAMP ( timestamp_lit )
EXAMPLE
The following example shows how to use the TO_TIMESTAMP function:
NOTES
COMPATIBILITY
Progress Extension
4–108
TRANSLATE Function
TRANSLATE Function
Translates each character in char_expression that is in from_set to the corresponding character
in to_set. The translated character string is returned as the result.
SYNTAX
EXAMPLE
This example substitutes underscores for spaces in customer names.
TRANSLATE EXAMPLE
-----------------
Sports_Cars_Inc.__________________________________
Mighty_Bulldozer_Inc._____________________________
Ship_Shapers_Inc._________________________________
Tower_Construction_Inc.___________________________
Chemical_Construction_Inc.________________________
Aerospace_Enterprises_Inc.________________________
Medical_Enterprises_Inc.__________________________
Rail_Builders_Inc.________________________________
Luxury_Cars_Inc.__________________________________
Office_Furniture_Inc._____________________________
10 records selected
NOTES
• For each character in char_expression, TRANSLATE checks for the same character in
from_set:
4–109
TRANSLATE Function
• If from_set is longer than to_set, TRANSLATE does not change trailing characters in
from_set that do not have a corresponding character in to_set.
COMPATIBILITY
Progress Extension
4–110
UCASE Function
UCASE Function
Returns the result of the argument character expression after converting all the characters to
uppercase. UCASE is identical to UPPER, but provides ODBC-compatible syntax.
SYNTAX
UCASE ( char_expression )
EXAMPLE
The example illustrates the UCASE function, returning columns from rows in the customer
table where the last_name column, after being converted to uppercase, is equal to ’SMITH’:
SELECT *
FROM customer
WHERE UCASE (last_name) = ’SMITH’ ;
NOTES
• A char_expression and the result may contain multi-byte characters. The uppercase
conversion is determined by the case table in the convmap file. The default case table is
BASIC.
COMPATIBILITY
ODBC Compatible
4–111
UPPER Function
UPPER Function
Returns the result of the argument character expression after converting all the characters to
uppercase.
SYNTAX
UPPER ( char_expression )
EXAMPLE
The example illustrates the UPPER function, returning columns from rows in the customer table
where the last_name column, after being converted to uppercase, is equal to ’SMITH’:
SELECT *
FROM customer
WHERE UPPER (last_name) = ’SMITH’ ;
NOTES
• A char_expression and the result may contain multi-byte characters. The uppercase
conversion is determined by the case table in the convmap file. The default case table is
BASIC.
COMPATIBILITY
SQL-92 Compatible
4–112
USER Function
USER Function
Returns a character-string identifier for the user of the current transaction, as determined by the
host operating system. This function takes no arguments, and the trailing parentheses are
optional.
SYNTAX
USER [ ( ) ]
NOTE: SQL statements can refer to USER anywhere they can refer to a character string
expression.
COMPATIBILITY
ODBC Compatible
4–113
WEEK Function
WEEK Function
Returns the week of the year as a short integer value in the range of 1-53.
SYNTAX
WEEK ( time_expression )
EXAMPLE
The example illustrates the WEEK function. The query returns all columns from rows in the
orders table where the order_date is in the fifth week of the year:
SELECT *
FROM orders
WHERE WEEK (order_date) = 5 ;
NOTES
COMPATIBILITY
ODBC Compatible
4–114
YEAR Function
YEAR Function
Returns the year as a short integer value in the range of 0-9999.
SYNTAX
YEAR ( date_expression )
EXAMPLE
The example illustrates the YEAR function. The query returns all columns in rows in the orders
table where the year in the order_date column is equal to ’1992’:
SELECT *
FROM orders
WHERE YEAR (order_date) = 1992;
NOTES
COMPATIBILITY
ODBC Compatible
4–115
YEAR Function
4–116
5
Java Stored Procedures and Triggers
This chapter describes when and how to use Java stored procedures and triggers. The elements
are described in the following sections:
• Using triggers
See Chapter 6, “Java Class Reference,” for detailed information on supported Java methods and
classes.
Progress SQL-92 Guide and Reference
• In a client server environment, client applications make a single request for the entire
procedure, instead of one or more requests for each SQL statement in the stored procedure
or trigger.
• Stored procedures and triggers are stored in compiled form as well as in source text form,
so execution is faster than a corresponding SQL script would be.
• Stored procedures can implement elaborate algorithms to enforce complex business rules.
The details of the procedure implementation can change without requiring changes in an
application that calls the procedure.
5–2
Java Stored Procedures and Triggers
• When you create a stored procedure, the SQL server processes the Java code, submits it to
the Java compiler, receives the compiled result, and stores the result in the database.
• When an application calls a stored procedure, the SQL server interacts with the Java
Virtual Machine (JVM) to execute the stored procedure and receive any result.
2. The Progress SQL-92 server adds code to the Java snippet to create a complete Java class
and submits the combined code to the Java compiler.
3. Presuming there are no Java compilation errors, the Java compiler returns compiled
bytecode back to the Progress SQL-92 server. If there are compilation errors, the Progress
SQL-92 server passes the first error message generated by the compiler back to the
application or tool that issued the CREATE PROCEDURE statement.
4. The Progress SQL-92 server stores both the Java source text and the bytecode form of the
procedure in the database.
5–3
Progress SQL-92 Guide and Reference
Figure 5–1 illustrates the general steps for creating a Java stored procedure.
Progress Database
5–4
Java Stored Procedures and Triggers
EXAMPLE
This example shows an excerpt from an ODBC application that calls a stored procedure
(order_parts) using the ODBC syntax { call procedure_name ( param ) }:
SQLUINTEGER Part_num;
SQLINTEGER Part_numInd = 0;
// Bind the parameter.
SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT,
SQL_C_SLONG, SQL_INTEGER, 0, 0, &Part_num, 0, Part_numInd);
// Place the department number in Part_num.
Part_num = 318;
// Execute the statement.
SQLExecDirect(hstmt, "{call order_parts(?)}", SQL_NTS);
1. The application calls the stored procedure through its native calling mechanism. The
previous example uses the ODBC call escape sequence.
2. Progress SQL-92 retrieves the compiled bytecode form of the procedure and submits it to
the Java Virtual Machine for execution.
3. For every SQL statement in the procedure, the Java Virtual Machine calls Progress
SQL-92.
4. Progress SQL-92 manages the interaction of the stored procedure with the database and
execution of the SQL statements, and returns any result to the Java Virtual Machine.
5. The Java Virtual Machine returns result (output parameters and result sets) of the
procedure to Progress SQL-92, which in turn passes them to the calling application.
5–5
Progress SQL-92 Guide and Reference
ODBC JDBC
1 Procedure call
2 Java bytecode
3 SQL Statements
Virtual Machine
Progress
SQL-92 Server 4 SQL Result Java
Stored procedure
5
result
Progress Database
5–6
Java Stored Procedures and Triggers
Stored procedures can take advantage of the power of Java programming features. Stored
procedures can:
• Handle exceptions
• Include any number and kind of SQL statements to access the database
Progress SQL-92 provides support for SQL statements in Java through several classes. See
Chapter 6, “Java Class Reference” for detailed reference information.
Table 5–1 summarizes the functionality of these Progress SQL-92-supplied classes.
Progress SQL-92
Functionality
Java Class
5–7
Progress SQL-92 Guide and Reference
SYNTAX
parameter_decl
SYNTAX
• Declares a class with the name username_procname_SP, where username is the user name
of the database connection that issued the CREATE PROCEDURE statement and
procname is the name supplied in the CREATE PROCEDURE statement.
• Declares a method within that class that includes the Java snippet. When an application
calls the stored procedure, the SQL server calls the Java virtual machine to invoke the
method of the username_procname_SP class.
5–8
Java Stored Procedures and Triggers
• The procedure specification provides the name of the procedure and can include other
optional clauses:
– Parameter declarations
– Import clause
• The procedure body contains the Java code that executes when an application invokes the
procedure.
EXAMPLE
A simple stored procedure requires the procedure name in the specification, and a statement
requiring no parameters in the body. The procedure in this example assumes the existence of a
table named HelloWorld, and inserts a quoted string into that table:
EXAMPLE
Subsequently, from SQL Explorer you can execute the procedure like this:
----
Hello World!
1 record selected
5–9
Progress SQL-92 Guide and Reference
• Parameter declarations specify the name and type of parameters that the calling
application will pass and receive from the procedure. Parameters can be input, output, or
both.
• The procedure result set declaration details the names and types of fields in a result set
the procedure generates. The result set is a set of rows that contain data generated by the
procedure. If a procedure retrieves rows from a database table, for instance, it can store the
rows in a result set for access by applications and other procedures. Note that the names
specified in the result-set declaration are not used within the stored procedure body.
Instead, methods of the Progress SQL-92 Java classes refer to fields in the result set by
ordinal number, not by name.
• The import clause specifies which packages the procedure needs from the Java core API.
By default, the Java compiler imports the java.lang package. The IMPORT clause must
list any other packages the procedure uses. Progress SQL-92 automatically imports the
packages it requires.
EXAMPLE
The following example shows a more complex procedure specification that contains these
elements:
BEGIN
.
.
.
END
5–10
Java Stored Procedures and Triggers
EXAMPLE
From the command prompt, you can invoke SQL Explorer and submit the file containing the
CREATE PROCEDURE statement as an input script, as shown in the following example:
From the command prompt, you can invoke SQL Explorer and submit the file containing the
CREATE PROCEDURE statement as an input script, as shown in the following example:
BEGIN
SQLIStatement Insert_HelloWorld = new SQLIStatement (
"INSERT INTO HelloWorld(fld1) values (’Hello World!’)");
Insert_HelloWorld.execute();
END
;
COMMIT WORK;
The Java snippet within the CREATE PROCEDURE statement does not execute as a
standalone program. Instead, it executes in the context of an application call to the method of
the class created by the SQL server. This characteristic has the following implications:
• It is meaningless for a snippet to declare a main method, since it will never be executed.
• If the snippet declares any classes, it must instantiate them within the snippet to invoke
their methods.
• The SQL server redirects the standard output stream to a file. This means method
invocations such as System.out.println will not display messages on the screen, but instead
writes them to that file.
5–11
Progress SQL-92 Guide and Reference
From ODBC
From ODBC, applications use the ODBC call escape sequence:
SYNTAX
Use parameter markers (question marks used as placeholders) for input or output parameters to
the procedure. You can also use literal values for input parameters only. Progress SQL-92 stored
procedures do not support return values in the ODBC escape sequence. See the Microsoft
ODBC Programmer’s Reference, Version 3.0, for more information on calling procedures from
ODBC applications.
Embed the escape sequence in an ODBC SQLExecDirect call to execute the procedure.
EXAMPLE
This example shows a call to a stored procedure named order_parts that passes a single input
parameter using a parameter marker:
SQLUINTEGER Part_num;
SQLINTEGER Part_numInd = 0;
From JDBC
The JDBC call escape sequence is the same as in ODBC:
SYNTAX
5–12
Java Stored Procedures and Triggers
EXAMPLE
This example shows the JDBC code parallel to the ODBC code excerpt shown in the previous
example:
try
{
CallableStatement statement;
int Part_num = 318;
EXAMPLE
This example shows the CALL statement that invokes the order_parts stored procedure, using
a literal value instead of a parameter marker:
• If you kept the original procedure definition in an SQL script file, edit the file and resubmit
it through SQL Explorer.
• Query system tables to extract the source of the CREATE PROCEDURE statement to a
file.
5–13
Progress SQL-92 Guide and Reference
The SQL DROP PROCEDURE statement deletes stored procedures from the database.
Exercise care in dropping procedures, since any procedure that calls the dropped procedure will
raise an error condition when the now nonexistent stored procedure is invoked.
• The privileges on a procedure can be granted to another user or to public either by the
owner of that procedure or by the DBA.
• Stored procedures are executed with the definer’s rights, not the invoker’s. In other words,
when a procedure is being executed on behalf of a user with EXECUTE privilege on that
procedure, for the objects that are accessed by the procedure, the procedure owner’s
privileges are checked and not the user’s. This enables a user to execute a procedure
successfully even when the user does not have the privileges to directly access the objects
that are accessed by the procedure, so long as the user has EXECUTE privilege on the
procedure.
5–14
Java Stored Procedures and Triggers
• To issue SQL statements that do not generate results (such as INSERT, GRANT, or
CREATE), use the SQLIStatement class for one-time execution, or the SQLPStatement
class for repeated execution.
• To issue SQL statements that generate results (SELECT and, in some cases, CALL), use
the SQLCursor class to retrieve rows from a database or another procedure’s result set.
In either case, if you want to return a result set to the application, use the DhSQLResultSet class
to store rows of data in a procedure result set. You must use DhSQLResultSet methods to
transfer data from an SQL result set to the procedure result set for the calling application to
process it. You can also use DhSQLResultSet methods to store rows of data generated
internally by the procedure.
In addition, Progress SQL-92 provides the DhSQLException class so procedures can process
and generate Java exceptions through the try, catch, and throw constructs.
5–15
Progress SQL-92 Guide and Reference
The setParam method takes two arguments. This is the syntax for setParam:
SYNTAX
marker_num
Specifies the ordinal number of the parameter marker in the SQL statement that is to
receive the value as an integer. 1 denotes the first parameter marker, 2 denotes the second,
n denotes the nth.
value
Specifies a literal, variable name, or input parameter that contains the value to be assigned
to the parameter marker.
EXAMPLE
This example shows an excerpt from a stored procedure that uses setParam to assign values
from two procedure variables to the parameter markers in an SQL INSERT statement. When
the procedure executes, it substitutes the value of the cust_number procedure variable for the
first parameter marker and the value of the cust_name variable for the second parameter marker:
The getValue Method: Pass Values from SQL Result Sets to Variables
The getValue method of the SQLCursor class assigns a single value from an SQL result set
(returned by an SQL query or another stored procedure) to a procedure variable or output
parameter.
SYNTAX
col_num
Specifies the desired column of the result set as integer. getValue retrieves the value in the
currently fetched record of the column denoted by col_num. ’1’ denotes the first column
of the result set, ’2’ denotes the second, n denotes the nth.
5–16
Java Stored Procedures and Triggers
sql_data_type
Specifies the corresponding SQL data type. For a complete list of appropriate data types,
refer to Table 5–2.
EXAMPLE
This example shows how the getValue() method works. This method returns a java object that
must be cast to the corresponding SQL data type :
5–17
Progress SQL-92 Guide and Reference
EXAMPLE
Declare input and output parameters in the specification section of a stored procedure, as shown
in the following example:
When the order_entry stored procedures executes, the calling application passes values for the
cust_name, item_num, quantity, and order_num input parameters. The body of the procedure
refers to them as Java variables. Similarly, Java code in the body of order_entry processes and
returns values in the status_code and order_num output parameters.
5–18
Java Stored Procedures and Triggers
EXAMPLE
The following example illustrates the use of the Java wrapper type Long for a SQL type
BIGINT:
BEGIN
f1 = new String("new rising sun");
f2 = new Java.math.BigInteger("999");
END
BEGIN
String in1 = new String("String type");
String out1 = new String();
Long out2 = new Long("0");
call_proc.setParam(2,new Long("111"));
call_proc.open();
out1 = (String)call_proc.getParam(1,CHAR);
call_proc.close();
END
5–19
Progress SQL-92 Guide and Reference
When the SQL server submits the Java class it creates from the stored procedure to the Java
compiler, the compiler checks for data-type consistency between the converted parameters and
variables you declare in the body of the stored procedure.
To avoid type mismatch errors, use the data-type mappings shown in Table 5–2 for declaring
parameters and result-set fields in the procedure specification and the Java variables in the
procedure body:
5–20
Java Stored Procedures and Triggers
• Immediate execution. Using methods of the SQLIStatement class, the procedure executes
a statement once.
• Prepared execution. Using methods of the SQLPStatement class, the procedure prepares a
statement for multiple executions in a procedure loop.
Table 5–3 shows the SQL statements that do not generate result sets. You can execute these
statements in a stored procedure using either the SQLIStatement or the SQLPStatement class.
INSERT REVOKE
Immediate Execution
Use immediate execution when a procedure needs to execute an SQL statement only once.
5–21
Progress SQL-92 Guide and Reference
EXAMPLE
This stored procedure in this sample script inserts a row in a table. The constructor for
SQLIStatement takes the SQL INSERT statement as its only argument. In this example, the
statement includes five parameter markers:
TeamProc.sql
-------------------------------------------------------------------------
-- File Name: TeamProc.sql
--
-- Purpose: Creates the insert_team stored procedure
-- in the current database.
--
-- Requirements:
-- (1) Database must be created
-- (2) Database must be running
-- (3) Submit this script to SQL Explorer as an input file
-- (character mode) or as a run file (GUI mode).
--
-- Revision History:
--
-- Date Author Change
-- ---- ------ ------
--
-- 11/99 DB-DOC Created, V9.1A
-------------------------------------------------------------------------
BEGIN
SQLIStatement insert_team = new SQLIStatement (
"INSERT INTO team (empnum, FirstName, LastName, State, Sport)
VALUES ( ?,?,?,?,? ) ");
insert_team.setParam (1, empnum);
insert_team.setParam (2, FirstName);
insert_team.setParam (3, LastName);
insert_team.setParam (4, State);
insert_team.setParam (5, Sport) ;
insert_team.execute ();
END
COMMIT WORK ;
5–22
Java Stored Procedures and Triggers
Prepared Execution
Use prepared execution when you need to execute the same SQL statement repeatedly. Prepared
execution avoids the overhead of creating multiple SQLIStatement objects for a single
statement.
There is an advantage to prepared execution when you execute the same SQL statement from
within a loop. Instead of creating an object with each iteration of the loop, prepared execution
creates an object once and supplies input parameters for each execution of the statement.
Once a stored procedure creates an SQLPStatement object, you can execute the object multiple
times, supplying different values for each execution.
EXAMPLE
This code fragment extends the previous example to use prepared execution:
BEGIN
SQLPStatement p_insert_cust = new SQLPStatement (
"INSERT INTO customer VALUES (?,?) ");
.
.
.
int i;
for (i = 0; i < new_custs.length; i++)
{
p_insert_cust.setParam (1, new_custs[i].cust_number);
p_insert_cust.setParam (2, new_custs[i].cust_name);
p_insert_cust.execute ();
}
END
• A SELECT statement queries the database and returns data that meets the criteria specified
by the query expression in the SELECT statement.
5–23
Progress SQL-92 Guide and Reference
• A CALL statement invokes another stored procedure that returns a result set specified by
the RESULT clause of the CREATE PROCEDURE statement.
Either way, once the procedure creates an object from the SQLCursor class, the processing of
result sets follows the same steps:
2. Check whether there are any records in the result set with the SQLCursor.Found method.
3. If there are records in the result set, loop through the result set:
• Check whether the fetch returned a record with the SQLCursor.Found method.
• If the fetch operation returned a record, assign values from the result-set record’s
fields to procedure variables or procedure output parameters with the
SQLCursor.getValue method.
• If the fetch operation did not return a record, exit the loop.
EXAMPLE
This example uses SQLCursor to process the result set returned by an SQL SELECT statement:
BEGIN
String ename = new String (20) ;
BigDecimal esal = new BigDecimal () ;
SQLCursor empcursor = new SQLCursor (
"SELECT name, sal FROM emp " ) ;
empcursor.Open () ;
empcursor.fetch ();
while (empcursor.found ())
{
empcursor.getValue (1, ename);
empcursor.getValue (2, esal);
// do something with the values here
}
empcursor.close () ;
END
5–24
Java Stored Procedures and Triggers
Stored procedures also use SQLCursor objects to process a result set returned by another stored
procedure. Instead of a SELECT statement, the SQLCursor constructor includes a CALL
statement that invokes the desired procedure.
EXAMPLE
The following example shows an excerpt from a stored procedure that processes the result set
returned by another procedure, get_customers:
• Declare the procedure result set through the RESULT clause of the procedure
specification.
• Populate the procedure result set in the body of the procedure using the methods of the
DhSQLResultSet class.
5–25
Progress SQL-92 Guide and Reference
When the SQL server creates a Java class from a CREATE PROCEDURE statement that
contains the RESULT clause, it implicitly instantiates an object of type DhSQLResultSet, and
calls it SQLResultSet. Invoke methods of the SQLResultSet instance to populate fields and
rows of the procedure result set.
EXAMPLE
The next example extends the get_sal procedure to return a procedure result set. For each row
of the SQL result set assigned to procedure variables, the procedure:
• Assigns the current values in the procedure variables to corresponding fields in the
procedure result set with the DhSQLResultSet.Set method
• Inserts a row into the procedure result set with the DhSQLResultSet.Insert method
empcursor.Open () ;
do
{
empcursor.Fetch ();
if (empcursor.found ())
{
ename = (String) empcursor.getValue (1, CHAR);
esal = (BigDecimal) empcursor.getValue (2, NUMERIC);
// NUMERIC and DECIMAL are synonyms
SQLResultSet.Set (1, ename);
SQLResultSet.Set (2, esal);
SQLResultSet.Insert ();
}
} while (empcursor.found ()) ;
empcursor.close () ;
END
5–26
Java Stored Procedures and Triggers
• Stored procedures might need to set the values of SQL statement input parameters or
procedure result fields to null.
• Stored procedures must check if the value of a field in an SQL result set is null before
assigning it through the SQLCursor.getValue method. The SQL server generates a
run-time error if the result-set field specified in getValue is null.
Setting SQL Statement Input Parameters and Procedure Result Set Fields to Null
Both the setParam method and set method take objects as their value arguments. For SQL
statement input parameters; see the “Using the Progress SQL-92 Java Classes” section. For
procedure result set fields, see the “Returning a Procedure Result Set to Applications: The
RESULT Clause and DhSQLResultSet” section. You can pass a null reference directly to the
method or pass a variable which has been assigned the null value.
EXAMPLE
This example shows using both techniques to set an SQL input parameter to null:
CREATE TABLE t1 (
c1 INTEGER,
c2 INTEGER,
c3 INTEGER)
insert_t1.execute();
END
5–27
Progress SQL-92 Guide and Reference
Assigning Null Values from SQL Result Sets: The SQLCursor.wasNULL Method
If the value of the field argument to the SQLCursor.getValue method is null, the SQL server
returns a run-time error.
EXAMPLE
This example illustrates the error returned when the argument to SQLCursor.getValue is null:
This means you must always check whether a value is null before attempting to assign a value
in an SQL result set to a procedure variable or output parameter. The SQLCursor class provides
the wasNULL method for this purpose.
The SQLCursor.wasNULL method returns TRUE if a field in the result set is null. It takes a
single integer argument that specifies which field of the current row of the result set to check.
5–28
Java Stored Procedures and Triggers
EXAMPLE
The next example illustrates using the wasNULL method:
5–29
Progress SQL-92 Guide and Reference
The error messages and the associated SQLSTATE and Progress SQL-92 error code values are
documented in Appendix A, “Progress SQL-92 Reference Information.”
5–30
Java Stored Procedures and Triggers
EXAMPLE
This example shows an excerpt from a stored procedure that uses
DhSQLException.getDiagnostics:
try
{
SQLIStatement insert_cust = new SQLIStatement (
"INSERT INTO customer VALUES (1,2) ");
}
catch (DhSQLException e)
{
errstate = e.getDiagnostics (RETURNED_SQLSTATE) ;
errmesg = e.getDiagnostics (MESSAGE_TEXT) ;
.
.
.
}
Stored procedures can also throw their own exceptions by instantiating a DhSQLException
object and throwing the object when the procedure detects an error in execution. The conditions
under which the procedure throws the exception object are completely dependent on the
procedure.
EXAMPLE
This example illustrates using the DhSQLException constructor to create an exception object
called excep. It then throws the excep object under all conditions:
5–31
Progress SQL-92 Guide and Reference
• An INOUT parameter calls both the SetParam and RegisterOutParam functions in any
order.
5–32
Java Stored Procedures and Triggers
5–33
Progress SQL-92 Guide and Reference
EXAMPLE
This example illustrates the steps required for calling one Java stored procedure from another:
commit work;
5–34
Java Stored Procedures and Triggers
SYNTAX
• The CREATE clause specifies the name of the trigger. Progress SQL-92 stores the
CREATE TRIGGER statement in the database under trigname. It also uses trigname in the
name of the Java class that Progress SQL-92 declares to wrap around the Java snippet. The
class name uses the format username_trigname_TP, where username is the user name of
the database connection that issued the CREATE TRIGGER statement.
• The BEFORE or AFTER keywords specify the trigger action time: whether the triggered
action implemented by java_snippet executes before or after the triggering INSERT,
UPDATE, or DELETE statement.
5–35
Progress SQL-92 Guide and Reference
• The ON table_name clause specifies the table for which the specified trigger event
activates the trigger. The ON clause cannot specify a view or a remote table.
• The optional REFERENCING clause is allowed only if the trigger also specifies the FOR
EACH ROW clause. It provides a mechanism for SQL to pass row values as input
parameters to the stored procedure implemented by java_snippet. The code in
java_snippet uses the getValue method of the NEWROW and OLDROW objects to
retrieve values of columns in rows affected by the trigger event and store them in
procedure variables. See the “OLDROW and NEWROW Objects: Passing Values to
Triggers” section for information.
• The FOR EACH clause specifies the frequency with which the triggered action
implemented by java_snippet executes.
• FOR EACH ROW means the triggered action executes once for each row being updated
by the triggering statement. CREATE TRIGGER must include the FOR EACH ROW
clause if it also includes a REFERENCING clause.
• FOR EACH STATEMENT means the triggered action executes only once for the whole
triggering statement. FOR EACH STATEMENT is the default.
• The IMPORT clause is the same as in stored procedures. It specifies standard Java classes
to import.
5–36
Java Stored Procedures and Triggers
EXAMPLE
This example shows the elements of a trigger:
BEGIN
.
.
.
END
• Triggers are automatic. When the trigger event (an INSERT, UPDATE, or DELETE
statement) affects the specified table (and, optionally in UPDATE operations, the
specified columns), the Java code contained in the body of the trigger executes. Stored
procedures, on the other hand, must be explicitly invoked by an application or another
procedure.
• Triggers cannot have output parameters or a result set. Since triggers are automatic, there
is no calling application to process any output they might generate. The practical
consequence of this is that the Java code in the trigger body cannot invoke methods of the
DhSQLResultSet class.
• Triggers have limited input parameters. The only possible input parameters for triggers are
values of columns in the rows affected by the trigger event. If the trigger includes the
REFERENCING clause, Progress SQL-92 passes the values (either as they existed in the
database or are specified in the INSERT or UPDATE statement) of each row affected. The
Java code in the trigger body can use those values in its processing by invoking the
getValue method of the OLDROW and NEWROW objects. See the “Using Stored
Procedures” section.
5–37
Progress SQL-92 Guide and Reference
The automatic nature of triggers makes them well suited for enforcing referential integrity. In
this regard they are like constraints, since both triggers and constraints can help ensure that a
value stored in the foreign key of a table must either be null or be equal to some value in the
matching unique or primary key of another table. However, triggers differ from constraints in
the following ways:
• Triggers are active, while constraints are passive. Constraints prevent updates that violate
referential integrity, and triggers perform explicit actions in addition to the update
operation.
• Triggers can do much more than enforce referential integrity. Because they are passive,
constraints are limited to preventing updates in a narrow set of conditions. Triggers are
more flexible. The next section outlines some common uses for triggers.
Cascading Deletes
A delete operation on one table causes additional rows to be deleted from other tables that are
related to the first table by key values. This is an active way of enforcing referential integrity
that a table constraint enforces passively.
Cascading Updates
An update operation on one table causes additional rows to be updated in other tables that are
related to the first table by key values. These updates are commonly limited to the key fields
themselves. This is an active way of enforcing referential integrity that a table constraint
enforces passively.
Summation Updates
An update operation in one table causes an update operation in a row of another table. The
second value is increased or decreased.
Automatic Archiving
A delete operation on one table creates an identical row in an archive table that is not otherwise
used by the database.
5–38
Java Stored Procedures and Triggers
• The OLDROW object contains values of a row as it exists in the database before an update
or delete operation. It is instantiated when triggers specify an UPDATE...REFERENCING
OLDROW or DELETE...REFERENCING OLDROW clause. It is meaningless and not
available for insert operations.
UPDATE is the only triggering statement that allows both NEWROW and OLDROW in the
REFERENCING clause.
Triggers use the OLDROW.getValue and NEWROW.getValue methods to assign a value from
a row being modified to a procedure variable. The format and arguments for getValue are the
same as in other Progress SQL-92 Java classes:
SYNTAX
col_num
Specifes the integer column number of the affected row. getValue retrieves the value in
the column denoted by col_num. ’1’ denotes the first column of the result set, ’2’ denotes
the second, n denotes the nth.
sql_data_type
Specifies the corresponding SQL data type. For a complete list of appropriate data types,
refer to Table 5–2.
5–39
Progress SQL-92 Guide and Reference
EXAMPLE
This example shows an excerpt from a trigger that uses getValue to assign values from both
OLDROW and NEWROW objects:
IMPORT
import java.sql.* ;
BEGIN
try
{
// column number of STATUS is 10
String old_status, new_status;
old_status = (String) OLDROW.getValue(10, CHAR);
new_status = (String) NEWROW.getValue(10, CHAR);
if ((old_status.CompareTo("OPEN") == 0) &&
(new_status.CompareTo("FIXED") == 0))
{
// If STATUS has changed from OPEN to FIXED
// increment the bugs_fixed_cnt by 1 in the
// row corresponding to current month
// and current year
SQLIStatement update_stmt (
" update BUG_STATUS set bugs_fixed_cnt = bugs_fixed_cnt + 1 "
" where month = ? and year = ?"
);
.
.
.
5–40
6
Java Class Reference
This reference chapter provides information on the Progress SQL Java classes and methods. The
Java Class Reference section lists all the methods in the Progress SQL Java classes and shows
which classes declare them. This chapter covers the following methods:
Subsequent sections describe each Java class and its methods in more detail. Some Java
methods are common to more than one class. The Java classes are presented in this order:
• DhSQLException
• DhSQLResultSet
• SQLCursor
• SQLIStatement
• SQLPStatement
Java Class Reference
setParam
Sets the value of an SQL statement’s input parameter to the specified value; a literal,
procedure variable, or procedure input parameter. The following Java classes declare
setParam:
• SQLIStatement
• SQLPStatement
• SQLCursor
makeNULL
Sets the value of an SQL statement’s input parameter to null. The following Java classes
declare makeNull:
• SQLIStatement
• SQLPStatement
• SQLCursor
• DhSQLResultSet
execute
Executes the SQL statement. The following Java classes declare execute:
• SQLIStatement
• SQLPStatement
6–2
Java Class Reference
rowCount
Returns the number of rows deleted, inserted, or updated by the SQL statement. The
following Java classes declare rowCount:
• SQLIStatement
• SQLPStatement
• SQLCursor
open
Opens the result set specified by the SELECT or CALL statement. The following Java
class declares open:
• SQLCursor
close
Closes the result set specified by the SELECT or CALL statement. The following Java
class declares close:
• SQLCursor
fetch
Fetches the next record in a result set. The following Java class declares fetch:
• SQLCursor
found
Checks whether a fetch operation returned to a record. The following Java class declares
found:
• SQLCursor
wasNULL
Checks if the value in a fetched field is null. The following Java class declares wasNull:
• SQLCursor
6–3
Java Class Reference
getValue
Stores the value of a fetched field in the specified procedure variable or procedure output
parameter. The following Java class declares getValue:
• SQLCursor
set
Sets the field in the currently active row of a procedure’s result set a literal, procedure
variable, or procedure input parameter. The following Java class declares set:
• DhSQLResultSet
insert
Inserts the currently active row into the result set of a procedure. The following Java class
declares insert:
• DhSQLResultSet
getDiagnostics
Returns the specified detail of an error message. The following Java class declares
getDiagnostics:
• DhSQLException
log
Writes a message to the log. The following Java classes inherit the log:
• SQLIStatement
• SQLPStatement
• SQLCursor
• DhSQLResult Set
• DhSQLException
6–4
Java Class Reference
err
Writes a message to the log. The following Java classes write to the log: :
• SQLIStatement
• SQLPStatement
• SQLCursor
• DhSQLResult Set
• DhSQLException
6–5
DhSQLException
DhSQLException
Extends the general java.lang. exception class to provide detail about errors in SQL statement
execution. Any such errors raise an exception with an argument that is an SQLException class
object. The getDiagnostics() method retrieves details of the error.
Constructors
public DhSQLException(int ecode, String errMsg)
Parameters
ecode
errMsg
EXAMPLE
This example illustrates using the DhSQLException constructor to create an exception object
called excep. It then throws the excep object under all conditions:
6–6
DhSQLException.getDiagnostics
DhSQLException.getDiagnostics
Returns the requested detail about an exception.
Format
public String getDiagnostics(int diagType)
Returns
A string containing the information specified by the diagType parameter as shown in Table
6–1.
Parameters
diagType
Throws
DhSQLException
6–7
DhSQLException.getDiagnostics
EXAMPLE
This code fragment illustrates DhSQLException.getDiagnostics:
try
{
SQLIStatement insert_cust = new SQLIStatement (
"INSERT INTO customer VALUES (1,2) ");
}
catch (DhSQLException e)
{
errstate = e.getDiagnostics (RETURNED_SQLSTATE) ;
errmesg = e.getDiagnostics (MESSAGE_TEXT) ;
.
.
.
}
6–8
DhSQLResultSet
DhSQLResultSet
Provides the stored procedure with a result set to return to the application that called the
procedure.
The Java code in a stored procedure does not explicitly create DhSQLResultSet objects. Instead,
when the SQL server creates a Java class from a CREATE PROCEDURE statement that
contains a Result clause, it implicitly instantiates an object of type DhSQLResultSet, and calls
it SQLResultSet.
Procedures invoke methods of the SQLResultSet instance to populate fields and rows of the
result set.
Constructors
No explicit constructor
Parameters
None
Throws
DhSQLException
DhSQLResultSet.insert
Inserts the currently active row into a procedure’s result set.
Format
public void insert()
Returns
None
Parameters
None
Throws
DhSQLException
6–9
DhSQLResultSet
EXAMPLE
This code fragment illustrates SQLResultSet.set and SQLResultSet.insert:
empcursor.Open () ;
do
{
empcursor.Fetch ();
if (empcursor.found ())
{
empcursor.getValue (1, ename);
empcursor.getValue (2, esal);
SQLResultSet.Set (1, ename);
SQLResultSet.Set (2, esal);
SQLResultSet.Insert ();
}
} while (empcursor.found ()) ;
empcursor.close () ;
END
DhSQLResultSet.makeNULL
Sets a field of the currently-active row in a procedure’s result set to null. This method is
redundant with using the DhSQLResultSet.set method to set a procedure result-set field to null.
Format
public void makeNULL(int field)
Returns
None
6–10
DhSQLResultSet
Parameters
field
An integer that specifies which field of the result-set row to set to null. 1 denotes the
first field in the row, 2 denotes the second, n denotes the nth.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates SQLResultSet.set and SQLResultSet.makeNULL:
BEGIN
SQLResultSet.set(1,char_in);
SQLResultSet.makeNULL(2);
END
DhSQLResultSet.set
Sets the field in the currently-active row of a procedure’s result set to the specified value (a
literal, procedure variable, or procedure input parameter).
Format
public void set(int field, Object val)
Returns
None
Parameters
field
An integer that specifies which field of the result-set row to set to the value specified
by val. (1 denotes the first field in the row, 2 denotes the second, and so on.)
val
6–11
DhSQLResultSet
A literal or the name of a variable or input parameter that contains the value to be
assigned to the field.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates SQLResultSet.Set:
empcursor.Open () ;
do
{
empcursor.Fetch ();
if (empcursor.found ())
{
empcursor.getValue (1, ename);
empcursor.getValue (2, esal);
SQLResultSet.Set (1, ename);
SQLResultSet.Set (2, esal);
SQLResultSet.Insert ();
}
} while (empcursor.found ()) ;
empcursor.close () ;
END
6–12
SQLCursor
SQLCursor
Allows rows of data to be retrieved from a database or another stored procedure’s result set.
Constructors
Parameters
statement
Generates a result set. Enclose the SQL statement in double quotes. The SQL statement is
either a SELECT or CALL statement.
NOTES
• A SELECT statement queries the database and returns data that meets the criteria specified
by the query expression in the SELECT statement.
• A CALL statement invokes another stored procedure that returns a result set specified by
the RESULT clause of the CREATE PROCEDURE statement.
Throws
DhSQLException
EXAMPLES
The following excerpt from a stored procedure instantiates an SQLCursor object called
cust_cursor that retrieves data from a database table:
SQLCursor empcursor = new SQLCursor ( "SELECT name, sal FROM emp " ) ;
The following excerpt from a stored procedure instantiates an SQLCursor object called
cust_cursor that calls another stored procedure:
6–13
SQLCursor
SQLCursor.close
Closes the result set specified by a SELECT or CALL statement.
Format
public void close()
Returns
None
Parameters
None
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the getValue and close methods:
{
if (cust_cursor.Found ())
{
cust_cursor.getValue (1, cust_number);
cust_cursor.getValue (2, cust_name) ;
}
else
break;
}
cust_cursor.close () ;
SQLCursor.fetch
Fetches the next record in a result set, if there is one.
Format
public void fetch()
6–14
SQLCursor
Returns
None
Parameters
None
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the fetch method and the getValue method:
for (;;)
{
cust_cursor.Fetch ();
if (cust_cursor.Found ())
{
cust_cursor.getValue (1, cust_number);
cust_cursor.getValue (2, cust_name) ;
}
else
break;
}
SQLCursor.found
Checks whether a fetch operation returned a record.
Format
public boolean found ()
Returns
Parameters
None
6–15
SQLCursor
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the fetch, found, and getValue methods:
for (;;)
{
cust_cursor.Fetch ();
if (cust_cursor.Found ())
{
cust_cursor.getValue (1, cust_number);
cust_cursor.getValue (2, cust_name) ;
}
else
break;
}
SQLCursor.getParam
Retrieves the values of Java OUT and INOUT parameters.
Format
inout_var = getParam( int fieldIndex, short fieldType ) ;
Returns
Parameters
inout_var
The target variable into which the value of an OUT or INOUT parameter is stored.
fieldIndex
An integer that specifies the position of the parameter in the parameter list.
6–16
SQLCursor
fieldType
A short integer that specifies the datatype of the parameter. The allowable defined
values for fieldType are listed in Table 6–2, grouped by category of data type.
Exact Approximate
Character Date-time Bit String
Numeric Numeric
– NUMERIC – – LVARBINARY
– DECIMAL – – –
Throws
DhSQLException
NOTES
• The getParam() method returns the value of an INOUT or OUT parameter identified by
the number you specify in the fieldIndex parameter. getParam() returns the value as an
object of the datatype you specify in the fieldType parameter. Since getParam() returns
the result as an instance of class Object, you must explicitly cast your inout_var variable
to the correct data type.
• See the “INOUT and OUT Parameters When One Java Stored Procedure Calls Another,”
section in Chapter 6, “Java Class Reference” for an example of how and when to use
SQLCursor.getParam().
6–17
SQLCursor
SQLCursor.getValue
Assigns a single value from a SQL result set to a procedure variable. The single field value is
the result of an SQL query or the result from another stored procedure.
Format
public Object getValue( int fieldNum, short fieldType )
Returns
Object
Parameters
fieldNum
An integer that specifies the position of the field to retrieve from the fetched record.
fieldType
A short integer that specifies the data type of the parameter. The allowable defined
values for fieldType are listed in Table 6–3, grouped by category of data type.
Exact Approximate
Character Date-time Bit String
Numeric Numeric
– NUMERIC – – LVARBINARY
– DECIMAL – – –
Throws
DhSQLException
6–18
SQLCursor
NOTES
• Before invoking getValue, you must test for the null condition by calling the
SQLCursor.wasNULL method. If the value returned is null, you must explicitly set the
target variable in the stored procedure to null.
• The getValue method returns a value from the result set identified by the number you
specify in the fieldNum parameter. getValue returns the value as an object of the datatype
you specify in the fieldType parameter. Since getValue returns the result as an instance
of class Object, you must explicitly cast your return value to the correct datatype.
• If the returned value is of datatype CHARACTER, then getValue returns a Java String
Object. You must declare a procedure variable of type String and explicitly cast the value
returned by getValue to type String.
EXAMPLE
This example illustrates testing for null and invoking the Java getValue method:
Select_t1.open();
Select_t1.fetch();
while(select_t1.found())
{
// Assign values from the current row of the SQL result set
// to the procedure variables. First check whether
// the values fetched are null. If null then explicitly
// set the procedure variables to null.
if ((select_t1.wasNULL(1)) == true)
pvar_int = null;
else
pvar_int = (Integer)select_t1.getValue(1, INTEGER);
if ((select_t1.wasNULL(2)) == true)
pvar_str = null;
else
pvar_str = (String)select_t1.getValue(1, CHAR);
}
6–19
SQLCursor
SQLCursor.makeNULL
Sets the value of an SQL statement’s input parameter to null. This method is common to the
SQLCursor, SQLIStatement, and SQLPStatement classes. This method is redundant with using
the setParam method to set an SQL statement’s input parameter to null.
Format
public void makeNULL(int f)
Returns
None
Parameters
An integer that specifies which input parameter of the SQL statement string to set to
null. ’1’ denotes the first input parameter in the statement, ’2’ denotes the second, n
denotes the nth.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the makeNULL method:
6–20
SQLCursor
SQLCursor.open
Opens the result set specified by the SELECT or CALL statement.
Format
public void open()
Returns
None
Parameters
None
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the open method:
SQLCursor empcursor = new SQLCursor ( "SELECT name, sal FROM emp " ) ;
empcursor.Open () ;
SQLCursor.registerOutParam
Register OUT parameters.
Format
Returns
None
Parameters
fieldIndex
An integer that specifies the position of the parameter in the parameter list.
6–21
SQLCursor
fieldType
A short integer that specifies the datatype of the parameter. The allowable defined
values for fieldType are listed in Table 6–4, grouped by category of data type:
Exact Approximate
Character Date-time Bit String
Numeric Numeric
– NUMERIC – – LVARBINARY
– DECIMAL – – –
Throws
DhSQLException
See the “INOUT and OUT Parameters When One Java Stored Procedure Calls Another” section
in Chapter 5, “Java Stored Procedures and Triggers” for an example of how and when to use
SQLCursor.registerOutParam().
SQLCursor.rowCount
Returns the number of rows affected (selected, inserted, updated, or deleted) by the SQL
statement. This method is common to the SQLCursor, SQLIStatement, and SQLPStatement
classes.
Format
public int rowCount()
Returns
6–22
SQLCursor
Parameters
None
Throws
DhSQLException
EXAMPLE
This example uses the rowCount method of the SQLIStatement class. It nests the method
invocation within SQLResultSet.set to store the number of rows affected (1, in this case) in the
procedure’s result set:
BEGIN
SQLCursor insert_test103 = new SQLIStatement (
"INSERT INTO test103 (fld1) values (17)");
insert_test103.execute();
SQLResultSet.set(1,new Long(insert_test103.rowCount()));
SQLResultSet.insert();
END
SQLCursor.setParam
Sets the value of an SQL statement’s input parameter to the specified value (a literal, procedure
variable, or procedure input parameter). This method is common to the SQLCursor,
SQLIStatement, and SQLPStatement classes.
Format
public void setParam(int f, Object val)
Returns
None
6–23
SQLCursor
Parameters
An integer that specifies which parameter marker in the SQL statement is to receive
the value. ’1’ denotes the first parameter marker, ’2’ denotes the second, n denotes
the nth.
val
A literal or the name of a variable or input parameter that contains the value to be
assigned to the parameter marker.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the setParam method:
BEGIN
// Assign local variables to be used as SQL input parameter references
Integer ins_fld_ref = new Integer(1);
Integer ins_small_fld = new Integer(3200);
Integer ins_int_fld = new Integer(21474);
Double ins_doub_fld = new Double(1.797E+30);
String ins_char_fld = new String("Athula");
String ins_vchar_fld = new String("Scientist");
Float ins_real_fld = new Float(17);
SQLIStatement insert_sfns1 = new SQLIStatement ("INSERT INTO sfns
(fld_ref,small_fld,int_fld,doub_fld,char_fld,vchar_fld)
values (?,?,?,?,?,?)" );
insert_sfns1.setParam(1,ins_fld_ref);
insert_sfns1.setParam(2,ins_small_fld);
insert_sfns1.setParam(3,ins_int_fld);
insert_sfns1.setParam(4,ins_doub_fld);
insert_sfns1.setParam(5,ins_char_fld);
insert_sfns1.setParam(6,ins_vchar_fld);
insert_sfns1.execute();
END
6–24
SQLCursor
SQLCursor.wasNULL
Checks if the value in a fetched field is null.
Format
public boolean wasNULL(int field)
Returns
Parameters
field
An integer that specifies which field of the fetched record is of interest. (1 denotes
the first column of the result set, 2 denotes the second, and so on.) wasNULL checks
whether the value in the currently-fetched record of the column denoted by field is
null.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the wasNULL method:
BEGIN
int small_sp = 0;
SQLCursor select_btypes =
new SQLCursor ("SELECT small_fld from sfns");
select_btypes.open();
select_btypes.fetch();
if ((select_btypes.wasNULL(1)) == true)
small_sp = null;
else
select_btypes.getValue(1,small_sp);
select_btypes.close();
END
6–25
SQLIStatement
SQLIStatement
Allows immediate (one-time) execution of SQL statements that do not generate a result set.
Constructors
Parameters
statement
An SQL statement that does not generate a result set. Enclose the SQL statement in
double quotes.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the SQLIStatement class:
BEGIN
SQLIStatement insert_cust = new SQLIStatement (
"INSERT INTO customer VALUES (?,?) ");
END
SQLIStatement.execute
Executes the SQL statement. This method is common to the SQLIStatement and
SQLPStatement classes.
Format
public void execute()
6–26
SQLIStatement
Returns
None
Parameters
None
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the setParam and execute methods:
BEGIN
SQLIStatement insert_cust = new SQLIStatement (
"INSERT INTO customer VALUES (?,?) ");
insert_cust.setParam (1, cust_number);
insert_cust.setParam (2, cust_name);
insert_cust.execute ();
END
SQLIStatement.makeNULL
Sets the value of an SQL statement’s input parameter to null. This method is common to the
SQLCursor, SQLIStatement, and SQLPStatement classes. This method is redundant with using
the setParam method to set an SQL statement’s input parameter to null.
Format
public void makeNULL(int f)
Returns
None
6–27
SQLIStatement
Parameters
An integer that specifies which input parameter of the SQL statement string to set to
null. ’1’ denotes the first input parameter in the statement, ’2’ denotes the second, n
denotes the nth.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the makeNULL method:
BEGIN
SQLIStatement insert_sfns1 = new SQLIStatement ("INSERT INTO sfns
(fld_ref,small_fld,int_fld,doub_fld,char_fld,vchar_fld)
values (?,?,?,?,?,?)" );
insert_sfns1.setParam(1,new Integer(66));
insert_sfns1.makeNULL(2);
insert_sfns1.makeNULL(3);
insert_sfns1.makeNULL(4);
insert_sfns1.makeNULL(5);
insert_sfns1.makeNULL(6);
insert_sfns1.execute();
END
SQLIStatement.rowCount
Returns the number of rows affected (selected, inserted, updated, or deleted) by the SQL
statement. This method is common to the SQLCursor, SQLIStatement, and SQLPStatement
classes.
Format
public int rowCount()
Returns
6–28
SQLIStatement
Parameters
None
Throws
DhSQLException
EXAMPLE
This example uses the rowCount method of the SQLIStatement class. It nests the method
invocation within SQLResultSet.set to store the number of rows affected (1, in this case) in the
procedure’s result set:
SQLIStatement.setParam
Sets the value of an SQL statement’s input parameter to the specified value (a literal, procedure
variable, or procedure input parameter). This method is common to the SQLCursor,
SQLIStatement, and SQLPStatement classes.
Format
public void setParam(int f, Object val)
Returns
None
6–29
SQLIStatement
Parameters
An integer that specifies which parameter marker in the SQL statement is to receive
the value (1 denotes the first parameter marker, 2 denotes the second, and so on).
val
A literal or the name of a variable or input parameter that contains the value to be
assigned to the parameter marker.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the setParam method:
BEGIN
// Assign local variables to be used as
// SQL input parameter references
Integer ins_fld_ref = new Integer(1);
Integer ins_small_fld = new Integer(3200);
Integer ins_int_fld = new Integer(21474);
Double ins_doub_fld = new Double(1.797E+30);
String ins_char_fld = new String("Athula");
String ins_vchar_fld = new String("Scientist");
Float ins_real_fld = new Float(17);
insert_sfns1.setParam(1,ins_fld_ref);
insert_sfns1.setParam(2,ins_small_fld);
insert_sfns1.setParam(3,ins_int_fld);
insert_sfns1.setParam(4,ins_doub_fld);
insert_sfns1.setParam(5,ins_char_fld);
insert_sfns1.setParam(6,ins_vchar_fld);
insert_sfns1.execute();
END
6–30
SQLPStatement
SQLPStatement
Allows prepared (repeated) execution of SQL statements that do not generate a result set.
Constructors
Parameters
statement
An SQL statement that does not generate a result set. Enclose the SQL statement in
double quotes.
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the SQLPStatement class:
SQLPStatement.execute
Executes the SQL statement. This method is common to the SQLIStatement and
SQLPStatement classes.
Format
public void execute()
Returns
None
Parameters
None
6–31
SQLPStatement
Throws
DhSQLException
EXAMPLE
This code fragment illustrates the execute and setParam methods in the SQLPStatement class:
SQLPStatement.makeNULL
Sets the value of an SQL statement’s input parameter to null. This method is common to the
SQLCursor, SQLIStatement, and SQLPStatement classes. This method is redundant with using
the setParam method to set an SQL statement’s input parameter to null.
Format
public void makeNULL(int f)
Returns
None
Parameters
An integer that specifies which input parameter of the SQL statement string to set to
null. (1 denotes the first input parameter in the statement, 2 denotes the second, and
so on.)
Throws
DhSQLException
6–32
SQLPStatement
EXAMPLE
This code fragment illustrates SQLPStatement.makeNULL:
BEGIN
SQLPStatement insert_sfns1 = new SQLPStatement ("INSERT INTO sfns
(fld_ref,small_fld,int_fld,doub_fld,char_fld,vchar_fld)
values (?,?,?,?,?,?)" );
insert_sfns1.setParam(1,new Integer(666));
insert_sfns1.makeNULL(2);
insert_sfns1.makeNULL(3);
insert_sfns1.makeNULL(4);
insert_sfns1.makeNULL(5);
insert_sfns1.makeNULL(6);
insert_sfns1.execute();
END
SQLPStatement.rowCount
Returns the number of rows affected (selected, inserted, updated, or deleted) by the SQL
statement. This method is common to the SQLCursor, SQLIStatement, and SQLPStatement
classes.
Format
public int rowCount()
Returns
Parameters
None
Throws
DhSQLException
6–33
SQLPStatement
EXAMPLE
This example uses the rowCount method of the SQLPStatement class. It nests the method
invocation within SQLResultSet.set to store the number of rows affected (1, in this case) in the
procedure’s result set:
BEGIN
SQLPStatement insert_test103 = new SQLPStatement (
"INSERT INTO test103 (fld1) values (17)");
insert_test103.execute();
SQLResultSet.set(1,new Long(insert_test103.rowCount()));
SQLResultSet.insert();
END
SQLPStatement.setParam
Sets the value of an SQL statement’s input parameter to the specified value (a literal, procedure
variable, or procedure input parameter). This method is common to the SQLCursor,
SQLIStatement, and SQLPStatement classes.
Format
public void setParam(int f, Object val)
Returns
None
Parameters
An integer that specifies which parameter marker in the SQL statement is to receive
the value (1 denotes the first parameter marker, 2 denotes the second, and so on).
val
A literal or the name of a variable or input parameter that contains the value to be
assigned to the parameter marker.
6–34
SQLPStatement
Throws
DhSQLException
EXAMPLE
This code fragment illustrates SQLPStatement.setParam:
BEGIN
// Assign local variables to be used as
// SQL input parameter references
Integer ins_fld_ref = new Integer(1);
Integer ins_small_fld = new Integer(3200);
Integer ins_int_fld = new Integer(21474);
Double ins_doub_fld = new Double(1.797E+30);
String ins_char_fld = new String("Athula");
String ins_vchar_fld = new String("Scientist");
Float ins_real_fld = new Float(17);
SQLPStatement insert_sfns1 = new SQLPStatement ("INSERT INTO sfns
(fld_ref,small_fld,int_fld,doub_fld,char_fld,vchar_fld)
values (?,?,?,?,?,?)" );
insert_sfns1.setParam(1,ins_fld_ref);
insert_sfns1.setParam(2,ins_small_fld);
insert_sfns1.setParam(3,ins_int_fld);
insert_sfns1.setParam(4,ins_doub_fld);
insert_sfns1.setParam(5,ins_char_fld);
insert_sfns1.setParam(6,ins_vchar_fld);
insert_sfns1.execute();
END
6–35
SQLPStatement
6–36
A
Progress SQL-92 Reference Information
This appendix provides reference information for Progress SQL-92. Specifically, it lists:
A–2
Progress SQL-92 Reserved Words
A–3
Progress SQL-92 Reserved Words
ON OPEN OPTION OR
A–4
Progress SQL-92 Reserved Words
YEAR – – –
A–5
Progress SQL-92 System Limits
A–6
Progress SQL-92 System Limits
A–7
Progress SQL-92 Error Messages
Overview
In addition to the Progress SQL-92-specific error codes, error conditions have an associated
SQLSTATE value. SQLSTATE is a five-character status parameter whose value indicates the
condition status returned by the most recent SQL statement. The first two characters of the
SQLSTATE value specify the class code and the last three characters specify the subclass code:
• Class codes of a–h and 0–4 are reserved by the SQL-92 standard. For those class codes
only, subclass codes of a–h and 0–4 are also reserved by the standard.
• Class codes of i–z and 5–9 are specific to database implementations such as Progress
SQL-92. All subclass codes in those classes are implementation defined except as noted
for ODBC.
SQL
Error
STATE Class Condition Subclass Message
Code
Value
10002 22503 Data exception Tuple Not Found for the Specified
TID
A–8
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
10400 22501 Data exception Invalid file size for alter log
statement
11102 50903 Progress/SQL rds error TDS area specified is not found
11103 50504 Progress/SQL rds error TDS not found for binding
A–9
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
A–10
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
16045 70734 Progress SQL-92 MM error MM– Set & Get isolation
A–11
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20019 50520 Progress SQL-92 rds error Cannot modify table referred to in
subquery
A–12
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20026 50527 Progress SQL-92 rds error Too many table references
20028 50529 Progress SQL-92 rds error An index with the same name
already exists
20029 50530 Progress SQL-92 rds error Index referenced not found
20031 50532 Progress SQL-92 rds error Cluster with same name already
exists
20032 50533 Progress SQL-92 rds error No cluster with this name
20035 50536 Progress SQL-92 rds error At least column spec or null clause
should be specified
A–13
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20043 50544 Progress SQL-92 rds error Tuple size too high
20044 50545 Progress SQL-92 rds error Array size too high
20045 08546 Connection exception File does not exist or not accessible
20046 50547 Progress SQL-92 rds error Field value not null for some tuples
20048 42549 Access rule violation Revoking for self not allowed
A–14
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20070 33571 Invalid SQL descriptor SQLDA buffer length too high
name
20073 2a574 Access rule violation View query specification for view
too long
A–15
Progress SQL-92 Error Messages
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20074 2a575 Access rule violation View column list must be specified
as expressions are given
20079 50580 Progress SQL-92 rds error More tables cannot be created
A–16
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (10 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20094 hz595 Remote database access Database link with same name
already exists
20098 22599 Data exception More than one row selected by the
query
A–17
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (11 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20105 5050f Progress SQL-92 rds error Statement not allowed in read only
isolation level
20109 hz50j Remote database access Remote database Name not valid
20114 33002 Invalid SQL descriptor Fetched Value NULL & indicator
name var not defined
A–18
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (12 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20132 5050u Progress SQL-92 rds error Revoke failed because of restrict
20134 5050v Progress SQL-92 rds error Invalid long datatype column
references
20135 5050x Progress SQL-92 rds error Contains operator is not supported
in this context
20136 5050z Progress SQL-92 rds error Contains operator is not supported
for this datatype
20137 50514 Progress SQL-92 rds error Index is not defined or does not
support CONTAINS
20138 50513 Progress SQL-92 rds error Index on long fields requires that it
can push down only CONTAINS
A–19
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (13 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20146 86005 Progress SQL-92 Triggers Trigger with this name already
exists
20147 86006 Progress SQL-92 Triggers Trigger with this name does not
exist
A–20
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (14 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
20239 2c000 Invalid character set name Invalid character set name
specified.
20240 5050y Progress SQL-92 rds error Invalid collation name specified
A–21
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (15 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
23000 22563 Progress SQL-92 Data Table create returned invalid table
exception id
23001 22564 Progress SQL-92 Data Index create returned invalid index
exception id
25128 j0j28 Progress SQL-92 odbc trans Query terminated as max row limit
layer exceeded for a remote table
25131 j0j29 Progress SQL-92 odbc trans Unable to read column info from
layer remote table
30001 5050w Progress SQL-92 rds error Query aborted on user request
A–22
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (16 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
30008 k0k08 Progress SQL-92 network Mismatch in pkt header size and
interface total argument size
30010 k0k10 Progress SQL-92 network Reply does not match the request
interface
30061 k0k16 Progress SQL-92 network Could not connect to sql network
interface daemon
A–23
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (17 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
A–24
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (18 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
A–25
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (19 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
210020 0AP03 Unsupported feature The first index created for a table
may not be dropped
211013 3F001 Bad schema reference SQL-92 cannot alter or drop a table
created by 4GL or SQL-89
218001 P8P18 Progress I18N NLS error Failure to create a NLS character
set conversion handler
A–26
Progress SQL-92 Error Messages
Table A–3: Progress SQL-92 Error Codes and Messages (20 of 20)
SQL
Error
STATE Class Condition Subclass Message
Code
Value
A–27
Progress SQL-92 Error Messages
A–28
B
Progress SQL-92 System Catalog Tables
Progress SQL-92 maintains a set of system tables for storing information about tables, columns,
indexes, constraints, and privileges. This appendix describes those System Catalog Tables.
Overview of System Catalog Tables
SYSTABLES Core Core system table. One row for each TABLE in the database.
SystemTable
SYSCOLUMNS Core Core system table. One row for each COLUMN of each table
SystemTable in the database.
SYSINDEXES Core Core system table. One row for each component of each
SystemTable INDEX in the database.
SYSCALCTABLE A single row with a single column set to the value 100.
System Table
SYSCHARSTAT System One row for each CHARACTER column in the database.
Table
SYSCOLAUTH System One row for each column for each user holding privileges on
Table the column.
B–2
Overview of System Catalog Tables
SYSDATESTAT System One row for each DATE column in the database.
Table
SYSDBAUTH System One row for each user with database-wide privileges.
Table
SYSINTSTAT System One row for each INTEGER column in the database.
Table
SYSNUMSTAT System One row for each NUMERIC column in the database.
Table
SYSPROCBIN System One row for each compiled Java stored procedure or trigger in
Table the database.
SYSPROCCOLUMNS One row for each column in the result set of a stored procedure.
System Table
SYSPROCTEXT System One row for each Java source code for a stored procedure or
Table trigger in the database.
SYSREALSTAT System One row for each REAL column in the database.
Table
B–3
Overview of System Catalog Tables
SYSTABAUTH System One row for each unique user/table combination holding table
Table privileges on a table in the database.
SYSTBLSTAT System Contains statistics for each user table in the database.
Table
SYSTIMESTAT System One row for each TIME column in the database.
Table
SYSTRIGCOLS System One row for each column specified in each trigger in the
Table database.
SYSTSSTAT System One row for each TIMESTAMP column in the database.
Table
SYS_KEYCOL_USAGE One row for each column in the database defined with a
System Table PRIMARY KEY or FOREIGN KEY.
B–4
Overview of System Catalog Tables
SYS_REF_CONSTRS One row for each table in the database defined with a
System Table REFERENTIAL INTEGRITY CONSTRAINT.
B–5
SYSTABLES Core SystemTable
creator VARCHAR 32
has_ccnstrs VARCHAR 1
has_fcnstrs VARCHAR 1
has_pcnstrs VARCHAR 1
has_ucnstrs VARCHAR 1
id INTEGER 4
owner VARCHAR 32
rssid INTEGER 4
segid INTEGER 4
tbl VARCHAR 32
tbl_status VARCHAR 1
tbltype VARCHAR 1
B–6
SYSCOLUMNS Core SystemTable
charset VARCHAR 32
col VARCHAR 32
collation VARCHAR 32
coltype VARCHAR 10
id INTEGER 4
nullflag VARCHAR 1
owner VARCHAR 32
scale INTEGER 4
tbl VARCHAR 32
width INTEGER 4
B–7
SYSINDEXES Core SystemTable
abbreviate BIT 1
active BIT 1
creator VARCHAR 32
colname VARCHAR 32
id INTEGER 4
idxcompress VARCHAR 1
idxmethod VARCHAR 2
idxname VARCHAR 32
idxorder CHARACTER 1
idxowner VARCHAR 32
idxsegid INTEGER 4
idxseq INTEGER 4
ixcol_user_misc VARCHAR 20
rssid INTEGER 4
tbl VARCHAR 32
tblowner VARCHAR 32
B–8
SYSCALCTABLE System Table
fld INTEGER 4
B–9
SYSCHARSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
B–10
SYSCOLAUTH System Table
col VARCHAR 32
grantee VARCHAR 32
grantor VARCHAR 32
ref VARCHAR 1
sel VARCHAR 1
tbl VARCHAR 32
tblowner VARCHAR 32
upd VARCHAR 1
B–11
SYSCOLSTAT System Table
colid INTEGER 4
coltype VARCHAR 10
rssid INTEGER 4
tblid INTEGER 4
B–12
SYSCOLUMNS_FULL System Table
array_extent INTEGER 4
charset VARCHAR 32
col VARCHAR 32
collation VARCHAR 32
coltype VARCHAR 10
col_label VARCHAR 60
col_label_sa VARCHAR 12
col_subtype INTEGER 4
dflt_value_sa VARCHAR 12
display_order INTEGER 4
field_rpos INTEGER 4
format VARCHAR 60
format_sa VARCHAR 12
help_sa VARCHAR 12
id VARCHAR 4
label VARCHAR 60
B–13
SYSCOLUMNS_FULL System Table
label_sa VARCHAR 12
nullflag CHARACTER 2
owner VARCHAR 32
scale INTEGER 4
tbl VARCHAR 32
user_misc VARCHAR 20
valmsg_sa VARCHAR 12
width INTEGER 4
B–14
SYSDATATYPES System Table
autoincr SMALLINT 2
casesensitive SMALLINT 2
createparams VARCHAR 32
datatype SMALLINT 2
dhtypename VARCHAR 32
literalprefix VARCHAR 1
literalsuffix VARCHAR 1
localtypename VARCHAR 1
nullable SMALLINT 2
odbcmoney SMALLINT 2
searchable SMALLINT 2
typeprecision INTEGER 4
unsignedattr SMALLINT 2
B–15
SYSDATESTAT System Table
rssid INTEGER 4
colid INTEGER 4
tblid INTEGER 4
val1 DATE 4
val2 DATE 4
val3 DATE 4
val4 DATE 4
val5 DATE 4
val6 DATE 4
val7 DATE 4
val8 DATE 4
val9 DATE 4
val10 DATE 4
B–16
SYSDBAUTH System Table
dba_acc VARCHAR 1
grantee VARCHAR 32
res_acc VARCHAR 1
B–17
SYSFLOATSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
val1 FLOAT 4
val2 FLOAT 4
val3 FLOAT 4
val4 FLOAT 4
val5 FLOAT 4
val6 FLOAT 4
val7 FLOAT 4
val8 FLOAT 4
val9 FLOAT 4
val10 FLOAT 4
B–18
SYSIDXSTAT System Table
idxid INTEGER 4
nleaf INTEGER 4
nlevels SMALLINT 2
recsz INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
B–19
SYSINTSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
val1 INTEGER 4
val2 INTEGER 4
val3 INTEGER 4
val4 INTEGER 4
val5 INTEGER 4
val6 INTEGER 4
val7 INTEGER 4
val8 INTEGER 4
val9 INTEGER 4
val10 INTEGER 4
B–20
SYSNUMSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
val1 NUMERIC 32
val2 NUMERIC 32
val3 NUMERIC 32
val4 NUMERIC 32
val5 NUMERIC 32
val6 NUMERIC 32
val7 NUMERIC 32
val8 NUMERIC 32
val9 NUMERIC 32
val10 NUMERIC 32
B–21
SYSPROCBIN System Table
id INTEGER 4
proc_type CHARACTER 2
rssid INTEGER 4
seq INTEGER 4
B–22
SYSPROCCOLUMNS System Table
argtype VARCHAR 32
col VARCHAR 32
datatype VARCHAR 32
id INTEGER 4
nullflag CHAR 1
proc_id INTEGER 4
rssid INTEGER 4
scale INTEGER 4
width INTEGER 4
B–23
SYSPROCEDURES System Table
creator VARCHAR 32
has_resultset CHARACTER 1
has_return_val CHARACTER 1
owner VARCHAR 32
proc_id INTEGER 4
proc_name VARCHAR 32
proc_type VARCHAR 32
rssid INTEGER 4
B–24
SYSPROCTEXT System Table
id INTEGER 4
proc_type CHARACTER 2
rssid INTEGER 4
seq INTEGER 4
B–25
SYSREALSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
val1 REAL 4
val2 REAL 4
val3 REAL 4
val4 REAL 4
val5 REAL 4
val6 REAL 4
val7 REAL 4
val8 REAL 4
val9 REAL 4
val10 REAL 4
B–26
SYSSMINTSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
val1 SMALLINT 2
val2 SMALLINT 2
val3 SMALLINT 2
val4 SMALLINT 2
val5 SMALLINT 2
val6 SMALLINT 2
val7 SMALLINT 2
val8 SMALLINT 2
val9 SMALLINT 2
val10 SMALLINT 2
B–27
SYSSYNONYMS System Table
ispublic SMALLINT 2
screator VARCHAR 32
sname VARCHAR 32
sowner VARCHAR 32
sremdb VARCHAR 32
stbl VARCHAR 32
stblowner VARCHAR 32
B–28
SYSTABAUTH System Table
alt VARCHAR 1
del VARCHAR 1
exe CHAR 1
grantee VARCHAR 32
grantor VARCHAR 32
ins VARCHAR 1
ndx VARCHAR 1
ref VARCHAR 1
sel VARCHAR 1
tbl VARCHAR 32
tblowner VARCHAR 32
upd VARCHAR 1
B–29
SYSTABLES_FULL System Table
creator VARCHAR 32
dump_name VARCHAR 16
file_label VARCHAR 60
file_label_sa VARCHAR 12
frozen BIT 1
has_ccnstrs VARCHAR 1
has_fcnstrs VARCHAR 1
has_pcnstrs VARCHAR 1
has_ucnstrs VARCHAR 1
hidden BIT 1
id INTEGER 4
last_change INTEGER 4
owner VARCHAR 32
prime_index INTEGER 4
rssid INTEGER 4
segid INTEGER 4
B–30
SYSTABLES_FULL System Table
tbl VARCHAR 32
tbltype VARCHAR 1
tbl_status VARCHAR 1
user_misc VARCHAR 20
valmsg_sa VARCHAR 12
B–31
SYSTBLSTAT System Table
card INTEGER 4
npages INTEGER 4
pagesz INTEGER 4
recsz INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
B–32
SYSTIMESTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
val1 TIME 4
val2 TIME 4
val3 TIME 4
val4 TIME 4
val5 TIME 4
val6 TIME 4
val7 TIME 4
val8 TIME 4
val9 TIME 4
val10 TIME 4
B–33
SYSTINYINTSTAT System Table
colid INTEGER 4
tblid INTEGER 4
val1 TINYINT 1
val2 TINYINT 1
val3 TINYINT 1
val4 TINYINT 1
val5 TINYINT 1
val6 TINYINT 1
val7 TINYINT 1
val8 TINYINT 1
val9 TINYINT 1
val10 TINYINT 1
B–34
SYSTRIGCOLS System Table
colid INTEGER 4
owner VARCHAR 32
triggername VARCHAR 32
B–35
SYSTRIGGER System Table
fire_4gl BIT 1
owner VARCHAR 32
refers_to_new CHAR 1
refers_to_old CHAR 1
rssid INTEGER 4
statement_or_row CHAR 1
tbl VARCHAR 32
tblowner VARCHAR 32
triggerid INTEGER 4
triggername VARCHAR 32
trigger_event VARCHAR 1
trigger_time VARCHAR 1
B–36
SYSTSSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
val1 TIMESTAMP 8
val2 TIMESTAMP 8
val3 TIMESTAMP 8
val4 TIMESTAMP 8
val5 TIMESTAMP 8
val6 TIMESTAMP 8
val7 TIMESTAMP 8
val8 TIMESTAMP 8
val9 TIMESTAMP 8
val10 TIMESTAMP 8
B–37
SYSVARCHARSTAT System Table
colid INTEGER 4
rssid INTEGER 4
tblid INTEGER 4
B–38
SYSVIEWS System Table
creator VARCHAR 32
owner VARCHAR 32
seq INTEGER 4
viewname VARCHAR 32
B–39
SYS_CHKCOL_USAGE System Table
cnstrname VARCHAR 32
colname VARCHAR 32
owner VARCHAR 32
tblname VARCHAR 32
B–40
SYS_CHK_CONSTRS System Table
chkseq INTEGER 4
cnstrname VARCHAR 32
owner VARCHAR 32
tblname VARCHAR 32
B–41
SYS_KEYCOL_USAGE System Table
cnstrname VARCHAR 32
colname VARCHAR 32
colposition INTEGER 4
owner VARCHAR 32
tblname VARCHAR 32
B–42
SYS_REF_CONSTRS System Table
cnstrname VARCHAR 32
deleterule VARCHAR 1
owner VARCHAR 32
refcnstrname VARCHAR 32
refowner VARCHAR 32
reftblname VARCHAR 32
tblname VARCHAR 32
B–43
SYS_TBL_CONSTRS System Table
cnstrname VARCHAR 32
cnstrtype VARCHAR 1
idxname VARCHAR 32
owner VARCHAR 32
tblname VARCHAR 32
B–44
C
Data Type Compatibility Issues with
Previous Versions of Progress
This appendix addresses compatibility issues when using the Progress SQL-92 environment and
earlier versions of the Progress database. Specifically, it discusses:
• Mapping between Progress 4GL supported data types and the corresponding Progress
SQL-92 data types.
• Progress SQL-92 support for the ARRAY data type created using the Progress 4GL
Dictionary.
Progress SQL-92 Guide and Reference
CHARACTER VARCHAR
DATE DATE
INTEGER INTEGER
LOGICAL BIT
RAW VARBINARY
RECID INTEGER
NOTES
• All other SQL-92 types are not compatible with 4GL. In particular, Progress SQL-92
CHARACTER data is not compatible with the 4GL. Use SQL-92 type VARCHAR to map
4GL CHARACTER data.
• Data columns created using the Progress SQL-92 environment that have a data type not
supported in the Progress 4GL environment are not accessible through Progress 4GL
applications and utilities.
C–2
Data Type Compatibility Issues with Previous Versions of Progress
C.2.1 Overview
Array fields are created using the Progress 4GL Dictionary. Progress SQL-92 provides a
mechanism for referencing and updating these arrays. Subscripted references are not supported.
Progress SQL-92 manages the arrays as NVARCHAR strings, and the string representation is
the concatenation of each array element, with a semicolon ( ; ) separating each element.
To escape an instance of a semicolon in the data of a Progress CHARACTER array, use the
escape character tilde before the semicolon ( ~; ). An unquoted question mark represents a
NULL element. To distinguish a NULL element from a question mark, use a tilde as an escape
character for a question mark in the data ( ~? ). A tilde is also the escape character for a
tilde ( ~~ ).
Progress SQL-92 supplies three built-in functions for extracting an element, and for adding
escape characters to and removing escape characters from a single element of a character array.
The PRO_ELEMENT, PRO_ARR_ESCAPE, and PRO_ARR_DESCAPE functions provide
full internationalization support. A description of each function follows.
SYNTAX
array_style_expression
start_position
The position in the string marking the beginning of the element PRO_ELEMENT is to extract.
end_position
The position in the string marking the end of the element to be extracted.
C–3
Progress SQL-92 Guide and Reference
EXAMPLES
The following example returns the string ’bb’:
PRO_ELEMENT(’aa;bb;cc’, 2, 2) ;
PRO_ELEMENT(’aa;bb;cc’, 1, 2) ;
PRO_ELEMENT(’aa~;aa;bb;cc’, 1, 1) ;
NOTES
• The returned string does not include the leading separator of the first element, or the
trailing separator ( ; ) of the last element.
• Even if you are extracting only one element, the escape characters are included in the
result.
C–4
Data Type Compatibility Issues with Previous Versions of Progress
SYNTAX
PRO_ARR_ESCAPE( ’char_element’ ) ;
char_element
EXAMPLES
The following example returns the string ’aa~;aa’:
PRO_ARR_ESCAPE(’aa;aa’) ;
The following example returns the string ’aa~aa’. There is no change, since another special
character does not follow the escape character:
PRO_ARR_ESCAPE(’aa~aa’) ;
PRO_ARR_ESCAPE(’aa~;aa’) ;
NOTES
• char_element must not be the name of an array column, since the column contains true
separators which would be destroyed by this function.
C–5
Progress SQL-92 Guide and Reference
SYNTAX
PRO_ARR_DESCAPE( ’char_element’ ) ;
char_element
EXAMPLES
The following example returns the string ’aa;aa’:
PRO_ARR_DESCAPE(’aa~;aa’) ;
The following example returns the string ’aa~aa’. There is no change, since another special
character does not follow the escape character:
PRO_ARR_DESCAPE(’aa~aa’) ;
PRO_ARR_DESCAPE(’aa~~;aa’) ;
NOTE: char_element should not be the name of an array column, since the column contains
true separators which would be destroyed by this function.
C–6
Data Type Compatibility Issues with Previous Versions of Progress
• Passes the element to the PRO_ARR_ESCAPE function for the addition of any necessary
escape characters
• Concatenates the result to a composite with the separator character ( ; ) between this
element and the next element
This results in dual data types for array fields. The fetch type is TPE_DT_NVARCHAR for the
unsubscripted references. The underlying Progress 4GL data type is the native type.
EXAMPLES
The first example assumes a character array named ARRAYCHAR containing three elements
in a row in the customer table where the cust_num column is equal to 88, and with values:
ARRAYCHAR[ 1 ] = ’aa’
ARRAYCHAR[ 2 ] = ’bb’
ARRAYCHAR[ 3 ] = ’cc’
ARRAYCHAR
---------
aa;bb;cc
1 record selected
C–7
Progress SQL-92 Guide and Reference
To retrieve an individual element from an array with any escape characters removed, use the
PRO_ELEMENT and PRO_ARR_DESCAPE functions. For example, ARRAYTYPE[ 2 ]
contains the value ’aa;bb’. The PRO_ELEMENT function in the ARRAYTYPE example
returns ’aa~;bb’ and PRO_ARR_DESCAPE(’aa~;bb’) removes the escape character ( ~ ),
returning the element value ’aa;bb’.
---------
aa;bb
1 record selected
SYNTAX
EXAMPLE
The ARRAYINT example assumes an integer array named ARRAYINT. The result of the
UPDATE operation is:
ARRAYINT[ 1 ] = 13
ARRAYINT[ 2 ] = 15
ARRAYINT[ 3 ] = 19
C–8
Data Type Compatibility Issues with Previous Versions of Progress
If the number of elements in the NVARCHAR string does not match the number of elements in
the target column for the update, Progress SQL-92 returns an error, unless there is exactly one
element in the NVARCHAR string for an INSERT operation.
If there is a single element in the NVARCHAR string, you can use the Progress SQL-92
INSERT statement to propagate the value to all elements of the array.
This is the SQL-92 syntax for this short form of an INSERT assignment:
SYNTAX
EXAMPLE
The following INSERT example illustrates how you can assign values to an entire date array
from a single value in the VALUES clause of an SQL-92 INSERT statement:
This INSERT example assigns the value ’01/01/00’ to every element of the date array
’begin_quota_date’ column in the customer table.
NOTE: Progress SQL-92 does not support the assignment of a single value to an entire array
using an SQL-92 UPDATE statement.
SYNTAX
C–9
Progress SQL-92 Guide and Reference
EXAMPLES
To assign a value to the first element of an array of size three, construct a literal string that
concatenates these components:
• Semicolon separator
Use PRO_ARR_ESCAPE to insert any necessary escape characters into the new value. Use
PRO_ELEMENT to extract the values for elements two and three from the array. This example
assigns the value ’aaa’ to the first element of the arraychar array for customer 99, and retains
the existing values for elements two and three.
To assign a value to the second element of an array of size three, construct a string that
concatenates these components:
• Semicolon separator
• Semicolon separator
Use PRO_ARR_ESCAPE to insert any necessary escape characters into the new value. Use
PRO_ELEMENT to extract the first and third elements from the array. This example assigns
the value ’bbb’ to the second element of the arraychar array for customer 99, and retains the
existing values for elements one and three in arraychar.
C–10
Data Type Compatibility Issues with Previous Versions of Progress
C–11
Progress SQL-92 Guide and Reference
C–12
D
Progress SQL-92 Elements and Statements
in Backus Naur Form (BNF)
This reference appendix presents Progress SQL-92 language elements and SQL-92 statements
in Backus Naur Form (BNF). The elements and statements are presented in this order:
• Data types
• Expressions
• Literals
• Query expressions
• Search conditions
DATA TYPE
SYNTAX
data_type ::=
char_data_type
| exact_numeric_data_type | approx_numeric_data_type
| date_time_data_type | bit_string_data_type
char_data_type ::=
{ CHARACTER | CHAR } [ ( length ) ]
| { CHARACTER VARYING | CHAR VARYING | VARCHAR }
[ (length) ]
exact_numeric_data_type ::=
TINYINT
| SMALLINT
| INTEGER
| NUMERIC | NUMBER [ ( precision [ , scale ] ) ]
| DECIMAL [ ( precision , scale ) ]
approx_numeric_data_type ::=
{ REAL | DOUBLE PRECISION | FLOAT [ ( precision ) ] }
D–2
Data Types Syntax in BNF
date_time_data_type ::
DATE | TIME | TIMESTAMP
bit_string_data_type ::=
BIT | BINARY [ ( length ) ]| VARBINARY [( length ) ]
| LONG VARBINARY [( length ) ]
D–3
Expressions Syntax in BNF
EXPRESSION (expr)
SYNTAX
expr ::=
[ { table_name.| alias. }] column_name
| character_literal
| numeric_literal
| date-time_literal
| aggregate_function
| scalar_function
| numeric_arith_expr
| date_arith_expr
| conditional_expr
| (expr)
numeric_arith_expr ::=
[ + | - ] { numeric_literal | numeric_expr }
[ { + | - | * | / } numeric_arith_expr ]
date_arith_expr ::=
date_time_expr { + | - } int_expr
| date_time_expr - date_time_expr
D–4
CONDITIONAL EXPRESSION
CONDITIONAL EXPRESSION
CASE EXPRESSION
A type of conditional expression.
SYNTAX
case_expr ::=
searched_case_expr | simple_case_expr
searched_case_expr ::=
CASE
WHEN search_condition THEN { result_expr | NULL } [ , ... ]
[ ELSE expr | NULL ]
END
simple_case_expr ::=
CASE primary_expr
WHEN expr THEN { result_expr | NULL }[ , ... ]
[ ELSE expr | NULL ]
END
D–5
Literals Syntax in BNF
date-literal ::=
{ d ’yyyy-mm-dd’ }
| mm-dd-yyyy
| mm/dd/yyyy
| mm-dd-yy
| mm/dd/yy
| yyyy-mm-dd
| yyyy/mm/dd
| dd-mon-yyyy
| dd/mon/yyyy
| dd-mon-yy
| dd/mon/yy
TIME LITERAL
SYNTAX
time_literal ::=
{ t ’hh:mi:ss’ } | hh:mi:ss[:mls ]
D–6
Query Expressions Syntax in BNF
QUERY EXPRESSION
SYNTAX
query_expression ::=
query_specification
| query_expression set_operator query_expression
| ( query_expression )
SET OPERATOR
SYNTAX
set_operator ::=
{ UNION [ ALL ] | INTERSECT | MINUS }
QUERY SPECIFICATION
SYNTAX
query_specification ::=
SELECT [ ALL | DISTINCT ]
{ *
D–7
Query Expressions Syntax in BNF
TABLE REFERENCE
SYNTAX
table_ref ::=
table_name [ AS ][ [ (column_alias [, ... ] ) ] ]
alias
| (query_expression) [ AS ] alias [ (column_alias [ ,... ] ) ]
| [ ( ] joined_table [ ) ]
JOINED TABLE
SYNTAX
joined_table ::=
{ table_ref CROSS JOIN table_ref
|table_ref [ INNER | LEFT [ OUTER ] ] JOIN
table_ref ON search_condition
}
from_clause_inner_join ::=
{ FROM table_ref CROSS JOIN table_ref
| FROM table_ref [ INNER ] JOIN table_ref
ON search_condition
}
where_clause_inner_join ::=
FROM table_ref, table_ref WHERE search_condition
from_clause_outer_join ::=
FROM table_ref LEFT OUTER JOIN table_ref
ON search_condition
D–8
Query Expressions Syntax in BNF
where_clause_outer_join ::=
WHERE [ table_name.]column (+) = [ table_name.]column
| WHERE [ table_name.]column = [ table_name.]column (+)
D–9
Search Conditions Syntax in BNF
search_condition ::=
[ NOT ] predicate
[ { AND | OR }{ predicate | ( search_condition ) } ]
PREDICATE
SYNTAX
predicate ::=
basic_predicate
| quantified_predicate
| between_predicate
| null_predicate
| like_predicate
| exists_predicate
| in_predicate
| outer_join_predicate
RELATIONAL OPERATOR
SYNTAX
relop ::=
= | <> | != | ^= | < | <= | > | >=
BASIC PREDICATE
SYNTAX
basic_predicate ::=
expr relop { expr | ( query_expression ) }
QUANTIFIED PREDICATE
SYNTAX
quantified_predicate ::=
expr relop { ALL | ANY | SOME } ( query_expression )
D–10
Search Conditions Syntax in BNF
BETWEEN PREDICATE
SYNTAX
between_predicate ::=
expr [ NOT ] BETWEEN expr AND expr
NULL PREDICATE
SYNTAX
null_predicate ::=
column_name IS [ NOT ] NULL
LIKE PREDICATE
SYNTAX
like_predicate ::=
column_name [ NOT ] LIKE string_constant
[ ESCAPE escape_character ]
EXISTS PREDICATE
SYNTAX
exists_predicate ::=
EXISTS (query_expression)
IN PREDICATE
SYNTAX
in_predicate ::=
expr [ NOT ] IN
{ (query_expression) | (constant , constant [ , ... ] ) }
outer_join_predicate ::=
[ table_name.]column = [ table_name.]column (+)
|[ table_name.]column (+) = [ table_name.]column
D–11
Statements, DDL and DML Syntax in BNF
SYNTAX
CALL Statement
SYNTAX
D–12
Statements, DDL and DML Syntax in BNF
CLOSE Statement
SYNTAX
close ::=
EXEC SQL CLOSE cursor_name ;
COMMIT Statement
SYNTAX
CONNECT Statement
SYNTAX
connect_string ::=
{ DEFAULT | db_name
| db_type:T:host_name:port_num:db_name }
D–13
Statements, DDL and DML Syntax in BNF
Parameter Declaration
SYNTAX
parameter_decl ::=
{ IN | OUT | INOUT } parameter_name data_type
D–14
Statements, DDL and DML Syntax in BNF
Column Definition
SYNTAX
column_definition ::=
column_name data_type
[ DEFAULT { literal | NULL | SYSDATE } ]
[ column_constraint [ column_constraint ... ] ]
Column Constraint
SYNTAX
column_constraint ::=
[ CONSTRAINT constraint_name ]
NOT NULL [ PRIMARY KEY | UNIQUE ]
| REFERENCES [ owner_name.]table_name [ ( column_name ) ]
| CHECK ( search_condition )
D–15
Statements, DDL and DML Syntax in BNF
Tabel Constraint
SYNTAX
table_constraint ::=
[ CONSTRAINT constraint_name ]
PRIMARY KEY ( column [, ... ] )
| UNIQUE ( column [, ...... ] )
| FOREIGN KEY ( column [, ... ] )
REFERENCES [ owner_name.]table_name [ ( column [, ... ] ) ]
| CHECK ( search_condition )
D–16
Statements, DDL and DML Syntax in BNF
SYNTAX
DELETE Statement
SYNTAX
SYNTAX
D–17
Statements, DDL and DML Syntax in BNF
DISCONNECT Statement
SYNTAX
D–18
Statements, DDL and DML Syntax in BNF
SYNTAX
EXECUTE Statement
SYNTAX
EXECUTE ::=
EXEC SQL EXECUTE statement_name
[ USING {[ SQL ] DESCRIPTOR structure_name
| :host_variable [[ INDICATOR ] :ind_variable ] , ... }
] ;
SYNTAX
D–19
Statements, DDL and DML Syntax in BNF
FETCH Statement
SYNTAX
fetch ::=
EXEC SQL FETCH cursor_name
{ USING SQL DESCRIPTOR structure_name
| INTO :host_var_ref [[ INDICATOR ] :ind_var_ref ] , ...
} ;
header_info_item ::=
{ NUMBER
| MORE
| COMMAND_FUNCTION
| DYNAMIC_FUNCTION
| ROW_COUNT
}
D–20
Statements, DDL and DML Syntax in BNF
detail_info_item ::=
{ CONDITION_NUMBER
| RETURNED_SQLSTATE
| CLASS_ORIGIN
| SUBCLASS_ORIGIN
| ENVIRONMENT_NAME
| CONNECTION_NAME
| CONSTRAINT_CATALOG
| CONSTRAINT_SCHEMA
| CONSTRAINT_NAME
| CATALOG_NAME
| SCHEMA_NAME
| TABLE_NAME
| COLUMN_NAME
| CURSOR_NAME
| MESSAGE_TEXT
| MESSAGE_LENGTH
| MESSAGE_OCTET_LENGTH
}
D–21
Statements, DDL and DML Syntax in BNF
PRIVILEGE
SYNTAX
privilege ::=
{ SELECT | INSERT | DELETE | INDEX
|UPDATE [ ( column , column , ... ) ]
| REFERENCES [ ( column , column , ... ) ] }
INSERT Statement
SYNTAX
OPEN Statement
SYNTAX
open ::=
EXEC SQL OPEN cursor_name
[ USING { [ SQL ] DESCRIPTOR structure_name
| :host_variable [[ INDICATOR ] :ind_variable ] , ... }
] ;
PREPARE Statement
SYNTAX
prepare ::=
EXEC SQL PREPARE statement_name FROM statement_string ;
D–22
Statements, DDL and DML Syntax in BNF
PRIVILEGE Syntax
SYNTAX
privilege ::=
{ SELECT | INSERT | DELETE | INDEX
|UPDATE [ ( column , column , ... ) ]
| REFERENCES [ ( column , column , ... ) ]}
ROLLBACK Statement
SYNTAX
D–23
Statements, DDL and DML Syntax in BNF
SELECT Statement
SYNTAX
isolation_level_name ::=
READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE
D–24
Statements, DDL and DML Syntax in BNF
UPDATE Statement
SYNTAX
ASSIGNMENT CLAUSE
SYNTAX
assignment ::=
column = { expr | NULL }
| ( column [, column ], ... ) = ( expr [, expr ], ... )
| ( column [, column ], ... ) = ( query_expression )
WHENEVER Statement
SYNTAX
whenever ::=
EXEC SQL WHENEVER
{ NOT FOUND | SQLERROR | SQLWARNING }
{ STOP | CONTINUE |{ GOTO | GO TO } host_lang_label } ;
D–25
Statements, DDL and DML Syntax in BNF
D–26
E
Compliance with Industry Standards
This appendix identifies the level of ANSI SQL-92 compliance and ODBC SQL Grammar
compliance for Progress SQL-92 statements, and the SQL-92 and ODBC compatibility for
Progress SQL-92 scalar functions.
• Scalar Functions
Scalar Functions
This section listsProgress SQL-92 scalar functions. Table E–1 identifies the compatibility of the
function as SQL-92 compatible, ODBC compatible, or a Progress extension.
Progress
Scalar Function SQL-92 ODBC Notes
Extension
ABS – √ – –
ACOS – √ – –
ADD_MONTHS – – √ –
ASCII – √ – –
ASIN – √ – –
ATAN – √ – –
ATAN2 – √ – –
CAST √ – – –
CEILING – √ – –
CHAR – √ – –
CHR – – √ –
COALESCE √ – – –
CONCAT – √ – –
COS – √ – –
CURDATE – √ – –
E–2
Scalar Functions
Progress
Scalar Function SQL-92 ODBC Notes
Extension
CURTIME – √ – –
DATABASE – √ – –
DAYNAME – √ – –
DAYOFMONTH – √ – –
DAYOFWEEK – √ – –
DAYOFYEAR – √ – –
DB_NAME – – √ –
DECODE – – √ –
DEGREES – √ – –
EXP – √ – –
FLOOR – √ – –
GREATEST – – √ –
HOUR – √ – –
IFNULL – √ – –
INITCAP – – √ –
INSERT – √ – –
INSTR – – √ –
LAST_DAY – – √ –
LCASE – √ – –
LEAST – – √ –
LEFT – √ – –
E–3
Scalar Functions
Progress
Scalar Function SQL-92 ODBC Notes
Extension
LENGTH – √ – –
LOCATE – √ – –
LOG10 – √ – –
LOWER √ – – –
LPAD – – √ –
LTRIM – √ – –
MINUTE – √ – –
MOD – √ – –
MONTH – √ – –
MONTHNAME – √ – –
MONTHS_BETWEEN – – √ –
NEXT_DAY – – √ –
NOW – √ – –
NULLIF √ – – –
NVL – √ –
PI – √ – –
POWER – – √ –
PREFIX – – √ –
PRO_ARR_DESCAPE – – √ –
PRO_ARR_ESCAPE – – √ –
PRO_ELEMENT – – √ –
E–4
Scalar Functions
Progress
Scalar Function SQL-92 ODBC Notes
Extension
QUARTER – √ – –
RADIAN – √ – –
RAND – √ – –
REPEAT – √ – –
REPLACE – √ – –
RIGHT – √ – –
ROUND – – √ –
ROWID – – √ –
RPAD – – √ –
RTRIM – √ – –
SECOND – √ – –
SIGN – √ – –
SIN – √ – –
SQRT – √ – –
SUBSTR – – √ –
SUBSTRING – √ – –
SUFFIX – – √ –
SYSDATE – – √ –
SYSTIME – – √ –
SYSTIMESTAMP – – √ –
TAN – √ – –
E–5
Scalar Functions
Progress
Scalar Function SQL-92 ODBC Notes
Extension
TO_CHAR – – √ –
TO_DATE – – √ –
TO_NUMBER – – √ –
TO_TIME – – √ –
TO_TIMESTAMP – – √ –
TRANSLATE – – √ –
UCASE – √ – –
UPPER √ – – –
USER √ √ √ –
WEEK – √ – –
YEAR – √ – –
E–6
SQL-92 DDL and DML Statements
ODBC
SQL-92 Progress
SQL-92 SQL Notes
Statement Extension
Grammar
ALTER USER – – √ –
BEGIN-END √ – – Compliant if C
DECLARE Language
SECTION types used
Embedded
SQL-92 only
CLOSE √ – – Embedded
SQL-92 only
COMMIT √ – – –
CREATE – Core √ –
PROCEDURE
CREATE – – √ –
SYNONYM
CREATE – Core √ –
TRIGGER
E–7
SQL-92 DDL and DML Statements
ODBC
SQL-92 Progress
SQL-92 SQL Notes
Statement Extension
Grammar
CREATE USER – – √ –
DELETE √ Extended – –
DESCRIBE √ – – Embedded
SQL-92 only
DISCONNECT √ – – –
DROP – Core √ –
PROCEDURE
DROP SYNONYM – – √ –
DROP TRIGGER – – √ –
DROP USER – – √ –
EXECUTE √ – – Embedded
SQL-92 only
EXECUTE √ – – Embedded
IMMEDIATE SQL-92 only
E–8
SQL-92 DDL and DML Statements
ODBC
SQL-92 Progress
SQL-92 SQL Notes
Statement Extension
Grammar
GET – – √ Embedded
DIAGNOSTICS SQL-92 only
INSERT √ Core – –
LOCK TABLE – – √ –
PREPARE √ – – Embedded
SQL-92 only
ROLLBACK √ – – –
SET √ – – –
CONNECTION
SET SCHEMA √ – – –
SET – – √ –
TRANSACTION
ISOLATION
LEVEL
E–9
SQL-92 DDL and DML Statements
ODBC
SQL-92 Progress
SQL-92 SQL Notes
Statement Extension
Grammar
UPDATE – – √ –
STATISTICS
E–10
Glossary
Add [ an ODBC Data Source ]
Makes a data source available to ODBC through the Add operation of the ODBC
Administrator utility. Adding a data source tells ODBC where a specific database resides
and which ODBC driver to use to access it. Adding a data source also invokes a setup
dialog box for the particular driver so you can provide other details the driver needs to
connect to the database.
Alias
A temporary name for a table or column specified in the FROM clause of an SQL query
expression. Also called Correlation Name. Derived tables and search conditions that join
a table with itself must specify an alias. Once a query specifies an alias, references to the
table or column must use the alias and not the underlying table or column name.
Applet
A special kind of Java program that a Java-enabled browser can download over the
network and execute.
ASCII
(American Standard Code for Information Interchange) seven-bit character set that
provides 128 character combinations.
Bytecode
Machine-independent code generated by a Java compiler and executed by a Java
interpreter.
Cardinality
Number of rows in a result table.
Progress SQL-92 Guide and Reference
Cartesian Product
Also called Cross-Product. In a query expression, the result table generated when a
FROM clause lists more than one table but specifies no join conditions. In such a case, the
result table is formed by combining every row of every table with all other rows in all
tables. Typically, Cartesian products are not useful and are slow to process.
Client
Generally, in client server systems, the part of the system that sends requests to Servers
and receives the results produced by acting on those requests.
Collation
The rules used to control how character strings in a character set compare with each other.
Each character set specifies a collating sequence that defines relative values of each
character for comparing, merging, and sorting character strings.
Column Alias
An alias specified for a column. See Alias.
Constraint
Part of an SQL table definition that restricts the values that can be stored in a table. When
you insert, delete, or update column values, the constraint checks the new values against
the conditions specified by the constraint. If the value violates the constraint, it generates
an error. Along with Triggers, constraints enforce Referential Integrity by ensuring that
a value stored in the foreign key of a table must either be null or be equal to some value in
the matching unique or primary key of another table.
Correlation Name
Another term for Alias.
Cross Product
Another term for Cartesian Product.
Data Dictionary
Another term for System Catalog.
Data Source
See ODBC Data Source.
Derived Table
A Virtual Table specified as a query expression in the FROM clause of another query
expression.
Glossary–2
Glossary
Driver Manager
See JDBC Driver Manager and ODBC Driver Manager.
Form of Use
The storage format for characters in a character set. Some character sets, such as ASCII,
require one byte (Octet) for each character. Others, such as Unicode, use multiple bytes,
and are called multi-octet character sets.
Java Snippet
See Snippet.
JDBC
(Java Database Connectivity) A database-independent SQL interface that allows Java
programs to access relational databases. JDBC is quite similar to ODBC.
JDBC Driver
Database-specific software that receives calls from the JDBC Driver Manager, translates
them into a form that a database server can process, and then returns data to the
application.
JDBC Driver Manager
A Java class that implements methods to route calls from a JDBC application to the
appropriate JDBC Driver for a particular JDBC URL.
Join
A relational operation that combines data from two tables.
Input Parameter
In a Stored Procedure specification, an argument that an application must pass when it
calls the stored procedure. In an SQL statement, a Parameter Marker in the statement
string that acts as a placeholder for a value that will be substituted when the statement
executes.
Interface
In Java, a definition of a set of methods that one or more objects will implement. Interfaces
declare only methods and constants, not variables.
Metadata
Data that describes the objects (tables, columns, views, and indexes) that are stored in the
database. Metadata is “data about data.” It is stored in a collection of tables called System
Tables.
Glossary–3
Progress SQL-92 Guide and Reference
Octet
A group of eight bits. Synonymous with byte, and often used in descriptions of character
set encoding format.
ODBC Application
Any program that calls ODBC functions and uses them to issue SQL statements.
ODBC Data Source
In ODBC terminology, a specific combination of a database system, the operating system
it uses, and any network software required to access it. Before applications can access a
database through ODBC, you use the ODBC Administrator to add a data source-register
information about the database and an ODBC driver that can connect to it-for that
database. More than one data source name can refer to the same database, and deleting a
data source does not delete the associated database.
ODBC Driver
Software that processes ODBC function calls for a specific data source. The driver
connects to the data source, translates the standard SQL statements into syntax the data
source can process, and returns data to the application. Progress SQL-92 includes an
ODBC Driver.
ODBC Driver Manager
A Microsoft-supplied program that routes calls from an application to the appropriate
ODBC driver for a data source.
Output Parameter
In a stored procedure specification, an argument in which the stored procedure returns a
value after it executes.
Package
A group of related Java classes and interfaces, like a class library in C++. The Java
development environment includes many packages of classes that procedures can import.
The Java run-time system automatically imports the java.lang package. Stored
procedures must explicitly import other classes by specifying them in the IMPORT clause
of a CREATE PROCEDURE statement.
Glossary–4
Glossary
Parameter Marker
A question mark (?) character in a procedure call or SQL statement string that acts as a
placeholder for a parameter’s value. The actual value for the input or output parameter will
be supplied at run time when the procedure executes. The CALL statement (or
corresponding ODBC or JDBC escape clause) uses parameter markers to pass parameters
to stored procedures, and the SQLIStatement, SQLPStatement, and SQLCursor objects use
them within procedures.
Primary Key
A subset of the columns in a table, characterized by the constraint that no two records in a
table can have the same primary key value, and that no columns of the primary key can
have a null value. Primary keys are specified in a CREATE TABLE statement.
Procedure Body
In a Stored Procedure, the Java code between the BEGIN and END keywords of a
CREATE PROCEDURE statement.
Procedure Result Set
In a stored procedure, a set of data rows returned to the calling application. The number
and data types of columns in the procedure result set are specified in the RESULT clause
of the CREATE PROCEDURE statement. The procedure can transfer data from an SQL
Result Set to the procedure result set or it can store data generated internally. A stored
procedure can have only one procedure result set.
Procedure Specification
In a CREATE PROCEDURE statement, the clauses preceding the procedure body that
specify the procedure name, any input and output parameters, any result set columns, and
any Java packages to import.
Procedure Variable
A Java variable declared within the body of a stored procedure, as compared to a
procedure Input Parameter or Output Parameter, which are declared outside the
procedure body and are visible to the application that calls the stored procedure.
Query Expression
An important element of the SQL languages. Query expressions specify a result table
derived from some combination of rows from the tables or views identified in the FROM
clause of the expression. Query expressions are the basis of the SELECT, UPDATE,
DELETE, and INSERT statements, and can be used in some expressions and search
conditions.
Glossary–5
Progress SQL-92 Guide and Reference
Referential Integrity
The condition where the value stored in a database table’s foreign key must either be null
or be equal to some value in another table’s matching unique or primary key. SQL
provides two mechanisms to enforce referential integrity: constraints specified as part of
CREATE TABLE statements prevent updates that violate referential integrity, and
Triggers specified in CREATE TRIGGER statements execute a stored procedure to
enforce referential integrity.
Repertoire
The set of characters allowed in a character set.
Result Set
In a Stored Procedure, either an SQL Result Set or a Procedure Result Set.
More generally, another term for Result Table.
Result Table
A virtual table of values derived from columns and rows of one or more tables that meet
conditions specified by an SQL query expression.
Row Identifier
Another term for Tuple identifier.
Search Condition
The SQL syntax element that specifies a condition that is true or false about a given row
or group of rows. Query expressions and UPDATE statements can specify a search
condition. The search condition restricts the number of rows in the result table for the
query expression or UPDATE statement. Search conditions contain one or more
predicates. Search conditions follow the WHERE or HAVING keywords in SQL
statements.
Selectivity
The fraction of a table’s rows returned by a query.
Server
Generally, in client server systems, the part of the system that receives requests from
Clients and responds by sending back the results produced by acting on them.
Snippet
In a stored procedure, the sequence of Java statements between the BEGIN and END
keywords in the CREATE PROCEDURE (or CREATE TRIGGER) statement. The Java
statements become a method in a class that SQL creates and submits to the Java compiler.
Glossary–6
Glossary
Glossary–7
Progress SQL-92 Guide and Reference
System Catalog
Tables created by SQL to store descriptions of objects (tables, columns, views, and
indexes) that are stored in the database.
System Table
Another term for System Catalog.
Tid
Another term for Tuple Identifier.
Transaction
A group of operations whose changes can be made permanent or undone only as a unit.
Trigger
A special type of Stored Procedure that helps ensure referential integrity for a database.
Like stored procedures, triggers also contain Java source code (embedded in a CREATE
TRIGGER statement) and use Progress SQL-92 Java classes. However, triggers are
automatically invoked (“fired”) by certain SQL operations (an insert, update, or delete
operation) on the trigger’s target table.
Trigger Action Time
The BEFORE or AFTER keywords in a CREATE TRIGGER statement. The trigger
action time specifies whether the actions implemented by the Trigger execute before or
after the triggering INSERT, UPDATE, or DELETE statement.
Trigger Event
The statement that causes a trigger to execute. Trigger events can be SQL INSERT,
UPDATE, or DELETE statements that affect the table for which a trigger is defined.
Triggered Action
The Java code within the BEGIN END clause of a CREATE TRIGGER statement. The
code implements actions to be completed when a triggering statement specifies the target
table.
Tuple Identifier
A unique identifier for a tuple (row) in a table. The SQL scalar function ROWID and
related functions return tuple identifiers to applications.
Glossary–8
Glossary
Unicode
A superset of the ASCII character set that uses multiple bytes for each character rather
than ASCII’s seven-bit representation. Able to handle 65,536 character combinations
instead of ASCII’s 128, Unicode includes alphabets for many of the world’s languages.
The first 128 codes of Unicode are identical to ASCII, with a second-byte value of zero.
View
A Virtual Table that re-creates the result table specified by a SELECT statement. No data
is stored in a view, but other queries can refer to it as if it were a table containing data
corresponding to the result table it specifies.
Virtual Table
A table of values that is not physically stored in a database, but instead derived from
columns and rows of other tables. SQL generates virtual tables in its processing of query
expressions: the FROM, WHERE, GROUP BY, and HAVING clauses each generate a
virtual table based on their input.
Virtual Machine
The Java specification for a hardware-independent and portable language environment.
Java language compilers generate code that can execute on a virtual machine.
Implementations of the Java virtual machine for specific hardware and software platforms
allow the same compiled code to execute without modification.
Glossary–9
Progress SQL-92 Guide and Reference
Glossary–10
Index
A Applet
definition Glossary–1
ABS scalar function 4–9 Arithmetic expressions
date 2–40
Progress SQL-92 Guide and Reference
Index–2
Index
Index–3
Progress SQL-92 Guide and Reference
Index–4
Index
Index–5
Progress SQL-92 Guide and Reference
Index–6
Index
Functions Functions
scalar functions (continued) scalar functions (continued)
LENGTH 4–58 USER 4–113
LOCATE 4–59 WEEK 4–114
LOG10 4–60 YEAR 4–115
LOWER 4–61
LPAD 4–62
LTRIM 4–64 G
MINUTE 4–65
MOD 4–66 GET DIAGNOSTICS statement 3–73
MONTH 4–67
MONTHNAME 4–68 getDiagnostics Java method 5–30
MONTHS_BETWEEN 4–69
getValue Java method 6–4
NEXT_DAY 4–70
NOW 4–71 GRANT statement 3–79
NULLIF 4–72
NVL 4–73 GREATEST scalar function 4–46
PI 4–74
POWER 4–75 GROUP BY clause of query expression
PREFIX 4–76 2–18
QUARTER 4–79
RADIANS 4–80
RAND 4–81 H
REPEAT 4–82
REPLACE 4–83 HAVING clause of query expression 2–19,
RIGHT 4–84 3–108
ROUND 4–85 to 4–87
ROWID 4–88 HOUR scalar function 4–47
RPAD 4–89
RTRIM 4–91
SECOND 4–92 I
SIGN 4–93
SIN 4–94 Identifiers 2–3 to 2–5
SQRT 4–95 conventional 2–3
SUBSTR 4–96 delimited 2–4
SUBSTRING 4–97 row 4–88
SUFFIX 4–98
SYSDATE 4–100 IFNULL scalar function 4–48
SYSTIME 4–101
SYSTIMESTAMP 4–102 Immediate execution
TAN 4–103 SQLIStatement 5–21
TO_CHAR 4–104
IMPORT clause
TO_DATE 4–105
CREATE PROCEDURE statement
TO_NUMBER 4–106
TO_TIME 4–107 3–19, 5–10
CREATE TRIGGER statement 3–29
TO_TIMESTAMP 4–108
TRANSLATE 4–109 IN predicate 2–36
UCASE 4–111 query expressions in 2–36
UPPER 4–112
Index–7
Progress SQL-92 Guide and Reference
Italic typeface
INTEGER data type 2–8
as typographical convention xix
Interface, in Java
definition Glossary–3
J
Internationalization
CHAR and CHR functions 4–26 Java class reference 6–2 to 6–5
character string literals 2–44
date-time literals 2–44 Java classes
language elements 2–2 DhSQLException 5–30, 6–6 to 6–8
relational operators 2–32 DhSQLResultSet 5–25, 6–9 to 6–12
specific elements SQLCursor 5–23, 5–25, 6–13 to 6–25
ASCII function 4–13 SQLIStatement 6–26 to 6–30
CHAR and CHR functions 4–25 SQLPStatement 6–31 to 6–35
CHARACTER and VARCHAR data using 5–15
types 2–7
Java classes, summary
CONCAT function 4–28
CONVERT function 4–31 DhSQLException 5–7
DhSQLResultSet 5–7
GREATEST function 4–46
SQLCursor 5–7
INITCAP function 4–49
INSERT function 4–51 SQLIStatement 5–7
SQLPStatement 5–7
INSTR function 4–53
LCASE function 4–55
Index–8
Index
Index–9
Progress SQL-92 Guide and Reference
Index–10
Index
O Output parameters
from stored procedures 5–17
Octet
definition Glossary–4
P
ODBC
SQLExecDirect call 5–12 Package, in Java
definition Glossary–4
ODBC Application
definition Glossary–4 Package, Java 5–10
Index–11
Progress SQL-92 Guide and Reference
Procedure Specification
definition Glossary–5 R
Procedure Variable RADIANS scalar function 4–80
definition Glossary–5
RAND scalar function 4–81
Procedures
CREATE PROCEDURE statement 3–19 REAL data type 2–10
declaring result set columns 3–20
DROP PROCEDURE statement 3–56 REFERENCES clause
names 3–19 foreign key constraint 3–9
referential integrity constraint 3–9
PUBLIC
granting privilege to 3–79 REFERENCES privilege
granting 3–79
Index–12
Index
Index–13
Progress SQL-92 Guide and Reference
Index–14
Index
Index–15
Progress SQL-92 Guide and Reference
Index–16
Index
Index–17
Progress SQL-92 Guide and Reference
Index–18
Index
V
Y
Value expressions, See also Expressions
YEAR scalar function 4–115
Values, specifying default values in
Index–19
Progress SQL-92 Guide and Reference
Index–20