Guia Oficial N°08. Vel30LG

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 209

Velocis

Language Guide
20-7205-1001
Trademarks
Centura, the Centura logo, Centura net.db, Centura Web Developer, Gupta, the Gupta
logo, Gupta Powered, the Gupta Powered logo, Fast Facts, Object Nationalizer, Quest,
QuickObjects, SQL/API, SQLBase, SQLBase Exchange, SQLConsole, SQLGateway,
SQLHost, SQLNetwork, SQLRouter, SQLTalk, and Team Object Manager, RDM, ROM,
and Velocis are trademarks of Centura Software Corporation and may be registered in the
United States of America and/or other countries. SQLWindows is a registered trademark
and TeamWindows, ReportWindows and EditWindows are trademarks exclusively used
and licensed by Centura Software Corporation.
Adobe is a trademark of Adobe Systems, Incorporated.
IBM, OS/2, NetBIOS, and AIX are registered trademarks of International Business
Machines Corporation.
UNIX is a registered trademark licensed exclusively by The Open Group.
SCO UNIX is a trademark of Santa Cruz Operation, Incorporated.
Microsoft is a registered trademark, and DOS, Windows, Windows NT, and Windows 95
are trademarks, of Microsoft Corporation.
Java and Solaris are trademarks of Sun Microsystems, Incorporated.
Microsoft, Internet Explorer, Internet Information Server, DOS, Win 32, Windows,
Windows NT, Windows 95 and Visual Basic are either registered trademarks or
trademarks of Microsoft Corporation in the United States of America and/or other
countries.
Novell is a registered trademark, and NetWare is a trademark, of Novell Incorporated.
All other product or service names mentioned herein are trademarks or registered
trademarks of their respective owners.

Copyright
Copyright  1999 by Centura Software Corporation. All rights reserved.
Velocis 3.0 Installation and Administration Guide
20-7301-1002
November 1999
Contents
Chapter 1 Introduction
1.1 Velocis Documentation................................................................................................ 1-1
1.1.1 About This Manual............................................................................................. 1-1
1.1.2 Related Velocis Documents ............................................................................... 1-1
1.1.3 Document Conventions ..................................................................................... 1-2
1.2 Other Helpful Resources ............................................................................................. 1-3
Chapter 2 Velocis SQL Overview
2.1 Velocis SQL Features ................................................................................................... 2-1
2.2 Conformance with the SQL ANSI Standard............................................................. 2-2
2.3 Conformance with ODBC Standard .......................................................................... 2-3

Chapter 3 Velocis SQL Language Elements


3.1 About Identifiers .......................................................................................................... 3-1
3.2 About Reserved Words ............................................................................................... 3-1
3.3 Specifying Constants.................................................................................................... 3-3
3.3.1 Specifying Numeric Constants.......................................................................... 3-3
3.3.2 Specifying String Constants .............................................................................. 3-3
3.3.3 Specifying Date, Time, and Timestamp Constants ........................................ 3-4
3.3.4 Specifying System Constants ............................................................................ 3-5
3.4 Creating Expressions ................................................................................................... 3-5
3.4.1 Creating Arithmetic Expressions...................................................................... 3-6
3.4.2 Creating String Expressions .............................................................................. 3-7
3.4.3 Creating Conditional Expressions .................................................................... 3-8
3.5 Calling Functions from Velocis SQL........................................................................ 3-10
3.5.1 Using Scalar (Built-In) Functions.................................................................... 3-10
3.5.1.1 String Functions ........................................................................................ 3-10
3.5.1.2 Numeric Functions ................................................................................... 3-11
3.5.1.3 Date and Time Functions ......................................................................... 3-12
3.5.1.4 System Functions ...................................................................................... 3-12
3.5.2 Using Aggregate (Calculation) Functions ..................................................... 3-13
3.5.3 Using the Conditional Selection Function ..................................................... 3-13
3.5.4 Using UDFs........................................................................................................ 3-13
3.6 Specifying Subqueries................................................................................................ 3-14

Chapter 4 Velocis SQL Statement Reference


(Alphabetical listing by statement name)............................................................................. 4-2

Contents i
Chapter 5 Velocis SQL-Callable Functions
(Alphabetical listing by function name) ............................................................................... 5-2
Chapter 6 Core DDL Statement Reference
blob file...................................................................................................................................... 6-2
data file...................................................................................................................................... 6-3
database..................................................................................................................................... 6-4
key file ....................................................................................................................................... 6-5
record ......................................................................................................................................... 6-6
set ....................................................................................................................................... 6-10
Appendix A Velocis SQL Syntax Summary
A.1 List of DDL Statements...............................................................................................A-1
A.2 List of DML Statements ..............................................................................................A-1
A.3 Syntax Summary .........................................................................................................A-2

ii Centura Velocis Language Guide


Tables
Table 1-1. Document Notational Conventions ................................................................ 1-2
Table 2-1. ODBC Compliance Levels for API Functions ................................................ 2-3
Table 3-1. Reserved Words................................................................................................. 3-2
Table 3-2. Literal System Constants .................................................................................. 3-5
Table 3-3. Precedence of Arithmetic Operators ............................................................... 3-7
Table 3-4. Boolean Operation Results ............................................................................... 3-9
Table 3-5. String Functions ............................................................................................... 3-10
Table 3-6. Numeric Functions .......................................................................................... 3-11
Table 3-7. Date/Time Functions ...................................................................................... 3-12
Table 3-8. System Functions ............................................................................................. 3-12
Table 3-9. Aggregate Functions ....................................................................................... 3-13
Table A-1. DDL Statements ................................................................................................A-1
Table A-2. DML Statements ...............................................................................................A-1

Contents iii
Chapter 1
Introduction
This book is the Language Guide for Centura Velocis Database Server. It provides
reference material for the interface design languages used in Velocis. The languages
detailed in this manual include Velocis SQL and the Core Database Definition Language
(DDL), which was formerly referred to as non-SQL DDL. To illustrate Velocis SQL and
its use, we have included several chapters devoted only to this subject.

1.1 Velocis Documentation


Velocis documentation is a four-manual set and includes this Language Guide, the Velocis
User’s Guide, Velocis Reference Manual and the Installation/Administration Guide.

1.1.1 About This Manual


The Language Guide is organized as described below. Related Velocis documents are
discussed in section 1.1.2.
Chapter 2, "Velocis SQL Overview," highlights some Velocis SQL features and describes
the Velocis SQL conformance to SQL industry standards.
Chapter 3, "Velocis SQL Language Elements," defines and gives examples for the
principal elements of the Velocis SQL language.
Chapter 4, "Velocis SQL Statement Reference," contains complete descriptions of all
Velocis SQL statements in an alphabetical reference format.
Chapter 5, "Velocis SQL-Callable Functions," contains complete descriptions of all
functions that are callable from Velocis SQL, arranged in an alphabetical reference format.
Chapter 6, "Core DDL Statement Reference," contains complete descriptions of all Core
DDL statements in an alphabetical reference format.
Appendix A, "Velocis SQL Syntax Summary," is a summary of the complete Velocis SQL
language.

1.1.2 Related Velocis Documents


Velocis Installation/Administration Guide contains installation instructions and details for
running Velocis on the server and client platforms. This guide also includes procedures
for the system administrator, including server configuration, routine maintenance,
diagnostic, and corrective maintenance procedures.

Introduction 1-1
Velocis User’s Guide provides a detailed description of Velocis and in-depth instructions
for the application developer.
Velocis Reference Manual provides developer-level details of Velocis utilities, application
programming interface (API) functions, complex data types, and return codes.

Note: The trademarked name of this product is Velocis Database Server and is reflected in
the actual titles of the manuals. For ease of reference within the manuals, the simpler
form of Velocis is used.

Velocis system components are furnished on a CD. The CD includes a readme.txt file
that contains the release notes for your particular operating environment. Be sure to read
this file carefully. It provides detailed information about:
• Recent changes to the system that are not documented in the current manuals.
• Issues specific to your particular operating system or compiler.

1.1.3 Document Conventions


Table 1-1 describes the notational conventions used in this guide.

Table 1-1. Document Notational Conventions

Convention Description
Bold Text Indicates the names of functions, commands, data structures,
statements, databases, utilities, files, etc. These names are
intended to be used exactly as shown. Case distinctions used in
the names are not significant for all operating systems.
Italic Text Represents the names of variables, such as parameters and
command options. Additionally, the Velocis documents use
italics for the titles of books.
Underline Text Indicates the default choice within a choice of values.
Courier Text Indicates a programming example or a command line entry.
Programming examples in this book are enclosed in boxes.
Brackets ([ ]) Indicates optional fields or parameters in command lines and
syntax statements.
Bar Symbol (|) Separates alternative selections. You may enter one of the items
separated by the bar.

1-2 Centura Velocis Language Guide


Table 1-1. Document Notational Conventions (continued)

Convention Description
Braces ({ }) Indicates a required field or parameter in command lines and
syntax statements.
Ellipsis (...) Indicates that you can repeat the preceding item. Both horizontal
and vertical ellipses are used in programming examples to
indicate code that has been omitted.
Arrow Symbols (< >) Indicates information that you must supply. For example,
<filename>.h represents a header file that you name. Arrow
symbols are also used in text to set off keyboard key names.

1.2 Other Helpful Resources


Centura offers various options for additional information on Velocis.
• Centura Books Online
The Centura Velocis document set is available online. This document collection
lets you perform full-text indexed searches across the product document set,
navigate the table of contents using the expandable/collapsible browser, or print
any chapter. Access the collection by going to the CD, navigating to the Book Set
folder, and opening the PDF file listed in that directory.
• Worldwide Web
The Centura Worldwide Web home page is located at http://www.centurasoft.com.
The Centura web server provides access to a wealth of information about Centura
products and services.

Introduction 1-3
Chapter 2
Velocis SQL Overview
Velocis SQL is a full-featured SQL implementation that contains a rich set of high-
performance capabilities. The design of Velocis SQL is based on a number of related SQL
standards, as follows:
• 1989 ANSI SQL with Integrity Enhancement
• Microsoft Open Database Connectivity (ODBC) API
• 1992 ANSI SQL (x3.135-1992)
When using SQL in your application, you access the Velocis SQL support module
through calls to the Velocis SQL API, which provides full relational access to the server
engine and database. Velocis dynamically compiles and executes the embedded SQL
statements in your application calls, and it retrieves result sets from the server.

2.1 Velocis SQL Features


Velocis SQL is an implementation of most the 1989 ANSI SQL with Integrity
Enhancement standard (see section 2.2 below). Also included are the date, time, and
timestamp data types from the 1992 ANSI SQL standard. In addition, Velocis SQL
includes a variety of extensions that provide programming flexibility and improved
performance. These features are listed below.
• High-speed, predefined joins. The Velocis SQL DDL includes a create join statement
that uses foreign and primary key specifications and direct access methods to maintain
relationships between tables.
• Implementation of server-based, user-defined functions (UDFs) and triggers.
• Implementation of SQL stored procedures and C-based user-defined procedures
(UDPs).
• High-speed transaction processing with row-level locking.
• Transaction isolation and consistency levels.
• Expanded data types long varbinary and long varchar for storage of BLOB (Binary
Large OBject) data.
• A cost-based SQL query optimizer.
• The ability to define multiple instances of a database.
• The ability to develop your own server-based import/export filters.
• Special data types in Velocis SQL to support Unicode character strings.

Velocis SQL Overview 2-1


2.2 Conformance with the SQL ANSI Standard
This release of Velocis SQL provides conformance to most of 1989 ANSI SQL and
includes the integrity enhancement feature. (Specific exceptions are described at the end
of this section.)
As the primary standard on which all others are based, 1989 ANSI SQL is the minimally
acceptable standard to which an SQL implementation should conform. However, the
capabilities specified in the 1989 ANSI SQL do not sufficiently address all basic
requirements of a typical database application. Most notably lacking are date and time
data types. The 1992 ANSI SQL standard added the date, time, and timestamp data types
and these are also included in Velocis SQL. (The 1992 ANSI SQL standard added many
other capabilities which are not yet implemented in Velocis.)
This release of Velocis SQL provides full 1989 SQL level 2 conformance with the integrity
enhancement feature, with the following exceptions:
• Cursors are based on ODBC (see below), not embedded SQL.
• The with grant option clause is not supported in the grant statement. In Velocis
SQL, only administrator users and the database owner can issue grant statements
for a particular database.
• The union operator. A Velocis SQL application can achieve the same results by
executing a stored procedure that contains separate select statements for each part
of the union.
• Updateable views of views are not supported. In Velocis SQL, a view is only
considered updateable when referenced tables are base tables.
• The numeric data type.
• Modules and embedded SQL are not supported.
• Meaning of null between an updateable view with check option and the check
table contraint. ANSI semantics that concern null values differ between check
constraints on tables and the with check option in views. Comparisons with nulls
have an "unknown" result. According to ANSI SQL an "unknown" result does not
violate a check constraint on a base table. For updates on view with the with
check option constraint, however, an "unknown" value does invalidate the
constraint. Velocis SQL treats constraints that involve nulls the same way for both
tables and views, following the ANSI semantics for the check clause on the base
table.
• The having clause cannot contain a subquery
• Strings are null terminated instead of padding strings with spaces

2-2 Centura Velocis Language Guide


2.3 Conformance with ODBC Standard
The goal of the Microsoft Open Database Connectivity (ODBC) specification is to provide
Windows client applications with a true vendor-independent database API that supports
a wide variety of DBMS server back-ends. With ODBC, a single Windows application
can access multiple database servers simultaneously from different vendors through use
of vendor-specific ODBC drivers. The Velocis ODBC implementation is based on version
2.1 of the ODBC specification.
The Microsoft ODBC standard defines three levels of driver compliance (described in
Table 2-1). The Velocis SQL API supports all level 1 ODBC functions and some of the
level 2 functions. Velocis SQL also provides additional functions that support specific
Velocis SQL enhancements. These functions are described in the Velocis Reference Manual.

Table 2-1. ODBC Compliance Levels for API Functions

Compliance Level Description


ODBC Core Includes functions in basic compliance with SQL Access Group Call-
Level Interface functions. (See list of "Core Functions" below.)
ODBC Level 1 Includes the core functions and some additional functions that allow
an application to interrogate an ODBC driver to discover its
capabilities. Level 1 functions retrieve information typically found in
a system catalog. (See list of "Level 1 Functions" below.)
ODBC Level 2 Includes the level 1 functions and support for advanced features,
such as asynchronous command execution and scrollable cursors.
(See list of "Level 2 Functions" below.)

Core Functions:

SQLAllocConnect SQLExecute
SQLAllocEnv SQLFetch
SQLAllocStmt SQLFreeConnect
SQLBindCol SQLFreeEnv
SQLBindParameter SQLFreeStmt
SQLCancel SQLGetCursorName
SQLColAttributes SQLNumResultCols
SQLConnect SQLPrepare
SQLDescribeCol SQLRowCount
SQLDisconnect SQLSetCursorName
SQLError SQLTransact
SQLExecDirect

Velocis SQL Overview 2-3


Level 1 Functions:

SQLColumns SQLParamData
SQLDriverConnect SQLPutData
SQLGetConnectOption SQLSetConnectOption
SQLGetData SQLSetStmtOption
SQLGetFunctions SQLSpecialColumns
SQLGetInfo SQLStatistics
SQLGetStmtOption SQLTables
SQLGetTypeInfo

Level 2 Functions

SQLExtendedFetch SQLNumParams
SQLForeignKeys SQLPrimaryKeys
SQLMoreResults SQLProcedures
SQLNativeSql SQLSetScrollOptions

The Velocis ODBC implementation of the level 2 ODBC functions provides scrollable
cursor support only for static, read-only cursors using function SQLExtendedFetch.
Dynamic, keyset-driven, and mixed cursors are not supported. Asynchronous execution
is also not supported.

2-4 Centura Velocis Language Guide


Chapter 3
Velocis SQL Language Elements
This chapter defines the principal elements of Velocis SQL, including identifiers, reserved
words, constants, expressions, callable functions, and the mechanism for subqueries. The
detailed references for all Velocis SQL statements appear in Chapter 4 of this manual,
while the callable functions are detailed in Chapter 5. All statements and functions in
these chapters are presented in alphabetical order for ease of reference.

3.1 About Identifiers


Velocis SQL identifiers are used to name tables, columns, indexes, joins, views, or stored
procedures, as well as other items. An identifier is formed by a combination of letters,
digits, and the underscore character, always beginning with a letter or an underscore. It
can be from 1 to 32 characters in length. Velocis SQL does not distinguish between
uppercase and lowercase letters in an identifier. Thus, CUSTOMER, customer, and
Customer all refer to the same item.

Note: A Velocis SQL identifier cannot be a Velocis reserved word (see section 3.2).

3.2 About Reserved Words


Reserved words are predefined identifiers that have special meaning in Velocis SQL. As
with identifiers, Velocis SQL does not distinguish between uppercase and lowercase
letters in reserved words. Table 3-1 lists the Velocis SQL reserved words. Some of the
listed words are not described in this document but have been retained for compatibility
with other SQL systems.

Velocis SQL Language Elements 3-1


Table 3-1. Reserved Words
abs convert filter mark quarter tablespace
acos cos first max rand tan
activate cot float member read temporary
admin count floor min readonly thousands
administrator create for minimum real through
age curdate foreign minute references thru
aggregate currency from mod repeat tid
all current function mode repeatability time
alter curtime functions month replace timeout
and data grant noinit restrict timestamp
any database group noinitialize revoke to
as date having nosort right today
asc dayofmonth hour not rollback trans
ascending dayofweek if now row transaction
ascii dayofyear ifnull null rowid true
asin db_addr in numeric rtrim ucase
atan deactivate index of run unicode
atan2 dec initialize off scalar unique
authorization decimal insert on schema unlock
auto default instance one second unsigned
avg delete int open select update
begin desc integer opt_limit set use
between descending into opt_yield share user
binary disable is option shared values
but display isolation optional short varbinary
by distinct join or sign varbyte
byte double key order sin varchar
c_data drop last outer smallint varying
call enable lcase output some view
cascade end left owner sorted virtual
ceiling escape length page sqrt wchar
char exclusive like pagesize statistics wcharacter
character exec locate pi stats week
check execute lock precision substring where
close exists log primary stogroup wild
column exp login privileges struct with
commands extension logout proc substring work
commit false long procedure sum wvarchar
concat file ltrim public table year

3-2 Centura Velocis Language Guide


3.3 Specifying Constants
A Velocis SQL constant is a number or string value that is used in a statement. The
following sections describe how to specify the constants.

3.3.1 Specifying Numeric Constants


The Velocis SQL numeric data types are smallint, integer, float, double, and decimal, as
detailed in Chapter 18 of the Velocis Reference Manual. Enter a numeric constant as shown
below.
[+|-]digits[.digits]

If you specify a constant with a decimal portion (that is, [.digits]), Velocis stores the
constant as a decimal. If you do not use the decimal part, the constant is stored as an
integer.
The following examples show several types of numeric constants.
1021
-50
3.14159
453.75
-81.75

For floating-point constants (data type float), you can use an exponential format, as
shown below.
[+|-]digits[.digits]E[+|-]ddd

Below are several examples of floating-point constants.


6.02E23
1.8E5
-3.776143E-12

3.3.2 Specifying String Constants


To form an ASCII string constant, enclose the characters in the string inside single
quotation marks (’ ’) or double quotation marks (" "). To form a Unicode string constant,
you also need to precede the quoted string with an uppercase L. If the string itself
contains quotation marks, you must precede each quotation mark by a backslash (\). To
include a backslash character in the string, enter a double backslash (\\).
The following are examples of string constants.

Velocis SQL Language Elements 3-3


"This is an ASCII string constant"
L"This is a Unicode string constant"
"this string contains \"quotation\" marks"
’this string contains a backslash (\\)’

The default maximum length of a Velocis SQL string constant is 256 characters. You can
change this value by modifying the MaxString configuration parameter in the [SQL]
section of velocis.ini. Refer to Chapter 6 in the Velocis Installation/Administration Guide for
more information.

3.3.3 Specifying Date, Time, and Timestamp Constants


The following syntax block shows the formats for date, time, and timestamp constants.
date_constant:
date "YYYY-MM-DD"
| @"[YY]YY-MM-DD"
time_constant:
time "HH:MM[:SS[.ffff]]"
| @"HH:MM[:SS[.ffff]]"
timestamp_constant:
timestamp "YYYY-MM-DD HH:MM[:SS[.ffff]]"
| @"YYYY-MM-DD [HH:MM[:SS[.ffff]]]"

The formats following the date, time, and timestamp keywords conform to the SQL2
standard. In the format for date constants, YYYY is the year (you must specify all four
digits), MM is the month number (1 to 12), and DD is the day of the month (1 to 31). The
@ symbol represents a nonstandard alternative. When only two digits are specified for
the year using the nonstandard format, the century is assumed to be 1900 where YY is
greater than or equal to 50; where YY is less than 50 in this format, the century is assumed
to be 2000.
In the format for time constants, HH is hours (0 to 23), MM is minutes (0 to 59), SS is
seconds, and .ffff is the fractional part of a second, with up to four decimal places of
accuracy. If you specify more than four places, the value rounds to four places. The
format for timestamp constants simply combines the formats for date and time constants.
You can use three alternative characters as separators in declaring date, time, and
timestamp constants. Besides hyphen ("-"), Velocis accepts slash ("/") and period (".").
The following are examples of the use of date, time, and timestamp constants.

3-4 Centura Velocis Language Guide


insert into sales_order(ord_num, ord_date, amount)
values(20001, @"93/9/23", 1550.00);

insert into note


values("HI-PRI", timestamp "1993-9-23 15:22:00", "SKM", "SEA");

select * from sales_order where ord_date >= date "1993-9-1";

insert into event(event_id, event_time)


values("Marathon", time "02:53:44.47");

To change the date constant input format, use the set date default Velocis SQL statement.
This statement allows you to change the separator character and the order of month, day,
and year. See Chapter 4 for more about this statement.

3.3.4 Specifying System Constants


Velocis SQL defines three built-in literal constants. These are described in Table 3-2.

Table 3-2. Literal System Constants

Constant Value
user The name of the user who is executing the statement.
today The current date at the execution time of the statement.
now The current timestamp at the execution time of the statement.

The following examples illustrate the use of the literal system constants.
.. a statement that could be executed from an extension module or
.. stored procedure that is always executed when a connection is made.
insert into login_log(user_name, login_time)
values(user, now);

.. check today’s action items


select cust_id, note_text from action_items where tickle_date = today;

3.4 Creating Expressions


A Velocis SQL expression is anything that follows the keyword select or where in a SQL
statement. Regular expressions in the select statement are simply expressions, unlike
expressions in a where clause, which are relational and/or conditional.

Velocis SQL Language Elements 3-5


A relational expression compares other expressions that evaluate to TRUE or FALSE. A
conditional expression is a sequence of relational expressions separated by the Boolean
operators and and or (see section 3.4.3). The conditional expression also evaluates to
TRUE or FALSE. For details of conditional expressions, see section 3.4.3.

Note: A relational expression can be a conditional expression that is enclosed in


parentheses. Similarly, a conditional expression in parentheses can be a relational
expression.

3.4.1 Creating Arithmetic Expressions


In Velocis SQL, arithmetic expressions specify arithmetic operations on database values
and constants. The operand of an expression can be a constant (section 3.3), a column
reference, a function (section 3.5), or an expression in parentheses. Use the syntax below
to form arithmetic expressions.
arith_expr:
arith_operand [arith_operator arith_operand]...
arith_operand:
constant | [table_name.]column_name | arith_function | (arith_expr)
arith_operator:
+|-|*|/
arith_function:
{sum | avg | max | min} (arith_expr)
| count ({* | [table_name.]column_name})
| if (cond_expr, arith_expr, arith_expr)
| numeric_function | datetime_function | system_function
| user_defined_function

You can qualify the column name with a table or correlation by using the table name as a
prefix (for example, item.prod_id). If more than one column in the resultant table will
have the same name, always qualify the column name with the table or correlation name.
Velocis SQL uses the standard arithmetic operators shown in Table 3-3. The Velocis SQL
support module evaluates arithmetic expressions by using the precedence of the
operators shown in the table.

3-6 Centura Velocis Language Guide


Table 3-3. Precedence of Arithmetic Operators

Priority Operator Use


