1033
DB2 ® IBM Informix IBM Informix Guide to SQL: Syntax Version 10.0/8.5 G251-2284-02

IBM Informix Guide to SQL - Syntax

Embed Size (px)

Citation preview

DB2 IBM Informix

Version 10.0/8.5

IBM Informix Guide to SQL: Syntax

G251-2284-02

DB2 IBM Informix

Version 10.0/8.5

IBM Informix Guide to SQL: Syntax

G251-2284-02

Note: Before using this information and the product it supports, read the information in Notices on page D-1.

Third Edition (December 2005) This document contains proprietary information of IBM. It is provided under a license agreement and is protected by copyright law. The information contained in this publication does not include any product warranties, and any statements provided in this manual should not be interpreted as such. When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. Copyright International Business Machines Corporation 1996, 2005. All rights reserved. US Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

ContentsIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ixIn This Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Types of Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x Software Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x Assumptions About Your Locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . x Demonstration Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x New Features in Dynamic Server, Version 10.0 . . . . . . . . . . . . . . . . . . . . . . . . xi 3 New Features in Dynamic Server, Version 10.00.xC3 . . . . . . . . . . . . . . . . . . . . . . xii 4 New Features in Dynamic Server, Version 10.00.xC4 . . . . . . . . . . . . . . . . . . . . . xiii New Features in Extended Parallel Server, Version 8.5 . . . . . . . . . . . . . . . . . . . . . xiii Documentation Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv Feature, Product, and Platform Markup . . . . . . . . . . . . . . . . . . . . . . . . . xiv Syntax Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Example Code Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii Additional Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix IBM Informix Information Center . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Installation Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Online Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Informix Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Online Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii IBM Informix Dynamic Server Version 10.0 and CSDK Version 2.90 Documentation Set . . . . . . . . . xxii Compliance with Industry Standards . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv IBM Welcomes Your Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv

Chapter 1. Overview of SQL Syntax . . . . . . . . . . . . . . . . . . . . . . . 1-1In This Chapter . . . . . . . . . . . . . . . . How to Enter SQL Statements . . . . . . . . . . . Using Syntax Diagrams and Syntax Tables . . . . . . Using Examples . . . . . . . . . . . . . . Using Related Information . . . . . . . . . . . How to Enter SQL Comments . . . . . . . . . . . Examples of SQL Comment Symbols. . . . . . . . Non-ASCII Characters in SQL Comments . . . . . . Categories of SQL Statements . . . . . . . . . . . Data Definition Language Statements . . . . . . . Data Manipulation Language Statements . . . . . . Data Integrity Statements . . . . . . . . . . . Cursor Manipulation Statements . . . . . . . . . Dynamic Management Statements . . . . . . . . Data Access Statements . . . . . . . . . . . . Optimization Statements . . . . . . . . . . . . Routine Definition Statements . . . . . . . . . . Auxiliary Statements . . . . . . . . . . . . . Client/Server Connection Statements . . . . . . . Optical Subsystem Statements (IDS) . . . . . . . . ANSI/ISO Compliance and Extensions . . . . . . . . ANSI/ISO-Compliant Statements . . . . . . . . . ANSI/ISO-Compliant Statements with Informix Extensions Statements that are Extensions to the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1-1 1-2 1-3 1-3 1-3 1-5 1-5 1-6 1-6 1-7 1-7 1-7 1-7 1-7 1-8 1-8 1-8 1-8 1-8 1-8 1-8 1-8 1-9

Chapter 2. SQL Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1 Copyright IBM Corp. 1996, 2005

iii

In This Chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 ALLOCATE COLLECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 ALLOCATE DESCRIPTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 ALLOCATE ROW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 ALTER ACCESS_METHOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 ALTER FRAGMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 ALTER FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31 ALTER INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33 ALTER PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35 ALTER ROUTINE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37 ALTER SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40 ALTER TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43 BEGIN WORK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-66 CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-68 CLOSE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-71 COMMIT WORK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-73 CONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-75 CREATE ACCESS_METHOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-82 CREATE AGGREGATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-84 CREATE CAST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-87 CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-90 CREATE DISTINCT TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-93 CREATE DUPLICATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-96 CREATE EXTERNAL TABLE (XPS) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-98 CREATE FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-107 CREATE FUNCTION FROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-114 CREATE INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-116 CREATE OPAQUE TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-136 CREATE OPCLASS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-141 CREATE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-145 CREATE PROCEDURE FROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-153 CREATE ROLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-155 CREATE ROUTINE FROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-157 CREATE ROW TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-158 CREATE SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-162 CREATE SCRATCH TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-164 CREATE SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-165 CREATE SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-168 CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-171 CREATE TEMP TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-208 CREATE Temporary TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-209 CREATE TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-216 CREATE VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-247 3 CREATE XADATASOURCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-252 3 CREATE XADATASOURCE TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-253 DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-255 DEALLOCATE COLLECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-257 DEALLOCATE DESCRIPTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-258 DEALLOCATE ROW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-259 DECLARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-260 DELETE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-275 DESCRIBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-281 DESCRIBE INPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-286 DISCONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-291 DROP ACCESS_METHOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-294 DROP AGGREGATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-295 DROP CAST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-296 DROP DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-297 DROP DUPLICATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-299 DROP FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-300 DROP INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-302

iv

IBM Informix Guide to SQL: Syntax

DROP OPCLASS . . . . . DROP PROCEDURE . . . . DROP ROLE . . . . . . . DROP ROUTINE . . . . . DROP ROW TYPE . . . . . DROP SEQUENCE . . . . . DROP SYNONYM . . . . . DROP TABLE . . . . . . DROP TRIGGER. . . . . . DROP TYPE . . . . . . . DROP VIEW . . . . . . . DROP XADATASOURCE . . . DROP XADATASOURCE TYPE EXECUTE . . . . . . . . EXECUTE FUNCTION . . . EXECUTE IMMEDIATE . . . EXECUTE PROCEDURE . . . FETCH . . . . . . . . . FLUSH . . . . . . . . . FREE . . . . . . . . . GET DESCRIPTOR . . . . . GET DIAGNOSTICS . . . . GRANT . . . . . . . . GRANT FRAGMENT . . . . INFO . . . . . . . . . INSERT . . . . . . . . . LOAD . . . . . . . . . LOCK TABLE . . . . . . MERGE . . . . . . . . MOVE TABLE . . . . . . OPEN . . . . . . . . . OUTPUT . . . . . . . . PREPARE . . . . . . . . PUT . . . . . . . . . . RENAME COLUMN . . . . RENAME DATABASE . . . . RENAME INDEX . . . . . RENAME SEQUENCE. . . . RENAME TABLE . . . . . REVOKE . . . . . . . . REVOKE FRAGMENT . . . . ROLLBACK WORK . . . . SAVE EXTERNAL DIRECTIVES SELECT . . . . . . . . SET ALL_MUTABLES . . . . SET AUTOFREE . . . . . . SET COLLATION . . . . . SET CONNECTION . . . . SET CONSTRAINTS . . . . SET Database Object Mode . . SET DATASKIP . . . . . . SET DEBUG FILE . . . . . SET Default Table Space . . . SET Default Table Type . . . SET DEFERRED_PREPARE . . SET DESCRIPTOR . . . . . SET ENCRYPTION PASSWORD SET ENVIRONMENT . . . . SET EXPLAIN . . . . . . SET INDEX . . . . . . . SET INDEXES . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2-304 2-305 2-307 2-308 2-310 2-312 2-313 2-314 2-316 2-317 2-318 2-319 2-320 2-321 2-329 2-334 2-336 2-344 2-353 2-355 2-357 2-362 2-371 2-388 2-393 2-395 2-407 2-413 2-416 2-419 2-424 2-431 2-433 2-442 2-449 2-451 2-452 2-453 2-454 2-456 2-471 2-474 2-476 2-479 2-527 2-529 2-531 2-534 2-538 2-539 2-545 2-547 2-549 2-550 2-552 2-554 2-560 2-563 2-568 2-573 2-574

Contents

v

