Post on 22-May-2020
transcript
Mimer SQLEngine
Documentation Set
Version 9.2
http://developer.mimer.comhttp://developer.mimer.com
Mimer SQL Engine, Documentation Set, Version 9.2, September 2003© Copyright Upright Database Technology AB.
The contents of this manual may be printed in limited quantities for use at a Mimer SQL installation site. No parts of the manual may be reproduced for sale to a third party.Information in this document is subject to change without notice. All registered names, product names and trademarks of other companies mentioned in this documentation are used for identification purposes only and are acknowledged as the property of the respective company. Companies, names and data used in examples herein are fictitious unless otherwise noted.
Produced and published by Upright Database Technology AB, Uppsala, Sweden.P.O. Box 1713,SE-751 47 Uppsala, Sweden.Tel +46(0)18-780 92 00.Fax +46(0)18-780 92 40.
Mimer SQL Web Sites:http://developer.mimer.comhttp://www.mimer.comhttp://www.upright.se
http://www.mimer.comhttp://www.upright.sehttp://developer.mimer.com
Mimer SQL Engine Version 9.2 iDocumentation Set
Contents
Documentation Set
SQL Reference ManualChapter 1 Introduction ....................................................................................... 1
About this Manual ............................................................................................................1
Chapter 2 Reading SQL Syntax Diagrams ....................................................... 5Key to Syntax Diagrams ..................................................................................................5Reading Standard Compliance Tables ............................................................................7
Chapter 3 Introduction to SQL Standards........................................................ 9History of Standards ........................................................................................................9SQL-99.............................................................................................................................9The Unicode Standard and ISO/IEC 10646...................................................................10
Chapter 4 Mimer SQL Database Objects ........................................................ 11The Data Dictionary .......................................................................................................12Databanks......................................................................................................................12Idents .............................................................................................................................13Schemas ........................................................................................................................14Tables ............................................................................................................................15Primary Keys and Indexes .............................................................................................16Stored Procedures .........................................................................................................17Synonyms ......................................................................................................................18Shadows ........................................................................................................................18Triggers..........................................................................................................................18Sequences .....................................................................................................................18Mimer SQL Character Sets ............................................................................................19Collations and Linguistic Sorting....................................................................................19
ii Contents
Data Integrity ..................................................................................................................25Privileges........................................................................................................................27
Chapter 5 SQL Syntax Elements..................................................................... 29Characters......................................................................................................................29Identifiers........................................................................................................................30Data Types in SQL Statements......................................................................................34Literals............................................................................................................................52
Chapter 6 Operators and Values..................................................................... 57Operators .......................................................................................................................57Value Specifications .......................................................................................................59Default Values ................................................................................................................60Assignments...................................................................................................................61Comparisons ..................................................................................................................63Result Data Types..........................................................................................................65
Chapter 7 Functions......................................................................................... 69About Set Functions .......................................................................................................69About Scalar Functions ..................................................................................................72Scalar Numeric Functions ..............................................................................................72Scalar String Functions ..................................................................................................88Scalar Interval Functions................................................................................................95Datetime Pseudo-Literals ...............................................................................................95String Pseudo-Literals ....................................................................................................98Standard Compliance.....................................................................................................99
Chapter 8 Expressions and Predicates ........................................................ 101Expressions..................................................................................................................101CASE Expression.........................................................................................................105CAST Specification ......................................................................................................107Predicates ....................................................................................................................109
Chapter 9 Search Conditions and Joins ...................................................... 117Search Conditions ........................................................................................................117Joined Tables ...............................................................................................................118INNER JOINs ...............................................................................................................119OUTER JOINs..............................................................................................................121Standard Compliance...................................................................................................123
Chapter 10 The SELECT Specification ......................................................... 125SELECT Specification Syntax ......................................................................................125
Mimer SQL Engine Version 9.2 iiiDocumentation Set
Chapter 11 Vendor-specific SQL................................................................... 131Escape Clauses ...........................................................................................................131Processing Escape Clauses ........................................................................................132Standard Compliance ..................................................................................................133
Chapter 12 SQL Statement Descriptions...................................................... 135Usage Modes...............................................................................................................138ALLOCATE CURSOR..................................................................................................139ALLOCATE DESCRIPTOR..........................................................................................140ALTER DATABANK .....................................................................................................141ALTER DATABANK RESTORE...................................................................................143ALTER IDENT..............................................................................................................145ALTER SHADOW ........................................................................................................146ALTER STATEMENT...................................................................................................148ALTER TABLE .............................................................................................................149CALL ............................................................................................................................152CASE ...........................................................................................................................153CLOSE.........................................................................................................................155COMMENT ..................................................................................................................156COMMIT ......................................................................................................................157COMPOUND STATEMENT.........................................................................................159CONNECT ...................................................................................................................161CREATE BACKUP.......................................................................................................163CREATE COLLATION .................................................................................................165CREATE DATABANK ..................................................................................................166CREATE DOMAIN .......................................................................................................168CREATE FUNCTION...................................................................................................170CREATE IDENT...........................................................................................................173CREATE INDEX ..........................................................................................................175CREATE MODULE ......................................................................................................177CREATE PROCEDURE...............................................................................................179CREATE SCHEMA ......................................................................................................182CREATE SEQUENCE .................................................................................................184CREATE SHADOW .....................................................................................................186CREATE STATEMENT................................................................................................188CREATE SYNONYM ...................................................................................................189CREATE TABLE ..........................................................................................................190CREATE TRIGGER .....................................................................................................198CREATE VIEW ............................................................................................................201
iv Contents
DEALLOCATE DESCRIPTOR .....................................................................................203DEALLOCATE PREPARE ...........................................................................................204DECLARE CONDITION ...............................................................................................205DECLARE CURSOR....................................................................................................206DECLARE HANDLER ..................................................................................................209DECLARE SECTION ...................................................................................................211DECLARE VARIABLE..................................................................................................212DELETE .......................................................................................................................213DELETE CURRENT.....................................................................................................215DESCRIBE ...................................................................................................................216DISCONNECT..............................................................................................................217DROP ...........................................................................................................................218ENTER .........................................................................................................................222EXECUTE ....................................................................................................................223EXECUTE IMMEDIATE ...............................................................................................224EXECUTE STATEMENT..............................................................................................225FETCH .........................................................................................................................226GET DESCRIPTOR .....................................................................................................229GET DIAGNOSTICS ....................................................................................................235GRANT ACCESS PRIVILEGE .....................................................................................243GRANT OBJECT PRIVILEGE......................................................................................246GRANT SYSTEM PRIVILEGE .....................................................................................248IF ..................................................................................................................................249INSERT ........................................................................................................................251ITERATE ......................................................................................................................253LEAVE..........................................................................................................................254LEAVE (PROGRAM ident) ...........................................................................................255LOOP ...........................................................................................................................256OPEN ...........................................................................................................................257PREPARE ....................................................................................................................259REPEAT .......................................................................................................................260RESIGNAL ...................................................................................................................261RETURN ......................................................................................................................262REVOKE ACCESS PRIVILEGE...................................................................................264REVOKE OBJECT PRIVILEGE ...................................................................................266REVOKE SYSTEM PRIVILEGE...................................................................................268ROLLBACK ..................................................................................................................269SELECT .......................................................................................................................271
Mimer SQL Engine Version 9.2 vDocumentation Set
SELECT INTO .............................................................................................................274SET ..............................................................................................................................276SET CONNECTION.....................................................................................................277SET DATABANK..........................................................................................................278SET DATABASE..........................................................................................................279SET DESCRIPTOR......................................................................................................280SET SESSION .............................................................................................................282SET SHADOW.............................................................................................................284SET TRANSACTION ...................................................................................................285SIGNAL........................................................................................................................288START .........................................................................................................................289UPDATE ......................................................................................................................291UPDATE CURRENT....................................................................................................293UPDATE STATISTICS.................................................................................................295WHENEVER ................................................................................................................296WHILE..........................................................................................................................297
Chapter 13 Data Dictionary Views................................................................. 299INFORMATION_SCHEMA...........................................................................................300INFO_SCHEM .............................................................................................................354FIPS_DOCUMENTATION ...........................................................................................369
Appendix A Reserved Words ........................................................................ 371
Appendix B Character Sets ........................................................................... 375Character Data.............................................................................................................375National Character Data – Unicode .............................................................................376
Appendix C Limits .......................................................................................... 377
Appendix D Deprecated Features ................................................................. 379Host Variables..............................................................................................................379Operators .....................................................................................................................379Statements...................................................................................................................379Communication Areas..................................................................................................381Program Idents ............................................................................................................382Datetime Scalar Functions...........................................................................................382Data Dictionary Views..................................................................................................383Host Variable Types.....................................................................................................383
Appendix E Return Status and Conditions .................................................. 385SQLSTATE Return Codes ...........................................................................................385
vi Contents
Appendix F SQL-99 Compliance ................................................................... 387
Appendix F ..................................................................................................... 387SQL-99 Core Features .................................................................................................387Features Outside Core Supported by Mimer SQL .......................................................393
Appendix G Languages ................................................................................. 397
Index ............................................................................................................... 401
Programmer’s ManualChapter 1 Introduction ....................................................................................... 1
About this Manual.............................................................................................................1Database APIs .................................................................................................................2
Chapter 2 Mimer SQL and the ODBC API......................................................... 5The Mimer ODBC Driver ..................................................................................................5Required Files ..................................................................................................................5Unicode and ANSI Interfaces ...........................................................................................6Examples in this Chapter .................................................................................................6Operating Systems...........................................................................................................7Declarations .....................................................................................................................7Initializing the ODBC Environment ...................................................................................8Error Handling ................................................................................................................11Transaction Processing..................................................................................................12Executing a Command ...................................................................................................13Repeating – Prepared Execution ...................................................................................14Result-set Processing ....................................................................................................16Updating Data ................................................................................................................17
Chapter 3 Mimer SQL and the JDBC API ....................................................... 19The Mimer JDBC Driver .................................................................................................19
Chapter 4 Embedded SQL ............................................................................... 21General Principles for Embedding SQL Statements ......................................................21Processing ESQL ...........................................................................................................23Essential Program Structure ..........................................................................................27Linking Applications........................................................................................................29
Chapter 5 Idents and Privileges ...................................................................... 31Mimer SQL Idents ..........................................................................................................31
Mimer SQL Engine Version 9.2 viiDocumentation Set
Database Privileges .......................................................................................................32
Chapter 6 Connecting to a Database .............................................................. 35The CONNECT Statement.............................................................................................35
Chapter 7 Communicating with the Application Program ............................ 39Using Host Variables .....................................................................................................39The SQLSTATE Variable...............................................................................................41The Diagnostics Area.....................................................................................................42The SQL Descriptor Area...............................................................................................42
Chapter 8 Accessing Data ............................................................................... 43Retrieving Data Using Cursors.......................................................................................43Retrieving Single Rows..................................................................................................47Retrieving Data from Multiple Tables .............................................................................48Entering Data into Tables ..............................................................................................51
Chapter 9 Transaction Handling and Database Security.............................. 55Transaction Principles....................................................................................................55Transactions and Logging..............................................................................................58Protecting Against Data Loss.........................................................................................58Transaction Control Statements.....................................................................................59
Chapter 10 Distributed Transactions.............................................................. 69Terms and Abbreviations ...............................................................................................69How Does it Work? ........................................................................................................70Handling failures ............................................................................................................70Mimer SQL Support For Microsoft DTC on Windows ....................................................71
Chapter 11 Dynamic SQL................................................................................. 73Principles of Dynamic SQL ............................................................................................73General Summary of Dynamic SQL Processing............................................................75SQL Descriptor Area......................................................................................................76Preparing Statements ....................................................................................................77Extended Dynamic Cursors ...........................................................................................77Describing Prepared Statements ...................................................................................78Handling Prepared Statements......................................................................................80Example Framework for Dynamic SQL Programs .........................................................81
Chapter 12 Mimer SQL Stored Procedures .................................................... 83About Routines ..............................................................................................................83Syntactic Components of a Routine Definition...............................................................88Modules .........................................................................................................................95
viii Contents
SQL Constructs in Routines ...........................................................................................96Manipulating Data ........................................................................................................102Result Set Procedures .................................................................................................106Managing Exception Conditions...................................................................................108Access Rights...............................................................................................................113Using DROP and REVOKE..........................................................................................114The Mimer SQL PSM Debugger ..................................................................................114
Chapter 13 Triggers........................................................................................ 119Creating a Trigger ........................................................................................................119Trigger Time .................................................................................................................120Trigger Event................................................................................................................121Trigger Action ...............................................................................................................121Comments on Triggers.................................................................................................123Using DROP and REVOKE..........................................................................................123
Chapter 14 Handling Errors and Exceptions ............................................... 125Syntax Errors................................................................................................................125Semantic Errors............................................................................................................125Run-time Errors ............................................................................................................126
Appendix A Host Language Dependent Aspects ........................................ 129ESQL in C/C++ Programs ............................................................................................130ESQL in COBOL Programs..........................................................................................135ESQL in FORTRAN Programs .....................................................................................139
Appendix B Return Codes ............................................................................. 143SQLSTATE Return Codes ...........................................................................................143Internal Mimer SQL Return Codes ...............................................................................149
Appendix C Deprecated Features ................................................................. 197INCLUDE SQLCA ........................................................................................................197SQLCODE....................................................................................................................197SQLDA .........................................................................................................................198Parameter Marker Representation ...............................................................................198VARCHAR(size) ...........................................................................................................198SET TRANSACTION....................................................................................................198DBERM4 ......................................................................................................................198
Index ............................................................................................................... 199
User’s Manual
Mimer SQL Engine Version 9.2 ixDocumentation Set
Chapter 1 Introduction ....................................................................................... 1About this Manual ............................................................................................................1
Chapter 2 Basic Concepts of Mimer SQL......................................................... 5Tables ..............................................................................................................................5Synonyms ........................................................................................................................8Primary Keys and Indexes ...............................................................................................9Data Integrity....................................................................................................................9Sequences .....................................................................................................................12Databanks......................................................................................................................13Shadows ........................................................................................................................13Mimer SQL Character Sets ............................................................................................14Collations and Linguistic Sorting....................................................................................14Stored Procedures .........................................................................................................14Idents .............................................................................................................................16Schemas ........................................................................................................................17Access Rights and Privileges.........................................................................................17The Data Dictionary .......................................................................................................19Mimer SQL Statements..................................................................................................19
Chapter 3 Managing Database Connections.................................................. 23Connecting to a Database .............................................................................................23PROGRAM Idents – ENTER and LEAVE......................................................................25
Chapter 4 Retrieving Data................................................................................ 27Simple Retrieval .............................................................................................................27Result Order...................................................................................................................28Table Names..................................................................................................................29Setting Column Labels...................................................................................................29Eliminating Duplicate Values..........................................................................................30Selecting Specific Rows.................................................................................................31Retrieving Computed Values .........................................................................................36Using Scalar Functions ..................................................................................................39Using the CASE Expression ..........................................................................................42Using the CAST Specification........................................................................................43Datetime Arithmetic and Functions ................................................................................44Using Set Functions.......................................................................................................46Grouped Set Functions – the GROUP BY Clause.........................................................48Selecting Groups – the HAVING Clause........................................................................49Ordering the Result Table..............................................................................................50
x Contents
Retrieving Data from More than One Table ...................................................................52Handling NULL Values ...................................................................................................66Conceptual Description of the Selection Process ..........................................................69
Chapter 5 Collations......................................................................................... 73About Collations .............................................................................................................73Using Collations .............................................................................................................74Using Collations – Examples..........................................................................................76
Chapter 6 Working with Data........................................................................... 83Inserting Data .................................................................................................................83Updating Tables .............................................................................................................86Deleting Rows from Tables ............................................................................................87Calling Procedures .........................................................................................................87Updatable Views ............................................................................................................88
Chapter 7 Managing Transactions.................................................................. 89Transaction Principles ....................................................................................................89Logging Transactions .....................................................................................................90Handling Transactions....................................................................................................90
Chapter 8 Creating a Database ....................................................................... 95Creating Idents and Schemas ........................................................................................95Creating Databanks........................................................................................................97Creating Tables ..............................................................................................................98Creating Sequences.....................................................................................................103Creating Domains.........................................................................................................103Creating Functions, Procedures, Triggers and Modules ..............................................104Creating Views .............................................................................................................106Creating Secondary Indexes ........................................................................................108Creating Synonyms ......................................................................................................109Commenting Objects....................................................................................................110Altering Databanks, Tables and Idents ........................................................................110Dropping Objects from the Database ...........................................................................113
Chapter 9 Defining Privileges........................................................................ 117Ident Structure..............................................................................................................118Granting Privileges .......................................................................................................119Revoking Privileges......................................................................................................121
Chapter 10 Mimer BSQL ................................................................................ 125Running BSQL .............................................................................................................125
Mimer SQL Engine Version 9.2 xiDocumentation Set
BSQL Commands ........................................................................................................129Variables in BSQL........................................................................................................152Transaction Handling in Mimer BSQL..........................................................................153LOBs in BSQL..............................................................................................................153Errors in BSQL.............................................................................................................154Error Messages............................................................................................................156
Appendix A The Example Environment........................................................ 159The EXLOAD program.................................................................................................159The MIMER_STORE Schema .....................................................................................161Procedures...................................................................................................................167Views ...........................................................................................................................167Triggers........................................................................................................................168Idents ...........................................................................................................................168The MIMER_STORE_MUSIC Schema........................................................................168The MIMER_STORE_BOOK Schema.........................................................................171The MIMER_STORE Schema Revisited......................................................................173The MIMER_STORE_WEB Schema ...........................................................................174Synonyms ....................................................................................................................175
Appendix B Deprecated Features ................................................................. 177BSQL Commands ........................................................................................................177
Index ............................................................................................................... 179
System Management HandbookChapter 1 Introduction ....................................................................................... 1
About this Manual ............................................................................................................1System Management Responsibilities .............................................................................3
Chapter 2 The Database Environment.............................................................. 5The Data Dictionary .........................................................................................................5Idents ...............................................................................................................................6Schemas ..........................................................................................................................7Databanks........................................................................................................................7Databank Options ............................................................................................................9Locating Databank Files ..................................................................................................9Organizing Databank Files.............................................................................................10Altering Databank Locations ..........................................................................................13Accessing Databank Files..............................................................................................14
xii Contents
Databank File Deletion ...................................................................................................14Transaction Control ........................................................................................................14Database Security ..........................................................................................................15Data Integrity ..................................................................................................................20
Chapter 3 Creating a Mimer SQL Database ................................................... 23Registering the Database...............................................................................................23The Local Database .......................................................................................................24Accessing a Database Remotely ...................................................................................24Mimer SQL License Key.................................................................................................26Generating the Mimer SQL System Databanks .............................................................28Managing Database Connections ..................................................................................33Running Mimer BSQL ....................................................................................................36
Chapter 4 Managing a Database Server ......................................................... 39Database Server Memory Areas ....................................................................................40Threads ..........................................................................................................................42Database Server System Requirements ........................................................................43Controlling the Database Server – MIMCONTROL........................................................44System Information – MIMINFO.....................................................................................50Database Server Log .....................................................................................................57Other Log Files...............................................................................................................58Several Installations on One Machine............................................................................58
Chapter 5 Backing-up and Restoring Data .................................................... 59Database Consistency ...................................................................................................59LOGDB and TRANSDB Importance...............................................................................60Updates Recorded in LOGDB ........................................................................................61TRANSDB Considerations .............................................................................................62SQLDB Considerations ..................................................................................................63Databank Backups .........................................................................................................63System vs. Online Backups............................................................................................64SQL Statements for Backing-up Databanks...................................................................64Backing-up and Restoring Databanks............................................................................66Restoring a Databank.....................................................................................................68Restoring SYSDB...........................................................................................................68Re-creating TRANSDB, LOGDB and SQLDB................................................................69Audit trail with READLOG ..............................................................................................71
Chapter 6 Databank Check Functionality....................................................... 73DBC Syntax....................................................................................................................73
Mimer SQL Engine Version 9.2 xiiiDocumentation Set
Authorization ..................................................................................................................74Result File Contents.......................................................................................................74
Chapter 7 DBOPEN........................................................................................... 79DBOPEN Syntax............................................................................................................79Functions .......................................................................................................................80Authorization ..................................................................................................................81DBOPEN Output Example .............................................................................................81
Chapter 8 Loading and Unloading Data ......................................................... 83Loading Data..................................................................................................................84Unloading Data ..............................................................................................................87Data Description Headers and Files ..............................................................................90File Format Specifications..............................................................................................92MIMLOAD ......................................................................................................................92Using STDIN/STDOUT/STDERR...................................................................................94EXPTOLOAD .................................................................................................................95
Chapter 9 Mimer SQL Shadowing ................................................................... 97About Databank Shadowing ..........................................................................................97Levels of Data Protection...............................................................................................99Creating and Managing Shadows................................................................................102SQL Shadowing Commands – an Example Session...................................................102Shadowing System Databanks ....................................................................................105Data Protection Strategy..............................................................................................108Configuring Your System .............................................................................................108Performance Aspects of Shadowing............................................................................109Troubleshooting ...........................................................................................................109
Chapter 10 Database Statistics ..................................................................... 111Authorization ................................................................................................................111The SQL Statistics Statements ....................................................................................111When to Use the SQL Statistics Statements................................................................112
Appendix A Executing in Single-user Mode ................................................ 115File Protection in Single- and Multi-user Mode ............................................................115Specifying Single-user Mode Access...........................................................................115Accessing in Single-user Mode....................................................................................116The SINGLEDEFS Parameter File...............................................................................117
Appendix B The SQLHOSTS File on VMS and UNIX ................................... 119The SQLHOSTS File ...................................................................................................119
xiv Contents
Appendix C The MULTIDEFS File on VMS and UNIX .................................. 125The MULTIDEFS Parameter File .................................................................................125MULTIDEFS Parameters .............................................................................................126
Appendix D UNIX Specifics ........................................................................... 131Man Pages ...................................................................................................................131Automatic Database Start and Stop .............................................................................131Using Raw Device Partitions ........................................................................................131Environment Variables .................................................................................................133UNIX Commands .........................................................................................................135
Appendix E Data Dictionary Tables .............................................................. 139Summary of Data Dictionary Tables.............................................................................140
Appendix F Deprecated Features ................................................................. 183Export/Import ................................................................................................................183Load/Unload .................................................................................................................183Readlog from UTIL .......................................................................................................183Backup/Restore from UTIL...........................................................................................183Statistics from UTIL ......................................................................................................183Shadowing Management from UTIL.............................................................................183
Index .............................................................................................................. 205
Mimer SQLEngine
SQL ReferenceManual
Version 9.2
http://developer.mimer.comhttp://developer.mimer.com
Mimer SQL Engine, SQL Reference Manual, Version 9.2, September 2003© Copyright Upright Database Technology AB.
The contents of this manual may be printed in limited quantities for use at a Mimer SQL installation site. No parts of the manual may be reproduced for sale to a third party.Information in this document is subject to change without notice. All registered names, product names and trademarks of other companies mentioned in this documentation are used for identification purposes only and are acknowledged as the property of the respective company. Companies, names and data used in examples herein are fictitious unless otherwise noted.
Produced and published by Upright Database Technology AB, Uppsala, Sweden.P.O. Box 1713,SE-751 47 Uppsala, Sweden.Tel +46(0)18-780 92 00.Fax +46(0)18-780 92 40.
Mimer SQL Web Sites:http://developer.mimer.comhttp://www.mimer.comhttp://www.upright.se
http://www.mimer.comhttp://www.upright.sehttp://developer.mimer.com
Mimer SQL Engine Version 9.2 iSQL Reference Manual
ContentsChapter 1 Introduction ....................................................................................... 1
About this Manual..........................................................................................................1Related Mimer SQL Publications.................................................................................... 1Suggestions for Further Reading.................................................................................... 2Acronyms, Terms and Trademarks ................................................................................ 3
Chapter 2 Reading SQL Syntax Diagrams ....................................................... 5Key to Syntax Diagrams................................................................................................5
KEYWORDS...................................................................................................................... 6Parameters ........................................................................................................................ 7Syntax Diagram Example ................................................................................................ 7
Reading Standard Compliance Tables.........................................................................7
Chapter 3 Introduction to SQL Standards........................................................ 9History of Standards......................................................................................................9SQL-99 ............................................................................................................................9The Unicode Standard and ISO/IEC 10646 ................................................................10
EOR - European Ordering Rules .................................................................................. 10
Chapter 4 Mimer SQL Database Objects ........................................................ 11System and Private Objects .......................................................................................... 11
The Data Dictionary .....................................................................................................12Databanks.....................................................................................................................12
System Databanks.......................................................................................................... 12User Databanks .............................................................................................................. 13Specifying the Location of User Databanks ................................................................ 13
Idents ............................................................................................................................13USER Idents.................................................................................................................... 13OS_USER Idents ............................................................................................................ 13PROGRAM Idents........................................................................................................... 14GROUP Idents ................................................................................................................ 14
Schemas .......................................................................................................................14Tables............................................................................................................................15
Base Tables and Views.................................................................................................. 15
ii Contents
Primary Keys and Indexes...........................................................................................16Stored Procedures .......................................................................................................17
Routines – Functions and Procedures ........................................................................ 17Modules ........................................................................................................................... 17
Synonyms .....................................................................................................................18Shadows........................................................................................................................18Triggers .........................................................................................................................18Sequences ....................................................................................................................18Mimer SQL Character Sets ..........................................................................................19Collations and Linguistic Sorting ...............................................................................19
Multilevel Comparisons ................................................................................................. 20Alternate Weighting........................................................................................................ 21Tailorings......................................................................................................................... 22Sorting ............................................................................................................................. 23Collating details .............................................................................................................. 24
Data Integrity ................................................................................................................25Domains .......................................................................................................................... 26Foreign Keys – Referential Integrity ............................................................................ 26Check Conditions ........................................................................................................... 26Check Options in View Definitions ............................................................................... 27
Privileges ......................................................................................................................27System Privileges........................................................................................................... 27Object Privileges ............................................................................................................ 27Access Privileges ........................................................................................................... 28About Privileges.............................................................................................................. 28
Chapter 5 SQL Syntax Elements..................................................................... 29Characters.....................................................................................................................29
Special Characters......................................................................................................... 30Identifiers ......................................................................................................................30
SQL Identifiers ................................................................................................................ 30Naming Objects .............................................................................................................. 31Qualified Object Names ................................................................................................ 31Outer References........................................................................................................... 32Host Identifiers................................................................................................................ 33Target Variables ............................................................................................................. 33Reserved Words............................................................................................................. 34Standard Compliance .................................................................................................... 34
Data Types in SQL Statements ...................................................................................34Character Strings ........................................................................................................... 34National Character Strings............................................................................................ 36Binary............................................................................................................................... 39Numerical ........................................................................................................................ 41Datetime .......................................................................................................................... 42Interval ............................................................................................................................. 43ROW Data Type ............................................................................................................. 46
Mimer SQL Engine Version 9.2 iiiSQL Reference Manual
The NULL Value.............................................................................................................. 47Data Type Compatibility ................................................................................................. 47Datetime and Interval Arithmetic................................................................................... 48Data Types for Parameter Markers .............................................................................. 49Host Variable Data Type Conversion........................................................................... 49Standard Compliance..................................................................................................... 51
Literals ..........................................................................................................................52String Literals................................................................................................................... 52Numerical Integer Literals.............................................................................................. 53Numerical Decimal Literals............................................................................................ 53Numerical Floating Point Literals .................................................................................. 54DATE, TIME and TIMESTAMP Literals ....................................................................... 54Interval Literals ................................................................................................................ 55Standard Compliance..................................................................................................... 56
Chapter 6 Operators and Values ..................................................................... 57Operators......................................................................................................................57
Set Operators .................................................................................................................. 57Arithmetical Operators.................................................................................................... 57String Operators.............................................................................................................. 58Comparison and Relational Operators......................................................................... 58Logical Operators............................................................................................................ 59Standard Compliance..................................................................................................... 59
Value Specifications ....................................................................................................59Standard Compliance..................................................................................................... 60
Default Values ..............................................................................................................60Standard Compliance..................................................................................................... 61
Assignments ................................................................................................................61String Assignments......................................................................................................... 61Numerical Assignments ................................................................................................. 61Datetime Assignment Rules .......................................................................................... 62Interval Assignment Rules ............................................................................................. 63Standard Compliance..................................................................................................... 63
Comparisons ................................................................................................................63Character String Comparisons...................................................................................... 63Numerical Comparisons................................................................................................. 64Datetime and Interval Comparisons ............................................................................. 64NULL Comparisons ........................................................................................................ 64Truth Tables..................................................................................................................... 65Standard Compliance..................................................................................................... 65
Result Data Types........................................................................................................65Standard Compliance..................................................................................................... 67
Chapter 7 Functions ......................................................................................... 69About Set Functions....................................................................................................69
Syntax for Set Functions................................................................................................ 69AVG .................................................................................................................................. 69
iv Contents
COUNT............................................................................................................................ 69MAX ................................................................................................................................. 69MIN................................................................................................................................... 69SUM ................................................................................................................................. 70Examples......................................................................................................................... 70Operational Mode........................................................................................................... 70NULL Values................................................................................................................... 70Restrictions ..................................................................................................................... 70Results of Set Functions ............................................................................................... 71Evaluating Set Functions .............................................................................................. 71Standard Compliance .................................................................................................... 72
About Scalar Functions ...............................................................................................72Scalar Numeric Functions ...........................................................................................72
ASCII_CODE .................................................................................................................. 72BIT_LENGTH.................................................................................................................. 73CHAR_LENGTH or CHARACTER_LENGTH ............................................................ 73CEILING .......................................................................................................................... 74CURRENT_VALUE........................................................................................................ 74DACOS............................................................................................................................ 75DASIN.............................................................................................................................. 75DATAN............................................................................................................................. 76DATAN2 .......................................................................................................................... 76DAYOFWEEK................................................................................................................. 76DAYOFYEAR.................................................................................................................. 77DCOS............................................................................................................................... 77DCOT............................................................................................................................... 78DDEGREES.................................................................................................................... 78DEXP ............................................................................................................................... 78DLOG............................................................................................................................... 79DLOG10 .......................................................................................................................... 79DPOWER ........................................................................................................................ 79DRADIAN ........................................................................................................................ 80DSIN................................................................................................................................. 80DSQRT ............................................................................................................................ 80DTAN ............................................................................................................................... 81EXTRACT........................................................................................................................ 81FLOOR ............................................................................................................................ 82IRAND.............................................................................................................................. 82MOD................................................................................................................................. 82NEXT_VALUE ................................................................................................................ 83OCTET_LENGTH........................................................................................................... 84POSITION ....................................................................................................................... 84ROUND............................................................................................................................ 85SIGN ................................................................................................................................ 86TRUNCATE..................................................................................................................... 86UNICODE_CODE .......................................................................................................... 87WEEK .............................................................................................................................. 87
Scalar String Functions ...............................................................................................88ASCII_CHAR .................................................................................................................. 88CURRENT_PROGRAM ................................................................................................ 88 LOWER .......................................................................................................................... 89
Mimer SQL Engine Version 9.2 vSQL Reference Manual
PASTE.............................................................................................................................. 89REPEAT........................................................................................................................... 90REPLACE ........................................................................................................................ 91SOUNDEX ....................................................................................................................... 91SUBSTRING.................................................................................................................... 92TAIL .................................................................................................................................. 93TRIM................................................................................................................................. 93UNICODE_CHAR ........................................................................................................... 94UPPER ............................................................................................................................. 95
Scalar Interval Functions ............................................................................................95ABS................................................................................................................................... 95
Datetime Pseudo-Literals ............................................................................................95CURRENT_DATE........................................................................................................... 96LOCALTIME .................................................................................................................... 96LOCALTIMESTAMP....................................................................................................... 97
String Pseudo-Literals.................................................................................................98CURRENT_USER .......................................................................................................... 98SESSION_USER............................................................................................................ 98USER................................................................................................................................ 99
Standard Compliance ..................................................................................................99
Chapter 8 Expressions and Predicates ........................................................ 101Expressions................................................................................................................101
Expression Syntax ........................................................................................................ 101Unary Operators............................................................................................................ 102Binary Operators........................................................................................................... 102Operands ....................................................................................................................... 102Evaluating Arithmetical Expressions .......................................................................... 102Evaluating String Expressions .................................................................................... 104Select Specification ...................................................................................................... 105
CASE Expression.......................................................................................................105CASE Expression First Form ...................................................................................... 105CASE Expression Second Form................................................................................. 106Short Forms for CASE.................................................................................................. 106
CAST Specification....................................................................................................107Rules............................................................................................................................... 107Example ......................................................................................................................... 108Standard Compliance................................................................................................... 108
Predicates...................................................................................................................109Predicate Syntax........................................................................................................... 109The Basic Predicate ..................................................................................................... 110The Quantified Predicate ............................................................................................. 110The IN Predicate ........................................................................................................... 111The BETWEEN Predicate............................................................................................ 111The LIKE Predicate....................................................................................................... 112The NULL Predicate ..................................................................................................... 113The EXISTS Predicate ................................................................................................. 113The OVERLAPS Predicate.......................................................................................... 114
vi Contents
Standard Compliance .................................................................................................. 115
Chapter 9 Search Conditions and Joins ...................................................... 117Search Conditions......................................................................................................117
Rules.............................................................................................................................. 117Examples....................................................................................................................... 118Standard Compliance .................................................................................................. 118
Joined Tables .............................................................................................................118INNER JOINs...............................................................................................................119
NATURAL JOIN............................................................................................................ 119JOIN USING ................................................................................................................. 120JOIN ON........................................................................................................................ 120
OUTER JOINs .............................................................................................................121LEFT OUTER JOIN ..................................................................................................... 121RIGHT OUTER JOIN................................................................................................... 122FULL OUTER JOIN ..................................................................................................... 123
Standard Compliance ................................................................................................123
Chapter 10 The SELECT Specification ......................................................... 125SELECT Specification Syntax .....................................................................