Professional Documents
Culture Documents
Guia Oficial N°08. Vel30LG
Guia Oficial N°08. Vel30LG
Guia Oficial N°08. Vel30LG
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
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
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.
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.
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.
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.
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.
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
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.
Note: A Velocis SQL identifier cannot be a Velocis reserved word (see section 3.2).
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
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.
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.
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.
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);
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.
The examples below illustrate the use of the Velocis SQL arithmetic operators in
arithmetic expressions.
sum(on_hand.quantity * cost)
(pi()*(radius/2.0) * delta)/1.414
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.
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.
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");
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.
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.
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.
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.
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.
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.
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.
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.
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;
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).
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");
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";
Example
begin trans new_salesperson;
insert into salesperson
values("SBB", "Scott Blades", 0.80, "West", 1, "MCK");
commit trans new_salesperson;
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.
Example
open sales, invntory;
...access databases
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.
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;
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);
Example
create database instance wa_accounts from us_accounts on wadev;
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.
Example
create device testdev as "d:\v30\test";
exec ShowDevices;
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.
Example
create extension file "sales.0x0" on sqldev for "sales.000" on sqldev;
exec ShowDbFiles("sales");
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
Example
create database sales on sqldev;
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.
Example
create filter bbscores in "Ief" on rdsdll;
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.
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;
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
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);
create join Create a join between a primary key and a foreign key
(DDL statement)
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.
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;
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.
c_type_spec:
c_base_type | struct { c_base_type field_name[dims]; ... }
c_base_type:
[unsigned] {char | short | int | long} | float | double | wchar
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
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;
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;
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;
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
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.
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;
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;
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.
Example
delete from on_hand where quantity = 0;
Example
drop database sales;
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.
Example
exec ShowDevices;
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.
Example
drop function geomean;
Example
drop procedure rlm_login;
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.
Example
drop table skm_sales;
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;
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.
Example
drop view temp_view;
Example
execute order_report(date "06-01-1992", date "06-30-1992");
execute Show the list of files for a given database (DML statement)
ShowDbFiles
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
Example
exec ShowDbFiles("sales");
Column
Name Type Length Description
Example
exec ShowDevices;
Example
exec ShowUsers;
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.
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;
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;
Example
initialize database sales;
initialize database invntory;
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
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).
See Also insert (from select), insert (values), lock table, open
convert (Chapter 5)
Example
insert into outlet file "outlet.asc" on catdev;
commit;
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).
Example
insert into game from filter bbscores(date ’1998-09-07’);
insert Insert rows that result from a query into a table, file, or filter
(from select) (DML statement)
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)
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;
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
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.
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;
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.
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 */
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;
Example
-- only administrators can modify the salesperson table
revoke insert, delete on salesperson from "Wayne", FLORESB;
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.
Example
begin work;
... /* make some changes to the database */
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.
Example
select company, ord_num, ord_date, amount, tax, amount+tax total
from customer, sales_order
where customer.cust_id = sales_order.cust_id;
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.
Example
set currency to "£";
select ord_date, convert(amount, char, 12, "£#,#.##") amount
from sales_order;
set date default Set the default date constant format (DML statement)
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.
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";
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.
Example
set decimal to ",";
set thousands to "."
select ord_date, convert(amount, char, 12, "#.#,##") amount
from sales_order;
set display Set the default character display format (DML statement)
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.
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
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.
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.
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;
set opt_limit Set the failure-to-improve threshold for the Velocis SQL query
optimizer (DML statement)
set thousands Set the numeric (thousands) separator character (DML statement)
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.
Example
set decimal to ",";
set thousands to "."
select ord_date, convert(amount, char, 12, "#.#,##") amount
from sales_order;
set timeout Set the lock waiting timeout value (DML statement)
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.
Example
set timeout to 5;
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.
Example
set wild one to "?";
set wild all to "*";
select company, city, state from customer
where cust_id like "S??" and company like "*Corp*";
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.
Example
lock table customer, sales_order in share mode;
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.
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";
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.
Example
update stats on sales, invntory;
Syntax abs(arith_expr)
Description This scalar numeric function retrieves the absolute value of the
specified arithmetic expression.
Syntax acos(arith_expr)
Description This scalar numeric function retrieves the arccosine, in radians, of the
specified arithmetic expression.
Syntax ascii(strexp)
Description This scalar string function retrieves the ASCII numeric value of the
initial character in the specified string expression.
Syntax asin(arith_expr)
Description This scalar numeric function retrieves the arcsine, in radians, of the
specified arithmetic expression.
Syntax atan(arith_expr)
avg Compute the average of the results for 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
Syntax ceiling(arith_expr)
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.
Syntax char(num)
Description This scalar string function retrieves the ASCII character that
corresponds to the specified code value.
Description This scalar string function concatenates one string (strexp2) to another
(strexp1). The operation is the same as using the concatenation ("^")
operator.
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).
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".
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"
Syntax cos(arith_expr)
Description This scalar numeric function retrieves the cosine of the specified
arithmetic expression. Cosine operations return values between -1.0
and +1.0.
Syntax cot(arith_expr)
Description This scalar numeric function retrieves the cotangent of the specified
arithmetic expression. Cotangent operations return values between
-∞ and +∞.
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
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.
Syntax curtime()
Parameters None
Description This scalar date/time function retrieves the current local (server)
time.
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").
Syntax dayofmonth(date_expr)
Description This scalar date/time function retrieves the day of the month in the
specified date expression as a number between 1 and 31.
Syntax dayofweek(date_expr)
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.
Syntax dayofyear(date_expr)
Description This scalar date/time function retrieves the day of the year in the
specified date expression as a number between 1 and 366.
Syntax exp(arith_expr)
Syntax floor(arith_expr)
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.
Syntax hour(time_expr)
Description This scalar date/time function retrieves the hour in the specified time
expression as a number between 0 and 23.
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;
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.
Syntax lcase(strexp)
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.
Syntax length(strexp)
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.
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.
Syntax log(arith_expr)
Description This scalar numeric function retrieves the natural logarithm of the
specified arithmetic expression.
Syntax ltrim(strexp)
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.
Syntax max(expression)
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
Syntax min(expression)
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
Syntax minute(time_expr)
Description This scalar date/time function returns the minute in the specified
time expression as a number between 0 and 59.
Syntax month(date_expr)
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
Syntax now()
Parameters None
Description This scalar date/time function retrieves a timestamp value for the
current date and time.
Syntax pi()
Parameters None
Description This scalar numeric function retrieves the value of pi as a double data
type (3.14159…).
Syntax quarter(date_expr)
Description This scalar date/time function retrieves the number of the quarter in
the specified date expression as a number between 1 and 4.
Syntax rand(num)
Syntax rtrim(strexp)
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.
Syntax second(time_expr)
Description This scalar date/time function returns the second in the specified
time expression as a number between 0 and 59.
Syntax sign(arith_expr)
Syntax sin(arith_expr)
Description This scalar numeric function retrieves the sine of the specified
arithmetic expression. Sine operations return values between -1.0
and +1.0.
Syntax sqrt(arith_expr)
Description This scalar numeric function retrieves the square root of the specified
arithmetic expression.
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.
Syntax sum(arith_expr)
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;
Syntax tan(arith_expr)
Description This scalar numeric function retrieves the tangent of the specified
arithmetic expression. Tangent operations return values between -∞
and +∞.
Syntax ucase(strexp)
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.
Syntax unicode(strexp)
Description This scalar string function retrieves the Unicode numeric value of the
initial character in the specified expression.
Syntax user()
Parameters None
Description This system function retrieves the database user name as a string.
Syntax week(date_expr)
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.
Syntax wchar(num)
Description This scalar string function retrieves the character that corresponds to
the specified Unicode code value.
Syntax year(date_expr)
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.
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.
Example
blob file [2048] "pics.dat" contains a_picture;
record rec_with_blob {
...
blob_id a_picture;
...
}
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.
Example
data file [2048] "info.dat" contains info;
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.
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.
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;
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.
Note: In a database, all record names must be distinct from all field
names.
type:
[unsigned] {int | short | long | char} | wchar
| float | double | db_addr | blob_id
| DefinedTypeName | struct DefinedStructureTag
dim:
[dim1] [[dim2] [[dim3]]]
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;
}
}
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.
Example
set comment {
order first;
owner note;
member project;
member task;
member work_day;
}