SET ISOLATION . . . . . SET LOCK MODE . . . . . SET LOG . . . . . . . . SET OPTIMIZATION . . . . SET PDQPRIORITY . . . . SET PLOAD FILE . . . . . SET Residency . . . . . . SET ROLE . . . . . . . . SET SCHEDULE LEVEL . . . SET SESSION AUTHORIZATION SET STATEMENT CACHE . . SET TABLE . . . . . . . SET TRANSACTION . . . . SET Transaction Mode . . . . SET TRIGGERS . . . . . . START VIOLATIONS TABLE . STOP VIOLATIONS TABLE . . 4 TRUNCATE (IDS) . . . . . TRUNCATE (XPS) . . . . . UNLOAD . . . . . . . . UNLOCK TABLE . . . . . UPDATE . . . . . . . . UPDATE STATISTICS . . . . WHENEVER . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . .

2-575 2-580 2-582 2-584 2-586 2-589 2-590 2-592 2-594 2-595 2-597 2-601 2-602 2-606 2-608 2-609 2-622 2-624 2-628 2-630 2-635 2-636 2-649 2-659

Chapter 3. SPL Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1In This Chapter . . CALL . . . . . CASE . . . . . CONTINUE . . . DEFINE . . . . EXIT . . . . . FOR . . . . . FOREACH . . . IF . . . . . . LET . . . . . ON EXCEPTION . RAISE EXCEPTION RETURN . . . SYSTEM . . . . TRACE . . . . WHILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1 . 3-2 . 3-4 . 3-6 . 3-7 . 3-16 . 3-17 . 3-20 . 3-25 . 3-28 . 3-31 . 3-35 . 3-37 . 3-39 . 3-41 . 3-43

Chapter 4. Data Types and Expressions . . . . . . . . . . . . . . . . . . . . . 4-1In This Chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 Scope of Segment Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 Use of Segment Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 Collection Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5 Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18 DATETIME Field Qualifier. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32 Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 INTERVAL Field Qualifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-127 Literal Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-129 Literal DATETIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-132 Literal INTERVAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-135 Literal Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-137 Literal Row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-139 Quoted String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-142 Relational Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-146

vi

IBM Informix Guide to SQL: Syntax

Chapter 5. Other Syntax Segments . . . . . . . . . . . . . . . . . . . . . . . 5-1In This Chapter . . . . . Arguments . . . . . . Collection-Derived Table . . Database Name . . . . Database Object Name . . External Routine Reference Identifier . . . . . . Jar Name . . . . . . Optimizer Directives . . . Owner Name . . . . . Purpose Options . . . . Return Clause . . . . . Routine Modifier . . . . Routine Parameter List . . Shared-Object Filename . . Specific Name . . . . . Statement Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1 . 5-2 . 5-5 . 5-15 . 5-17 . 5-20 . 5-22 . 5-33 . 5-34 . 5-43 . 5-46 . 5-51 . 5-54 . 5-61 . 5-65 . 5-68 . 5-69

Appendix A. Reserved Words for IBM Informix Dynamic Server . . . . . . . . . . . A-1 Appendix B. Reserved Words for IBM Informix Extended Parallel Server . . . . . . . B-1 Appendix C. Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . C-1 Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D-1 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . X-1

Contents

vii

viii

IBM Informix Guide to SQL: Syntax

IntroductionIn This Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Types of Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x Software Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x Assumptions About Your Locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . x Demonstration Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x New Features in Dynamic Server, Version 10.0 . . . . . . . . . . . . . . . . . . . . . . . . xi 3 New Features in Dynamic Server, Version 10.00.xC3 . . . . . . . . . . . . . . . . . . . . . . xii 4 New Features in Dynamic Server, Version 10.00.xC4 . . . . . . . . . . . . . . . . . . . . . xiii New Features in Extended Parallel Server, Version 8.5 . . . . . . . . . . . . . . . . . . . . . xiii Documentation Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv Feature, Product, and Platform Markup . . . . . . . . . . . . . . . . . . . . . . . . . xiv Syntax Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv How to Read a Command-Line Syntax Diagram . . . . . . . . . . . . . . . . . . . . . xvi Keywords and Punctuation . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Identifiers and Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii Example Code Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii Additional Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix IBM Informix Information Center . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Installation Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Online Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Locating Online Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx Online Notes Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Informix Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Online Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Printed Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii Online Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii IBM Informix Dynamic Server Version 10.0 and CSDK Version 2.90 Documentation Set . . . . . . . . . xxii Compliance with Industry Standards . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv IBM Welcomes Your Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv

In This IntroductionThis introduction provides an overview of the information in this manual and describes the documentation conventions that it uses.

About This ManualThis manual describes the syntax of the Structured Query Language (SQL) and Stored Procedure Language (SPL) statements for Version 10.0 of IBM Informix Dynamic Server and Version 8.5 of IBM Informix Extended Parallel Server. This manual is a companion volume to the IBM Informix Guide to SQL: Reference, the IBM Informix Guide to SQL: Tutorial, and the IBM Informix Database Design and Implementation Guide. The IBM Informix Guide to SQL: Reference provides reference information about the system catalog, the built-in SQL data types, and environment variables that can affect SQL statements. The IBM Informix Guide to SQL: Tutorial shows how to use basic and advanced SQL and SPL routines to

Copyright IBM Corp. 1996, 2005

ix

access and manipulate the data in your databases. The IBM Informix Database Design and Implementation Guide shows how to use SQL to implement and manage relational databases.

Types of UsersThis manual is written for the following users: v Database users v Database administrators v Database-application programmers This manual assumes that you have the following background: v A working knowledge of your computer, your operating system, and the utilities that your operating system provides v Some experience working with relational databases or exposure to database concepts v Some experience with computer programming If you have limited experience with relational databases, SQL, or your operating system, refer to the IBM Informix Getting Started Guide for your database server for a list of supplementary titles.

Software DependenciesThis manual assumes that you are using one of the following database servers: v IBM Informix Extended Parallel Server, Version 8.5 v IBM Informix Dynamic Server, Version 10.0

Assumptions About Your LocaleIBM Informix products can support many languages, cultures, and code sets. All culture-specific information is brought together in a single environment, called a Global Language Support (GLS) locale. This manual assumes that you use the U.S. 8859-1 English locale as the default locale. The default is en_us.8859-1 (ISO 8859-1) on UNIX platforms or en_us.1252 (Microsoft 1252) for Windows environments. These locales support U.S. English format conventions for dates, times, and currency, and also support the ISO 8859-1 or Microsoft 1252 code set, which includes the ASCII code set plus many 8-bit characters such as , , and . If you plan to use non-ASCII characters in your data or in SQL identifiers, or if you want to conform to localized collation rules of character data, you need to specify an appropriate nondefault locale. For instructions on how to specify a nondefault locale, additional syntax, and other considerations related to GLS locales, see the IBM Informix GLS User's Guide.

Demonstration DatabasesThe DBAccess utility, which is provided with your IBM Informix database server products, includes one or more of the following demonstration databases: v The stores_demo database illustrates a relational schema with information about a fictitious wholesale sporting-goods distributor. Many examples in IBM Informix manuals are based on the stores_demo database.

x

IBM Informix Guide to SQL: Syntax

v For Extended Parallel Server only, the sales_demo database illustrates a dimensional schema for data-warehousing applications. For conceptual information about dimensional data modeling, see the IBM Informix Database Design and Implementation Guide. v For Dynamic Server only, the superstores_demo database illustrates an object-relational schema that contains examples of extended data types, data-type inheritance and table inheritance, and user-defined routines. For information about how to create and populate the demonstration databases, see the IBM Informix DBAccess User's Guide. For descriptions of the databases and their contents, see the IBM Informix Guide to SQL: Reference. The scripts that you use to install the demonstration databases reside in the $INFORMIXDIR/bin directory on UNIX platforms and in the %INFORMIXDIR%\bin directory in Windows environments.