Highest () Parenthetical expressions
+ Unary plus
- Unary minus
* Multiplication
/ Division
+ Addition
Lowest - Subtraction

The examples below illustrate the use of the Velocis SQL arithmetic operators in
arithmetic expressions.
sum(on_hand.quantity * cost)

if(quantity < 20, price, .9*price)

(pi()*(radius/2.0) * delta)/1.414

3.4.2 Creating String Expressions


A Velocis SQL string expression operates on string constants (section 3.3.2), columns of
type varchar, char, wchar, or wvarchar, and string functions (section 3.5.1.1). The only
valid operator is the caret ("^"), which concatenates the operand strings. Use the syntax
below for forming string expressions.
string_expr:
string_operand [^ string_operand]
string_operand:
"string" | [table_name.]column_name
| if (cond_expr, string_expr, string_expr)
| string_function
| user_defined_function

As for an arithmetic expression (section 3.4.1), you might need to qualify the column
name with a table or correlation by using the table name as a prefix (for example,
item.prod_id). If more than one column in the resultant table will have the same name,
always qualify the column name with the table or correlation name.

Velocis SQL Language Elements 3-7


3.4.3 Creating Conditional Expressions
Velocis SQL conditional expressions are used in the where and having clauses of the
select statement and in the if conditional selection function (section 3.5.3). The select
statement reports rows containing conditional expressions that evaluate to TRUE. The
block below shows the syntax to form conditional expressions.
cond_expr:
rel_expr [bool_oper rel_expr]...
rel_expr:
expression [not] rel_oper
{expression | [{any | some} | all] (subquery)}
| expression [not] between constant and constant
| expression [not] in {(constant [, constant]...) | (subquery)}
| [table_name.]column_name is [not] null
| string_expr [not] like "string"
| not rel_expr
| (cond_expr)
| [not] exists (subquery)
| [table_name.]column_name *= [table_name.]column_name
| [table_name.]column_name =* [table_name.]column_name
subquery:
select {* | expression} from {table_list | path_spec}
[where cond_expr]
rel_oper:
= | == (equal)
| < (less than)
| > (greater than)
| <= (less than or equal)
| >= (greater than or equal)
| <> | != | /= (not equal)
bool_oper:
& | && | and (true if both operands are true)
| "|" | "||" | or (true if one or both operands are true)

Note that in a Velocis select statement, use of null is ANSI complient. That is, *=null and
!=null are non-ANSI and are not supported by Velocis. You must use "is null and "is not
null" instead.
The conditional expression consists of a relational expression optionally combined with
other relational expressions (one or more) using a Boolean operator, such as and. Table
3-4 applies two arbitrary relational expressions to each of the Boolean operators, and and
or, and lists all possible results.

3-8 Centura Velocis Language Guide


Table 3-4. Boolean Operation Results

r1 r2 and or
true true true true
true false false true
false true false true
false false false false

A relational expression uses the standard relational comparison operators to compare the
results of two expressions. The *= (=*) operators specify that a left (right) outer join is to
be performed on the specified columns.
The between operator in the relational expression specifies a range of values so that the
arithmetic expression can provide values inclusively. The in operator evaluates to TRUE
when the value of the expression is contained in a specified list of values.
In the relational expression, the like operator allows wildcard checking of string
expressions. An underscore ("_") in the check string will match any single character, and
a percent sign ("%") in the check string will match zero or more characters. You can
change these match characters by using the set wild statement described in Chapter 4.
The specified expression must return a string result.
The is null operator allows a check for null column values. Null column values occur
when a value is actually null, or the related row of an outer join does not exist (that is, all
columns in the row are null).
The examples below show some conditional expressions used in select statements.
select company, amount from customer, sales_order
where customer.cust_id = sales_order.cust_id and
(amount >= 10000 or company = "IBM");

select company, city from customer where state in ("AZ","CA","OR","WA");

select company, city, state, phone, amount from salesperson, customer


where company like "%Computer%" and amount between 10000 and 50000
and customer.sale_id = salesperson.sale_id;

select sale_name, commission*sum(amount)


from salesperson sp, customer c, sales_order so
where sp.sale_id = c.sale_id and c.cust_id = so.cust_id
group by 1 having commission*sum(amount) <= 1000;

select sale_name, company from salesperson, customer


where salesperson.sale_id *= customer.sale_id;

Velocis SQL Language Elements 3-9


3.5 Calling Functions from Velocis SQL
Your Velocis SQL application can call certain Velocis functions from SQL statements. The
callable Velocis functions include scalar (built-in) and aggregate (calculation) functions,
and a conditional selection function. You can also write your own C-based user-defined
functions (UDFs) to call from Velocis SQL statements. The callable functions are
described below. Alphabetical function references are provided in Chapter 5.

3.5.1 Using Scalar (Built-In) Functions


A scalar function operates on a single value and retrieves a single value. This section lists
the scalar (built-in) functions that you can call from a Velocis SQL statement.

3.5.1.1 String Functions


Velocis SQL supports several string functions. These functions are listed in Table 3-5 and
detailed in Chapter 5.

Table 3-5. String Functions

Function Description
ascii Retrieves the numeric ASCII value of a character.
char Retrieves an ASCII character.
concat Concatenates two strings.
insert Inserts a string into another string.
lcase Converts a string to lowercase.
left Retrieves the leftmost characters from a string.
length Retrieves the length of a string.
locate Looks for a string within another string.
ltrim Removes all leading spaces from a string.
repeat Repeats a string.
replace Replaces a string within another string.
right Retrieves the rightmost characters from a string.
rtrim Removes all trailing spaces from a string.
substring Retrieves a substring from a string.
ucase Converts a string to uppercase.
unicode Retrieves the numeric Unicode value of a character.
wchar Retrieves a Unicode character.

3-10 Centura Velocis Language Guide


3.5.1.2 Numeric Functions
Table 3-6 lists the numeric functions that are callable from Velocis SQL.

Table 3-6. Numeric Functions

Function Description
abs Retrieves the absolute value of an expression.
acos Retrieves the arccosine of an expression.
asin Retrieves the arcsine of an expression.
atan Retrieves the arctangent of an expression.
atan2 Retrieves the arctangent of an x-y coordinate pair.
ceiling Finds the upper bound for an expression.
cos Retrieves the cosine of an angle.
cot Retrieves the cotangent of an angle.
exp Retrieves the value of an exponential function.
floor Finds the lower bound for an expression.
log Retrieves the natural logarithm of an expression.
mod Performs a modulo arithmetic operation.
pi Retrieves the value of pi.
rand Retrieves a random floating-point number.
sign Retrieves the sign of an expression.
sin Retrieves the sine of an angle.
sqrt Retrieves the square root of an expression.
tan Retrieves the tangent of an angle.

Velocis SQL Language Elements 3-11


3.5.1.3 Date and Time Functions
To manipulate dates and times, your Velocis SQL application can call the scalar functions
that are listed in Table 3-7.

Table 3-7. Date/Time Functions

Function Description
curdate Retrieves the current date.
curtime Retrieves the current time.
dayofmonth Retrieves the day of the month.
dayofweek Retrieves the day of the week.
dayofyear Retrieves the day of the year.
hour Retrieves the hour.
minute Retrieves the minute.
month Retrieves the month.
now Retrieves the current timestamp.
quarter Retrieves the quarter.
second Retrieves the second.
week Retrieves the week.
year Retrieves the year.

3.5.1.4 System Functions


Table 3-8 lists the system functions that your Velocis SQL application can call to make
general system adjustments and requests.

Table 3-8. System Functions

Function Description
c_data Extracts an element of a c_data column.
convert Converts an expression to a data type or a character string.
database Retrieves the name of a database.
ifnull Retrieves an expression if another expression is null.
user Retrieves the user name.

3-12 Centura Velocis Language Guide


3.5.2 Using Aggregate (Calculation) Functions
Your application can call five aggregate functions from the select statement by using the
group by clause. Each of these functions operates on multiple values and returns a single
value. They perform computations on sets of rows that result from the select statement.
The five aggregate functions are described in Table 3-9 and detailed in Chapter 5.

Table 3-9. Aggregate Functions

Function Description
avg Computes the average of the results for an aggregate result set.
count Counts the rows of an aggregate result set.
max Computes the maximum of the results for an aggregate result set.
min Computes the minimum of the results for an aggregate result set.
sum Computes the sum of the results for an aggregate result set.

3.5.3 Using the Conditional Selection Function


Using the Velocis SQL select statement, your application can access the if function to
implement a conditional selection. This function is detailed in the alphabetical function
references in Chapter 5.

3.5.4 Using UDFs


As mentioned earlier, you can write your own scalar and aggregate user-defined
functions to use in any SQL expression. UDFs are written in C/C++, reside in a
dynamically linked library on the Velocis server, and are called from the Velocis SQL
support module. They are registered by using the create function statement, as
described in Chapter 10 of the Velocis User’s Guide.

Velocis SQL Language Elements 3-13


3.6 Specifying Subqueries
A Velocis SQL subquery allows restriction of where clause results based on the evaluated
result of a nested select statement. You can specify subqueries according to the syntax
options shown below.
subquery_syntax:
expr rel_oper (select expr from ...)
expr rel_oper {{any | some} | all} (select expr from ...)
expr [not] in (select expr from ...)
[not] exists (select * from ...)

A subquery of the first type shown above can only return a single value. For example,
the following query retrieves all sales orders for which the total amount of the order is
greater than the average. Here, the subquery retrieves only the single value.
select * from sales_order
where amount > (select avg(amount) from sales_order);

A subquery of the second type can retrieve multiple rows. The subquery uses a
quantifier (any or all) to determine whether the relational operation applies to all rows or
to any (at least 1) row from the result set. For example, in this query, the orders retrieved
are all those larger than all orders booked by salespersons that SSW manages.
select sale_name, ord_num, ord_date, amount
from salesperson, customer, sales_order
where salesperson.sale_id = customer.sale_id and
customer.cust_id = sales_order.cust_id and
amount > all
(select amount
from salesperson sp, customer c, sales_order so
where sp.sale_id = c.sale_id and
c.cust_id = so.cust_id and
mgr_id = "SSW");

Note: In the second type of subquery, you can use some as a quantifier instead of any.
A subquery of the third type is simply a different representation of the second subquery
type. Therefore, "expr in (select ...)" is the same as "expr = any (select ...)," and
"expr not in (select ...)" is the same as "expr <> all (select ...)".
A subquery of the fourth type does not retrieve any rows. It simply returns TRUE if the
subquery finds at least one row, and it retrieves FALSE if no rows are found. For
example, assuming the sale_id column in the customer table is an undeclared foreign key
to the salesperson table, the update statement shown below uses a subquery to ensure
the referenced salesperson does exist.

3-14 Centura Velocis Language Guide


update customer set sale_id = "CMB"
where cust_id = "SEA" and
exists (select * from salesperson where sale_id = "CMB");

Subqueries can themselves contain subqueries. Velocis SQL does not impose any
arbitrary limits on levels of nesting.
Sometimes, a subquery needs to refer to a column from the outer query. Such a column
reference is called an "outer reference," and a subquery that contains it is called a
"correlated subquery." The following example shows orders by salesperson that are
larger than all orders that are booked by non-manager salespersons.
select sale_name, mgr_id, ord_num, ord_date, amount
from salesperson sp1, customer c1, sales_order so1
where sp1.sale_id = c1.sale_id and
c1.cust_id = so1.cust_id and
sp1.mgr_id is not null and
amount > all (select amount
from salesperson sp2, customer c2, sales_order so2
where sp1.mgr_id != sp2.mgr_id and
sp2.sale_id = c2.sale_id and
c2.cust_id = so2.cust_id);

The query example above requires that the subquery exclude rows from the inner query
that have the same manager as those of the outer query. To provide the exclusion, a
correlation name (for example, sp1 and sp2) must be supplied for each separate table
reference to salesperson, to distinguish between the inner and outer salesperson tables.

Velocis SQL Language Elements 3-15


Chapter 4
Velocis SQL Statement Reference
This chapter contains complete descriptions of all Velocis SQL statements, which are
presented in alphabetical order for easy reference. Each statement description includes a
concise definition and statement type, a syntax summary section, and all relevant
operational details. Examples are included to illustrate the use of the statement.
The statement type indicates whether the statement is part of the DDL or the DML for
Velocis SQL. SQL DDL statements can only be processed by the sddlp utility, but the
server itself processes SQL DML statements. Some ANSI DDL statements are classified
in this chapter as DML statements, because they are processed directly by the server.
To learn how to use the Velocis SQL statements, see the Velocis User’s Guide. Chapter 5
tells you how to write a database schema using the SQL DDL, while the remainder of the
book illustrates the use of the DML statements.

Velocis SQL Statement Reference 4-1


activate index

activate index Activate an optional index (DML statement)

Syntax activate [optional] index index_name

Statement activate [optional] index index_name


Elements Makes an optional index active. The optional
keyword can be included for clarity.

Description This statement activates an optional index, which is an index that can
be deactivated. The activate index statement locks and scans the
table associated with the index and stores index values for rows that
do not have a corresponding index entry. When an optional index
has been deactivated, the index is not used by the SQL system; insert
statements will not store the index values, and the optimizer will not
use the index. When an optional index is active, it operates just like
any other index.
The Velocis SQL query optimizer only uses active indexes. If your
application calls the Velocis SQL support module to execute a view
or UDP using an inactive index, the module returns the
errACTINDEX code indicating the condition. See Chapter 19 in the
Velocis Reference Manual for a description of this code.

See Also create index, deactivate index

Example
deactivate index search_key1;
deactivate index search_key2;
lock table lookup_table exclusive;
insert into lookup_table from file "newrows.txt" on mydev;
commit;
activate index search_key1;
activate index search_key2;

4-2 Centura Velocis Language Guide


alter
extension file
alter Alter the file size attributes for a base or extension file
extension file (DML statement)

Syntax alter [extension] file extno


for "basename"
on basedev
set {maxsize = maxsize | cresize = cresize | extsize = extsize}...

Statement alter [extension] file extno


Elements Specifies a number that indicates which
database file is getting the attribute changes. To
indicate the base file, specify 0; to indicate the
nth extension file, specify n.
for "basename" Specifies the base file name of the database that
is associated with the extension file.
on basedev Specifies the device that contains the database
file.
set {maxsize = maxsize | cresize = cresize | extsize = extsize}...
Specifies which file size attribute to change and
its new default setting, in bytes. You can change
the maximum size of the file, the size of the file
when it is created, or the size of the block that is
added to the end of a file whenever the file
needs to be extended.

Description This statement can be used to change the default size settings for a
base or an extension database file. The extension file to be altered is
specified by the extension number, extno. Extension number 0 refers
to the base database file itself, extension number 1 is the first
extension file, and so on. Up to three file size settings can be
specified. Only the specified values will be changed.
The maxsize specification sets the maximum size, in bytes, to which
the file can grow. The total maximum size for the logical database
file is equal to the sum of the individual maximum size values for the
base file and each extension file associated with it. The maximum
physical size of a file varies by operating system and page size, but it
usually has a default value of 2,147,482,624 bytes.
The cresize value specifies the size, in bytes, with which the file will
be initially created. This will occur upon the first write to the file.
The default creation size is 32,768 bytes (or the value of the
FileCreateSize velocis.ini parameter).

Velocis SQL Statement Reference 4-3


alter
extension file
The extsize value specifies the number of bytes that will be written to
the end of the file whenever the file needs to be extended. The
default extend size is also 32,768 (or the value of the FileExtendSize
velocis.ini parameter).
The specified values will be truncated to the nearest page boundary
for the file being modified, so the actual value may be slightly lower
than the value you specified.
You will not be able to set the maximum size to a value below the
currently written size of the file. Also, once the maximum size has
been reached and the next extension file has been written, you will
not be able to change the maximum size value at all.
Only administrator users can execute this statement.

See Also create extension file, execute ShowDbFiles

Example
create extension file "sales.0x0" on sqldev for "sales.000" on sqldev;
alter extension file 1 for "sales.000" on sqldev
set maxsize = 1234567890;
exec ShowDbFiles("sales");

FILENO EXTNO DEVNAME FILENAME TOTSIZE MAXSIZE CRESIZE EXTSIZE


0 0 sqldev sales.000 149504 2147482624 32768 32768
0 1 sqldev sales.0x0 0 1234567168 32768 32768
1 0 sqldev sales.001 18432 2147482624 32768 32768
2 0 sqldev sales.002 20480 2147482624 32768 32768
3 0 sqldev sales.003 41984 2147482624 32768 32768
4 0 sqldev sales.004 1024 2147482624 32768 32768
5 0 sqldev sales.005 2048 2147481600 32768 32768
6 0 sqldev sales.006 4096 2147479552 32768 32768

4-4 Centura Velocis Language Guide


alter user

alter user Alter a user’s password (DML statement)

Syntax alter user {username | "username"}


set password = "password"

Statement alter user {username | "username"}


Elements Specifies the name of the user for which to
change the password.
set password = "password"
Specifies the new password for the user.

Description This statement changes a user’s password. Normal users can use this
statement only to change their own password. Administrator users
can use it to change the password for any user.
Only the specified user or administrator users can execute this
statement.

See Also create user, drop user, execute ShowUsers, grant, revoke

Example
alter user Randy set password = "xyzzy";

Velocis SQL Statement Reference 4-5


begin

begin Begin a database transaction (DML statement)

Syntax begin [trans | transaction | work] [trans_id]

Statement begin [trans | transaction | work] [trans_id]


Elements Specifies the start of a database transaction. The
trans, transaction, or work keyword can be
included for clarity. An optional identifier can
be specified for the transaction.

Description This statement marks the beginning of a transaction. The begin


statement is a Velocis-specific language feature. ANSI SQL specifies
that a transaction begins immediately following a database open, and
only after a prior transaction is terminated by a commit or rollback
statement. Thus, the use of begin is optional, but it does allow you
to name a specific transaction and clearly delineate the transaction
boundaries. The statements processed between begin and commit
define the transaction.
Once a transaction is started, another transaction cannot be started in
the same connection until the active transaction has been terminated
by a commit or rollback statement.
Any statements that can change the contents of a database must be
bounded by transactions and are put into effect only through the
execution of the corresponding commit statement. Once committed,
the changes become a permanent part of the database.
A transaction identifier can be specified, if desired, and may
optionally be referenced in the commit or rollback statements. See
Chapter 8 of the Velocis User’s Guide for begin usage instructions.

See Also commit, mark, rollback

Example
begin trans new_salesperson;
insert into salesperson
values("SBB", "Scott Blades", 0.80, "West", 1, "MCK");
commit trans new_salesperson;

4-6 Centura Velocis Language Guide


close

close Close a database or databases (DML statement)

Syntax close dbname [, dbname]...

Statement close dbname [, dbname]...


Elements Specifies the names of the databases to close.

Description This statement closes the specified databases. The open and close
statements are useful when the same table name appears in multiple
databases or when you are using database instancing. Your
application cannot issue the close statement for a database with
active transactions.

Note: Velocis automatically closes any open databases when your


application disconnects.

See Also begin, commit, open, rollback

Example
open sales, invntory;
...access databases

close sales, invntory;

Velocis SQL Statement Reference 4-7


commit

commit Commit a transaction (DML statement)

Syntax commit [trans | transaction | work] [trans_id]

Statement commit [trans | transaction | work] [trans_id]


Elements Commits the transaction. The trans, transaction,
or work keyword can be included for clarity
(work is required for ANSI SQL). An optional
identifier can be specified for the transaction.

Description This statement commits (that is, makes permanent) all changes made
since the beginning of a transaction. If the statement contains a
transaction identifier, it must be the same as the one specified on the
most recently executed begin statement. See Chapter 8 of the Velocis
User’s Guide for commit usage instructions.
A transaction begins with the first begin or immediately following a
database open, and only after a prior transaction is terminated by a
commit or rollback statement. The statements processed between
begin and commit define the transaction.
Any statements that can change the contents of a database must be
bounded by transactions and are put into effect only through the
execution of the commit statement. Once committed, the changes
become a permanent part of the database, and they can no longer be
rolled back.

See Also begin, mark, rollback

Example
begin work new_salesperson;
insert into salesperson
values("DMM", "Mayes, Doug", 0.07, 1, "DEN", "BNF");
commit work new_salesperson;
insert into salesperson
values("MMT", "Thomas, Mike", 0.07, 2, "ATL", "GAP");
commit work;

4-8 Centura Velocis Language Guide


create database

create database Create a new database definition (DDL statement)

Syntax {create {database | schema authorization} dbname |


create schema dbname [authorization username]}
[pagesize bytes]
[on device_name]
[enable null values | disable null values]
[enable references count | disable references count]

Statement create {database | schema authorization} dbname


Elements Creates a database with the specified name. If
ANSI SQL compliance is required, you must use
the schema authorization clause. The name that
is specified for the database is truncated to eight
characters by the schema compiler. The user
who executes this statement becomes the owner
of the created database.
create schema dbname [authorization username]
Creates a database with the specified name, and
optionally specifies the owner of the database.
Only administrator users can specify a different
owner. If an owner is not specified, the user
who executes this statement becomes the owner
of the created database.
[pagesize bytes] Specifies the page size, in bytes. The default
page size is 1,024 bytes.
[on device_name] Specifies the device on which to store the
database.
[enable null values | disable null values]
Specifies whether to use null values in the
database. Null column values are managed
through a null value indicator that is contained
in a hidden column in each table. If your Velocis
SQL application does not need to use null
column values, this feature can be disabled, and
the hidden column will not be created.
[enable references count | disable references count]
Specifies whether to enable reference counting.
The references count is used by SQL to enforce
referential integrity checking. When checking is
disabled, it will not be possible to delete rows

Velocis SQL Statement Reference 4-9


create database

from tables that are referenced by foreign keys


on which a create join has not been defined.

Description This statement creates a new permanent database or a new version of


an existing database. See Chapter 5 of the Velocis User’s Guide for
usage instructions.
You do not necessarily have to use this statement to enable or disable
null values or reference counts. The schema compiler utility (sddlp)
includes command-line options for these operations. If you do
choose to use a null values or references count clause, it supersedes
the sddlp command-line options.

See Also create file, create index, create join, create table

Example
create schema invntory on sqldev;
create table product
(
prod_id smallint primary key
"product identification code",
prod_desc char(39) not null
"product description",
price float
"retail price",
cost float
"wholesale cost"
);
create unique index prod_key on product(prod_id);
create index prod_pricing on product(price desc, prod_id);

4-10 Centura Velocis Language Guide


create
database instance
create Create a database instance (DML statement)
database instance

Syntax create database instance newdb


from sourcedb
[with data | {init | initialize} | {noinit | noinitialize}]
[on devname]

Statement create database instance newdb


Elements Specifies the name of the database instance to
create. This name must be unique for all
databases on the server.
from sourcedb Specifies the name of the database from which to
create the instance.
[with data | {init | initialize} | {noinit | noinitialize}]
Specifies what happens to the database files
when the new instance is created. If with data is
used, the database files and optimizer statistics
are copied under exclusive access from the
source database to the device where the new
instance is stored. If used, init or noinit
specifies whether to initialize the database files
for the created instance. If none of these
attributes are used, the compiler initializes the
database files by default.
[on devname] Specifies the name of the device that stores the
database.

Description This statement is used in an administration application to create a


new database instance from an existing database. You cannot create
a database instance from any source database that references, or is
referenced by, other databases. See Chapter 5 of the Velocis User’s
Guide for usage instructions.

Note: The create database instance statement can only be executed


by administrators or the database owner.

Velocis SQL Statement Reference 4-11


create
database instance
The application must make sure that the specified device has already
been created by the system administrator, as described in Chapter 6
of the Velocis Installation and Administration Guide. In addition, this
device cannot be used to store other instances of the schema
associated with the source database. Because the file names for all
instances of a database are identical, they must be stored on separate
devices.

See Also create database, drop database

Example
create database instance wa_accounts from us_accounts on wadev;

4-12 Centura Velocis Language Guide


create device

create device Create a device (DML statement)

Syntax create [readonly] device devname


as "directory_path"

Statement create [readonly] device devname


Elements Specifies the name of the device to create. You
can also make the device read-only (for example,
if the device is a CD-ROM drive).
as "directory_path" Specifies the directory path of the device.