New Features in Dynamic Server, Version 10.0For a comprehensive list of new database server features, see the IBM Informix Getting Started Guide. This section lists new features introduced in Version 10.00.xC1 that are relevant to this manual. The following list provides information about the new features of IBM Informix Dynamic Server, Version 10.00.xC1, that this manual describes. v The following new SQL statements are documented in Chapter 2, SQL Statements, on page 2-1: SAVE EXTERNAL DIRECTIVES SET ENCRYPTION PASSWORD SET ENVIRONMENT OPTCOMPIND v The following SQL statements support new syntax in Version 10.0: Statement ALTER FRAGMENT ALTER TABLE CREATE INDEX CREATE INDEX CREATE TABLE DROP INDEX GRANT REVOKE New Keywords PARTITION PARTITION ONLINE PARTITION PARTITION ONLINE DEFAULT ROLE DEFAULT ROLE

SET ROLE DEFAULT v The DBSA (Database Server Administrator) can use the GRANT ROLE EXTEND statement to assign the new built-in role EXTEND to users. When this security feature is enabled, only users who hold the EXTEND role can register or drop external UDRs or create shared libraries in the database. v This release introduces default roles that the DBA can grant or revoke. These take effect when a user who holds a default role connects to the database, so that appropriate access privileges are available for using applications that do not include GRANT statements that reference individual users. New SQL functions can return the current role or the default role of the user.Introduction

xi

v The CREATE INDEX and DROP INDEX statements can specify the ONLINE keyword to define or drop an index without applying table locks that might interfere with concurrent users. v Tables and indexes now can use fragmentation strategies that define multiple named fragments within the same dbspace. v Data values returned by distributed DML operations or UDRs in databases of the same Dynamic Server instance now can return the built-in opaque data types BLOB, BOOLEAN, CLOB, and LVARCHAR. They can also return UDTs, and DISTINCT types whose base types are built-in types, if the UDTs and DISTINCT types are explicitly cast to built-in data types, and if the casts, DISTINCT types, and UDTs are defined in all the participating databases. v The DS_NONPDQ_QUERY_MEM configuration parameter can be set to improve the performance of certain non-PDQ queries. v This release supports external optimizer directives that reside in the database and that are automatically applied to specified queries. These can be enabled or disabled for a given session by a configuration parameter. v The SET ENVIRONMENT OPTCOMPIND statement can reset the value of OPTCOMPIND dynamically, overriding the corresponding configuration parameter or environment variable setting. This can improve performance during sessions that use queries for both DS (decision-support) and OLTP (online-transaction-processing). v The SET ENCRYPTION PASSWORD statement can specify a session password to support column-level and cell-level encryption of sensitive data. This statement, and new built-in encryption and decryption functions, can support compliance with data security and data confidentiality requirements that are mandated for some industries and jurisdictions. v User-defined functions can include multiple INOUT parameters. 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

New Features in Dynamic Server, Version 10.00.xC3For a comprehensive list of new database server features in Version 10.00.xC3, see the IBM Informix Getting Started Guide. This section lists new features introduced in Version 10.00.xC3 that this manual describes. New data definition language (DDL) statements support XA-compliant external data sources. Use these to apply the transactional semantics of Dynamic Server and two-phase commit protocols to transactions with external data sources: v CREATE XADATASOURCE v CREATE XADATASOURCE TYPE v DROP XADATASOURCE v DROP XADATASOURCE TYPE New Projection Clause syntax of the SELECT statement can control the number of qualifying rows in the result set of a query: v SKIP offset v LIMIT max The SKIP offset clause excludes the first offset qualifying rows from the result set, for offset an integer. If you also include the LIMIT max clause (where LIMIT is a keyword synonym for FIRST), no more than max rows are returned. The offset and max values can be specified as literal integers in the SERIAL8 range, or as host variables, or as local SPL variables. You can save the result set as a collection-derived table (CDT).

xii

IBM Informix Guide to SQL: Syntax

3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

If you also include the ORDER BY clause, qualifying rows are first arranged by the ORDER BY specification before SKIP offset and LIMIT max clauses are applied.

New Features in Dynamic Server, Version 10.00.xC4For a comprehensive list of new database server features in Version 10.00.xC4, see the IBM Informix Getting Started Guide. In addition to documenting the new feature of Version 10.00.xC4 that is described in this section, this manual corrects errata that have been identified since the previous edition. A new TRUNCATE data definittion language (DDL) statement of SQL removes all active rows and the entire B-tree structure of all indexes from all partitions of a specified table in the local database. Storage formerly occupied by these data rows and indexes becomes available for other tables, or you can optionally reserve the space for reuse in subsequent operations on the same table or index partition. While the TRUNCATE statement is executing, no other session can lock or modify the table until TRUNCATE completes and is either committed or rolled back. In a database with transaction logging, a subsequent ROLLBACK statement can restore the table to its state before the transaction that included TRUNCATE began, but no operation except COMMIT or ROLLBACK can follow TRUNCATE within a transaction. After the TRUNCATE statement successfully executes, the database server automatically resets the statistics and distributions for the table and for its indexes, as if UPDATE STATISTICS had been executed for that table. Any Delete trigger that is defined on the table is ignored when TRUNCATE executes, and the serial counter for SERIAL and SERIAL8 columns is not reset. The table that you truncate can be a raw, temporary, or standard table. It can also be a virtual table, or a table with a virtual-index interface, provided that the virtual table or the virtual-index interface has a valid am_truncate( ) purpose function that was explicitly registered in the sysams system catalog table. This feature offers performance advantages over the DELETE table statement, because TRUNCATE empties a table without logging individual deleted rows or index updates, and without activating Delete triggers. Unlike the DROP TABLE statement, TRUNCATE does not remove the definitions of the table or its indexes, triggers, views, constraints, privileges, and other properties from the system catalog. The TRUNCATE statement can also make storage management more efficient through its ability to free space, or to reuse the space for the same table and its indexes.

New Features in Extended Parallel Server, Version 8.5The following new SQL statements of IBM Informix Extended Parallel Server, Version 8.5 are documented in Chapter 2, SQL Statements, on page 2-1: v MERGE v MOVE v SET ALL_MUTABLES For a complete list of new features in Extended Parallel Server, Version 8.5, see the Getting Started With IBM Informix Extended Parallel Server Guide.

Introduction

xiii

Documentation ConventionsThis section describes the conventions that this manual uses. These conventions make it easier to gather information from this and other volumes in the documentation set. The following conventions are discussed: v Typographical conventions v Other conventions v Syntax diagrams v Command-line conventions v Example code conventions

Typographical ConventionsThis manual uses the following conventions to introduce new terms, illustrate screen displays, describe command syntax, and so forth.Convention KEYWORD italics Meaning Keywords of SQL, SPL, and some other programming languages appear in uppercase letters in a serif font. Within text, new terms and emphasized words appear in italics. Within syntax and code examples, variable values that you are to specify appear in italics. Names of program entities (such as classes, events, and tables), environment variables, file and pathnames, and interface elements (such as icons, menu items, and buttons) appear in boldface. Information that the product displays and information that you enter appear in a monospace typeface. Keys that you are to press appear in uppercase letters in a sans serif font. This symbol indicates a menu item. For example, Choose Tools > Options means choose the Options item from the Tools menu.

boldface

monospace KEYSTROKE >

Tip: When you are instructed to enter characters or to execute a command, immediately press RETURN after the entry. When you are instructed to type the text or to press other keys, no RETURN is required.

Feature, Product, and Platform MarkupFeature, product, and platform markup identifies paragraphs that contain feature-specific, product-specific, or platform-specific information. Some examples

xiv

IBM Informix Guide to SQL: Syntax

of this markup follow: Dynamic Server Identifies information that is specific to IBM Informix Dynamic Server End of Dynamic Server Windows Only Identifies information that is specific to the Windows environment End of Windows Only This markup can apply to one or more paragraphs within a section. When an entire section applies to a particular product or platform, this is noted as part of the heading text, for example: Table Sorting (Linux)

Syntax DiagramsThis guide uses syntax diagrams built with the following components to describe the syntax for statements and all commands other than system-level commands. Syntax diagrams depicting SQL and command-line statements have changed in the following ways: v The symbols at the beginning and end of statements are double arrows. v The symbols at the beginning and end of syntax segment diagrams are vertical lines. v How many times a loop can be repeated is explained in a diagram footnote, whose marker appears above the path that is describes. v Syntax statements that are longer than one line continue on the next line. v Product or condition-specific paths are explained in diagram footnotes, whose markers appear above the path that they describe. v Cross-references to the descriptions of other syntax segments appear as diagram footnotes, whose markers immediately follow the name of the segment that they reference. The following table describes syntax diagram components.Component represented in PDF Component represented in HTML >>---------------------Meaning Statement begins.

----------------------->

Statement continues on next line. Statement continues from previous line. Statement ends. Required item.

>--------------------------------------------->< --------SELECT----------

Introduction

xv

Component represented in PDF

Component represented in HTML --+-----------------+--------LOCAL------ ---+-----ALL-------+--+--DISTINCT-----+ ---UNIQUE------

Meaning Optional item.

Required item with choice. One and only one item must be present.

---+------------------+--+--FOR UPDATE-----+ --FOR READ ONLY-- .---NEXT---------. ----+----------------+--+---PRIOR--------+ ---PREVIOUS-----

Optional items with choice are shown below the main line, one of which you might specify. The values below the main line are optional, one of which you might specify. If you do not specify an item, the value above the line will be used as the default. Optional items. Several items are allowed; a comma must precede each repetition.

.-------,-----------. V | ---+-----------------+--+---index_name---+ ---table_name---

>>-| Table Reference |->< Table Reference |--+-----view--------+--| +------table------+ ----synonym------

Reference to a syntax segment. Syntax segment.

How to Read a Command-Line Syntax DiagramThe following command-line syntax diagram uses some of the elements listed in the table in the previous section. Creating a No-Conversion Jobonpladm create job job -p project -n -d device -D database

-t table

xvi

IBM Informix Guide to SQL: Syntax

(1) Setting the Run Mode -S server -T target

Notes: 1 See page Z-1

The second line in this diagram has a segment named Setting the Run Mode, which according to the diagram footnote, is on page Z-1. If this was an actual cross-reference, you would find this segment in on the first page of Appendix Z. Instead, this segment is shown in the following segment diagram. Notice that the diagram uses segment start and end components. Setting the Run Mode:l c -f d p a u n N

To see how to construct a command correctly, start at the top left of the main diagram. Follow the diagram to the right, including the elements that you want. The elements in this diagram are case sensitive because the illustrates utility syntax. Other types of syntax, such as SQL, are not case sensitive. The Creating a No-Conversion Job diagram illustrates the following steps: 1. Type onpladm create job and then the name of the job. 2. Optionally, type -p and then the name of the project. 3. Type the following required elements: v -n v -d and the name of the device v -D and the name of the database v -t and the name of the table 4. Optionally, you can choose one or more of the following elements and repeat them an arbitrary number of times: v -S and the server name v -T and the target server name v The run mode. To set the run mode, follow the Setting the Run Mode segment diagram to type -f, optionally type d, p, or a, and then optionally type l or u. 5. Follow the diagram to the terminator. Your diagram is complete.

Keywords and PunctuationKeywords are words reserved for statements and all commands except system-level commands. When a keyword appears in a syntax diagram, it isIntroduction

xvii

shown in uppercase letters. When you use a keyword in a command, you can write it in uppercase or lowercase letters, but you must spell the keyword exactly as it appears in the syntax diagram. You must also use any punctuation in your statements and commands exactly as shown in the syntax diagrams.

Identifiers and NamesVariables serve as placeholders for identifiers and names in the syntax diagrams and examples. You can replace a variable with an arbitrary name, identifier, or literal, depending on the context. Variables are also used to represent complex syntax elements that are expanded in additional syntax diagrams. When a variable appears in a syntax diagram, an example, or text, it is shown in lowercase italic. The following syntax diagram uses variables to illustrate the general form of a simple SELECT statement.SELECT column_name FROM table_name

When you write a SELECT statement of this form, you replace the variables column_name and table_name with the name of a specific column and table.

Example Code ConventionsExamples of SQL code occur throughout this manual. Except as noted, the code is not specific to any single IBM Informix application development tool. If only SQL statements are listed in the example, they are not delimited by semicolons. For instance, you might see the code in the following example:CONNECT TO stores_demo ... DELETE FROM customer WHERE customer_num = 121 ... COMMIT WORK DISCONNECT CURRENT

To use this SQL code for a specific product, you must apply the syntax rules for that product. For example, if you are using DBAccess, you must delimit multiple statements with semicolons. If you are using an SQL API, you must use EXEC SQL at the start of each statement and a semicolon (or other appropriate delimiter) at the end of the statement. Tip: Ellipsis points in a code example indicate that more code would be added in a full application, but it is not necessary to show it to describe the concept being discussed. For detailed directions on using SQL statements for a particular application development tool or SQL API, see the manual for your product.

xviii

IBM Informix Guide to SQL: Syntax

Additional DocumentationFor additional information, refer to the following types of documentation: v Installation guides v Online notes v Informix error messages v Manuals v Online help

IBM Informix Information CenterThe Informix Dynamic Server Information Center integrates the entire IBM Informix Dynamic Server 10.0 and IBM Informix Client SDK (CSDK) 2.90 documentation sets in both HTML and PDF formats. The Information Center provides full text search, a master index, logical categories, easy navigation, and links to troubleshooting and support files. The IBM Informix Information Center site is located at http://publib.boulder.ibm.com/infocenter/ids9help/index.jsp.

Installation GuidesInstallation guides are located in the /doc directory of the product CD or in the /doc directory of the products compressed file if you downloaded it from the IBM Web site. Alternatively, you can obtain installation guides from the IBM Informix Online Documentation site at http://www.ibm.com/software/data/informix/pubs/library/ or the IBM Informix Information Center at http://publib.boulder.ibm.com/infocenter/ids9help/index.jsp.

Online NotesThe following sections describe the online files that supplement the information in this manual. Please examine these files before you begin using your IBM Informix product. They contain vital information about application and performance issues.

Introduction

xix

Online File TOC Notes

Description The TOC (Table of Contents) notes file provides a comprehensive directory of hyperlinks to the release notes, the fixed and known defects file, and all the documentation notes files for individual manual titles. The documentation notes file for each manual contains important information and corrections that supplement the information in the manual or information that was modified since publication. The release notes file describes feature differences from earlier versions of IBM Informix products and how these differences might affect current products. For some products, this file also contains information about any known problems and their workarounds.

Format HTML

Documentation Notes

HTML, text

Release Notes

HTML, text

Machine Notes

(Non-Windows platforms only) The machine text notes file describes any platform-specific actions that you must take to configure and use IBM Informix products on your computer. This text file lists issues that have been identified with the current version. It also lists customer-reported defects that have been fixed in both the current version and in previous versions. text

Fixed and Known Defects File

Locating Online NotesOnline notes are available from the IBM Informix Online Documentation site at http://www.ibm.com/software/data/informix/pubs/library/ and in the IBM Informix Information Center at http://publib.boulder.ibm.com/infocenter/ids9help/index.jsp. Additionally you can locate these files before or after installation as described below. Before Installation All online notes are located in the /doc directory of the product CD. The easiest way to access the documentation notes, the release notes, and the fixed and known defects file is through the hyperlinks from the TOC notes file. The machine notes file and the fixed and known defects file are only provided in text format. After Installation On UNIX platforms in the default locale, the documentation notes, release notes, and machine notes files appear under the $INFORMIXDIR/release/en_us/0333 directory. Dynamic Server On Windows the documentation and release notes files appear in the Informix folder. To display this folder, choose Start > Programs > IBM product name version > Documentation Notes or Release Notes from the taskbar.

xx

IBM Informix Guide to SQL: Syntax

Machine notes do not apply to Windows platforms. End of Dynamic Server