Description This statement creates an new Velocis device. Devices are logical
names for file system directories. The directory path should be a
fully qualified path name including the device specification. Relative
path names can be specified. A relative path is interpreted by
Velocis as being relative to the catalog directory as specified by the
CATPATH environment variable (for example, the catdev device is
located at ".\"). The specified directory path must already exist; the
create device statement will not create the directory for you.
Moreover, no other device can exist that refers to the same directory.
The readonly attribute can be specified to indicate that the directory
path be located on a read-only device, such as a CD-ROM.
Only administrator users can execute this statement.

See Also drop device, execute ShowDevices

Example
create device testdev as "d:\v30\test";
exec ShowDevices;

NAME TYPE PATH


catdev Read/Write .\
emsamp Read/Write ..\examples\em\
rdsdll Read/Write ..\dll\nt_i\
samples Read/Write ..\examples\tims.nt_i\
sqldev Read/Write ..\sqldb.nt_i\
sqlsamp Read/Write ..\examples\emsql\
sysdev Read/Write ..\syslog.nt_i\
testdev Read/Write d:\v30\test\

Velocis SQL Statement Reference 4-13


create
extension file
create Create an extension file for a database file (DML statement)
extension file

Syntax create extension file "extname"


on extdev
for "basename"
on basedev

Statement create extension file "extname"


Elements Specifies the name of the extension file to create.
on extdev Specifies the name of the device on which to
store the extension file.
for "basename" Specifies the name of the base database file to
extend.
on basedev Specifies the name of the device that contains the
base database file.

Description This statement creates an extension file that will be stored on device
extdev. The extension file will be added to the base database file
contained on device basedev. The default maximum physical file size
can vary by operating system and page size, but it is typically
2,147,482,624 bytes. You can use the alter extension file statement to
specify a lower maximum file size for a base file or an extension file
and to specify an initial creation size and/or extend size.
Only administrator users can execute this statement.

See Also alter extension file, execute ShowDbFiles

Example
create extension file "sales.0x0" on sqldev for "sales.000" on sqldev;
exec ShowDbFiles("sales");

FILENO EXTNO DEVNAME FILENAME TOTSIZE MAXSIZE CRESIZE EXTSIZE


0 0 sqldev sales.000 149504 2147482624 32768 32768
0 1 sqldev sales.0x0 0 2147482624 32768 32768
1 0 sqldev sales.001 18432 2147482624 32768 32768
2 0 sqldev sales.002 20480 2147482624 32768 32768
3 0 sqldev sales.003 41984 2147482624 32768 32768
4 0 sqldev sales.004 1024 2147482624 32768 32768
5 0 sqldev sales.005 2048 2147481600 32768 32768
6 0 sqldev sales.006 4096 2147479552 32768 32768

4-14 Centura Velocis Language Guide


create file

create file Create a database file (DDL statement)

Syntax create {file | tablespace} file_name


[pagesize bytes]
[on device_name]

Statement create {file | tablespace} file_name


Elements Specifies the name of the file to create. This
name must be a unique file identifier for the
database. Exclude the suffix or the file name
extension from the name.
[pagesize bytes] Specifies the page size, in bytes. The default
page size is 1024 bytes.
[on device_name] Optionally defines the device for the database
file. If you omit this clause, the file is stored on
the database device.

Description This statement defines a database file that contains one or more
database tables or indexes. A file cannot contain both tables and
indexes. The file is stored on the database device unless you specify
a device using the on clause. The contents of a file are specified
through use of the in clause of the create table and create index
statements. See Chapter 5 of the Velocis User’s Guide for create file
usage instructions.
The create file statement specifies an alias for the file; it does not
specify the actual name of the file. Use the alias to specify file
locations for tables, keys, or BLOBs. For example, if you want two
tables in the same file, the in clause of the two create table
statements should use the alias for that file.

Note: Velocis SQL databases always contain files that are named
dbname.000, dbname.001, dbname.002, etc. You are not allowed to
change the naming scheme.

See Also create database, create index, create join, create table

Velocis SQL Statement Reference 4-15


create file

Example
create database sales on sqldev;

create file salesd0;


create file salesd1;
create file salesd2;
create file salesd3;
create file salek0;
create file salek1 pagesize 2048;
create file salek2 pagesize 4096;

4-16 Centura Velocis Language Guide


create filter

create filter Create an import/export filter (DML statement)

Syntax create filter filter_name ["description"] [with auto commit]


in dllname
on devname

Statement create filter filter_name ["description"] [with auto commit]


Elements Specifies the name of the filter to create. A text
description may also be specified. To
automatically commit each insertion of a row
from the import filter into a Velocis table,
specify with auto commit. (If omitted, this
option can still be specified in the insert
statement that invokes the filter.)
in dllname Specifies the file name of the library module that
contains the filter.
on devname Specifies the name of the Velocis device that
contains the module.

Description This statement registers a filter with Velocis SQL. Filters, which are
written in C, are used to access data from other sources. A filter
must be registered before it can be used. To learn how to write a
filter, see Chapter 9 of the Velocis User’s Guide.
There are two types of filters. An import filter retrieves data from an
outside source (typically an input file), processes the data, and inserts
the data as rows into a database table. An export filter retrieves rows
of data from a database table, processes the rows, and inserts them in
the appropriate format into an outside target (typically an output
file). To use filters for database import and export, see the insert
(from filter) statement and the insert (from select) statement,
respectively.

See Also insert (from filter), insert (from select)


SQL IEF module functions (ief prefix)

Example
create filter bbscores in "Ief" on rdsdll;

Velocis SQL Statement Reference 4-17


create function

create function Create a user-defined function (DML statement)

Syntax create fcn_spec [fcn_spec]...


in libname
on devname
fcn_spec:
[scalar | aggregate] function[s] name_list
name_list:
fcn_name ["description"] [, fcn_name ["description"]]...

Statement create fcn_spec [fcn_spec]...


Elements Specifies the creation of one or more user-
defined functions (UDFs).
in libname Specifies the name of the dynamically linked
library (DLL) file that contains the UDF module.
The file name extension does not need to be
specified.
on devname Specifies the name of the device on which the
DLL is stored.
[scalar | aggregate] function[s] name_list
Specifies the names and function type of UDFs
to create. A scalar function (the default) returns
a single value for a single table row. An
aggregate function returns a single value that
results from a calculation on a group of table
rows.
fcn_name ["description"] [, fcn_name ["description"]]...
Specifies the names and optional descriptions of
the internal functions that are included in the
UDF module. Function names must be unique
identifiers and can have up to 32 characters.

Description This statement registers in the Velocis SQL system catalog (syscat)
one or more UDF modules that are contained in a DLL stored on a
Velocis device. You must register a UDF module by using this
statement before the module can be called from a Velocis SQL
statement. See Chapter 12 of the Velocis User’s Guide for
create function usage instructions.

See Also drop function

4-18 Centura Velocis Language Guide


create function

Example
create scalar function
baseline "return baseline constant"
aggregate functions
devsq "compute sum of the squares of deviations",
stddev "compute standard deviation",
geomean "compute the geometric mean"
in statpack on add_ins;

Velocis SQL Statement Reference 4-19


create index

create index Create an index (DDL statement)

Syntax create [optional | unique] index index_name


on base_table_name (column [asc | desc] [, column [asc | desc]]...)
[in file_name]

Statement create [optional | unique] index index_name


Elements Creates an index. The name of the index can
have up to 32 characters. You may specify that
the index be optional (that is, one that can be
deactivated) or unique.
on base_table_name (column [asc | desc] [, column [asc | desc]]...)
Specifies the name of the table on which to
create the index and the names of columns
within that table to include in the index. You
may also specify a sorting order for each listed
column; the default order is ascending.
[in file_name] Optionally defines the database file that includes
the index. If you do not use this clause with the
create index statement, the database maintains
the index in a separate file using the default
page size (1024 bytes).

Description This statement creates an index for the specified columns in the
indicated table. The index is stored in the order specified by the list
of columns. Each index column can be in either ascending (asc) or
descending (desc) order. See Chapter 5 of the Velocis User’s Guide for
create index usage instructions.
Your application can issue a create index statement to specify an
index for a temporary table. However, create index must be
specified before you insert any rows into the temporary table.
Velocis SQL does not support dynamic index creation on permanent
tables. Also, statements that create a temporary index cannot include
the in clause.
In your schema, be sure to index all unique and primary key columns
(except those of type rowid). If you do not specify a create index
statement for a unique or primary key, one will automatically be
created when you compile the schema.
The optional attribute is used to define an index that can be
deactivated. When an optional index is deactivated, the index is not

4-20 Centura Velocis Language Guide


create index

used by the SQL system; insert statements will not store the key
values and the optimizer will not use the index. When an optional
index is active, it operates just like any other index. The activate and
deactivate index statements are used to enable and disable use of an
optional index. The activate index statement will scan the associated
table and store index values for those rows that do not have a
corresponding key. The deactivate index statement simply marks
the index as inactive. Existing key values remain unchanged. This
feature cannot be specified if you are creating an index on a
temporary table.

See Also activate index, create join, create table, deactivate index

Example
create database invntory on sqldev;
create table outlet
(
loc_id char(3) primary key,
city char(17) not null,
state char(2) not null,
region smallint not null
"regional U.S. sales area"
);
create unique index loc_key on outlet(loc_id);
create optional index loc_geo on outlet(state, city);

Velocis SQL Statement Reference 4-21


create join

create join Create a join between a primary key and a foreign key
(DDL statement)

Syntax create join join_name


{ order {first | last} on forkey [and forkey]...
| order sorted on forkey sort_spec [and forkey sort_spec]...
}
forkey:
[virtual | non_virtual] base_table_name [(colname [, colname]...)]
sort_cols:
by colname [asc | desc][, colname [asc | desc]]...

Statement create join join_name


Elements Specifies the name of the join being created.
order {first | last} on forkey [and forkey]...
Specifies the foreign key(s) on which to create
the join, and the location for adding new rows of
foreign keys. To add new rows at the beginning
or end of the list of matching foreign key values,
specify first or last, respectively.
order sorted on forkey [sort_cols] [and forkey [sort_cols]]...
Specifies the columns on which to create the
sorted join and the column sorting order.
[virtual | non_virtual] base_table_name [(colname [, colname]...)]
Identifies the table containing the foreign key on
which to define the join. You may also specify
the names of foreign key columns in that table
that are involved in the join definition. If the
table only has one declared key, however, you
can omit the column name.
You can specify foreign key columns to be
virtual (the default) or non-virtual. Values for a
virtual column are obtained from the related
primary key row. Values for a non-virtual
column are actually stored in the physical
foreign key table.
by colname [asc | desc][, colname [asc | desc]]...
Specifies the columns on which to sort rows with
matching foreign key values. Each column can

4-22 Centura Velocis Language Guide


create join

be sorted in ascending (asc, the default) or


descending (desc) order.

Description The create join statement is used to specify a predefined natural join,
which will be maintained by Velocis SQL on each insert, update, and
delete operation. This statement creates a predefined join or
connection relating a table with a referencing foreign key column in
another table. The application can then manipulate data from the
referenced table.
The specified columns for each base table must have been defined as
a foreign key (through the references or foreign key clause) in the
create table statement for that table. If no columns are listed, then
the base table must have a single foreign key or references clause. If
more than one base table is specified (through the and clause), each
must reference the same table.
The create join statement guarantees that only a single logical disk
access is needed to retrieve the related row in the referenced table.
This means that the performance of referential integrity checking and
select statement join processing will be optimal. It also guarantees
optimal performance in locating all the rows of the tables with a
particular foreign key value, and that the retrieval can occur from
either the many-to-one or the one-to-many direction (thus
supporting both inner and outer join processing). No indexing of the
foreign keys is needed to achieve this performance. See Chapter 5 of
the Velocis User’s Guide for create join usage instructions.

Note: You cannot create joins between tables in different databases.

See Also create index, create table

Velocis SQL Statement Reference 4-23


create join

Example
create table note
(
note_id char(12) not null,
note_date date not null,
sale_id char(3) not null references salesperson,
cust_id char(3) references customer,
primary key(sale_id, note_id, note_date)
) in salesd2;
create unique index note_key
on note(sale_id, note_id, note_date) in salek1;
create join tickler order sorted
on note(sale_id) by note_date desc;
create join actions order sorted
on note(cust_id) by note_date desc;

create table note_line


(
note_id char(12) not null,
note_date date not null,
sale_id char(3) not null,
txtln char(81) not null,
foreign key(sale_id, note_id, note_date) references note
) in salesd3;
create join comments order last on note_line;

4-24 Centura Velocis Language Guide


create
procedure
create Create a stored SQL procedure or a C-based, user-defined procedure
procedure (UDP) (DML statement)

Syntax For Stored SQL Procedures


create {proc | procedure} proc_name [(arg_spec [, arg_spec]...)] as
SQL_statement[;] [SQL_statement[;]]...
end {proc | procedure}
arg_spec:
arg_name type_spec [default constant]
type_spec:
integer | smallint | real | float | decimal
| {char | character} | date | time | timestamp
For C-Based, User-Defined Procedures (UDPs)
create {proc | procedure} proc_name in dllname on devname

Statement create {proc | procedure} proc_name [(arg_spec [, arg_spec]...)] as


Elements Specifies a name for the stored SQL procedure
and the arguments that are required by the
procedure. The name can have up to 32
characters and must be different from any other
procedure name that is stored on the server.
SQL_statement[;] [SQL_statement[;]]...
Specifies the SQL statements to execute in the
procedure.
end {proc | procedure}
Declares the end of the stored SQL procedure.
arg_spec: arg_name type_spec [default constant]
Specifies the name, data type, and default value
of a procedure parameter.
type_spec: ... Specifies the data type for the parameter.
Possible data types are defined in Chapter 18 of
the Velocis Reference Manual.
create {proc | procedure} proc_name in dllname on devname
Creates a C-based, user-defined procedure
(UDP). You must specify names for the
procedure, the dynamically linked library file
(without the suffix) that contains the UDP, and
the device that stores the UDP. The procedure

Velocis SQL Statement Reference 4-25


create
procedure
name can have up to 32 characters, but it must
be different from any other procedure name on
the server. The suffix for the library file name is
.dll on Windows and .so on UNIX.

Description This statement creates a SQL stored procedure that, when executed,
will process one or more SQL statements. Stored procedures are
precompiled and stored in the Velocis SQL system catalog. They can
be specified with arguments that will be resolved when the
procedure is called.
Stored procedures are invoked by the execute command. They can
contain calls to other stored procedures. A stored procedure can
contain any Velocis SQL DML statement except create procedure,
create temporary table, and create view.
Your application can also use the create procedure statement to
register a C-based UDP. The application must use the statement to
register each UDP before it can be invoked. Refer to Chapter 12 in
the Velocis User’s Guide for programming details for these
procedures.
You can optionally use semicolons (";") to separate the declarations of
the SQL statements in the create procedure statement for a stored
procedure. However, if you use the rsql utility to create the
procedure, be sure not to end a line with a semicolon. The utility will
interpret it as the end of a statement and prematurely process the
create procedure clause before you have time to enter the
end procedure clause.

Note: When you recompile an SQL database schema, any stored


procedures that existed in the original database are invalidated,
because the new database contains new identification numbers for
the tables. You will need to re-create the procedure definitions. To
simplify resubmission of these definitions, we recommend that you
save them in script files for the rsql utility and run the scripts after
recompiling.

See Also drop procedure, execute

4-26 Centura Velocis Language Guide


create
procedure
Example The following example illustrates a create procedure statement for a
stored SQL procedure.
create procedure order_report(start_date date,
end_date date default today) as
select sale_name, company, ord_num, ord_date, amount, tax
from salesperson, customer, sales_order
where salesperson.sale_id = customer.sale_id and
customer.cust_id = sales_order.cust_id and
ord_date between start_date and end_date
end procedure;

The next statement illustrates how to use create procedure (proc) to


register a UDP with the Velocis SQL module.
create proc tims_data in udp on rdsdll;

Velocis SQL Statement Reference 4-27


create table

create table Create a database table (DDL statement)

Syntax create [readonly] table base_table_name ["description"]


(column_defn [, column_defn]... [, table_constraint]...)
[in file_name]
column_defn:
column_name column_spec ["description"]
table_constraint:
{unique | primary key} (cols)
| foreign key (cols) references [dbname.]base_table_name [(cols)]
| check (cond_expr)
cols:
column_name [, column_name]...
column_spec:
type_spec
[default {constant | null | auto}]
[not null]
[unique | primary key]
[references [dbname.]base_table_name [(column_name)]]
[check (cond_expr)]
[compare (cmpFcnId)]
| long {varchar | varbinary}
[default {constant | null}]
[not null]
[in file_name]
type_spec:
{varchar | char | wvarchar | wchar} (length)
| {double [precision] | float}
| real
| {integer | int | long}
| {smallint | short}
| decimal [(precision [, scale])]
| date | time [(precision)] | timestamp [(precision)]
| rowid
| c_data[dims] c_type_spec
dims:
[dim] [[dim]]...

4-28 Centura Velocis Language Guide


create table

c_type_spec:
c_base_type | struct { c_base_type field_name[dims]; ... }
c_base_type:
[unsigned] {char | short | int | long} | float | double | wchar

Statement create [readonly] table base_table_name ["description"]


Elements Creates a table with the specified base name.
This name must be different from all other table
and view names in the database. You can
include a table description, which gets stored in
the Velocis SQL system catalog (syscat). The
table can be marked read-only, which means
that the record cannot be modified during
normal operation (database opened in shared
mode). To update a read-only record, you must
open the database in exclusive access mode.
(column_defn [, column_defn]... [, table_constraint]...)
Specifies the columns that are in the table and
the constraints that apply to the table.
[in file_name] Optionally defines the name of the file
containing the table rows or the data for the
long varchar or long varbinary column.
column_name column_spec ["description"]
Specifies the name and definition for a column.
You can include a column description, which
gets stored in the Velocis SQL system catalog
(syscat).
table_constraint: ... Specifies the constraints that apply to the created
table. Use this section to require a condition to
be met for values in the table or to declare a
group of columns to collectively be a unique,
primary, or foreign key.
{unique | primary key} (cols)
Declares certain columns (up to eight)
collectively to be a unique key or a primary key.
A unique key requires its columns to collectively
have different values for each row in the table.
A primary key is also unique, but it is the main
key in the table; a table can have only one
primary key.

Velocis SQL Statement Reference 4-29


create table

foreign key (cols) references [dbname.]base_table_name [(cols)]


Declares that certain columns collectively form a
foreign key that takes the specified table’s
primary key columns as a reference. The
amount of specified foreign key columns must
equal the number of primary key columns in the
referenced table. You can qualify the table name
with its database name, and you can omit the
primary key column names for that table.
check (cond_expr) Defines a condition that must be true for every
value of a column in the database.
cols: column_name [, column_name]...
Specifies a list of column names. All column
names must be distinct from all table names in
the same database.
column_spec: ... Specifies the data type and other characteristics
that define a column.
[default {constant | null | auto}]
Declares a default value for the column. You
can specify a non-null constant value, or if you
want a null value to be the default, specify null.
For integer columns, you can also specify auto to
automatically assign a monotonically increasing,
non-negative integer value for each row in that
column.
[not null] Prohibits the column from having a null value.
[unique | primary key]
Declares the column to be a unique or primary
key.
[references [dbname.]base_table_name [(column_name)]]
Declares the column to be a foreign key that
takes the specified table’s primary key column as
a reference. You can qualify the table name with
its database name, and you can omit the name of
the primary key for that table.
[compare (cmpFcnId)]
Specifies the identifier of a comparison function
that is used to sort the column. Comparison
functions are created in C modules that use the
customized comparison functions (cmp prefix).

4-30 Centura Velocis Language Guide


create table

type_spec: ... Specifies the data type of a column. Some data


types require parameters such as length (in
bytes) or the number of digits of precision or
scale. For definitions of supported data types,
see Chapter 18 of the Velocis Reference Manual.
You can also specify C data types.
c_data[dims] c_type_spec
Specifies the data type of a column to be a C data
type.
dims: [dim] [[dim]]...
Specifies the number of dimensions and their
sizes in a C data type column.
c_base_type | struct { c_base_type field_name[dims]; ... }
Defines the C data type. The C data type can be
a base type, an arrayed base type, or a structure
that contains members that are base types (or
arrays of base types).
c_base_type: ... Specifies what C base types are available to use
in a c_data column or structure.

Description This statement creates a database table. Each column of the base
table is defined by an identifier, column name, and a data type. The
column name must be distinct from the other columns in this table
but can be used in other tables. A column can be identified as
containing only non-null data, unique values, or as the table’s
primary key. The references clause identifies the column as a foreign
key.
The unique table constraint specifies that the column (or columns
taken together) must contain a different value for each row in the
table. The primary key clause identifies the column (or columns
taken together) which must be unique and which forms the primary
key of the table. A table can have only one primary key. A unique
or primary key can be composed of up to eight columns. Only tables
with a unique or primary key constraint can be specified in a
references clause of another create table statement.
You can use the check clause to define a condition that must be true
for every value of the column in the database. This condition can
include constants and call built-in or user-defined functions but can
only refer to the single column. The check condition cannot have a

Velocis SQL Statement Reference 4-31


create table

subquery. If the check clause is specified as a table constraint, it can


include references to any of the columns declared in the table.
The optional in clause specifies the name of a file to contain the table.
If you do not specify a file, Velocis stores the table rows in a separate
file with a name derived from the database name and the default
page size. See Chapter 5 of the Velocis User’s Guide for create table
usage instructions.
Databases containing c_data columns cannot be updated through
Velocis SQL. Modifications can only be made using the Velocis Core
(d_ prefix) API. The ability to declare columns of this type is
intended to provide for compatibility with RDM applications that
have been migrated to Velocis where SQL access is desired for
queries and reports.

See Also create database, create index, create join

Example
create table salesperson
(
sale_id char(3) primary key,
sale_name char(30) not null,
dob date
"date of birth",
commission decimal(4,3) check(commission between 0.0 and 0.15)
"salesperson’s commission rate",
region smallint check(region in (0,1,2,3))
"regional U.S. sales area",
office char(3) references invntory.outlet(loc_id)
"location where salesperson works",
mgr_id char(3) references salesperson
"salesperson id of sales mgr"
) in salesd0;

4-32 Centura Velocis Language Guide


create
temporary table
create Dynamically create a temporary table (DML statement)
temporary table

Syntax create temporary table temp_table_name


(column_defn [, column_defn]...)
column_defn:
column_name column_spec ["description"]
column_spec:
type_spec [default {constant | null}] [not null]
type_spec:
{varchar | char | wvarchar | wchar} (length)
| {double [precision] | float} | real
| {integer | int | long} | {smallint | short}
| decimal [(precision [, scale])]
| date | time [(precision)] | timestamp [(precision)]
| rowid

Statement create temporary table temp_table_name


Elements Specifies the name of the temporary table to
create.
column_name column_spec ["description"]
Supplies a name and a specification for a column
in the table. A text description for the column
can optionally be specified.
type_spec [default {constant | null}] [not null]
Specifies a data type and other attributes for a
column. You can also specify a default value
(which can be null) for the column, and you can
prohibit the column from having a null value
(not null).
type_spec: ... Specifies the data type of a column. Some data
types require parameters such as length (in
bytes) or the number of digits of precision or
scale. For definitions of supported data types,
see Chapter 18 of the Velocis Reference Manual.

Description This statement creates a table to hold the temporary results of a


query, usually implemented from a select statement on a permanent
database. A temporary table is only accessible from within the

Velocis SQL Statement Reference 4-33


create
temporary table
connection in which it was created. Velocis automatically drops the
table when the session is disconnected.
Indexes can be created on temporary tables. They must be specified,
using create index, before any rows are inserted into the table.
See Chapter 9 of the Velocis User’s Guide for create temporary table
usage instructions.

See Also create index, drop table

Example
create temporary table sp_sales(
company char(30),
city char(17),
state char(2),
ord_date date,
amount float
);
create index skm_ndx on sp_sales(state);
insert into sp_sales
select company, city, state, ord_date, amount
from customer, sales_order
where customer.sale_id = "SKM" and
customer.cust_id = sales_order.cust_id
order by 1, 4;

4-34 Centura Velocis Language Guide


create user

create user Create a user (DML statement)

Syntax create [administrator | admin] user {username | "username"}


password "password"
on devname

Statement create [administrator | admin] user {username | "username"}


Elements Specifies the name of the user to create. You
may optionally give administrative privileges to
the user.
password "password"
Specifies the user’s password.
on devname
Specifies the name of the user’s home device.

Description This statement creates a new Velocis user. Administrator users have
full access rights to all databases and commands. The access rights
for normal (non-administrator) users must be specified through use
of the grant statement. The user’s home device will be used as the
default device for database objects that are created without an
explicit device reference.
Only administrator users can execute this statement.

See Also alter user, drop user, execute ShowUsers, grant, revoke

Example
create user Randy password "1981mar14" on sqldev;
exec ShowUsers;

USER_NAME RIGHTS HOME_DEVICE


Randy Normal sqldev
admin Admin catdev
guest Normal catdev
wayne Normal samples

Velocis SQL Statement Reference 4-35


create view

create view Create a view (DML statement)

Syntax create view view_name ["description"] [(view_column_list)]


as select_stmt
[with check option]
view_column_list:
column_name [, column_name]...

Statement create view view_name ["description"] [(view_column_list)]


Elements Specifies the name of the view to create. A view
description and a list of columns to include in
the view can also be specified. If you omit the
column list, the view columns are the same as
the ones that are specified in the select
statement.
as select_stmt Defines the create view statement to be based on
a select statement.
[with check option]
Optionally specifies that any insert or update
statements referencing the view must satisfy the
where condition of the defining select statement.
column_name [, column_name]...
Specifies the names of the columns to include in
the view.

Description This statement defines a view of columns of a table (or tables) that
results when a select statement is executed. The where clause of the
select statement constrains the rows of the view. Your application
cannot execute a create view statement inside a transaction or a
stored procedure.
A view is considered updateable (that is, it can be the table
referenced in an insert, delete, or update statement) when the select
statement that defines the view meets the following conditions:
• It does not contain a subquery or a distinct or group by clause.
• It does not contain any column expressions.
• It has a from clause that refers to only a single table, and if that
table is itself a view, then that view must be updateable.
A view that has a with check option specification must be
updateable. When specified, the with check option will require that

4-36 Centura Velocis Language Guide


create view

any insert or update statements that reference the view satisfy the
where condition of the view’s defining select statement.

Note: When you recompile an SQL database schema, any views that
existed in the original database are invalidated, because the new
database contains new identification numbers for the tables. You
will need to re-create the view definitions. To simplify resubmission
of these definitions, we recommend that you save them in script files
for the rsql utility and run the scripts after recompiling.

See Also create table, drop view

Example The following create view statement defines a view named acct_sale
for the sales database.
create view acct_sale as
select * from salesperson, customer, sales_order
where salesperson.sale_id = customer.sale_id
and customer.cust_id = sales_order.cust_id;

The following example gives the acct_sale view its own column
names by including column aliases.
create view acct_sale(sale_id, name, svc_area, company, order_number,
order_date, total)as
select sale_id, sale_name, region, company, ord_num, ord_date,
amount + tax
from salesperson, customer, sales_order
where salesperson.sale_id = customer.sale_id
and customer.cust_id = sales_order.cust_id;

The following example is a view of the customer table that shows


salespersons who only service customers on the west coast.
create view pacific as
select * from customer where state in ("CA","OR","WA")
with check option;

Velocis SQL Statement Reference 4-37


deactivate index

deactivate index Deactivate an optional index (DML statement)

Syntax deactivate [optional] index index_name

Statement deactivate [optional] index index_name


Elements Specifies the name of an optional index to delete.
(The optional keyword can be specified, but it is
only for clarity.)

Description This statement deactivates an optional index activated by the


activate index statement. The deactivate index statement simply
marks the optional index as inactive and leaves existing key values
unchanged. Velocis SQL will not use a deactivated index. In other
words, insert statements will not store key values, and the Velocis
SQL query optimizer will not use a deactivated index.
If your application calls Velocis SQL to execute a view or UDP that
uses an inactive index, SQL will return an errACTINDEX code
indicating the condition. See Chapter 19 in the Velocis Reference
Manual for a description of this code.

See Also activate index, create index

Example
deactivate index search_key1;
deactivate index search_key2;
lock table lookup_table exclusive;
insert into lookup_table from file "newrows.txt" on mydev;
commit;
activate index search_key1;
activate index search_key2;

4-38 Centura Velocis Language Guide


delete

delete Delete a row or rows from a table (DML statement)

Syntax delete from table_name


where {cond_expr | current of cursor_name}

Statement delete from table_name


Elements Specifies the name of the table that contains the
rows to delete.

where {cond_expr | current of cursor_name}


Specifies either a conditional expression that
selects which rows to delete, or the name of the
cursor that is positioned at the row to delete.

Description This statement deletes one or more rows from the specified table. It
is capable of two types of deletions. Using a "searched delete," the
delete statement deletes all rows of the table that satisfy the
conditional expression (cond_expr) specified in the where clause.
Alternatively, in a "positioned delete", the delete statement deletes
the current row associated with the specified cursor (cursor_name) in
the where current of clause. See Chapter 9 of the Velocis User’s Guide
for delete statement usage instructions.

Note: The application can only request a positioned delete if it has


previously defined the cursor_name parameter, via a call to either
SQLGetCursorName or SQLSetCursorName in the Velocis SQL
API.

See Also insert, update


SQLGetCursorName, SQLSetCursorName (functions)

Example
delete from on_hand where quantity = 0;

Velocis SQL Statement Reference 4-39


drop database

drop database Delete a database instance (DML statement)

Syntax drop database dbname

Statement drop database dbname


Elements Specifies the name of the database instance to
delete.

Description This statement is used to delete a database instance, as long as it is


not being used by any other applications (users). Statement
processing does not delete database files or database definition
information associated with the database schema. See Chapter 5 of
the Velocis User’s Guide for instructions on using this statement.

Note: The drop database statement can only be executed by


administrators or the database owner.

When the drop database statement is processed, the Velocis SQL


support module removes instance-specific information from the
system catalog. The module also removes all entries from the lookup
tables that are used by the SQLTables, SQLColumns, and
SQLSpecialColumns functions in the Velocis SQL API.

See Also create database, create database instance

Example
drop database sales;

4-40 Centura Velocis Language Guide


drop device

drop device Drop a device (DML statement)

Syntax drop device devname

Statement drop device devname


Elements Specifies the name of the device to drop.

Description This statement drops a Velocis device. Devices are logical names for
file system directories. The device will only be dropped if it does not
contain any items (for example, database files or extension modules).
Dropping the device will not cause any files to be deleted, and it will
not remove the file directory.
Only administrator users can execute this statement.

See Also create device, execute ShowDevices

Example
exec ShowDevices;

NAME TYPE PATH


catdev Read/Write .\
emsamp Read/Write ..\examples\em\
rdsdll Read/Write ..\dll\nt_i\
samples Read/Write ..\examples\tims.nt_i\
sqldev Read/Write ..\sqldb.nt_i\
sqlsamp Read/Write ..\examples\emsql\
sysdev Read/Write ..\syslog.nt_i\
testdev Read/Write d:\v30\test\

drop device testdev;

Velocis SQL Statement Reference 4-41


drop function

drop function Drop a UDF definition (DML statement)

Syntax drop function fcnname

Statement drop function fcnname Specifies the name of the UDF to drop.
Elements

Description This statement deletes a UDF from the Velocis SQL system catalog.

See Also create function

Example
drop function geomean;

4-42 Centura Velocis Language Guide


drop procedure

drop procedure Drop a stored procedure (DML statement)

Syntax drop procedure proc_name [cascade | restrict]

Statement drop procedure proc_name [cascade | restrict]


Elements Specifies the name of the procedure to drop. To
also drop procedures that are dependent on this
procedure, specify cascade (the default). To
keep the dependent procedures, specify restrict.

Description This statement deletes a stored procedure from Velocis. The


statement can include the cascade clause to also drop all stored
procedures that call the specified procedure. If the statement uses
the restrict clause instead, the statement fails if dependent
procedures exist.
If the statement is used to drop a user-defined procedure, the
cascade and restrict elements are not needed.

See Also create procedure

Example
drop procedure rlm_login;

Velocis SQL Statement Reference 4-43


drop table

drop table Drop a temporary table (DML statement)

Syntax drop table tabname [, tabname]...

Statement drop table tabname [, tabname]...


Elements Specifies the name of the temporary table to
drop.

Description This statement drops the listed temporary tables from Velocis. Each
table must be a temporary table that was created in the current
session by a create temporary table statement.

See Also create temporary table, initialize

Example
drop table skm_sales;

4-44 Centura Velocis Language Guide


drop user

drop user Drop a user (DML statement)

Syntax drop user {username | "username"}

Statement drop user {username | "username"}


Elements Specifies the name of the user to drop.

Description This statement deletes the specified user. After having been
dropped, the user will no longer have access to the Velocis server.
Only the specified user or administrator users can execute this
statement.

See Also create user, alter user, execute ShowUsers, grant, revoke

Example
drop user Randy;

Velocis SQL Statement Reference 4-45


drop view

drop view Drop a view (DML statement)

Syntax drop view view_name [cascade | restrict]

Statement drop view view_name [cascade | restrict]


Elements Drops the specified view. To indicate whether
to also drop any views that are dependent on
this view, you can specify cascade (the default)
to drop dependent views or restrict to leave
them.

Description This statement deletes the specified view. If the statement includes
the cascade clause, it automatically drops the named view and all
views that depend on it (views that reference the named view in
select statements). If the statement includes the restrict clause and
dependent views exist, the drop operation is not allowed.

See Also create view

Example
drop view temp_view;

4-46 Centura Velocis Language Guide


execute

execute Execute a stored procedure or UDP (DML statement)

Syntax {exec | execute | run} proc_name [(arg [, arg]...)]

Statement {exec | execute | run} proc_name [(arg [, arg]...)]


Elements Specifies the name of a procedure to execute and
any procedure parameters that need to be
supplied. Each parameter must be a literal
constant or a parameter marker (?), and it must
match the data type that was specified when the
procedure was created (in the create procedure
statement).

Description This statement invokes a stored procedure or UDP. If the procedure


has parameters, the application must pass them to the execute
statement in the order of their definition in the create procedure
statement. The application does not have to supply a value for any
parameter that is defined by the default clause of the
create procedure statement. In the execute statement, you can skip a
parameter by using a comma.

See Also create procedure

Example
execute order_report(date "06-01-1992", date "06-30-1992");

Velocis SQL Statement Reference 4-47


execute ShowDbFiles

execute Show the list of files for a given database (DML statement)
ShowDbFiles

Syntax {exec | execute} ShowDbFiles("dbname")

Statement {execute | exec} ShowDbFiles("dbname")


Elements Executes a stored procedure that returns the list
of the database and extension files for the
specified database.

Description This statement executes the built-in Velocis stored procedure


ShowDbFiles, which lists all database and extension files for a
database. This procedure retrieves a result set that contains one row
for each base and extension file in the database. The result set
consists of these eight columns:

Column
Name Type Length Description

FILENO smallint N/A The file number of the logical database file
EXTNO smallint N/A The Extension number:
st
0 = base file, 1 = 1 extension, etc.
DEVNAME char 32 The name of the device on which the
physical file is stored
FILENAME char 47 The name of the file
TOTSIZE integer N/A The current total size of the logical file
(includes base plus all extension files)
MAXSIZE integer N/A The maximum size of the individual
physical file
CRESIZE integer N/A The initial creation size of the individual
physical file
EXTSIZE integer N/A The extend size of the individual physical
file

Only administrator users can execute this statement.

See Also alter extension file, create extension file

4-48 Centura Velocis Language Guide


execute ShowDbFiles

Example
exec ShowDbFiles("sales");

FILENO EXTNO DEVNAME FILENAME TOTSIZE MAXSIZE CRESIZE EXTSIZE


0 0 sqldev sales.000 149504 2147482624 32768 32768
0 1 sqldev sales.0x0 0 1234567168 32768 32768
1 0 sqldev sales.001 18432 2147482624 32768 32768
2 0 sqldev sales.002 20480 2147482624 32768 32768
3 0 sqldev sales.003 41984 2147482624 32768 32768
4 0 sqldev sales.004 1024 2147482624 32768 32768
5 0 sqldev sales.005 2048 2147481600 32768 32768
6 0 sqldev sales.006 4096 2147479552 32768 32768

Velocis SQL Statement Reference 4-49


execute ShowDevices

execute Show the list of all Velocis devices (DML statement)


ShowDevices

Syntax {execute | exec} ShowDevices

Statement {execute | exec} ShowDevices


Elements Executes a stored procedure that returns a list of
the Velocis devices.

Description This statement executes the built-in Velocis stored procedure


ShowDevices, which lists all Velocis devices. The procedure retrieves
a result set that contains one row for all currently registered devices
in the Velocis catalog. The result set consists of these three columns:

Column
Name Type Length Description

NAME char 32 The name of the device


TYPE char 12 The device type:
"read/write" or "read/only"
PATH char 455 The directory path

Only administrator users can execute this statement.

See Also create device, drop device

Example
exec ShowDevices;

NAME TYPE PATH


catdev Read/Write .\
emsamp Read/Write ..\examples\em\
rdsdll Read/Write ..\dll\nt_i\
samples Read/Write ..\examples\tims.nt_i\
sqldev Read/Write ..\sqldb.nt_i\
sqlsamp Read/Write ..\examples\emsql\
sysdev Read/Write ..\syslog.nt_i\
testdev Read/Write d:\v30\test\
cddev Read/Only M:\

4-50 Centura Velocis Language Guide


execute ShowUsers

execute Show the list of all Velocis users (DML statement)


ShowUsers

Syntax {execute | exec} ShowUsers

Statement {execute | exec} ShowUsers


Elements Executes a stored procedure that returns a list of
the Velocis users.

Description This statement executes the built-in Velocis stored procedure


ShowUsers, which lists all Velocis users. The procedure retrieves a
result set that contains one row for all currently registered users in
the Velocis catalog. The result set consists of these three columns:

Column Name Type Length Description

USER_NAME char 32 The name of the user


RIGHTS char 10 The user’s access privileges:
"Admin" or "Normal"
HOME_DEVICE char 32 The name of the user’s home device

Only administrator users can execute this statement.

See Also alter user, create user, drop user

Example
exec ShowUsers;

USER_NAME RIGHTS HOME_DEVICE


Randy Normal sqldev
admin Admin catdev
guest Normal catdev
wayne Normal samples

Velocis SQL Statement Reference 4-51


grant

grant Grant user permissions (DML statement)

Syntax grant cmd_spec to user_id[, user_id]...


| grant item_spec to {public | user_id[, user_id]...}
cmd_spec:
all commands [but command [, command]...]
| commands command [, command]...
command:
create database | create view | create procedure
| insert | update | delete | lock table | unlock table
item_spec:
{privilege [, privilege]... | all [privileges]} on table_name
privilege:
select | delete | insert | update [(colname [, colname]...)]

Statement grant cmd_spec to user_id[, user_id]...


Elements Grants command permissions for the specified
users to employ certain commands.

grant item_spec to {public| user_id[, user_id]...}


Grants permission for either all users (public) or
the specified users to have certain access
privileges on a database table.
{privilege [, privilege]... | all [privileges]} on table_name
Specifies the table privileges to grant and the
table on which they take effect. You can grant
all privileges if you wish.
all commands [but command [, command]...]
Grants permission to use all commands. You
may specify commands to exclude from the
permission granting.
commands command [, command]...
Grants permission to use the listed commands.
select | delete | insert | update [(colname [, colname]...)]
Specifies the access privilege to grant for a table.
You may grant permission to query the table
(select), insert or delete rows in the table (insert

4-52 Centura Velocis Language Guide


grant

and delete, respectively), and update the entire


table or specific columns in the table (update).
command: ... Specifies the SQL commands that the user or
users can always use. These commands include
the ability to define a database (create database),
view (create view), or stored procedure
(create procedure), insert or delete table rows
(insert and delete, respectively), update a table
or specific columns in that table (update), and
lock or unlock a table (lock table).

Description This statement allows the system administrator or database owner to


grant two types of user privileges: item privileges and command
privileges. The statement is only used to assign access rights to
normal users. Administrator users always have total database access.
You can use the revoke statement to cancel privileges that have been
granted with the grant statement.
Item privileges are access rights for database tables (base tables and
views). Initially, besides administrators, only the owner of a
database has permission to access that database. Access rights can be
granted by the database owner to other users.
Database security in Velocis is layered between SQL and Velocis
engine-level security. It is administered through the Velocis admin
or rdsadm utility. Individual databases can be marked as global,
which means that all users have retrieval, create, update, and delete
privileges. If a database is not global, the access rights to the
database must be assigned to individual users. These access rights
indicate the kinds of operations that the user can issue on that
database. Besides read access, these rights include create, update,
and delete access.
When issuing a grant statement for a user, the underlying engine-
level security must be consistent with the security that the grant
statement assigns. For example, SQL will not allow you to grant
delete privileges on a table to a user who does not have delete
privileges on the database that contains the table.

Note: If the application specifies a view instead of a table, it can only


use the insert, delete, or update clause to grant item privileges if the
view is updateable (see the description of create view).

Velocis SQL Statement Reference 4-53


grant

Command privileges are simply the Velocis SQL statements that the
user can enter. New user accounts are created by using the Velocis
admin or rdsadm utility or the create user SQL statement. Once the
user account has been created and that user connects to SQL for the
first time, the SQL system only allows that user to issue select
statements. To enable a user to execute other database access
commands (for example, insert or running the sddlp utility), an
administrator user must issue a grant commands statement for that
user.
A SQL user must have both the proper command and table
privileges to be able to perform particular operations on a database.
For example, users who do not have delete command privileges will
not be allowed to issue a delete statement even if they do have delete
table privileges.

Note: User names are specified as identifiers. Identifiers are


automatically converted to uppercase. Velocis allows for mixed-case
user names. Thus, if the ANSI standard form of grant is to be used,
you must install your user names into Velocis as all uppercase
identifiers. Velocis SQL provides a form of the grant statement that
allows user names to be specified as a string. This form, however, is
non-standard.

See Chapter 6 of the Velocis Installation and Administration Guide for


instructions on using the grant statement.

See Also revoke

Example
grant insert, update, delete on salesperson to "Wayne";
grant insert, update, delete on customer to "Randy";
grant insert, update, delete on sales_order to FLORESB;
grant insert, update, delete on item to FLORESB;

4-54 Centura Velocis Language Guide


initialize

initialize Initialize a temporary table (DML statement)

Syntax initialize table_name

Statement table_name Specifies the name of the temporary table to


Elements initialize.

Description This statement quickly initializes the specified temporary table by


deleting all rows. Only the application that created the table (by
using create temporary table) can initialize it.

See Also create temporary table, insert (from select)

Example
initialize sp_sales;
insert into sp_sales
select company, city, state, ord_date, amount
from customer, sales_order
where customer.sale_id = "BNF" and
customer.cust_id = sales_order.cust_id
order by 1, 4;

Velocis SQL Statement Reference 4-55


initialize
database
initialize Initialize a database (DML statement)
database

Syntax initialize database dbname

Statement initialize database dbname


Elements Specifies the name of the database to initialize.

Description This statement can be used to initialize a Velocis database. Before


initializing a database, the database must be closed by all users
(including you) who currently have the database opened.
Execution of this statement is unrecoverable. The only way to restore
the database is to restore from your last backup. If a database
contains rows that are referenced from another database, initializing
the referenced database will invalidate the referential integrity
between those databases.
Only administrator users can execute this statement.

Example
initialize database sales;
initialize database invntory;

4-56 Centura Velocis Language Guide


insert
(from file)
insert Insert rows into a table from a file (DML statement)
(from file)

Syntax insert [with auto commit] into table_name


[from] [ascii | unicode] file "filename" [, "delim"]
[on devname]

Statement insert [with auto commit] into table_name


Elements Specifies the name of the table in which to place
the rows. If with auto commit is specified, a
transaction commit will be issued after each row
is inserted. In this mode, the locks are freed
after each row is stored. However, if errors are
encountered during processing of the insert
statement, the statement will still be terminated,
but Velocis will not discard the changes that
have been made up to that point.
[from] [ascii | unicode] file "filename" [, "delim"]
Specifies the name of the file that contains the
information to insert into the table. The from
statement can be included for clarity, and you
can specify whether the file text is in ASCII (the
default) or Unicode format. You must specify
the single-character field delimiter that the file
uses if it is not a comma (",").
on devname Specifies the device name. If the application
does not specify a device, the file is searched for
in the device for the application (user).

Description This version of the insert statement imports one or more rows from
an ASCII or Unicode file into a table, thus allowing a bulk load of the
table. If a Unicode import file is specified and the corresponding
column or columns in the table are of type char (varchar), the implicit
conversion function is used, and vice versa. The statement requires a
device name so that it can locate the file. If a device is not specified,
the file must reside in the user’s home device.
Values must be specified for all columns in the table. The values
must be listed in the order in which the columns have been declared
in the table. Null values can be specified by using the null keyword.
Default values and auto-generated values (default auto or rowid
primary key columns), if specified in the column definition, will be

Velocis SQL Statement Reference 4-57


insert
(from file)
used for columns that do not have a corresponding value (indicated
by two delimiters in a row, e.g., ",,").

Note: Velocis SQL defines four versions of the insert statement. This
version is for insertion into a table from a file. The other versions of
the statement are insert (from filter), insert (from select) and insert
(values).

During insert processing, if the insert statement finds that an


insertion row violates any integrity constraints defined for the table,
the statement terminates with an error. It automatically rolls back all
rows already inserted (unless with auto commit is specified).
If the number of rows to be inserted is very large, it is recommended
that either an exclusive table lock be first issued on table_name or the
database be explicitly opened in exclusive access mode. Otherwise,
the server will be forced to maintain a growing number of record
locks for the table, which could result in severe performance
degradation on the server.

See Also insert (from select), insert (values), lock table, open
convert (Chapter 5)

Example
insert into outlet file "outlet.asc" on catdev;
commit;

4-58 Centura Velocis Language Guide


insert
(from filter)
insert Insert rows from a filter into a table (DML statement)
(from filter)

Syntax insert [with auto commit] into table_name [(colname [, colname]…)]


from filter filter_name [(value [, value]...)]

Statement insert into table_name[(colname[, colname]…)]


Elements Specifies a table into which to insert rows. To
limit the insertion to certain columns, you can
specify the names of those columns.
[with auto commit]
To have SQL automatically perform a
transaction commit after the insertion of each
row, specify with auto commit. In this mode,
the locks are freed after each row is stored.
However, any errors encountered during insert
statement processing will still terminate the
statement, but changes up to that point are not
discarded. (If the filter was registered with that
option, transaction commits are always
performed regardless of whether the option is
present here.)
from filter filter_name [(value [, value]…)]
Specifies the name of a filter from which rows
are imported. The number, type, and order of
values required by the filter depend on how the
filter was defined. Typical values include a data
input file name and control parameters (such as
delimiters).

Description This statement inserts rows into a table from a user-defined import
filter. Before using this statement, you must define the filter in C,
build the filter module, and execute the create filter statement, which
registers the module. See Chapter 9 of the Velocis User’s Guide for
information on writing a filter.

Note: Velocis SQL defines four versions of the insert statement. This
version is for insertion into a table from a filter function call. The
other versions are insert (from file), insert (from select), and insert
(values).

Velocis SQL Statement Reference 4-59


insert
(from filter)
See Also create filter, insert (from select)
SQL IEF Module Functions (ief Prefix)

Example
insert into game from filter bbscores(date ’1998-09-07’);

4-60 Centura Velocis Language Guide


insert (from select)

insert Insert rows that result from a query into a table, file, or filter
(from select) (DML statement)

Syntax {insert [with auto commit] into table_name [(colname [, colname]...)]


| insert into {file_spec | filter_spec}}
[from] select_stmt
file_spec:
[ascii | unicode] file "filename" [, "delim"] [on devname]
filter_spec:
filter filter_name [(value [, value]...)]

Statement insert into table_name[(colname[, colname]…)]


Elements Specifies a table into which to insert rows. To
limit the insertion to certain columns, you can
specify the names of those columns.
[with auto commit]
If with auto commit is specified, a transaction
commit will be issued after each row is inserted
into a table. In this mode, the locks are freed
after each row is stored. However, any errors
encountered during insert statement processing
will still terminate the statement, but changes up
to that point are not discarded.
insert into {file_spec | filter_spec}
Specifies the insertion of rows into a file or an
export filter.
[from] select_stmt Specifies the select statement from which to
retrieve rows for the insertion. The
from keyword may be added for clarity.
[ascii | unicode] file "filename" [, "delim"] [on devname]
Specifies a file destination for the selected rows.
You can specify a file content of ASCII (the
default) or Unicode text. The default delimiter is
a comma (","), and the default device is the user's
home device.
filter filter_name [(value [, value]...)]
Specifies the name of a filter to which rows are
exported. The number, type, and order of
values that are required by the filter depend on
how the filter was defined. Typical values to use

Velocis SQL Statement Reference 4-61


insert (from select)

include a data output file name and control


parameters (such as delimiters).

Description This version of the insert statement can be used in three ways. First,
the application can use it to put the results of select statement query
processing in a table (usually temporary). Second, the application
can use the file clause with the statement to export data from a
Velocis SQL database into an ASCII or Unicode file. For Unicode
files, implicit conversion is used if the data is exported from a
column of type char (varchar) into a Unicode file and vice versa.
Third, the application can use the statement to copy data into an
export filter, which can be used to process the data and put it in the
appropriate format in an outside target (usually a file). Before using
this form, you must define the filter in C, build the filter module, and
execute the create filter statement, which registers the module. See
Chapter 9 of the Velocis User’s Guide for information on writing a
filter.

Note: Velocis SQL defines four versions of the insert statement. This
version is for insertion of the results of a select statement. The other
versions are insert (from file), insert (from filter), and insert
(values).
When inserting rows in a table, the data type and length of each
result column from the select statement must exactly match the
corresponding column in the table. During processing, if the insert
statement finds that an insertion row violates an integrity constraint
for the table, the statement terminates with an error. It automatically
rolls back all rows that have already been inserted (unless
with auto commit is specified).
An insert statement that uses the insert into file clause places the
results of query processing for a select statement in the specified file
and device. If the application does not specify a device, the file will
reside in the device for the application (user).

See Also create filter, insert (from file), insert (from filter), insert (values),
lock table, open, select
convert (SQL-callable function)
SQL IEF Module Functions (ief Prefix)

4-62 Centura Velocis Language Guide


insert (from select)

Example
create temporary table sp_sales(
company char(30),
city char(17),
state char(2),
ord_date date,
amount float
);
insert into sp_sales
select company, city, state, ord_date, amount
from customer, sales_order
where customer.sale_id = "SKM"
and customer.cust_id = sales_order.cust_id
order by 1, 4;

insert into file "skm0193.asc" on salesdev from


select * from sp_sales
where ord_date between date "1993-01-01"
and date "1993-01-31";

Velocis SQL Statement Reference 4-63


insert
(values)
insert Insert a row into a database table (DML statement)
(values)

Syntax insert into table_name [(colname[, colname]...)]


values ({constant | null} [, {constant | null}]...)

Statement insert into table_name [(colname[, colname]...)]


Elements Specifies the name of the table for which to place
values. You may also specify the columns in the
table for which the values are inserted.

values ({constant | null} [, {constant | null}]...)


Specifies the values to insert into the table. For
non-null constants, use a data type as defined in
Chapter 18 of the Velocis Reference Manual. To
indicate a null value, specify null.

Description This version of the insert statement places a new row in a table or
view. The values clause explicitly specifies the values to be inserted.
The application must include a non-null value for each table column
that holds non-null data. If a column name list is not specified, the
application also needs to define the values in the same order as the
column order that was specified in the create table statement for this
table or view. Any check clauses in the create table statement for the
table must evaluate to TRUE for the insertion to be successful.
If the application specifies a view instead of a table, the view must be
updateable (see the description of create view). If the application has
formed the view by using the with check option clause with the
create view statement, the values in the insert statement must satisfy
the where clause of the create view statement.

Note: Velocis SQL defines four versions of the insert statement. This
version is for insertion of values into a table. The other versions of
the statement are insert (from file), insert (from filter), and insert
(from select).

See Also create view, delete, insert (from file), insert (from select), update

4-64 Centura Velocis Language Guide


insert
(values)
Example The example stores a new customer in the database and connects it to
the salesperson table for Sidney Krieg (SKK).
insert into customer values("PHX", "Cardinal Caskets, Inc",
"1715 Central", "Phoenix", "AZ", "80237", "602-999-1993", "SKK");

Velocis SQL Statement Reference 4-65


lock table

lock table Lock a table for shared/exclusive access (DML statement)

Syntax lock table table_name [[in] share | exclusive [mode]]


[, table_name [[in] share | exclusive [mode]]]...

Statement lock table table_name [[in] share | exclusive [mode]]


Elements Locks the specified table. The table can be read-
locked (share, the default) or write-locked
(exclusive). The in and mode keywords can be
included for clarity.

Description This statement is used to explicitly lock one or more tables. The
statement must specify whether each table has a read lock (share
clause) or a write lock (exclusive clause). Velocis denies the lock
request if any of the lock requests for any of the specified tables are
denied.
By default, Velocis requests the appropriate locks as needed during
the processing of database modification statements. However, this
can result in multiple lock requests, increasing the possibility of lock
contention and possibly requiring the application to rollback
transactions to avoid any potential deadlock situations. With a single
lock request, the lock table statement allows the explicit locking of
all tables that are needed for a transaction.
Your application can free a table lock by issuing a commit or
rollback statement. Read locks can also be freed using the unlock
table command.

See Also commit, rollback, unlock table

Example
lock table product, outlet, on_hand exclusive;
insert into product from file "product.asc" on catdev;
insert into outlet from file "outlet.asc" on catdev;
insert into on_hand from file "onhand.asc" on catdev;
commit;
update stats on invntory;

4-66 Centura Velocis Language Guide


mark

mark Mark a transaction rollback point (DML statement)

Syntax mark [trans | transaction | work] mark_id

Statement mark [trans | transaction | work] mark_id


Elements Specifies a transaction mark and a mark
identifier. The trans, transaction, or work
keyword can be included for clarity.

Description This statement marks a rollback point in a transaction (a save point),


which is used in rollback processing to undo a portion of changes
without having to abort the entire transaction. Velocis discards all
database modifications that have been made between execution of
the mark statement and execution of a subsequent rollback
statement that uses the same mark_id.

Note: The application can use the commit statement to commit all
modifications that have been made in a single transaction. Therefore,
a commit operation must not use the mark_id marker.

See Also begin, commit, rollback

Example
begin transaction new_order;
/* get new customer info */
insert into customer values(...);
mark transaction order_info;
/* get sales order info */
insert into sales_order values(...)
/* get product info */
if insufficient quantity
rollback order_info;
commit transaction new_order;
/* at minimum the new customer will be entered */

Velocis SQL Statement Reference 4-67


open

open Open a database or databases (DML statement)

Syntax open dbname [, dbname]...


[[as] {shared | temporary | read
| exclusive [with transaction off]}]

Statement open dbname [, dbname]...


Elements Specifies the names of the databases to open.
[[as] {shared | temporary | read
Specifies the mode in which to open the
database. The as keyword can be included
for clarity. In shared mode (the default), the
database can be accessed by multiple users.
In temporary mode, the database is initially
empty, data that is inserted into the database
is private (that is, visible only to the one user
connection), and executing a close statement
discards the data. In read mode, the user is
prohibited from executing any database
modification statements.
exclusive [with transaction off]}]
Specifies opening the database in exclusive
mode. In this mode, the database is private
and accessible by only one user. To speed
operation, an exclusive database can be
opened without having to log transactions
(with transaction off), but this means that
rollback or recovery cannot be performed.

Description This statement opens the specified databases in shared, temporary,


read, or exclusive mode, as described. If the application does not
explicitly open the database before using it, Velocis automatically
opens it in shared mode.
If your application attempts to open an existing database (that is, one
that already contains data) in temporary mode, it cannot access the
data in the permanent database. Velocis automatically creates a new
database with the same definition.

See Also close

4-68 Centura Velocis Language Guide


open

Example
..do as fast a load as possible
open invntory exclusive with transaction off;
insert into product from file "product.txt" on catdev;
insert into outlet from file "outlet.txt" on catdev;
insert into on_hand from file "onhand.txt" on catdev;
commit;
close invntory;
update stats on invntory;

Velocis SQL Statement Reference 4-69


revoke

revoke Revoke user permissions (DML statement)

Syntax revoke cmd_spec from user_id [, user_id]...

| revoke item_spec from {public | user_id[, user_id]...}


cmd_spec:
all commands [but command [, command]...]
| commands command [, command]...
command:
create database | create view | create procedure
| insert | update | delete | lock table | unlock table
item_spec:
{privilege [, privilege]... | all [privileges]} on table_name
privilege:
select | delete | insert | update [(colname [, colname]...)]

Statement revoke cmd_spec from user_id [, user_id]...


Elements Revokes permission from a user or users to
employ certain commands.
revoke item_spec from {public | user_id[, user_id]...}
Revokes permission of certain table privileges
from all users (public) or the specified users.
all commands [but command [, command]...]
Denies permission from use of all commands.
You may specify commands to exclude from the
permission revocation.
commands command [, command]...
Denies permission for use of the listed
commands.
command: ... Specifies the SQL commands that the user or
users can never use. These commands include:
defining a database (create database)
creating a view (create view)
creating a stored procedure (create procedure)
inserting (insert) or deleting (delete ) table rows
updating a table or table columns (update)
locking or unlocking a table (lock table)

4-70 Centura Velocis Language Guide


revoke

{privilege [, privilege]... | all [privileges]} on table_name


Specifies the table privileges to revoke and the
table on which they take effect. You can deny all
privileges if you wish.
select | delete | insert | update [(colname [, colname]...)]
Specifies the privilege on which to revoke user
permission for a table. You may deny
permission to query the table (select), insert or
delete rows in the table (insert and delete,
respectively), and update the entire table or
specific columns in the table (update).

Description This statement allows the system administrator or database owner to


deny user privileges. The statement is only used to modify access
rights assigned to normal users. Administrator users always have
total database access.
There are two types of user privileges: item privileges and command
privileges. Item privileges are access rights for database tables (base
tables and views). Command privileges are simply the Velocis SQL
statements that the user can enter. See Chapter 6 of the Velocis
Installation and Administration Guide for instructions on using the
revoke statement.

Note: When the application revokes the select privilege on a table,


Velocis automatically drops all views that the application (user) has
defined on that table.

See Also grant

Example
-- only administrators can modify the salesperson table
revoke insert, delete on salesperson from "Wayne", FLORESB;

Velocis SQL Statement Reference 4-71


rollback

rollback Discard all changes made since a transaction start or mark


(DML statement)

Syntax rollback [trans | transaction | work] [trans_id]

Statement rollback [trans | transaction | work] [trans_id]


Elements Undoes all changes made since execution of the
last mark, begin, commit, or open statement.
The trans, transaction, or work keyword can be
included for clarity.

Description This statement discards all database changes that have been made
since the most recent of the following events, which are listed in
order of Velocis SQL priority:
1. Execution of a mark statement, where the mark identifier must
be the same as the specified transaction identifier
2. Execution of a begin statement
3. Execution of a commit statement
4. Execution of an open statement for the database
5. Beginning of the login session.

See Also begin, commit, mark

Example
begin work;
... /* make some changes to the database */

... /* system detects invalid data */


rollback work;

4-72 Centura Velocis Language Guide


select

select Retrieve columns and rows (DML statement)

Syntax select [first | all | distinct]


{* | select_item [, select_item]…}
from tabname [, tabname]...
[where cond_expr]
[with exclusive lock | [group_by] order_by]
alias:
identifier | "alt_hdg"
select_item:
{tabname | corname}.* | expression [alias]
tabname:
[dbname.]table_name [corname]
group_by:
group by col_ref [, col_ref]... [having cond_expr]
order_by:
order by col_ref [asc | desc] [, col_ref [asc | desc]]...
col_ref:
number | [[dbname.]tabname.]colname

Statement select [first | all | distinct]


Elements Specifies conditions on the size of the result set.
To retrieve only the first row of the result set,
specify first. To retrieve all rows, including
duplicates, specify all (the default). To exclude
duplicate rows, specify distinct. (When distinct
is specified, Velocis SQL sorts the entire result
set to check for duplicate rows, which can be
time-consuming for large result sets.)
{* | select_item [, select_item]…}
Specifies the list of columns to be returned from
the result set. To retrieve all columns in the
tables listed in the from clause, specify an
asterisk.
{tabname | corname}.* | expression [alias]
To retrieve all columns in one of the tables listed
in the from clause, specify the table (or
correlation name) followed by ".*". To retrieve

Velocis SQL Statement Reference 4-73


select

only certain columns, specify either the name of


the column or an arithmetic expression that
involves table columns, a literal constant, or a
function. Multiple column names and
expressions can be specified, and an alias can be
given for each one.
from tabname [, tabname]...
Specifies the table or tables from which to
retrieve data.
[where cond_expr] Defines the condition which must be satisfied by
each result row of the select statement.
with exclusive lock
This clause instructs the system to place a write
lock on each row of the result set. It can only be
specified with updateable select statements
(thus, you cannot specify it with an order by or
group by clause). Its use is execution of a
subsequent update on one or more of the
retrieved rows.
alias: identifier | "alt_hdg"
Specifies an identifier or an alternate heading
string for a column expression. An order by or
group by clause can refer to the alias.
[dbname.]table_name [corname]
Specifies a table from which to retrieve data.
The database name can be used to qualify a table
name, and a correlation name can be specified
for use as an alias for a table. Correlation names
are used to distinguish between multiple
references to the same table. The table_name is
the name of a base table or a view.
group by col_ref [, col_ref]... [having cond_expr]
Specifies a group by clause, which identifies the
columns for which aggregate computations are
made during the selection process. The optional
having clause defines a condition to apply to the
resultant rows after the group by is processed,
and it includes comparisons that involve the
aggregate calculation functions in the select
statement.

4-74 Centura Velocis Language Guide


select

order by col_ref [asc | desc] [, col_ref [asc | desc]]...


Specifies an order by clause, which identifies the
columns by which to sort the result set. For each
column, you can specify whether to sort in
ascending (asc, the default) or descending (desc)
order.
col_ref: number | [[dbname.]tabname.]colname
Specifies either a column name (including the
table name and database name, if necessary) or
the ordinal position of the column in the column
reference list (for example, 1 for the first column,
2 for the second column, etc.). The first column
listed is the major sort column.

Description This statement retrieves a subset of data (the result set) from a table
or tables. The result set contains rows that satisfy a conditional
expression (where clause). If there is no condition for the where
clause, the select statement retrieves all rows from the table. If the
select statement includes a group by clause, only rows that satisfy
the where clause are reflected in grouping calculations.
The with exclusive lock clause causes Velocis to exclusively lock any
rows that were selected by the select statement. If a transaction has
not been started, this clause will start one automatically. To free the
locks, roll back or commit the transaction. (This can be done even if
no update or delete operation has been performed; in this case,
Velocis simply releases the exclusive locks.)
When using with exclusive lock, if Velocis times out while trying to
upgrade the lock to an exclusive lock, Velocis frees the read lock that
is currently held on the row. This action enables other processes to
obtain an exclusive lock on the row. To refetch the row, call
SQLFetch, which attempts to get an exclusive lock on the row.
The group by clause defines a set of aggregate rows upon which
computations are to be made. An aggregate consists of those rows
that have identical values in the columns that are named in the
group by specification. Each of the other selected columns should
either have a unique value within each aggregate or be a
computation that uses of one or more calculation functions (sum,
avg, min, max, count, or an aggregate UDF). Only one row is
reported for each aggregate resulting from the select.

Velocis SQL Statement Reference 4-75


select

The having clause is similar to the where clause in that it is used to


conditionally select which resultant rows will be reported. However,
the having conditional expression is not evaluated until after the
group by processing has been performed. The conditional
expression will include comparisons that typically involve the
calculation functions in the select column list.
Refer to Chapter 9 of the Velocis User’s Guide for details of select
statement processing.

Example
select company, ord_num, ord_date, amount, tax, amount+tax total
from customer, sales_order
where customer.cust_id = sales_order.cust_id;

select sale_name, amount from salesperson, customer, sales_order


where amount >= 10000.00
and salesperson.sale_id = customer.sale_id
and customer.cust_id = sales_order.cust_id
order by amount desc;

select company, city, state, phone from customer


where company like "Micro%";

select sale_name, company, city, state


from salesperson s, customer c
where s.sale_id = c.sale_id
and state in ("ID", "OR", "WA")
order by state;

select company, ord_date, amount from customer, sales_order


where customer.cust_id = sales_order.cust_id and
ord_date between @"93-06-01" and @"93-06-30";

select sale_id, sum(amount), avg(amount), min(amount), max(amount)


from salesperson, customer, sales_order
where salesperson.sale_id = customer.sale_id
and customer.cust_id = sales_order.cust_id
group by sale_name;

4-76 Centura Velocis Language Guide


set currency

set currency Set the default currency symbol (DML statement)

Syntax set currency to "char"

Statement set currency to "char"


Elements Specifies the currency symbol used. The system
default currency symbol is the dollar sign ("$").

Description This statement sets the default currency symbol to the specified
character value. The symbol is used by the convert function, which
is one of the built-in functions used with Velocis SQL statements as
described in Chapter 9 of the Velocis User’s Guide.
The user can assign the specified currency symbol for use until it is
changed using another set currency statement or the user
disconnects from the server. Only the system administrator can
permanently set the value by adding this line to the [SQL] section of
velocis.ini.
CurrSymb=char
Refer to Chapter 6 in the Velocis Installation and Administration Guide
for more information.

See Also set display


convert function

Example
set currency to "£";
select ord_date, convert(amount, char, 12, "£#,#.##") amount
from sales_order;

Velocis SQL Statement Reference 4-77


set date default

set date default Set the default date constant format (DML statement)

Syntax set date default to "format"

Statement set date default to "format"


Elements Specifies a string that represents the new date
format. Possible values are:
1. "MM-DD-YYYY"
2. "YYYY-MM-DD"
(the system default; conforms to
ODBC specification)
3. "DD-MM-YYYY"

Note: The administrator can replace the hyphen (-) separator with
any special character except a colon (":"). For example,
"MM/DD/YYYY" is a valid date format.

Description This statement sets the format for date constants. Changes made
using the set date default statement apply only to the current session
for the user making the change. Only the system administrator can
permanently change the system default, by adding this line to the
[SQL] section of velocis.ini:
DateFormat=num
For this environment variable, you need to specify the number that
corresponds to the desired format above. See Chapter 6 of the Velocis
Installation and Administration Guide for more information.

See Also set display

Example
set date default to "MM/DD/YYYY";
select ord_num, ord_date, amount from sales_order
where ord_date between date "06/01/1993"
and date "06/30/1993";

4-78 Centura Velocis Language Guide


set decimal

set decimal Set the default decimal symbol (DML statement)

Syntax set decimal to "char"

Statement set decimal to "char"


Elements Specifies a new value for the decimal symbol.
The system default is a period (".").

Description This statement sets the default decimal symbol to the specified
character value. This symbol is used by the convert function, as
described in Chapter 9 of the Velocis User’s Guide.
The user can assign the specified decimal symbol for use until it is
changed using another set decimal statement or the user disconnects
from the server. The system administrator can permanently
configure the decimal symbol by adding this line to the [SQL] section
of velocis.ini:
DecSymb=char
Refer to Chapter 6 of the Velocis Installation and Administration Guide
for more information.

See Also convert (SQL-callable function)

Example
set decimal to ",";
set thousands to "."
select ord_date, convert(amount, char, 12, "#.#,##") amount
from sales_order;

Velocis SQL Statement Reference 4-79


set display

set display Set the default character display format (DML statement)

Syntax set type display(width, "format")


type:
char | wchar | smallint | integer | real | double | decimal |
date | time | timestamp

Statement set type display(width, "format")


Elements Specifies the character width and the display
format for a data type. For details, see the usage
instructions for the convert function in
Chapter 9 of the Velocis User’s Guide.

Description This statement sets the default character display format for a data
type. This format applies to result sets that are displayed after
execution of a select statement. The user can assign a format for use
until it is changed by another set display statement or the user
disconnects from the server. It cannot be changed system-wide and
permanently, but a login procedure can be used to the same effect.

See Also set login, set login proc/set logout proc


convert function

Example
set float display(16,"$#,#.##");
select ord_date, amount from sales_order where ord_num = 2206;

ORD_DATE AMOUNT

01-02-1993 $15,753.19

4-80 Centura Velocis Language Guide


set login

set login Enable or disable the use of login/logout procedures


(DML statement)

Syntax set login to {on | off}

Statement set login to {on | off}


Elements Indicates whether to allow the use of
login/logout procedures. Specify on or off to
enable or disable their use, respectively.

Description The set login statement is used to turn the use of login/logout
procedures on or off. The effect is system-wide, and it will persist
until the next set login statement is issued by any administrator user.
Use of login procedures is initially turned off. Only administrator
users can issue this statement.
Login/logout procedures are stored procedures that the SQL system
calls automatically whenever a user connects to or disconnects from a
server. Two types of login/logout procedures are available:
• Public login/logout procedures are called whenever any user
connects or disconnects with the server.
• Private login/logout procedures are associated with particular
users and are only called when those users connect or disconnect.
If both a public and a private procedure have been defined for a user,
both procedures are called; the public procedure is called before the
private procedure.
Login/logout procedures cannot return a result set and cannot have
arguments. They are typically used for setting user environment
values (e.g., display formats) or for performing specialized security
functions. A login or logout procedure can be written either as a
standard SQL stored procedure or as a C-based, user-defined
procedure.

See Also set login proc

Velocis SQL Statement Reference 4-81


set login proc
set logout proc
set login proc Set a login or logout procedure for a one or more users
set logout proc (DML statement)

Syntax set {login | logout} proc for {public | user [, user]...}


to {procname | null}

Statement set {login | logout} proc for {public | user [, user]...}


Elements Specifies the names of users for which to use the
login/logout procedure. To call the procedure
for all users, specify public.

to {procname | null}
Specifies the name of the stored procedure or
UDP to call. To stop using the current
login/logout procedure, specify null.

Description The set login proc and set logout proc statements are used to
register login and logout procedures. Private login/logout
procedures are specified by including a list of users for whom the
procedures apply. The user name is either an identifier or a string.
The SQL lexical analyzer converts the identifiers to uppercase, so
they will only match uppercase user names. Mixed-case user names
must be specified by using string literals (for example, "Wayne"). To
de-register a login/logout procedure, specify null.
Only administrator users can issue this statement.

See Also set login

Example
create proc german as
set currency to "dm";
set date display(12, "yyyy mmm dd");
set decimal to ",";
set thousands to ".";
set decimal display(20, "#.#,##’ dm’");
end proc;
set login proc for "Kurt", "Wolfgang", "Helmut", "Werner"
to german;

4-82 Centura Velocis Language Guide


set opt_limit

set opt_limit Set the failure-to-improve threshold for the Velocis SQL query
optimizer (DML statement)

Syntax set opt_limit to constant

Statement set opt_limit to constant


Elements Defines a value to set for the failure-to-improve
threshold. To disable the failure-to-improve
check so that the Velocis SQL query optimizer
will always run to completion, specify 0; the
optimizer will then check all possible access
plans.

Description This statement sets the failure-to-improve threshold of the Velocis


SQL query optimizer to the specified value for the current session.
Only an administrator user can issue the statement. The system
default can be changed by adding this line to the [SQL] section of
velocis.ini.
OPTLimit=constant
Refer to Chapter 6 of the Velocis Installation and Administration Guide
for more information.
The failure-to-improve threshold limit is included in the Velocis SQL
query optimizer algorithm. It is based on the number of step
iterations in the access plan. If the algorithm fails to generate a better
access plan within the specified number of iterations, the optimizer
stops and uses the best plan found up to that point. The number of
iterations that the algorithm processes depends on the number of
tables that are being accessed and the number of usable access
methods that can be chosen.
Reducing the threshold limit results in faster optimization of
complex queries, but it can also lead to a less-than-optimal access
plan. Increasing (or disabling) this value improves the chances of
producing the best access plan.
The time required to optimize a query grows exponentially with the
number of tables specified in the from clause of the select statement.
The time is negligible for up to about eight to ten tables. For ten or
more tables, the time that is required to optimize can become quite
noticeable. The algorithm that is used by the query optimizer will
often, but not always, determine the best access plan early in the
optimization phase.

Velocis SQL Statement Reference 4-83


set read repeatability

set read Set transaction read repeatability mode (DML statement)


repeatability

Syntax set read repeatability {on | off}

Statement set read repeatability {on | off}


Elements Specifies whether to enable transaction read
repeatability mode. If this statement is missing,
read repeatability is disabled.

Description This statement sets transaction read repeatability mode. Read


repeatability mode ensures that, within a transaction, any rows that
have been previously read are guaranteed to be unaltered when
those rows are re-fetched. To enforce read repeatability, Velocis SQL
places a read lock on all rows that are fetched within the transaction,
and it holds those locks until the transaction is either committed or
rolled back.
Velocis SQL operates by default with read repeatability turned off;
instead, it operates in cursor stability mode. This mode places a read
lock on each row when it is fetched from the database. If the row is
modified (for example, through a positioned update), the read lock is
upgraded to a write lock, and, if granted, the modification is
performed. If the row is not modified, the read lock is freed when
the next row is fetched. Thus, in this mode it is possible for a
previously fetched row to have been modified or deleted by another
user if it is refetched later within that same transaction. The write
locks on modified rows remain in place until the transaction ends.
See Chapter 8 of the Velocis User’s Guide for a discussion of
transaction processing.

See Also set transaction isolation

4-84 Centura Velocis Language Guide


set thousands

set thousands Set the numeric (thousands) separator character (DML statement)

Syntax set thousands to "char"

Statement set thousands to "char"


Elements Specifies a new value for the numeric thousands
separator. The system default is a comma (",").

Description This statement sets the default numeric thousands separator symbol
to the specified character value. This symbol is used by the convert
function as described in Chapter 9 of the Velocis User’s Guide.
The user can assign a symbol for the numeric thousands separator
until it is changed by another set thousands statement or the user
disconnects from the server. A system administrator can
permanently configure the separator symbol by adding this line to
the [SQL] section of velocis.ini:
ThouSymb=char
Refer to Chapter 6 of the Velocis Installation and Administration Guide
for more information.

See Also set decimal

Example
set decimal to ",";
set thousands to "."
select ord_date, convert(amount, char, 12, "#.#,##") amount
from sales_order;

Velocis SQL Statement Reference 4-85


set timeout

set timeout Set the lock waiting timeout value (DML statement)

Syntax set timeout to constant

Statement set timeout to constant


Elements Specifies a new value, in seconds, for the lock
waiting timeout. The system default is
30 seconds.

Description This statement sets the waiting timeout value for locks, which are
placed on accessed table rows to synchronize database access among
multiple users. This value can be changed for the session in which it
is issued. To permanently change the system default lock waiting
timeout, the system administrator can add this line to the [SQL]
section of velocis.ini:
LockTime=constant
Refer to Chapter 6 of the Velocis Installation and Administration Guide
for more information. Refer to Chapter 3 of the Velocis User’s Guide
for details of lock management for Velocis databases.

Note: In general, Velocis issues read locks for select statements, and
write locks for update and delete statements.

See Also delete, select, update

Example
set timeout to 5;

4-86 Centura Velocis Language Guide


set transaction isolation

set transaction Set transaction isolation mode (DML statement)


isolation

Syntax set transaction isolation {on | off}

Statement set transaction isolation {on | off}


Elements Specifies whether to enable transaction isolation
mode. If this statement is omitted, the mode is
enabled (on) by default.

Description This statement sets the transaction isolation mode. In the ANSI SQL
standard uncommitted changes that are made within a transaction
can be visible only to the task that is executing the particular
transaction. To enforce this requirement, Velocis SQL places the
appropriate locks on all accessed and modified rows. The rows that
have been modified within a given transaction remain write-locked
until the transaction commits or is rolled back. Until such time, the
write-locked rows cannot be accessed by any other task. This
standard operating mode is called transaction isolation.
A session that has disabled transaction isolation is in dirty read
mode. In this mode, a session can read information from a database
without having to place read locks on the accessed rows. Although
this behavior ensures that the task will never have to wait to see the
results, the reading task will be able to access changes that are still
uncommitted.
If a task has turned off transaction isolation, the resulting rows of a
select statement that is executed outside of a transaction are not
locked and may, therefore, be "dirty." However, the rows that are
fetched from a query that is executed within a transaction are locked
according to the rules governed by the read repeatability mode.
See Chapter 8 of the Velocis User’s Guide for a discussion of
transaction processing.

See Also begin, set read repeatability

Velocis SQL Statement Reference 4-87


set wild

set wild Set the wildcard pattern-matching character (DML statement)

Syntax set wild {all | one} to "char"

Statement set wild {all | one} to "char"


Elements Changes the character to use for wildcard
pattern matching. Specifying all sets the symbol
for matching zero, one, or many characters
(default is "%"). Specifying one sets the symbol
for matching a single character (default is "_").

Description This statement changes the wildcard pattern-matching characters


that can be used in the like relational operator. The new wildcard
pattern-matching character is valid only for the application that
issues the set wild statement, and the new setting remains in effect
until the user disconnects from the server. To permanently change
the system default wildcard pattern matching character, a system
administrator can enter the following lines in the [SQL] section of
velocis.ini.
Wildall=char_all
Wildone=char_one
See Chapter 6 of the Velocis Installation /Administration Guide for more
information.

See Also select


Conditional expressions (Chapter 3)

Example
set wild one to "?";
set wild all to "*";
select company, city, state from customer
where cust_id like "S??" and company like "*Corp*";

4-88 Centura Velocis Language Guide


unlock table

unlock table Free the lock on a shared table (DML statement)

Syntax unlock table table_name [, table_name]...

Statement unlock table table_name [, table_name]...


Elements Specifies the names of the shared tables to
unlock.

Description This statement explicitly unlocks a table that was locked in shared
mode by a lock table statement. To unlock a locked table
automatically, use the commit or rollback statement. For details on
locking, see Chapter 8 in the Velocis User’s Guide.

See Also commit, lock table, rollback

Example
lock table customer, sales_order in share mode;

select company, sum(amount), sum(tax) from customer, sales_order


where customer.cust_id = sales_order.cust_id and sale_id = "SWR"
group by 1;

unlock table customer, sales_order;

Velocis SQL Statement Reference 4-89


update

update Update rows in a table (DML statement)

Syntax update table_name


set column_name = {expr | null} [, column_name = {expr | null}]...
where {cond_expr | current of cursor_name}

Statement update table_name Specifies the name of the table or view where
Elements the update occurs.
set column_name = {expr | null} [, column_name = {expr | null}]...
Specifies the names of the columns to update
and their new values. You may specify null as a
column value.
where {cond_expr | current of cursor_name}
Specifies the row or rows where the update
occurs. To update the rows for which a certain
condition is met, use a conditional expression.
To update the current row for a particular
cursor, use the current of clause.

Description This statement modifies the column values in one or more rows from
the specified table. The statement sets the column values to the
results of the specified expressions or null.
The update statement is capable of two types of updates: searched
updates and positioned updates. In a searched update, the update
statement modifies all rows of the table that satisfy a conditional
expression. In a positioned update, the update statement modifies
the current row that is associated with a cursor.

Note: An application can request a positioned update only if a


cursor has been previously defined by a call to SQLGetCursorName
or SQLSetCursorName in the Velocis SQL API.

If a primary or unique key is referenced by foreign keys, the update


statement can update columns that make up this key only when no
references are active. However, if all referencing foreign keys are
part of a predefined join, the update is allowed. Because all the
foreign key columns are virtual, there is no redundant data.
If execution of the update statement violates any integrity constraints
for the table, the statement is aborted, and Velocis SQL reports the
error. It discards all updates made by the statement up to the time of

4-90 Centura Velocis Language Guide


update

the error. (This behavior only applies to searched updates, because a


positioned update can only update a single row.)
The update statement works on a view only if the view is
updateable. (See the create view statement for details.) If the view
has been created by using the with check option clause in the
create view statement, the column values used in the update
statement must satisfy the where clause of the originating select
statement.
See Chapter 9 of the Velocis User’s Guide for instructions on how to
use the update statement.

See Also create view, delete, insert, select

Example In the following example, the update statement moves all of Mont
Green’s (MFG) customer accounts to Sidney Krieg (SK).
update customer
set sale_id = "SKK"
where sale_id = "MFG";

Velocis SQL Statement Reference 4-91


update stats

update stats Update database usage statistics (DML statement)

Syntax update {stats | statistics} on db_name [, db_name]...

Statement update {stats | statistics} on db_name [, db_name]...


Elements Specifies the names of the databases for which to
update usage statistics.

Description This statement updates the database usage statistics that the Velocis
SQL query optimizer uses to generate query execution plans. Only
administrator users can execute this statement.
By executing the update stats statement, the application collects
database usage statistics and stores them in the system catalog. The
optimizer uses these statistics until the next time update stats is
executed. Therefore, the application should execute this statement
whenever a significant number of database modifications have
occurred.

See Also set opt_limit

Example
update stats on sales, invntory;

4-92 Centura Velocis Language Guide


Chapter 5
Velocis SQL-Callable Functions
This chapter presents the functions that your application can call from Velocis SQL
statements. These functions include the scalar (built-in) functions, the aggregate
(calculation) functions, and the conditional selection function if. Function references are
arranged in alphabetical order.

Velocis SQL-Callable Functions 5-1


abs

abs Retrieve the absolute value of an expression

Syntax abs(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This scalar numeric function retrieves the absolute value of the
specified arithmetic expression.

5-2 Centura Velocis Language Guide


acos

acos Retrieve the arccosine of an expression

Syntax acos(arith_expr)

Parameters arith_expr An arithmetic expression with a value between -1.0


and +1.0.

Description This scalar numeric function retrieves the arccosine, in radians, of the
specified arithmetic expression.

Velocis SQL-Callable Functions 5-3


ascii

ascii Retrieve the numeric ASCII value of a character

Syntax ascii(strexp)

Parameters strexp A string expression.

Description This scalar string function retrieves the ASCII numeric value of the
initial character in the specified string expression.

5-4 Centura Velocis Language Guide


asin

asin Retrieve the arcsine of an expression

Syntax asin(arith_expr)

Parameters arith_expr An arithmetic expression with a value between -1.0


and +1.0.

Description This scalar numeric function retrieves the arcsine, in radians, of the
specified arithmetic expression.

Velocis SQL-Callable Functions 5-5


atan

atan Retrieve the arctangent of an expression

Syntax atan(arith_expr)

Parameters arith_expr An arithmetic expression with a value between -∞


and +∞.

Description This scalar numeric function retrieves the arctangent, in radians, of


the specified arithmetic expression.

5-6 Centura Velocis Language Guide


atan2

atan2 Retrieve the arctangent of an x-y coordinate pair

Syntax atan2(arith_exprx, arith_expry)

Parameters arith_exprx The x coordinate.


arith_expry The y coordinate.

Description This scalar numeric function retrieves the arctangent, in radians, of


the specified x and y coordinates.

Velocis SQL-Callable Functions 5-7


avg

avg Compute the average of the results for an aggregate result set

Syntax avg (arith_expr)

Parameters arith_expr An arithmetic expression.

Description This aggregate (calculation) function computes the average of the


results of the specified expression for all rows of an aggregate result
set.

Example
select sale_name,
convert(avg(amount), char, 10, "$#,#.##") "avg sale amt"
from salesperson, customer, sales_order
where salesperson.sale_id = customer.sale_id
and customer.cust_id = sales_order.cust_id
group by 1;
sale_name avg sale amt
Flores, Bob $19,233.56
Jones, Walter $28,170.70
Kennedy, Bob $61,362.11
McGuire, Sidney $18,948.37
Nash, Gail $34,089.70
Porter, Greg $87,869.30
Robinson, Stephanie $24,993.63
Stouffer, Bill $3,631.66
Warren, Wayne $21,263.85
Williams, Steve $27,464.44
Wyman, Eliska $23,617.38

5-8 Centura Velocis Language Guide


c_data

c_data Extract an element of a c_data column

Syntax c_data(col[dims] [, elt[dims]])

Parameters col The c_data column from which to extract data.


dims The array element of the column and/or structure to
retrieve.
elt The structure element to retrieve. This parameter is
used only if the column is a structure.

Description This system function extracts an element of a c_data column. This


function is a Velocis SQL scalar function called from a select
statement. The Velocis SQL application can qualify the specified
column name with the table or correlation name (for example,
cd1.cd1_t03).
If the c_data column is an array, it must include the appropriate
number of subscripts, specified in the normal C-language notation.
A subscript can be any expression that retrieves a smallint value
(parameter markers are allowed). If the c_data column is a structure,
the structure member must be specified.

Velocis SQL-Callable Functions 5-9


ceiling

ceiling Find the upper bound for an expression

Syntax ceiling(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This scalar numeric function retrieves an upper bound (ceiling) for
the specified arithmetic expression. The ceiling is the smallest
integer greater than or equal to the expression.

5-10 Centura Velocis Language Guide


char

char Retrieve an ASCII character

Syntax char(num)

Parameters num An ASCII code value between 0 and 255.

Description This scalar string function retrieves the ASCII character that
corresponds to the specified code value.

Velocis SQL-Callable Functions 5-11


concat

concat Concatenate two strings

Syntax concat(strexp1, strexp2)

Parameters strexp1 The string to which the function concatenates a


second string (strexp2).
strexp2 The string to be concatenated.

Description This scalar string function concatenates one string (strexp2) to another
(strexp1). The operation is the same as using the concatenation ("^")
operator.

5-12 Centura Velocis Language Guide


convert

convert Convert an expression to a data type or a character string

Syntax convert(expr, type)


convert(expr, {char | wchar}, width, "fmt")

Parameters expr The expression to convert.


type A data type. Possible types are listed below and
defined in Chapter 19 of the Velocis Reference Manual.
• char
• wchar
• smallint
• integer
• real
• float
• decimal
• date
• time
• timestamp
char | wchar Specifies the result type when using the second form
of the convert function specified above.
width The width, in bytes, of the character string.
fmt The character string format to use for numeric values
or date/time values. The types of format specifiers
are described in the Numeric Format Specifier and
Date/Time Format Specifier sections below.

Description This system function converts an expression to a different type or


string representation. There are two forms of this function.
The first form of this function, shown above, converts an expression
to the specified data type. The second form converts an expression
to a character string in the specified format. See Chapter 7 of the
Velocis User’s Guide for details on using the convert function.

Velocis SQL-Callable Functions 5-13


convert

Numeric Format The format specifier for numeric values is represented as shown in
Specifier the box below. The minimum specifier that must be used for a
numeric format is "#". If the display field width (width parameter) is
too small to contain a numeric value, the convert function formats
the value in exponential format (for example, 1.759263e08).

"[<< | >> | ><][’text’ | $][- | (][#,]#[.#[#]...][e | E][’text’ | $ | %]"


The elements for this specifier are explained below:
[<< | >> | ><]
The justification specifier. You can specify left-justified
text (<<), right-justified text (>>), or centered text (><).
The default for numeric values is right-justified.
[’text’ | $] A text character or string to use as a prefix for the result
string. You must enclose the character or text with single
quotation marks unless the prefix is one dollar sign.
[- | (] The display specifier for negative values. You can show
negative values with a minus sign or with parentheses
around the value. If parentheses are used, positive
values are shown with an ending space to ensure
alignment of the decimal point.
[#,]#[.#[#]...]
The numeric format specifier. You can specify whether
to show commas every third place before the decimal
point. Also, you can specify how many digits (if any) to
show after the decimal point.
[e | E] Whether to use exponential format to show numeric
values. If this option is omitted, exponential format is
used only when the value is too large or small to be
shown otherwise. You can specify display of an
lowercase or uppercase exponent indicator.
[’text’ | $ | %]
A text character or string to use as a suffix for the result
string. You must enclose the character or text with single
quotation marks unless the suffix is one dollar or percent
sign.

5-14 Centura Velocis Language Guide


convert

Date/Time Format The box below shows the format specifier for date/time values. The
Specifier date/time format specifier can contain any number of text items or
special characters that are interspersed with the date or time codes.
You can arrange these items in any order, but a time specifier must
adhere to the ordering rules described below under "time_code".

"[<< | >> | ><][’text’ | spchar | date_code | time_code]..."


date_code:
m | mm | mmm | mon | mmmm | month
| d | dd | ddd | dddd | day
| yy | yyyy
time_code:
h| hh | m | mm | s|ss | .f[f]...
| a/p | am/pm | A/P | AM/PM]
where:
[<< | >> | ><]
The justification specifier. You can specify left-justified
text (<<), right-justified text (>>), or centered text (><).
The default for numeric values is left-justified.
’text’ | spchar
A string or a special character (for example, "-", "/", or ".")
to be copied into the result string. The special character
is often useful in separating the entities within a date
and time.
date_code
Specifies a date formatting element as follows:
m month number (1-12) without a leading zero
mm month number with a leading zero
mmm three-character month abbreviation (e.g., "Jan")
mon same as mmm
mmmm fully spelled month name (e.g., "January")
month same as mmmm
d day of month (1-31) without leading zero
dd day of month with leading zero
ddd three character day of week abbreviation
(e.g., "Wed")

Velocis SQL-Callable Functions 5-15


convert

dddd fully spelled day of week (e.g., "Wednesday")


day same as dddd
yy two-digit year AD with leading zero if year
between 1950 and 2049; otherwise same as
yyyy.
yyyy year AD up to four digits without leading zero
time_code
The time formatting elements are defined below. For the
minute codes to be interpreted as minutes (and not
months) they must follow the hour codes. You cannot
specify the minutes of a time value without also
specifying the hour. You can specify the hour by itself.
Similarly, you cannot specify the seconds without having
specified minutes and you cannot specify fractions of a
second without specifying seconds. Thus, the order
"hours, minutes, seconds, fractions" must be preserved.
h hour of day (0-12 or 23) without leading zero
hh hour of day with leading zero
m minute of hour (0-59) without leading zero
(only after h or hh)
mm minute of hour with leading zero
(only after h or hh)
s second of minute (0-59) without leading zero
(only after m or mm)
ss second of minute with leading zero
(only after m or mm)
.f[f]… fraction of a second: four decimal place
accuracy (only after s or ss)
a/p | am/pm | A/P | AM/PM
hour of day is 0-12; AM or PM indicator will
be output to result string (only after last time
code element)

5-16 Centura Velocis Language Guide


convert

Example The following examples show numeric format specifiers and their
results.
Function Result
convert(14773.1234, char, 10, "#.#") " 14773.1"
convert(736620.3795, char, 12, "#,#.###") " 736,620.380"
convert(736620.3795, char, 12, "$#,#.##") " $736,620.38"
convert(736620.3795, char, 12, "<<#.######e") "7.366204e05"
convert(56.75, char, 8, "#.##%") " 56.75%"
convert(56.75, char, 8, "#.##’ percent’") " 56.75 percent"

The examples below show date/time format specifiers and


corresponding results. These examples show how Tuesday, October
23, 1951 at 4:42:27.1750 a.m. can be returned. The format specifier,
rather than the entire function, is shown here in the left column.
Format (fmt) Result
mmm dd, yyyy Oct 23, 1951
hh’hours’ on ddd month dd, yyyy 04hours on Tue October 23, 1951
dd ’of’ month ’of the year’ yyyy 23 of October of the year 1951
dddd hh.mm.ss.ffff mm-dd-yyyy Tuesday 04.42.27.1750 10-23-1951
’date:’yyyy.mm.dd ’at’ hh:mm A/P date:1951.10.23 at 04:42 AM

Velocis SQL-Callable Functions 5-17


cos

cos Retrieve the cosine of an angle

Syntax cos(arith_expr)

Parameters arith_expr An arithmetic expression, in radians.

Description This scalar numeric function retrieves the cosine of the specified
arithmetic expression. Cosine operations return values between -1.0
and +1.0.

5-18 Centura Velocis Language Guide


cot

cot Retrieve the cotangent of an angle

Syntax cot(arith_expr)

Parameters arith_expr An arithmetic expression, in radians.

Description This scalar numeric function retrieves the cotangent of the specified
arithmetic expression. Cotangent operations return values between
-∞ and +∞.

Velocis SQL-Callable Functions 5-19


count

count Count the rows of an aggregate result set

Syntax count({* | column_name})

Parameters * All columns of the result set.


column_name A column name.

Description This aggregate (calculation) function returns the total number of


rows of an aggregate.

Example
select company, count(ord_num) from customer, sales_order
where customer.cust_id = sales_order.cust_id group by 1;

COMPANY COUNT(ORD_NUM)
"Bills We Pay" Financial Corp. 5
Bears Market Trends, Inc. 5
Bengels Imports 5
Broncos Air Express 7
Browns Kennels 7
Bucs Data Services 4
Cardinals Bookmakers 5
Chargers Credit Corp. 3
Chiefs Management Corporation 5
Colts Nuts & Bolts, Inc. 8
Cowboys Data Services 3
Dolphins Diving School 2
Eagles Electronics Corp. 5
Falcons Microsystems, Inc. 3
Forty-Niners Venture Group 3
Giants Garments, Inc. 2
Jets Overnight Express 4
Lions Motor Company 5
Oilers Gas and Light Co. 3
Packers Van Lines 4
Patriots Computer Corp. 6
Raiders Development Co. 4
Rams Data Processing, Inc. 8
Redskins Outdoor Supply Co. 4
Saints Software Support 3
Seahawks Data Services 6
Steelers National Bank 2
Vikings Athletic Equipment 6

5-20 Centura Velocis Language Guide


curdate

curdate Retrieve the current date

Syntax curdate()

Parameters None

Description This scalar date/time function retrieves the current date. You can
also use today as a literal for the current date.

See Also curtime, now

Velocis SQL-Callable Functions 5-21


curtime

curtime Retrieve the current time

Syntax curtime()

Parameters None

Description This scalar date/time function retrieves the current local (server)
time.

See Also curdate, now

5-22 Centura Velocis Language Guide


database

database Retrieve the name of a database

Syntax database()

Parameters None

Description This system function retrieves a string containing the names of the
databases that are open for the current session. If more than one
database is open, the names are separated by commas with no
intervening spaces (for example, "sales,invntory,syscat").

Velocis SQL-Callable Functions 5-23


dayofmonth

dayofmonth Retrieve the day of the month

Syntax dayofmonth(date_expr)

Parameters date_expr A date expression.

Description This scalar date/time function retrieves the day of the month in the
specified date expression as a number between 1 and 31.

5-24 Centura Velocis Language Guide


dayofweek

dayofweek Retrieve the day of the week

Syntax dayofweek(date_expr)

Parameters date_expr A date expression.

Description This scalar date/time function retrieves the day of the week in the
specified date expression as a number between 1 and 7, where 1 is
Sunday.

Velocis SQL-Callable Functions 5-25


dayofyear

dayofyear Retrieve the day of the year

Syntax dayofyear(date_expr)

Parameters date_expr A date expression.

Description This scalar date/time function retrieves the day of the year in the
specified date expression as a number between 1 and 366.

5-26 Centura Velocis Language Guide


exp

exp Retrieve the value of an exponential function

Syntax exp(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This scalar numeric function retrieves the value of an exponential


function with the specified arithmetic expression as an exponent
(that is, earith_expr).

Velocis SQL-Callable Functions 5-27


floor

floor Find the lower bound for an arithmetic expression

Syntax floor(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This scalar numeric function retrieves the lower bound (floor) for the
specified arithmetic expression. The floor is the largest integer less
than or equal to the expression.

5-28 Centura Velocis Language Guide


hour

hour Retrieve the hour

Syntax hour(time_expr)

Parameters time_expr An expression representing either a time or a


timestamp value.

Description This scalar date/time function retrieves the hour in the specified time
expression as a number between 0 and 23.

Velocis SQL-Callable Functions 5-29


if

if Implement a conditional selection

Syntax if(cond_expr, expression1, expression2)

Parameters cond_expr The conditional expression.


expression1 The value to return if the conditional expression
evaluates to TRUE.
expression2 The value to return if the conditional expression
evaluates to FALSE.

Description This function evaluates an expression. The evaluation is based on the


specified condition for each row in the result set that is retrieved by a
select statement. If the conditional expression evaluates to TRUE,
the if function evaluates and retrieves the value of the first
expression (expression1). If the conditional expression evaluates to
FALSE, the function evaluates and returns the value of the second
expression (expression2). Both expressions must return values of
identical data types.

Example
select quantity, prod_id, prod_desc,
if(quantity > 20, .8*price, if(quantity > 5, .9*price, price)) "PRICE"
from item, product where item.prod_id = product.prod_id;

update sales_order
set tax = if(state="WA", amount*0.085,
if(state="CO", amount*0.062, 0.0))
where state in ("CA","WA");

select
sum(if(prod_id=10320, quantity, 0)) "386/20",
sum(if(prod_id=10333, quantity, 0)) "386/33",
sum(if(prod_id=10433, quantity, 0)) "486/33",
sum(if(prod_id=10450, quantity, 0)) "486/50",
from item;

5-30 Centura Velocis Language Guide


ifnull

ifnull Retrieve an expression if another expression is null

Syntax ifnull(expr1, expr2)

Parameters expr1 The expression to evaluate.


expr2 The alternative expression.

Description This system function retrieves the specified expression (expr1) if it is


not null. If expr1 is null, the ifnull function retrieves a second
expression (expr2). The two expressions must be of compatible data
types.

Velocis SQL-Callable Functions 5-31


insert

insert Insert a string into another string

Syntax insert(strexp1, num1, num2, strexp2)

Parameters strexp1 The string in which to insert another string.


num1 The beginning position of area for insertion. The first
position is 1, not 0.
num2 The number of characters to replace in strexp1.
strexp2 The string to use as the replacement.

Description This scalar string function retrieves the string that results from
replacing num2 amount of characters in a string (strexp1), beginning
at position num1. The insert function replaces these characters with
the specified string (strexp2). The string parameters can be either
ASCII or Unicode strings. If one of them is Unicode, the other one is
implicitly converted into Unicode before insertion and the function
returns a Unicode string.

Example Function Result


insert("Wayne", 2, 1, "Bill") "WBillyne"
insert(L"Wayne", 1, 4, "Bob") L"Bobe"
insert("Wayne", 1, 8, L"Bill") L"Bill"

5-32 Centura Velocis Language Guide


lcase

lcase Convert a string to lowercase

Syntax lcase(strexp)

Parameters strexp The string to convert.

Description This scalar string function converts the specified string to lowercase.
The string can be an ASCII string or a Unicode string. If a Unicode
string is specified, the function returns a Unicode string.

Velocis SQL-Callable Functions 5-33


left

left Retrieve the leftmost characters from a string

Syntax left(strexp, num)

Parameters strexp A string expression.


num The number of characters to retrieve.

Description This scalar string function retrieves the specified number of


characters from the leftmost part of a string. The string can be an
ASCII string or a Unicode string. If a Unicode string is specified, the
function returns a Unicode string.

5-34 Centura Velocis Language Guide


length

length Retrieve the length of a string

Syntax length(strexp)

Parameters strexp A string expression.

Description This scalar string function retrieves the length, in bytes, of the
specified string. The string can be an ASCII string or a Unicode
string. If a Unicode string is specified, the function returns a
Unicode string.

Velocis SQL-Callable Functions 5-35


locate

locate Looks for a string within another string

Syntax locate(strexp1, strexp2, num)

Parameters strexp1 The string to locate.


strexp2 The string in which the other string is located.
num The character position at which strexp1 begins. The
first character is at position 1, not 0.

Description This scalar string function retrieves the character position in one
string (strexp2) where another string (strexp1) begins. The search
begins at character position num. The locate function returns a 0 if it
does not find strexp1. The string parameters can be ASCII or
Unicode strings. If one of them is Unicode, the other one is implicitly
converted into Unicode before insertion and the function returns a
Unicode string.

5-36 Centura Velocis Language Guide


log

log Retrieve the natural logarithm of an expression

Syntax log(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This scalar numeric function retrieves the natural logarithm of the
specified arithmetic expression.

Velocis SQL-Callable Functions 5-37


ltrim

ltrim Remove all leading spaces from a string

Syntax ltrim(strexp)

Parameters strexp A string expression.

Description This scalar string function removes all leading spaces from the
specified string. The string parameter can be an ASCII string or a
Unicode string. If a Unicode string is specified, the function returns
a Unicode string.

5-38 Centura Velocis Language Guide


max

max Compute the maximum of the results for an aggregate

Syntax max(expression)

Parameters expression An expression that is used in a select statement.

Description This aggregate (calculation) function computes the maximum of


results of the specified expression for all rows of an aggregate.

Example
set double display(12, "#,#.##");
select month(ord_date), max(amount) from sales_order group by 1;

month(ord_date) max(amount)
1 274,375.00
2 124,660.00
3 143,375.00
4 252,425.00
5 39,675.95
6 104,019.50

Velocis SQL-Callable Functions 5-39


min

min Compute the minimum of the results for an aggregate

Syntax min(expression)

Parameters expression An expression that is used in a select statement.

Description This aggregate (calculation) function computes the minimum of


results of the specified expression for all rows of an aggregate.

Example
set double display(12, "#,#.##");
select month(ord_date), min(amount) from sales_order group by 1;

month(ord_date) min(amount)
1 408.00
2 344.48
3 631.78
4 68.75
5 2,673.75
6 4,487.76

5-40 Centura Velocis Language Guide


minute

minute Retrieve the minute

Syntax minute(time_expr)

Parameters time_expr An expression that is either a time or a timestamp


value.

Description This scalar date/time function returns the minute in the specified
time expression as a number between 0 and 59.

Velocis SQL-Callable Functions 5-41


mod

mod Perform a modulo arithmetic operation

Syntax mod(arith_expr1, arith_expr2)

Parameters arith_expr1 The expression to divide.


arith_expr2 The expression that is used as the divisor.

Description This scalar numeric function performs a modulo arithmetic operation


of the form arith_expr1 modulo arith_expr2. In other words, the
function retrieves the remainder resulting from dividing arith_expr1
by arith_expr2.

5-42 Centura Velocis Language Guide


month

month Retrieve the month

Syntax month(date_expr)

Parameters date_expr A date expression.

Description This scalar date/time function retrieves the number of the month in
the specified date expression as a number between 1 and 12.

Example
set double display(12, "#,#.##");
select month(ord_date), min(amount) from sales_order group by 1;

month(ord_date) min(amount)
1 408.00
2 344.48
3 631.78
4 68.75
5 2,673.75
6 4,487.76

Velocis SQL-Callable Functions 5-43


now

now Retrieve the current timestamp

Syntax now()

Parameters None

Description This scalar date/time function retrieves a timestamp value for the
current date and time.

See Also curdate, curtime

5-44 Centura Velocis Language Guide


pi

pi Retrieve the value of pi

Syntax pi()

Parameters None

Description This scalar numeric function retrieves the value of pi as a double data
type (3.14159…).

Velocis SQL-Callable Functions 5-45


quarter

quarter Retrieve the quarter

Syntax quarter(date_expr)

Parameters date_expr A date expression.

Description This scalar date/time function retrieves the number of the quarter in
the specified date expression as a number between 1 and 4.

5-46 Centura Velocis Language Guide


rand

rand Retrieve a random floating-point number

Syntax rand(num)

Parameters num An integer to use as the seed for the floating-point


number.

Description This scalar numeric function retrieves a random floating-point


number (between 0.0 and 1.0) using the specified integer as the seed.
If 0 is specified, the rand function retrieves the next random floating-
point number for the current seed.

Velocis SQL-Callable Functions 5-47


repeat

repeat Repeat a string

Syntax repeat(strexp, num)

Parameters strexp The string expression to repeat.


num The number of repetitions for the string.

Description This scalar string function concatenates the specified expression to


itself (num-1) times.

5-48 Centura Velocis Language Guide


replace

replace Replace a string within another string

Syntax replace(strexp1, strexp2, strexp3)

Parameters strexp1 The string in which to make the replacement.


strexp2 The string to replace.
strexp3 The replacement string.

Description This scalar string function replaces all occurrences of strexp2 in


strexp1 with strexp3. If the function does not find any occurrences of
strexp2, it retrieves strexp1. The three string parameters can be ASCII
or Unicode strings. If one of them is Unicode, the other one is
implicitly converted into Unicode before replacement and the
function returns a Unicode string.

Velocis SQL-Callable Functions 5-49


right

right Retrieve the rightmost characters from a string

Syntax right(strexp, num)

Parameters strexp A string expression.


num The number of characters to retrieve.

Description This scalar string function retrieves the specified number of


characters from the rightmost part of a string. The string parameter
can be an ASCII string or a Unicode string. If a Unicode string is
specified, the function returns a Unicode string.

5-50 Centura Velocis Language Guide


rtrim

rtrim Remove all trailing spaces from a string

Syntax rtrim(strexp)

Parameters strexp A string expression.

Description This scalar string function removes all trailing spaces from the
specified string. The string parameter can be an ASCII string or a
Unicode string. If a Unicode string is specified, the function returns
a Unicode string.

Velocis SQL-Callable Functions 5-51


second

second Retrieve the second

Syntax second(time_expr)

Parameters time_expr An expression that is either a time or a timestamp


value.

Description This scalar date/time function returns the second in the specified
time expression as a number between 0 and 59.

5-52 Centura Velocis Language Guide


sign

sign Retrieve the sign of an expression

Syntax sign(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This scalar numeric function returns -1 if arith_expr is less than 0, 0 if


arith_expr equals 0, and 1 if arith_expr is greater than 0.

Velocis SQL-Callable Functions 5-53


sin

sin Retrieve the sine of an angle

Syntax sin(arith_expr)

Parameters arith_expr An arithmetic expression, in radians.

Description This scalar numeric function retrieves the sine of the specified
arithmetic expression. Sine operations return values between -1.0
and +1.0.

5-54 Centura Velocis Language Guide


sqrt

sqrt Retrieve the square root of an expression

Syntax sqrt(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This scalar numeric function retrieves the square root of the specified
arithmetic expression.

Velocis SQL-Callable Functions 5-55


substring

substring Retrieve a substring from a string

Syntax substring(strexp, num1, num2)

Parameters strexp A string expression from which to retrieve a


substring.
num1 The character position at which the retrieval begins.
The position of the first character is 1, not 0.
num2 The length, in bytes, of the substring to retrieve.

Description This scalar string function retrieves the substring of length num2 that
begins at character position num1 of the specified expression. The
string parameter can be an ASCII string or a Unicode string. If a
Unicode string is specified, the function returns a Unicode string.

5-56 Centura Velocis Language Guide


sum

sum Compute the sum of the results for an aggregate

Syntax sum(arith_expr)

Parameters arith_expr An arithmetic expression.

Description This aggregate (calculation) function computes the sum of results of


the specified expression for each row of an aggregate.

Example
set double display(12, "#,#.##");
select cust_id, company, sum(amount) from customer, sales_order
where customer.cust_id = sales_order.cust_id
group by 1;

cust_id company sum(amount)


ATL Falcons Microsystems, Inc. 113,659.75
BUF ’Bills We Pay’ Financial Corp. 263,030.36
CHI Bears Market Trends, Inc. 160,224.65
CIN Bengels Imports 120,800.56
CLE Browns Kennels 43,284.54
DAL Cowboys Data Services 43,392.40
DEN Broncos Air Express 498,952.76
DET Lions Motor Company 439,346.50
GBP Packers Van Lines 163,177.30
HOU Oilers Gas and Light Co. 77,781.36
IND Colts Nuts & Bolts, Inc. 29,053.30
KCC Chiefs Management Corporation 141,535.34
LAA Raiders Development Co. 167,411.68
LAN Rams Data Processing, Inc. 172,936.31
MIA Dolphins Diving School 29,481.99
MIN Vikings Athletic Equipment 49,461.20
NEP Patriots Computer Corp. 120,184.69
NOS Saints Software Support 185,633.50
NYG Giants Garments, Inc. 15,829.64
NYJ Jets Overnight Express 124,487.78
PHI Eagles Electronics Corp. 130,006.17
PHO Cardinals Bookmakers 237,392.56
PIT Steelers National Bank 15,386.04
SDC Chargers Credit Corp. 34,556.48
SEA Seahawks Data Services 60,756.36
SFF Forty-niners Venture Group 112,345.66
TBB Bucs Data Services 104,038.25
WAS Redskins Outdoor Supply Co. 63,039.90

Velocis SQL-Callable Functions 5-57


tan

tan Retrieve the tangent of an angle

Syntax tan(arith_expr)

Parameters arith_expr An arithmetic expression, in radians.

Description This scalar numeric function retrieves the tangent of the specified
arithmetic expression. Tangent operations return values between -∞
and +∞.

5-58 Centura Velocis Language Guide


ucase

ucase Convert a string to uppercase

Syntax ucase(strexp)

Parameters strexp The string to convert.

Description This scalar string function converts the specified string to uppercase.
The string parameter can be an ASCII string or a Unicode string. If a
Unicode string is specified, the function returns a Unicode string.

Velocis SQL-Callable Functions 5-59


unicode

unicode Retrieve the numeric Unicode value of a character

Syntax unicode(strexp)

Parameters strexp A Unicode string expression.

Description This scalar string function retrieves the Unicode numeric value of the
initial character in the specified expression.

5-60 Centura Velocis Language Guide


user

user Retrieve the user name

Syntax user()

Parameters None

Description This system function retrieves the database user name as a string.

Velocis SQL-Callable Functions 5-61


week

week Retrieve the week

Syntax week(date_expr)

Parameters date_expr A date expression.

Description This scalar date/time function retrieves the number of the week of
the year in the specified date expression as a number between 1 and
53.

5-62 Centura Velocis Language Guide


wchar

wchar Retrieve a Unicode character

Syntax wchar(num)

Parameters num A Unicode code value for the character.

Description This scalar string function retrieves the character that corresponds to
the specified Unicode code value.

Velocis SQL-Callable Functions 5-63


year

year Retrieve the year

Syntax year(date_expr)

Parameters date_expr A date expression.

Description This scalar date/time function retrieves the number of the year in the
specified date expression. The earliest year for a Velocis SQL date is
1 A.D.

5-64 Centura Velocis Language Guide


Chapter 6
Core DDL Statement Reference
This chapter describes the DDL statements used to prepare a database schema for use
with a Core (i.e., non-SQL) application. All statements are presented in alphabetical
order for easy reference. Each statement description includes a syntax summary section
and all relevant operational details. Examples are included to illustrate the use of the
statement.
In addition to the statements described in this chapter, you can use prologue statements
in the database schema before the database statement. Prologue statements, which are
similar to C-language elements, include comments and directives for defining constants,
types, and structures. The ddlproc schema compiler copies this text, without change, into
the database header file. You can include the following prologue statements:
• /* comment */
• #define macroname macrovalue
• const constantname=constantvalue;
• typedef type typename;
• struct structname { field_spec; ... };
• typedef struct { field_spec; ... } typename;
The record statement contains details on which types, dimensions, and field specifications
you can use. To learn how to use Core DDL statements in your database schema, see
Chapter 4 of the Velocis User’s Guide.

Core DDL Statement Reference 6-1


blob file

blob file Create a BLOB file

Syntax blob file [[pgsize]] [fileid =] "filename"


contains [recname.]fldname [, [recname.]fldname]...

Statement blob file [[pgsize]] [fileid =] "filename"


Elements Creates a BLOB file. The name of the BLOB file can
be up to 47 characters and should exclude any path
information. A file identifier can be specified for use
in the dictionary access (c_) functions. If the
fixed-length page size, in bytes, of the BLOB file is
not specified, the database page size is used (default
is 1,024). Otherwise, use a multiple of the basic
block size for your operating system (a multiple of
512 works for most systems).

contains [recname.]fldname [, [recname.]fldname]...


Specifies which BLOB identifier (blob_id) fields to
put in the BLOB file. If a field name is used in more
than one record type, you must also specify the
name of the record associated with the field.

Description This statement declares a BLOB file for the database. Each blob_id
field that is defined in the database schema must be contained in a
BLOB file. All occurrences of a given BLOB field are stored in a
single file. A single BLOB file can store the BLOBs for one or more
blob_id fields. Thus, you can use one file to contain all BLOB fields,
or you can use a separate file for each BLOB field.
Each page in the BLOB file consists of one BLOB field slot.
Therefore, a small BLOB field takes up the same space as a larger
field, leaving unused space in the file. You can adjust the BLOB file’s
page size to accommodate the best fit based on your BLOB usage.

See Also data file, key file

Example
blob file [2048] "pics.dat" contains a_picture;
record rec_with_blob {
...
blob_id a_picture;
...
}

6-2 Centura Velocis Language Guide


data file

data file Create a data file

Syntax data file [[pgsize]] [fileid =] "filename"


contains recname [, recname]...

Statement data file [[pgsize]] [fileid =] "filename"


Elements Creates a data file. The file name can be up to 47
characters in length and should exclude any path
information. A file identifier can be specified for use
in the dictionary access (c_) functions. If the page
size, in bytes, of the data file is not specified, the
database page size is used (default is 1,024).
Otherwise, use a multiple of the basic block size for
your operating system (a multiple of 512 works for
most systems).

contains recname [, recname]...


Specifies the names of records to include in the data
file.

Description This statement creates a data file for the database. Each record type
defined in the database schema must be contained in a data file. All
occurrences of a given record type are stored in a single file. A data
file can contain one or more record types. Thus, you can use one file
to contain all record types, or you can use a separate file for each
record type.
Each page in the data file consists of one or more fixed-length record
slots. The size of the record slots is based on the size of the largest
record type contained in the file. Therefore, a smaller record type
takes up the same space as a larger type, which leaves unused space
in the file.

See Also blob file, key file

Example
data file [2048] "info.dat" contains info;

Core DDL Statement Reference 6-3


database

database Create a database

Syntax database dbname [[pgsize]] {


file_stmt...
record_stmt...
[set_stmt]...
}

Statement database dbname [[pgsize]]


Elements Specifies the database name, which can be up to 31
characters in length. The database page size, in
bytes, can also be specified (default is 1024). This
value becomes the default page size for file
statements in which a page size is not specified. Use
a multiple of the basic block size for your operating
system (a multiple of 512 works for most systems).
file_stmt... Specifies the files that are used to store all BLOBs,
records, and keys in the database. See the blob file,
data file, and key file statements, respectively, for
details.
record_stmt... Defines the records in the database. See the record
statement for details.
[set_stmt]... Defines the sets in the database. See the set
statement for details.

Description This statement creates a database for Core applications. At compile


time, the ddlproc schema processor uses the specified database name
to set up the database, name the database dictionary file, and name
the C header files that it produces. You can create only one database
in a schema file.
To open the database that you created, pass the database name to the
Core API function d_open or d_iopen.

Note: The ddlproc schema compiler uses only the first few
characters of the database name (8 on Windows and 11 on UNIX) to
form the database dictionary and header file names.

6-4 Centura Velocis Language Guide


key file

key file Create a key file

Syntax key file [[pgsize]] [fileid =] "filename"


contains [recname.]keyfld [, [recname.]keyfld]...

Statement key file [[pgsize]] [fileid =] "filename"


Elements Specifies the name of the key file to create. The
name can be up to 47 characters in length and
should exclude any path information. A file
identifier can be specified for use in the dictionary
access (c_) functions. If the page size, in bytes, of the
key file is not specified, the database page size is
used (default is 1,024). Otherwise, use a multiple of
the basic block size for your operating system (a
multiple of 512 works for most systems).

contains [recname.]keyfld [, [recname.]keyfld]...


Specifies the names of the key fields to store in the
key file. If multiple record types have the same field
name, include the name of the specific record type of
the key field to store.

Description This statement creates a key file for the database. Each key field that
is defined in the database schema must be contained in a key file. A
key file can contain one or more key fields. Key field values are
stored in the key file in natural order, based on data type.
Each page in the key file consists of one or more fixed-length key
slots. The size of the key slots is based on the size of the largest key
field contained in the file. Thus, a small key field takes up the same
space as a larger field, which leaves unused space in the file.

See Also blob file, data file

Example
key file[1024] keyfile1="chkg.k01" contains code;
key file[2048] keyfile2="chkg.k02" contains check_no;
key file "invnt.k01" contains stock.id_code, bkorder.id_code;

Core DDL Statement Reference 6-5


record

record Create a database record

Syntax [static] record recname {


[field_stmt]...
[comkey_stmt]...
}

Statement [static] record recname


Elements Specifies the name of the record. The name can be
up to 31 characters and must contain at least one
lowercase letter. To prohibit modification of this
record during normal operation (database in shared
mode), specify static.
[field_stmt]... Defines one or more data and/or key fields. The
syntax for data field declarations is described in the
Field Declaration Syntax section, below.
[comkey_stmt]...
Specifies one or more compound key fields in a
record. The syntax for compound key declarations is
described in the Field Declaration Syntax section,
below.

Description This statement defines a group of related data fields, key fields, and
compound key fields that are stored and accessed as a single unit in
the database.
Defining a data or key field is similar to that for an elementary data
declaration. Most elementary data types are directly supported in
the schema, but Velocis does not directly support elementary bit
fields. The syntax is shown in the Field Declaration Syntax section,
and described in the Field Declaration Elements section.
Compound keys are key field definitions that include any
combination of fields (not necessarily contiguous) from a given
record. The major and minor sort sequences are determined by the
order in which the fields are specified. The syntax is shown in the
Compound Key Declaration Syntax section, and it is described in the
Compound Key Declaration Elements section.
Unlike normal key fields, compound keys do not define additional
data fields in the record. This means that a field can appear in
multiple keys within a record without needing to duplicate the field’s
value.

6-6 Centura Velocis Language Guide


record

When the schema is compiled, the compiler creates several C names


that are based on the record declaration. These names are used in
Velocis Core API functions. Here are the names and their
descriptions:
• The structure tag that represents the record. The structure
contains C-based declarations for the fields in the record
(excluding compound keys). The structure tag and the structure
members have the same names as the record and its respective
fields.
• A short-integer constant that represents the record, and
long-integer constants that represent the fields in the record
(including compound keys). The names of the constants are the
uppercase forms of the record name and its field names,
respectively.
• Short-integer constants that represent the sizes, in bytes, that are
occupied by each field in the record (excluding compound keys).
The names of these constants start with SIZEOF_ and end in the
name of the respective fields, in uppercase form.
• The structure tags that represent the compound keys in the
record. The structure contains C-based declarations of the fields
in the compound key. The structure tag and the structure
members have the same names as the compound key and its
respective fields.
If there are duplicate field and structure names in different record
types, use the -d option in the ddlproc utility to compile the schema.
This makes those names in the header file unique by prefixing the
uppercase form of the record name and an underscore ("_") to each
field and structure declaration.

Note: In a database, all record names must be distinct from all field
names.

Field Declaration field_stmt:


Syntax [[optional | unique] key] [compare(cmpFnId)] field_spec;
field_spec:
type fldname[dim] | struct { field_spec; ... } fldname[dim]

Core DDL Statement Reference 6-7


record

type:
[unsigned] {int | short | long | char} | wchar
| float | double | db_addr | blob_id
| DefinedTypeName | struct DefinedStructureTag
dim:
[dim1] [[dim2] [[dim3]]]

Field Declaration field_stmt: [[optional | unique] key] [compare(cmpFnId)] field_spec;


Elements Declares a data or key field. If a key field is
specified, the size of the key field can be up to 244
bytes (240 if you are using the default database page
size for a key file). You can also specify a
customized comparison function to use to sort or
compare data in the field.
A key field can be optional or unique. An optional
key is only stored when the Core API function
d_keystore is called. A unique key must contain a
value that is different from the other key field values
when the application enters the record into the
database. Otherwise, if the record is entered or
modified with a duplicate value in the unique key,
the server returns S_DUPLICATE and does not
perform the operation.
field_spec: type fldname[dim] | struct { field_spec; ... } fldname[dim]
Specifies the name and data type of the field. The
field can be an array of one, two, or three
dimensions. It can also be a structure.
type: ... Specifies the data type of the field. You can use any
data type shown above, or you can use any type or
structure tag that has been defined in a prologue
statement. For details on prologue statements, see
the beginning of this chapter. For details on
standard Velocis data types, see Chapter 19 of the
Velocis Reference Manual.
dim: [dim1] [[dim2] [[dim3]]]
Specifies the number of elements for each dimension
of an array field. Velocis supports arrays of one,
two, or three dimensions.

6-8 Centura Velocis Language Guide


record

Note: If you are administering an SQL database, the Core schema


that the SQL schema compiler produces may include additional
statement elements not shown here. These elements are the virtual
data field attribute, the sysnulls_[][1] character array field, and the
sysrefs_[] long integer array field. For details, see Chapter 6, "Core
API Access to SQL Databases," in the Velocis User’s Guide.

Compound Key comkey_stmt:


Declaration compound [optional | unique] key keyname {
Syntax fldname [asc[ending] | desc[ending]];
...
}

Compound Key compound [optional | unique] key keyname


Declaration Creates a compound key with the specified name. A
Elements compound key can be labeled optional or unique.
An optional key is only stored when the application
calls d_keystore. A unique key contains values that
cannot be duplicated.
fldname [asc[ending] | desc[ending]];
Specifies the name of a field from the record to
contain in the compound key. The field must
already be defined in the field and cannot be a
structure. The sort order (ascending or descending)
may also be specified. If the sort order is omitted,
the field is sorted in ascending order.

See Also set

Example
record trans {
unique key int checkno;
int trdate;
char vendid[8];
long amount;
compound key tr_key {
trdate descending;
vendid ascending;
}
compound key ven_chks {
vendid;
checkno;
}
}

Core DDL Statement Reference 6-9


set

set Create a data relationship among records

Syntax set setname {


order {ascending | descending | first | last | next};
owner ownerrec;
member memberrec [by fldname [, fldname]...];
[member memberrec [by fldname [, fldname]...];]...
}

Statement set setname Specifies the name of the new set.


Elements order {ascending | descending | first | last | next};
Specifies the order in which member records are
inserted into the set. New members can be placed in
ascending or descending alphabetical order within
the member list, at the beginning or end of the list,
or immediately after the current member in the set.
(If you specify order next and the current member is
null, the new member will be inserted at the
beginning of the list.)
owner ownerrec;
Declares an existing record as the owner of the set.
member memberrec [by fldname[, fldname]...];
Declares an existing record to be a member of the
set. If members are sorted by field (that is,
order ascending or order descending is specified for
this set), you must specify the names of the fields by
which to order the member records.
Note: In a sorted set, if the sort field values of new member records
are duplicates of existing members, the new members are added in
front of the members with matching values.

Description This statement declares a set, which is used to form a relationship


among database records. The set establishes a one-to-many
relationship between an owner record and any number of member
records, and it designates the ordering method for the set.
The names of the sets are used to create C names. When the schema
is compiled, the compiler places definitions of the set names, in
uppercase form, as constant numbers in the database header file.
To implement a many-to-many relationship among records, use a
special intersect member record through two set declarations. The

6-10 Centura Velocis Language Guide


set

owners of the two sets are the record types to be related. This
method is described in Chapter 4 of the Velocis User’s Guide.
Velocis does not implement ascending or descending sets through an
index. As with all sets, they are implemented as a linked list (or
chained) structure. Velocis does provide keyed record access
(through a B-tree index), but it is totally distinct from sets. A record
can have keys as well as be an owner and/or a member of sets. Sets,
however, do not use keys, and keys do not use sets. Thus, sort fields
of ascending or descending sets need not be declared as key fields.

See Also record

Example
set comment {
order first;
owner note;
member project;
member task;
member work_day;
}

Core DDL Statement Reference 6-11


Appendix A
Velocis SQL Syntax Summary
A.1 List of DDL Statements
Table A-1. DDL Statements
Statement Description
create database Creates a new database definition
create file Creates a database file
create index Creates an index
create join Creates a join between a primary key and a foreign key
create table Creates a database table

A.2 List of DML Statements


Table A-2. DML Statements
Statement Description
activate index Activates an optional index
alter extension file Alters the file size attributes for a base or extension file
alter user Alters a user’s password
begin Begins a database transaction
close Closes a database or databases
commit Commits a transaction
create database instance Creates a database instance
create device Creates a device
create extension file Creates an extension file for a database file
create filter Creates an import/export filter
create function Creates a UDF definition
create index Creates an index
create procedure Creates a stored SQL procedure or a Core user-defined procedure (UDP)
create temporary table Dynamically creates a temporary table
create user Creates a user
create view Creates a view
deactivate index Deactivates an optional index
delete Deletes a row or rows from a table
drop database Deletes a database instance

Velocis SQL Syntax Summary A-1


Table A-2. DML Statements (continued)
Statement Description
drop device Drops a device
drop function Drops a UDF definition
drop procedure Drops a stored procedure
drop table Drops a temporary table
drop user Drops a user
drop view Drops a view
execute Executes a stored procedure or a UDP
execute ShowDbFiles Shows the list of files for a given database
execute ShowDevices Shows the list of all Velocis devices
execute ShowUsers Shows the list of all Velocis users
grant Grants user permissions
initialize Initializes a temporary table
initialize database Initializes a database
insert Inserts a row or rows into a table, file, or filter
lock table Locks a table for shared/exclusive access
mark Marks a transaction rollback point
open Opens a database or databases
revoke Revokes user permissions
rollback Discards all changes made since a transaction start or mark
select Retrieves columns and rows
set Sets database options
unlock table Frees the lock on a shared table
update Updates a row or rows in a table
update stats Updates database usage statistics

A.3 Syntax Summary

activate index : activate [optional] index index_name


alias : identifier | "alt_hdg"
alter extension file : alter [extension] file extno
for "basename" on device_name
set { maxsize = maxsize
| cresize = cresize
| extsize = extsize}...
alter user : alter user {username | "username"}
set password = "password"
arg_spec : arg_name arg_type [default constant]

A-2 Centura Velocis Language Guide


arg_type : integer | smallint | real | float | decimal
| char | wchar | character | wcharacter
| date | time | timestamp
arith_expr : arith_operand [arith_operator arith_operand]...
arith_function : {sum | avg | max | min} (arith_expr)
| count ( {* | column_ref )
| if (cond_expr, arith_expr, arith_expr)
| numeric_function
| datetime_function
| system_function
| fcn_name([arg [, arg]...])
arith_operand : constant | column_ref
| arith_function
| (arith_expr)
arith_operator : + | - | * | /
begin : begin [trans | transaction | work] [trans_id]
bool_oper : [ & | && | and]
| [ "|" | "||" | or]
c_base_type : [unsigned] {char | wchar | short | int | long}| float | double
c_type_spec : c_base_type
| struct {
c_base_type field_name[dims];
[c_base_type field_name[dims];]...
}
close : close db_name [, db_name]...
column_ref : [{table_name | correlation_name}.] column_name
column_list : column_name [, column_name]...
column_defn : column_name column_spec ["description"]
column_spec : {type_basic | type_extended}
[default {constant | null | auto}]
[not null]
[unique | primary key]
[references [db_name.]base_table_name [(column_name)]]
[check (cond_expr)]
[compare (compare_fcn_id)]
| long {varchar | varbinary}
[default {constant | null}]
[not null]
[in file_name]

Velocis SQL Syntax Summary A-3


cmd_spec : {privilege [, privilege]... | all [privileges]} on table_name
| all commands [but command [, command]...]
| commands command [, command]...
command : create database | create view | create procedure
| insert | update | delete | lock table
commit : commit [trans | transaction | work] [trans_id]
cond_expr : rel_expr [bool_oper rel_expr]...
constant : "string literal" | numeric_literal
| user | today | now | date | time | timestamp
create database : create {schema | database} db_name
[pagesize number]
[authorization user_name]
[on device_name]
[enable null values | disable null values]
[enable references count | disable references count]
create database instance : create database [instance] db_name
from db_name
[with data | {init | initialize} | {noinit | noinitialize}]
[on device_name]
create device : create [readonly] device device_name
as "directory_path"
create extension file : create extension file "extname" on device_name
for "basename" on device_name
create file : create {file | tablespace} file_name
[pagesize number]
[on device_name]
create filter : create filter filter_name ["description"] [with auto commit]
in dll_name on device_name
create function : create create_function_list...
in dll_name on device_name
create_function_list : [scalar | aggregate] function[s]
fcn_name ["description"] [, fcn_name ["description"]]...
create index : create [optional | unique] index index_name
on base_table_name (ordered_cols)
[in file_name]

A-4 Centura Velocis Language Guide


create join : create join join_name
{ order {first | last} on foreign_key
[and foreign_key ]...
| order sorted on foreign_key [by ordered_cols]
[and foreign_key [by ordered_cols]]...
}
create procedure : create {proc | procedure} proc_name [(arg_spec [, arg_spec]...)]
SQL_statement[;] [SQL_statement[;]]...
end {proc | procedure}
| create {proc | procedure} proc_name
in dll_name on device_name
create table : create table base_table_name ["description"]
(column_defn [, column_defn]... [, table_constraint]...)
[in file_name]
create temporary table : create temporary table temp_table_name ["description"]
(temp_column_defn [,temp_column_defn]...)
create user : create [administrator | admin] user {user_name | "user_name"}
password "password"
on device_name
create view : create view table_name ["description"]
[(column_name [, column_name]...)]
as select_stmt [with check option]
datetime_function : curdate()
| curtime()
| dayofmonth(column_ref)
| dayofweek(column_ref)
| dayofyear(column_ref)
| hour(column_ref)
| minute(column_ref)
| month(column_ref)
| now()
| quarter(column_ref)
| second(column_ref)
| week(column_ref)
| year(column_ref)
deactivate index : deactivate [optional] index index_name
delete : delete from table_name
where {cond_expr | current of cursor_name}
drop database : drop database db_name
drop device : drop device device_name

Velocis SQL Syntax Summary A-5


drop function : drop function fcn_name
drop procedure : drop {proc | procedure} proc_name [cascade | restrict]
drop table : drop table table_name [, table_name]...
drop user : drop user {user_name | "user_name"}
drop view : drop view view_name [cascade | restrict]
execute : {exec | execute | run} [db_name.]proc_name [(arg [, arg]...)]
| {exec | execute} ShowDbFiles ("db_name")
| {exec | execute} ShowDevices
| {exec | execute} ShowUsers
expression : arith_expr | string_expr
foreign_key_column : [virtual | non_virtual] base_table_name [(column_list)]
grant : grant cmd_spec to
{user_name | "user_name"} [, {user_name | "user_name"}]...
initialize : initialize temp_table_name [, temp_table_name]...
| initialize database db_name
insert : insert [with auto commit] into table_name [from] insert_file
| insert [with auto commit] into insert_table from insert_filter
| insert [with auto commit] into insert_table [from] select_stmt
| insert into insert_file [from] select_stmt
| insert into insert_filter [from] select_stmt
| insert into insert_table
values ({constant | null} [, {constant | null}]...)
insert_file : [unicode | ascii] file "filename" [, "delim"] [on device_name]
insert_filter : filter filter_name [(value [, value]...)]
insert_table : table_name [(column_name [, column_name]...)]
lock table : lock table table_name {[in] share | exclusive [mode]}
[, table_name {[in] share | exclusive [mode]}]...
mark : mark [trans | transaction | work] mark_id

A-6 Centura Velocis Language Guide


numeric_function : abs(arith_expr)
| acos(arith_expr)
| asin(arith_expr)
| atan(arith_expr)
| atan2(arith_expr, arith_expr)
| ceiling(arith_expr)
| cos(arith_expr)
| cot(arith_expr)
| exp(arith_expr)
| floor(arith_expr)
| log(arith_expr)
| mod(arith_expr, arith_expr)
| pi()
| rand(number)
| sign(arith_expr)
| sin(arith_expr)
| sqrt(arith_expr)
| tan(arith_expr)
open : open db_name [, db_name]...
[[as] {shared | temporary | read |
exclusive [with transaction off]}]
ordered_cols : column_name [asc | desc] [, column_name [asc | desc]]...
privilege : select | delete | insert
| update [(column_name [, column_name]...)]
rel_expr : expression [not] rel_oper
{expression | [{any | some} | all] (subquery)}
| expression [not] between constant and constant
| expression [not] in {(constant [, constant]...) | (subquery)}
| column_ref is [not] null
| string_expr [not] like "string literal" [escape "esc_char"]
| not rel_expr
| (cond_expr)
| [not] exists (subquery)
| column_ref *= column_ref
| column_ref =* column_ref
rel_oper : [ = | == ]
| < | > | <= | >=
| [ != | <> | /= ]
revoke : revoke cmd_spec from
{user_name | "user_name"} [, {user_name | "user_name"}]...
rollback : rollback [trans | transaction | work] [trans_id]

Velocis SQL Syntax Summary A-7


select : select [first] [distinct] {* | select_item] [, select_item]...}
from table_list
[where cond_expr]
[with exclusive lock |
[group by sort_col [,sort_col]... [having cond_expr]]
[order by sort_col [asc | desc] [, sort_col [asc | desc]]…]
select_item : expression [alias_name | "column heading"]
| {table_name | correlation_name}.*
set : set currency to "char"
| set date default to "date format "
| set decimal to "char"
| set type_name display(width, "format specifier")
| set login to {on | off}
| set {login | logout} proc for {public | user [, user]...}
to {proc_name | null}
| set opt_limit to constant
| set read repeatability {on | off}
| set thousands to "char"
| set timeout to constant
| set transaction isolation {on | off}
| set wild {all | one} to "char"
sort_col : number | column_ref
string_expr : string_operand [^ string_operand]
string_function : ascii(string_expr)
| char(number)
| concat(string_expr, string_expr)
| insert(string_expr, number, number, string_expr)
| lcase(string_expr)
| left(string_expr, number)
| length(string_expr)
| locate(string_expr, string_expr, number)
| ltrim(string_expr)
| repeat(string_expr, number)
| replace(string_expr, string_expr, string_expr)
| right(string_expr, number)
| rtrim(string_expr)
| substring(string_expr, number, number)
| ucase(string_expr)
| unicode(string_expr)
| wchar(number)

A-8 Centura Velocis Language Guide


string_operand : "string" | column_ref
| if (cond_expr, string_expr, string_expr)
| string_function
| fcn_name([arg [, arg]...])
subquery : select {* | expression} from table_list [where cond_expr]
system_function : convert(expression, type_name)
| convert(expression, char, number, "format specifier")
| c_data(column_name[, number] [, struct_elt [, number]] )
| user()
| database()
| ifnull(expression, expression)
table_constraint : {unique | primary key} (column_list)
| foreign key (column_list)
references [db_name.]base_table_name [(column_list)]
| check (cond_expr)
table_list : table_name [correlation_name][, table_name [correlation_name]]...-
table_name : [db_name.]{base_table_name | view_name}
| [temp_table_name.]temp_table_name
temp_column_defn : column_name type_basic
[default {constant | null}]
[not null]
type_basic : {varchar | char | wvarchar | wchar} (length)
| {double [precision] | float} | real
| {integer | int | long} | {smallint | short}
| decimal [(precision [, scale])]
| date | time [(precision)] | timestamp [(precision)]
type_extended : rowid
| c_data[ [array_size] [[array_size]]... ] c_type_spec
type_name : char | wchar | smallint | integer | real | float | decimal
| date | time | timestamp
unlock table : unlock table table_name [, table_name]...
update : update table_name
set column_name = {expression | null}
[, column_name = {expression | null}]...
where {cond_expr | current of cursor_name}
update stats : update {stats | statistics} on db_name [, db_name]...

Velocis SQL Syntax Summary A-9


Index
A
calculation functions 3-13. See also
abs numeric function 5-2 aggregate functions
access rights 4-53, 4-70 defined 3-13
acos function 5-3 table of 3-13
activate index statement ceiling function 5-10
defined 4-2 Centura
aggregate functions Web home page 1-3
avg 5-8 char function 5-11
count 5-20 close statement
max 5-39 defined 4-7
min 5-40 command privileges 4-70
sum 5-57 commit statement 4-6, 4-8
arithmetic expressions 3-6 defined 4-8
arithmetic operators concat function 5-12
precedence 3-6 conditional expressions
ascii function 5-4 where used 3-8
asin function 5-5 conditional selection
atan function 5-6 function 3-10, 3-13
atan2 function 5-7 if function implementation 5-30
avg function 5-8 convert function 4-84, 5-13
B and currency symbol 4-76
begin statement 4-6, 4-8 and decimal symbol 4-78
begin transaction statement correlated subquery 3-15
defined 4-6 cos function 5-18
BLOB cot function 5-19
ID field size 6-2 count function 5-20
BLOB file statement create database instance statement
defined 6-2 defined 4-11
built-in functions 3-10. See also scalar create database statement
functions defined 4-10
defined 3-10 create file statement 4-15
bulk load create filter statement 4-17
of table with insert statement 4-57 create function statement 4-18
create index statement 4-20
C create join statement 4-23
c_data function 5-9 create procedure statement
defined 4-26

Centura Velocis Language Guide Index-1


create schema 4-10 defined 4-40
create table statement 4-31 drop function statement
create temporary table statement defined 4-42
defined 4-33 drop procedure statement
create view statement defined 4-43
defined 4-36 drop table statement
curdate function 5-21 defined 4-44
currency symbol 4-76 drop view statement
cursors 4-39 defined 4-46
curtime function 5-22
E
D errACTINDEX 4-2
data file statement execute statement
defined 6-3 defined 4-47
database function 5-23 exp function 5-27
database statement expressions
defined 6-4 arithmetic 3-6
date constants relational 3-6
Velocis SQL 3-4 Velocis SQL 3-5
date/time functions. See also scalar
F
functions
table of 3-12 floor function 5-28
dayofmonth function 5-24 format
dayofweek function 5-25 year 2000 3-4
dayofyear function 5-26 functions
DDL aggregate 3-10, 3-13
database statement 6-4 built-in 3-10
record statement 6-6 calculation 3-13
DDL schema conditional selection 3-10, 3-13
create database 4-10 scalar 3-10
DDL statements string 3-10
alphabetical list A-1 user-defined 3-10, 3-13
Velocis SQL 4-1 G
ddlproc 6-4 grant statement
deactivate index statement defined 4-53, 4-70
defined 4-38
decimal symbol 4-78, 4-84 H
delete statement hour function 5-29
defined 4-39
I
DML statements
alphabetical list A-1 identifiers
Velocis SQL 4-1 Velocis SQL 3-1
drop database statement if function 3-13, 5-30

Index-2 Centura Velocis Language Guide


ifnull function 5-31 mod function 5-42
in clause month function 5-43
and create table 4-32
N
initialize statement
defined 4-55 now function 5-44
insert (from file) statement null, correct format of 3-8
defined 4-57 numeric constants
insert (from filter) statement Velocis SQL 3-3
defined 4-59 numeric functions
insert (from select) statement abs 5-2
defined 4-62 acos 5-3
insert (values) statement asin 5-5
defined 4-64 atan 5-6
insert function 5-32 atan2 5-7
intersect record 6-11 ceiling 5-10
item privileges 4-70 cos 5-18
cot 5-19
J exp 5-27
join, predefined 2-1 floor 5-28
log 5-37
K
mod 5-42
key file statement pi 5-45
defined 6-5 rand 5-47
L sign 5-53
lcase function 5-33 sin 5-54
left function 5-34, 5-35 sqrt 5-55
literal (system) constants table of 3-11
Velocis SQL 3-5 tan 5-58
locate function 5-36 O
lock table statement ODBC
defined 4-65 level 1 2-3
lock waiting timeout 4-85 level 2 2-3
locking, table 4-65 standard 2-3
log function 5-37 open statement
ltrim function 5-38 defined 4-67
M optimizing a query 4-82
manual conventions 1-2 order statement
mark transaction statement defined 6-10
defined 4-66 P
max function 5-39 pi function 5-45
min function 5-40 positioned delete 4-39
minute function 5-41 positioned update 4-89

Centura Velocis Language Guide Index-3


predefined join 2-1 week 5-62
year 5-64
Q
sddlp utility 4-1, 4-10, 4-20
quarter function 5-46 searched delete 4-39
query searched update 4-89
optimizing 4-82 second function 5-52
R select statement 4-72
rand function 5-47 defined 4-74
readme.txt file 1-2 use of null 3-8
record statement set currency statement
defined 6-6 defined 4-76
relational expressions 3-6, 3-9 set date default statement
between operator 3-9 defined 4-77
in operator 3-9 set decimal statement
is null operator 3-9 defined 4-78
like operator 3-9 set display statement
repeat function 5-48 defined 4-79
replace function 5-49 set login
reserved words defined 4-80
Velocis SQL 3-1 set login proc statement
right function 5-50 defined 4-81
rollback statement 4-6, 4-8 set opt_limit statement
defined 4-71 defined 4-82
rsql set read repeatability statement
and semicolons 4-26 defined 4-83
rtrim function 5-51 set statement
run 4-47 defined 6-10
set thousands statement 4-84
S defined 4-84
savepoints 4-66 set timeout statement
scalar functions defined 4-85
curdate 5-21 set transaction isolation statement
curtime 5-22 defined 4-86
dayofmonth 5-24 set wild statement 3-9
dayofweek 5-25 defined 4-87
dayofyear 5-26 sign function 5-53
defined 3-10 sin function 5-54
hour 5-29 SQL
minute 5-41 features 2-1
month 5-43 standards
now 5-44 basis of Velocis 2-1
quarter 5-46 sqrt function 5-55
second 5-52

Index-4 Centura Velocis Language Guide


statements, Velocis SQL 4-1. See also set login proc 4-81
statements, Core DDL set opt_limit 4-82
activate index 4-2 set read repeatability 4-83
begin transaction 4-6 set thousands 4-84
close 4-7 set transaction isolation 4-86
commit 4-8 set wild 4-87
create database 4-9 timeout 4-85
create database instance 4-11 unlock table 4-88
create file 4-15 update 4-89, 4-91
create filter 4-17 statements, Core DDL 6-1. See also
create function 4-18 statements, Velocis SQL
create index 4-20 blob file 6-2
create join 4-22 data file 6-3
create procedure 4-25 database 6-4
create table 4-28 key file 6-5
create temporary table 4-33 record 6-6
create view 4-36 set 6-10
deactivate index 4-38 stored procedures
delete 4-39 dropping 4-43
drop database 4-40 executing 4-47
drop function 4-42 string constants
drop procedure 4-43 Velocis SQL 3-3
drop table 4-44 string expressions
drop view 4-46 syntax 3-7
execute 4-47 string functions
grant 4-52, 4-69 ascii 5-4
initialize 4-55 char 5-11
insert (from file) 4-57 concat 5-12
insert (from filter) 4-59 insert 5-32
insert (from select) 4-61 lcase 5-33
insert (values) 4-64 left 5-34
lock table 4-65 length 5-35
mark transaction 4-66 locate 5-36
open 4-67 ltrim 5-38
order 6-10 repeat 5-48
owner 6-10 replace 5-49
rollback 4-71 right 5-50
select 4-72 rtrim 5-51
set currency 4-76 substring 5-56
set date default 4-77 table of 3-10
set decimal 4-78 ucase 5-59
set display 4-79 unicode 5-60
set login 4-80 wchar 5-63

Centura Velocis Language Guide Index-5


subquery defined 4-91
correlated 3-15 user function 5-61
syntax 3-14 user-defined functions 3-10, 3-13
substring function 5-56
V
sum function 5-57
system functions Velocis
c_data 5-9 manual set, summary 1-1
convert 5-13 Velocis Language Guide
database 5-23 chapter summaries 1-1
ifnull 5-31 Velocis SQL
table of 3-12 1989 ANSI conformance 2-2
user 5-61 1992 ANSI conformance 2-2
date constants 3-4
T expressions 3-5
table locks 4-65 identifiers 3-1
tan function 5-58 literal (system) constants 3-5
time constants numeric constants 3-3
Velocis SQL 3-4 reserved words 3-1
time/date functions string constants 3-3
table of 3-12 time constants 3-4
timestamp constants timestamp constants 3-4
Velocis SQL 3-4 Velocis SQL statements
transaction syntax summary A-2
commit 4-8 views
rollback 4-71 creating 4-36
savepoint 4-66 dropping 4-46
U W
ucase function 5-59 wchar function 5-63
UDFs 3-10 week function 5-62
defined 3-13 with check option
unicode function 5-60 and nulls 2-2
unlock table statement defined 4-36
defined 4-88
Y
updatable views
of views 2-2 Y2K format 3-4
update statement year 2000 format 3-4
defined 4-89 year function 5-64
update statistics statement

Index-6 Centura Velocis Language Guide

You might also like