Online Notes FilenamesOnline notes have the following file formats:Online File TOC Notes Documentation Notes Release Notes Machine Notes Fixed and Known Defects File File Format prod_os_toc_version.html prod_bookname_docnotes_version.html/txt prod_os_relnotes_version.html/txt prod_machine_notes_version.txt prod_defects_version.txt Examples ids_win_toc_10.0.html ids_hpl_docnotes_10.0.html ids_unix_relnotes_10.0.txt ids_machine_notes_10.0.txt ids_defects_10.0.txt client_defects_2.90.txt ids_win_fixed_and_known _defects_10.0.txt

ids_win_fixed_and_known _defects_version.txt

Informix Error MessagesThis file is a comprehensive index of error messages and their corrective actions for the Informix products and version numbers. On UNIX platforms, use the finderr command to read the error messages and their corrective actions. Dynamic Server On Windows, use the Informix Error Messages utility to read error messages and their corrective actions. To display this utility, choose Start > Programs > IBM product name version > Informix Error Messages from the taskbar. End of Dynamic Server You can also access these files from the IBM Informix Online Documentation site at http://www.ibm.com/software/data/informix/pubs/library/ or in the IBM Informix Information Center at http://publib.boulder.ibm.com/infocenter/ids9help/index.jsp.

ManualsOnline ManualsA CD that contains your manuals in electronic format is provided with your IBM Informix products. You can install the documentation or access it directly from the CD. For information about how to install, read, and print online manuals, see the installation insert that accompanies your CD. You can also obtain the same online manuals from the IBM Informix Online Documentation site at http://www.ibm.com/software/data/informix/pubs/library/ or in the IBM Informix Information Center at http://publib.boulder.ibm.com/infocenter/ids9help/index.jsp.

Introduction

xxi

Printed ManualsTo order hardcopy manuals, contact your sales representative or visit the IBM Publications Center Web site at http://www.ibm.com/software/howtobuy/data.html.

Online HelpIBM Informix online help, provided with each graphical user interface (GUI), displays information about those interfaces and the functions that they perform. Use the help facilities that each GUI provides to display the online help.

AccessibilityIBM is committed to making our documentation accessible to persons with disabilities. Our books are available in HTML format so that they can be accessed with assistive technology such as screen reader software. The syntax diagrams in our manuals are available in dotted decimal format, which is an accessible format that is available only if you are using a screen reader. For more information about the dotted decimal format, see the Accessibility appendix.

IBM Informix Dynamic Server Version 10.0 and CSDK Version 2.90 Documentation SetThe following tables list the manuals that are part of the IBM Informix Dynamic Server, Version 10.0 and the CSDK Version 2.90, documentation set. PDF and HTML versions of these manuals are available at http://www.ibm.com/software/data/informix/pubs/library/ or in the IBM Informix Information Center at http://publib.boulder.ibm.com/infocenter/ids9help/index.jsp. You can order hardcopy versions of these manuals from the IBM Publications Center at http://www.ibm.com/software/howtobuy/data.html.Table 1. Database Server Manuals Manual Administrators Guide Administrators Reference Subject Understanding, configuring, and administering your database server. Reference material for Informix Dynamic Server, such as the syntax of database server utilities onmode and onstat, and descriptions of configuration parameters, the sysmaster tables, and logical-log records. The concepts and methods you need to understand when you use the ON-Bar and ontape utilities to back up and restore data. Using the following DataBlade modules that are included with Dynamic Server: v MQ DataBlade module, to allow IBM Informix database applications to communicate with other MQSeries applications. v Large Object Locator, a foundation DataBlade module that can be used by other modules that create or store large-object data. DB-Access Users Guide DataBlade API Function Reference DataBlade API Programmers Guide Using the DB-Access utility to access, modify, and retrieve data from Informix databases. The DataBlade API functions and the subset of ESQL/C functions that the DataBlade API supports. You can use the DataBlade API to develop client LIBMI applications and C user-defined routines that access data in Informix databases. The DataBlade API, which is the C-language application-programming interface provided with Dynamic Server. You use the DataBlade API to develop client and server applications that access data stored in Informix databases.

Backup and Restore Guide Built-In DataBlade Modules Users Guide

xxii

IBM Informix Guide to SQL: Syntax

Table 1. Database Server Manuals (continued) Manual Database Design and Implementation Guide Enterprise Replication Guide Error Messages file Getting Started Guide Subject Designing, implementing, and managing your Informix databases. How to design, implement, and manage an Enterprise Replication system to replicate data between multiple database servers. Causes and solutions for numbered error messages you might receive when you work with IBM Informix products. Describes the products bundled with IBM Informix Dynamic Server and interoperability with other IBM products. Summarizes important features of Dynamic Server and the new features for each version. Information about Informix databases, data types, system catalog tables, environment variables, and the stores_demo demonstration database. Detailed descriptions of the syntax for all Informix SQL and SPL statements. A tutorial on SQL, as implemented by Informix products, that describes the basic ideas and terms that are used when you work with a relational database. Accessing and using the High-Performance Loader (HPL), to load and unload large quantities of data to and from Informix databases. Instructions for installing IBM Informix Dynamic Server on Windows. Instructions for installing IBM Informix Dynamic Server on UNIX and Linux. Writing user-defined routines (UDRs) in the Java programming language for Informix Dynamic Server with J/Foundation. Conversion to and reversion from the latest versions of Informix database servers. Migration between different Informix database servers. The Optical Subsystem, a utility that supports the storage of BYTE and TEXT data on optical disk. Configuring and operating IBM Informix Dynamic Server to achieve optimum performance. Creating R-tree indexes on appropriate data types, creating new operator classes that use the R-tree access method, and managing databases that use the R-tree secondary access method. The IBM Informix subagent that allows a Simple Network Management Protocol (SNMP) network manager to monitor the status of Informix servers. Informix Storage Manager (ISM), which manages storage devices and media for your Informix database server. The secure-auditing capabilities of Dynamic Server, including the creation and maintenance of audit logs. How to define new data types and enable user-defined routines (UDRs) to extend IBM Informix Dynamic Server. Creating a secondary access method (index) with the Virtual-Index Interface (VII) to extend the built-in indexing schemes of IBM Informix Dynamic Server. Typically used with a DataBlade module. Creating a primary access method with the Virtual-Table Interface (VTI) so that users have a single SQL interface to Informix tables and to data that does not conform to the storage scheme of Informix Dynamic Server.

Guide to SQL: Reference Guide to SQL: Syntax Guide to SQL: Tutorial High-Performance Loader Users Guide Installation Guide for Microsoft Windows Installation Guide for UNIX and Linux J/Foundation Developers Guide Migration Guide Optical Subsystem Guide Performance Guide R-Tree Index Users Guide

SNMP Subagent Guide Storage Manager Administrators Guide Trusted Facility Guide User-Defined Routines and Data Types Developers Guide Virtual-Index Interface Programmers Guide Virtual-Table Interface Programmers Guide

Introduction

xxiii

Table 2. Client/Connectivity Manuals Manual Client Products Installation Guide Embedded SQLJ Users Guide Subject Installing IBM Informix Client Software Developers Kit (Client SDK) and IBM Informix Connect on computers that use UNIX, Linux, and Windows. Using IBM Informix Embedded SQLJ to embed SQL statements in Java programs.

ESQL/C Programmers Manual The IBM Informix implementation of embedded SQL for C. GLS Users Guide The Global Language Support (GLS) feature, which allows IBM Informix APIs and database servers to handle different languages, cultural conventions, and code sets. Installing and using Informix JDBC Driver to connect to an Informix database from within a Java application or applet. Using Informix .NET Provider to enable .NET client applications to access and manipulate data in Informix databases. Using the Informix ODBC Driver API to access an Informix database and interact with the Informix database server. Installing and configuring Informix OLE DB Provider to enable client applications, such as ActiveX Data Object (ADO) applications and Web pages, to access data on an Informix server. The architecture of the C++ object interface and a complete class reference.

JDBC Driver Programmers Guide .NET Provider Reference Guide ODBC Driver Programmers Manual OLE DB Provider Programmers Guide Object Interface for C++ Programmers Guide

Table 3. DataBlade Developers Kit Manuals Manual DataBlade Developers Kit Users Guide DataBlade Module Development Overview DataBlade Module Installation and Registration Guide Subject Developing and packaging DataBlade modules using BladeSmith and BladePack. Basic orientation for developing DataBlade modules. Includes an example illustrating the development of a DataBlade module. Installing DataBlade modules and using BladeManager to manage DataBlade modules in Informix databases.

Compliance with Industry StandardsThe American National Standards Institute (ANSI) and the International Organization of Standardization (ISO) have jointly established a set of industry standards for the Structured Query Language (SQL). IBM Informix SQL-based products are fully compliant with SQL-92 Entry Level (published as ANSI X3.135-1992), which is identical to ISO 9075:1992. In addition, many features of IBM Informix database servers comply with the SQL-92 Intermediate and Full Level and X/Open SQL Common Applications Environment (CAE) standards.

IBM Welcomes Your CommentsWe want to know about any corrections or clarifications that you would find useful in our manuals, which will help us improve future versions. Include the following information: v The name and version of the manual that you are using v Section and page number v Your suggestions about the manual Send your comments to us at the following email address:

xxiv

IBM Informix Guide to SQL: Syntax

[email protected] This email address is reserved for reporting errors and omissions in our documentation. For immediate help with a technical problem, contact IBM Technical Support. For instructions, see the IBM Informix Technical Support website at http://www306.ibm.com/software/data/informix/support/contact.html. We appreciate your suggestions.

Introduction

xxv

xxvi

IBM Informix Guide to SQL: Syntax

Chapter 1. Overview of SQL SyntaxIn This Chapter . . . . . . . . . . . . . . . . How to Enter SQL Statements . . . . . . . . . . . Using Syntax Diagrams and Syntax Tables . . . . . . Using Examples . . . . . . . . . . . . . . Using Related Information . . . . . . . . . . . How to Enter SQL Comments . . . . . . . . . . . Examples of SQL Comment Symbols. . . . . . . . Non-ASCII Characters in SQL Comments . . . . . . Categories of SQL Statements . . . . . . . . . . . Data Definition Language Statements . . . . . . . Data Manipulation Language Statements . . . . . . Data Integrity Statements . . . . . . . . . . . Cursor Manipulation Statements . . . . . . . . . Dynamic Management Statements . . . . . . . . Data Access Statements . . . . . . . . . . . . Optimization Statements . . . . . . . . . . . . Routine Definition Statements . . . . . . . . . . Auxiliary Statements . . . . . . . . . . . . . Client/Server Connection Statements . . . . . . . Optical Subsystem Statements (IDS) . . . . . . . . ANSI/ISO Compliance and Extensions . . . . . . . . ANSI/ISO-Compliant Statements . . . . . . . . . ANSI/ISO-Compliant Statements with Informix Extensions Statements that are Extensions to the ANSI/ISO Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1-1 1-2 1-3 1-3 1-3 1-5 1-5 1-6 1-6 1-7 1-7 1-7 1-7 1-7 1-8 1-8 1-8 1-8 1-8 1-8 1-8 1-8 1-9

In This ChapterThis chapter provides information about how to use the SQL statements, SPL statements, and syntax segments that subsequent chapters of this book discuss. The chapter is organized into the following sections.Section How to Enter SQL Statements How to Enter SQL Comments on page 1-3 Categories of SQL Statements on page 1-6 ANSI/ISO Compliance and Extensions on page 1-8 Scope How to use syntax diagrams and descriptions to enter SQL statements correctly How to enter comments in SQL statements The SQL statements, listed by functional category The SQL statements, listed by degree of ANSI/ISO compliance

How to Enter SQL StatementsSQL is a free-form language, like C or PASCAL, that generally ignores whitespace characters like TAB, LINEFEED, and extra blank spaces between statements or statement elements. At least one blank character or other delimiter, however, must separate keywords and identifiers from other syntax tokens. SQL is lettercase-insensitive, except within quoted strings; see also Identifier on page 5-22. In an ANSI-compliant database, if you do not delimit the owner of an object by single ( ) quotation marks, and the ANSIOWNER environment variable Copyright IBM Corp. 1996, 2005

1-1

was not set to 1 when the database server was initialized, the database server stores the owner name in uppercase letters. Statement descriptions are provided in this manual to help you to enter SQL statements successfully. A statement description includes this information: v A brief introduction that explains what the statement does v A syntax diagram that shows how to enter the statement correctly v A syntax table that explains each input parameter in the syntax diagram v Rules of usage, typically with examples that illustrate these rules For some statements, this information is provided for individual clauses. Most statement descriptions conclude with references to related information in this manual and in other manuals. Chapter 2 provides descriptions of each SQL statement, arranged in alphabetical order. Chapter 3 describes each of the SPL statements, using the same format. The major aids for entering SQL statements include: v The combination of the syntax diagram and syntax table v The examples of syntax that appear in the rules of usage v The references to related information

Using Syntax Diagrams and Syntax TablesBefore you try to use the syntax diagrams in this chapter, it is helpful to read the section Syntax Diagrams on page xv of the Introduction. This section is the key to understanding the syntax diagrams and explains the elements that can appear in a syntax diagram and the paths that connect the elements to each other. This section also includes an example that illustrates the elements of typical syntax diagrams. The narrative that follows the example diagram shows how to read the diagram in order to enter the statement successfully. Notes to the diagram can reference other syntax segments or can specify various restrictions. If you are using an application programming interface, such as ESQL/C or 4GL, only the SQL syntax rules that both your client application and the database server support are valid. When a syntax diagram includes input specifications that are not keywords or punctuation symbols, such as identifiers, expressions, filenames, host variables, the syntax diagram is followed by a table that describes how to enter the term without generating errors. Each syntax table includes four columns: v The Element column lists each variable term in the syntax diagram. v The Description column briefly describes the term and identifies the default value, if the term has one. v The Restrictions column summarizes the restrictions on the term, such as acceptable ranges of values. (For some diagrams, restrictions that cannot be tersely summarized appear in the Usage notes, rather than in this column.) v The Syntax column points to the SQL segment that gives the detailed syntax for the term. For a few terms, such as the names of host variables, pathnames, or literal characters, no page reference is provided.

1-2

IBM Informix Guide to SQL: Syntax

The diagrams generally provide an intuitive notation for what is valid in a given SQL statement, but for some statements, dependencies or restrictions among syntax elements are identified only in the text of the Usage section.

Using ExamplesTo understand the main syntax diagram and subdiagrams for a statement, study the examples of syntax that appear in the rules of usage for each statement. These examples have two purposes: v To show how to accomplish specific tasks with the statement or its clauses v To show how to use syntax of the statement or its clauses in a concrete way Tip: An efficient way to understand a syntax diagram is to find an example of the syntax and compare it with the keywords and parameters in the syntax diagram. By mapping the concrete elements of the example to the abstract elements of the syntax diagram, you can understand the syntax diagram and use it more effectively. For an explanation of the conventions used in the examples in this manual, see Example Code Conventions on page xviii of the Introduction. These code examples are program fragments to illustrate valid syntax, rather than complete SQL programs. In some code examples, ellipsis ( . . . ) symbols indicate that additional code has been omitted. To save space, however, ellipses are not shown at the beginning or end of the program fragments.

Using Related InformationFor help in understanding concepts and terms in the SQL statement description, check the Related Information section at the end of each statement. This section points to related information in this manual and other manuals to help you understand the statement in question. The section provides some or all of the following information: v The names of related statements that might contain a fuller discussion of topics in this statement v The titles of other manuals that provide extended discussions of topics in this statement Tip: If you do not have extensive knowledge and experience with SQL, the IBM Informix Guide to SQL: Tutorial gives you the basic SQL knowledge that you need to understand and use the statement descriptions in this manual.

How to Enter SQL CommentsYou can add comments to clarify the purpose or effect of particular SQL statements. You can also use comment symbols during program development to disable individual statements without deleting them from your source code. Your comments can help you or others to understand the role of the statement within a program, SPL routine, or command file. The code examples in this manual sometimes include comments that clarify the role of an SQL statement within the code, but your own SQL programs will be easier to read and to maintain if you document them with frequent comments.

Chapter 1. Overview of SQL Syntax

1-3

The following table shows the SQL comment indicators that you can enter in your code. Here a Y in a column signifies that you can use the symbol with the product or with the type of database identified in the column heading. An N in a column signifies that you cannot use the symbol with the indicated product or with a database of the indicated ANSI-compliance status.ANSICompliant Databases Y Databases Not ANSI Compliant Y

Comment Symbol double hyphen (--)

ESQL/C Y

SPL Routine Y

DBAccess Y

Description The double hyphen precedes a comment within a single line. To comment more than one line, put double hyphen symbols at the beginning of each comment line. Braces enclose the comment. The { precedes the comment, and the } follows it. Braces can delimit single- or multiple-line comments, but comments cannot be nested. C-language style slash and asterisk ( /* */ ) paired delimiters enclose the comment. The /* precedes the comment, and the */ follows it. These can delimit single-line or multiple-line comments, but comments cannot be nested.

braces ({...})

N

Y

Y

Y

Y

slash and asterisk /* . . . */

Y

Y

Y

Y

Y

Characters within the comment are ignored by the database server. The section Optimizer Directives on page 5-34 describes a context where information within comments can influence query plans of Dynamic Server. If the product that you use supports all of these comment symbols, your choice of a comment symbol depends on requirements for ANSI/ISO compliance: v Double hyphen ( -- ) complies with the ANSI/ISO standard for SQL. v Braces ( { } ) are an Informix extension to the ANSI/ISO standard. v C-style slash-and-asterisk ( /* . . . */ ) comply with the SQL-99 standard. If ANSI/ISO compliance is not an issue, your choice of comment symbols is a matter of personal preference. In DBAccess, you can use any of these comment symbols when you enter SQL statements with the SQL editor and when you create SQL command files with the SQL editor or a system editor. C-style ( /* . . . */ ) comments, however, are not supported by DBAccess within CONNECT, DISCONNECT, INFO, LOAD, OUTPUT, SET CONNECT, nor UNLOAD statements.

1-4

IBM Informix Guide to SQL: Syntax

An SQL command file is an operating-system file that contains one or more SQL statements. Command files are also known as command scripts. For more information about command files, see the discussion of command scripts in the IBM Informix Guide to SQL: Tutorial. For information on how to create and modify command files with the SQL editor or a system editor in DBAccess, see the IBM Informix DBAccess User's Guide. You can use either comment symbol in any line of an SPL routine. See the discussion of how to comment and document an SPL routine in the IBM Informix Guide to SQL: Tutorial. In ESQL/C, the double hyphen ( -- ) can begin a comment that extends to the end of the same line. For information on language-specific comment symbols in ESQL/C programs, see the IBM Informix ESQL/C Programmer's Manual.

Examples of SQL Comment SymbolsThese examples illustrate different ways to use the SQL comment indicators.

Examples of the Double-Hyphen SymbolThe next example uses the double hyphen ( -- ) to include a comment after an SQL statement. The comment appears on the same line as the statement.SELECT * FROM customer -- Selects all columns and rows

The following example uses the same SQL statement and the same comment as in the preceding example, but places the comment on a separate line:SELECT * FROM customer -- Selects all columns and rows

In the following example, the user enters the same SQL statement as in the preceding example but now enters a multiple-line comment:SELECT * FROM customer -- Selects all columns and rows -- from the customer table

Examples of the Braces SymbolsThis example uses braces ( { } ) to delimit a comment after an SQL statement. In this example, the comment appears on the same line as the statement.SELECT * FROM customer {Selects all columns and rows}

The next example uses the same SQL statement and the same comment as in the preceding example, but the comment appears on a line by itself:SELECT * FROM customer {Selects all columns and rows}

In the following example, the same SQL statement as in the preceding example is followed by a multiple-line comment:SELECT * FROM customer {Selects all columns and rows from the customer table}

Non-ASCII Characters in SQL CommentsYou can enter non-ASCII characters (including multibyte characters) in SQL comments if the database locale supports the non-ASCII characters. For further information on the GLS aspects of SQL comments, see the IBM Informix GLS User's Guide.Chapter 1. Overview of SQL Syntax

1-5

Categories of SQL StatementsSQL statements are traditionally divided into the following logical categories: v Data definition statements. These data definition language (DDL) statements can declare, rename, modify, or destroy objects in the local database. v Data manipulation statements. These data manipulation language (DML) statements can retrieve, insert, delete, or modify data values. v Cursor manipulation statements. These statements can declare, open, and close cursors, which are data structures for operations on multiple rows of data. v Dynamic management statements. These statements support memory management and allow users to specify at runtime the details of DML operations. v Data access statements. These statements specify access privileges and support concurrent access to the database by multiple users. v Data integrity statements. These implement transaction logging and support the referential integrity of the database. v Optimization statements. These can be used to improve the performance of operations on the database. v Routine definition statements. These can declare, define, modify, execute, or destroy user-defined routines that the database stores. v Client/server connection statements. These can open or close a connection between a database and a client application. v Auxiliary statements. These can provide information about the database. (This is also a residual category for statements that are not closely related to the other statement categories.) v Optical subsystem statements. These statements are separately documented in IBM Informix Optical Subsystem Guide. The SQL statements of each category are listed in the pages that follow. As Chapter 2 indicates, some statements (and some statement options, as noted in the syntax diagrams) are specific to Dynamic Server (sometimes abbreviated as IDS) or are specific to Extended Parallel Server (sometimes abbreviated as XPS).

Data Definition Language Statements3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ALTER ACCESS_METHOD ALTER FRAGMENT ALTER FUNCTION ALTER INDEX ALTER PROCEDURE ALTER ROUTINE ALTER SEQUENCE ALTER TABLE CLOSE DATABASE CREATE ACCESS_METHOD CREATE AGGREGATE CREATE CAST CREATE DATABASE CREATE DISTINCT TYPE CREATE DUPLICATE CREATE EXTERNAL TABLE CREATE FUNCTION 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE CREATE FUNCTION FROM INDEX OPAQUE TYPE OPCLASS PROCEDURE PROCEDURE FROM ROLE ROUTINE FROM ROW TYPE SCHEMA SEQUENCE SYNONYM TABLE Temporary TABLE TRIGGER VIEW XADATASOURCE

1-6

IBM Informix Guide to SQL: Syntax

3 3 3 3 3 3 3 3 3 3 3 3 3 3

CREATE XADATASOURCE TYPE DROP ACCESS_METHOD DROP AGGREGATE DROP CAST DROP DATABASE DROP DUPLICATE DROP FUNCTION DROP INDEX DROP OPCLASS DROP PROCEDURE DROP ROLE DROP ROUTINE DROP ROW TYPE DROP SEQUENCE

3 3 3 3 3 3 3 3 3 3 3 3 3 3

DROP SYNONYM DROP TABLE DROP TRIGGER DROP TYPE DROP VIEW DROP XADATASOURCE DROP XADATASOURCE TYPE MOVE RENAME COLUMN RENAME DATABASE RENAME INDEX RENAME SEQUENCE RENAME TABLE TRUNCATE

Data Manipulation Language StatementsDELETE INSERT LOAD MERGE SELECT UNLOAD UPDATE Note: The DELETE, INSERT, SELECT, and UPDATE statements are DML statements in the ANSI/ISO standard for SQL. Although LOAD, UNLOAD, and MERGE resemble DML in their functionality, these are out-of-scope for most references in this manual to DML statements.

Data Integrity StatementsBEGIN WORK COMMIT WORK ROLLBACK WORK SET Database Object Mode SET LOG SET PLOAD FILE SET Transaction Mode START VIOLATIONS TABLE STOP VIOLATIONS TABLE

Cursor Manipulation StatementsCLOSE DECLARE FETCH FLUSH FREE OPEN PUT SET AUTOFREE

Dynamic Management StatementsALLOCATE COLLECTION ALLOCATE DESCRIPTOR ALLOCATE ROW DEALLOCATE COLLECTION DEALLOCATE DESCRIPTOR DEALLOCATE ROW DESCRIBE DESCRIBE INPUT EXECUTE EXECUTE IMMEDIATE FREE GET DESCRIPTOR INFO PREPARE SET DEFERRED_PREPARE SET DESCRIPTOR

Data Access StatementsGRANT GRANT FRAGMENT LOCK TABLE REVOKE REVOKE FRAGMENT SET ISOLATION SET LOCK MODE SET ROLE SET SESSION AUTHORIZATION SET TRANSACTION SET Transaction Mode UNLOCK TABLEChapter 1. Overview of SQL Syntax

1-7

Optimization StatementsSAVE EXTERNAL DIRECTIVES SET ALL_MUTABLES SET Default Table Space SET Default Table Type SET ENVIRONMENT SET EXPLAIN SET OPTIMIZATION SET PDQPRIORITY SET Residency SET SCHEDULE LEVEL SET STATEMENT CACHE UPDATE STATISTICS

Routine Definition StatementsALTER FUNCTION ALTER PROCEDURE ALTER ROUTINE CREATE FUNCTION CREATE FUNCTION FROM CREATE PROCEDURE CREATE PROCEDURE FROM CREATE ROUTINE FROM DROP FUNCTION DROP PROCEDURE DROP ROUTINE EXECUTE FUNCTION EXECUTE PROCEDURE SET DEBUG FILE TO

Auxiliary StatementsGET DIAGNOSTICS INFO OUTPUT SET COLLATION SET DATASKIP SET ENCRYPTION PASSWORD WHENEVER

Client/Server Connection StatementsCONNECT DATABASE DISCONNECT SET CONNECTION

Optical Subsystem Statements (IDS)ALTER OPTICAL CLUSTER CREATE OPTICAL CLUSTER DROP OPTICAL CLUSTER RELEASE RESERVE SET MOUNTING TIMEOUT Important: See the IBM Informix Optical Subsystem Guide for more information.

ANSI/ISO Compliance and ExtensionsLists that follow show statements that match the ANSI SQL-92 standard at the entry level, statements that are ANSI compliant but include Informix extensions, and statements that are Informix extensions to the ANSI/ISO standard.

ANSI/ISO-Compliant StatementsCLOSE COMMIT WORK EXECUTE IMMEDIATE ROLLBACK WORK SET SESSION AUTHORIZATION SET TRANSACTION

ANSI/ISO-Compliant Statements with Informix ExtensionsALLOCATE DESCRIPTOR ALTER TABLE CONNECT CREATE SCHEMA

1-8

IBM Informix Guide to SQL: Syntax

CREATE TABLE CREATE Temporary TABLE CREATE VIEW DEALLOCATE DESCRIPTOR DECLARE DELETE DESCRIBE DESCRIBE INPUT DISCONNECT EXECUTE FETCH GET DESCRIPTOR GET DIAGNOSTICS

GRANT INSERT OPEN PREPARE REVOKE SELECT SET CONNECTION SET CONSTRAINTS SET DESCRIPTOR SET Transaction Mode UPDATE WHENEVER

Statements that are Extensions to the ANSI/ISO StandardALLOCATE COLLECTION ALLOCATE ROW ALTER ACCESS_METHOD ALTER FRAGMENT ALTER FUNCTION ALTER INDEX ALTER OPTICAL CLUSTER ALTER PROCEDURE ALTER ROUTINE ALTER SEQUENCE BEGIN WORK CLOSE DATABASE CREATE ACCESS_METHOD CREATE AGGREGATE CREATE CAST CREATE DATABASE CREATE DISTINCT TYPE CREATE DUPLICATE CREATE EXTERNAL TABLE CREATE FUNCTION CREATE FUNCTION FROM CREATE INDEX CREATE OPAQUE TYPE CREATE OPCLASS CREATE OPTICAL CLUSTER CREATE PROCEDURE CREATE PROCEDURE FROM CREATE ROLE CREATE ROUTINE FROM CREATE ROW TYPE CREATE SEQUENCE CREATE SYNONYM CREATE TRIGGER CREATE XADATASOURCE CREATE XADATASOURCE TYPE DATABASE DEALLOCATE COLLECTION DEALLOCATE ROW DROP ACCESS_METHOD DROP AGGREGATE DROP CAST DROP DATABASE DROP DUPLICATE DROP FUNCTION DROP INDEX DROP OPCLASS DROP OPTICAL CLUSTER DROP PROCEDURE DROP ROLE DROP ROUTINE DROP ROW TYPE DROP SEQUENCE DROP SYNONYM DROP TABLE DROP TRIGGER DROP TYPE DROP VIEW DROP XADATASOURCE DROP XADATASOURCE TYPE EXECUTE FUNCTION EXECUTE PROCEDURE FLUSH FREE GET DIAGNOSTICS GRANT FRAGMENT LOAD LOCK TABLE MERGE MOVE OUTPUT PUT

Chapter 1. Overview of SQL Syntax

1-9

RELEASE RENAME COLUMN RENAME DATABASE RENAME INDEX RENAME SEQUENCE RENAME TABLE RESERVE REVOKE FRAGMENT SAVE EXTERNAL DIRECTIVES SET ALL_MUTABLES SET AUTOFREE SET COLLATION SET Database Object Mode SET DATASKIP SET DEBUG FILE TO SET Default Table Space SET Default Table Type SET DEFERRED_PREPARE SET ENCRYPTION PASSWORD SET ENVIRONMENT SET EXPLAIN SET ISOLATION SET LOCK MODE SET LOG SET MOUNTING TIMEOUT SET OPTIMIZATION SET PDQPRIORITY SET PLOAD FILE SET Residency SET ROLE SET SCHEDULE LEVEL SET STATEMENT CACHE START VIOLATIONS TABLE STOP VIOLATIONS TABLE TRUNCATE UNLOAD UNLOCK TABLE UPDATE STATISTICS

1-10

IBM Informix Guide to SQL: Syntax

Chapter 2. SQL StatementsIn This Chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 ALLOCATE COLLECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 ALLOCATE DESCRIPTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 ALLOCATE ROW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 ALTER ACCESS_METHOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 ALTER FRAGMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 ALTER FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31 ALTER INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33 ALTER PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35 ALTER ROUTINE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37 ALTER SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40 ALTER TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43 BEGIN WORK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-66 CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-68 CLOSE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-71 COMMIT WORK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-73 CONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-75 CREATE ACCESS_METHOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-82 CREATE AGGREGATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-84 CREATE CAST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-87 CREATE DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-90 CREATE DISTINCT TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-93 CREATE DUPLICATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-96 CREATE EXTERNAL TABLE (XPS) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-98 CREATE FUNCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-107 CREATE FUNCTION FROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-114 CREATE INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-116 CREATE OPAQUE TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-136 CREATE OPCLASS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-141 CREATE PROCEDURE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-145 CREATE PROCEDURE FROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-153 CREATE ROLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-155 CREATE ROUTINE FROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-157 CREATE ROW TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-158 CREATE SCHEMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-162 CREATE SCRATCH TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-164 CREATE SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-165 CREATE SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-168 CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-171 CREATE TEMP TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-208 CREATE Temporary TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-209 CREATE TRIGGER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-216 CREATE VIEW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-247 3 CREATE XADATASOURCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-252 3 CREATE XADATASOURCE TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-253 DATABASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-255 DEALLOCATE COLLECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-257 DEALLOCATE DESCRIPTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-258 DEALLOCATE ROW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-259 DECLARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-260 DELETE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-275 DESCRIBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-281 DESCRIBE INPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-286 DISCONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-291 DROP ACCESS_METHOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-294 Copyright IBM Corp. 1996, 2005

2-1

DROP AGGREGATE . . . . DROP CAST . . . . . . . DROP DATABASE . . . . . DROP DUPLICATE . . . . . DROP FUNCTION . . . . . DROP INDEX . . . . . . DROP OPCLASS . . . . . DROP PROCEDURE . . . . DROP ROLE . . . . . . . DROP ROUTINE . . . . . DROP ROW TYPE . . . . . DROP SEQUENCE . . . . . DROP SYNONYM . . . . . DROP TABLE . . . . . . DROP TRIGGER. . . . . . DROP T