Oracle Rdb7™ SQL Reference Manual Volume 1
Total Page:16
File Type:pdf, Size:1020Kb
Oracle Rdb7™ SQL Reference Manual Volume 1 Release 7.0 Part No. A42814-1 ® SQL Reference Manual, Volume 1 Release 7.0 Part No. A42814-1 Copyright © 1987, 1996, Oracle Corporation. All rights reserved. This software/documentation contains proprietary information of Oracle Corporation; it is provided under a license agreement containing restrictions on use and disclosure and is also protected by copyright law. Reverse engineering of the software is prohibited. The information contained in this document is subject to change without notice. If you find any problems in the documentation, please report them to us in writing. Oracle Corporation does not warrant that this document is error-free. Restricted Rights Legend Programs delivered subject to the DOD FAR Supplement are ’commercial computer software’ and use, duplication and disclosure of the Programs shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement. Otherwise, Programs delivered subject to the Federal Acquisition Regulations are ’restricted computer software’ and use, duplication and disclosure of the Programs shall be subject to the restrictions in FAR 52.227-14, Rights in Data—General, including Alternate III (June 1987). Oracle Corporation, 500 Oracle Parkway, Redwood City, CA 94065. The programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently dangerous applications. It shall be licensee’s responsibility to take all appropriate fail-safe, back up, redundancy and other measures to ensure the safe use of such applications if the Programs are used for such purposes, and Oracle disclaims liability for any damages caused by such use of the Programs. Oracle is a registered trademark of Oracle Corporation. Oracle CDD/Administrator, Oracle CDD/Repository, Oracle Rally, Oracle Rdb, Oracle RMU, Oracle SQL/Services, Distributed Option for Rdb, Rdb Transparent Gateway to RMS, Rdb Transparent Gateway to DB2, Rdb Transparent Gateway to Oracle, and Rdb7 are trademarks of Oracle Corporation. All other product or company names mentioned are used for identification purposes only, and may be trademarks of their respective owners. Contents Send Us Your Comments ........................................... xi Preface ........................................................... xiii Technical Changes and New Features ............................... xvii 1 Introduction to SQL Syntax 1.1 Conformance to Federal Information Processing Standard . ........ 1–1 1.2 Using SQL ................................................ 1–2 1.2.1 Invoking SQL Images . ................................. 1–3 1.3 Samples Directory . ......................................... 1–4 1.4 How to Read Syntax Diagrams ................................ 1–4 1.5 Executable and Nonexecutable Statements ....................... 1–7 1.6 Summary of SQL Statements . ................................. 1–8 1.7 Keywords and Line Terminators ............................... 1–13 1.7.1 Statement Terminators and Comment Characters ............... 1–13 1.8 Support for Multivendor Integration Architecture . ................ 1–15 2 Language and Syntax Elements 2.1 Supported Character Sets . ................................. 2–1 2.1.1 Logical Names for Character Sets . ......................... 2–5 2.1.2 Identifier Character Sets . ................................. 2–6 2.1.3 Default Character Sets . ................................. 2–8 2.1.4 National Character Sets . ................................. 2–9 2.1.5 Literal Character Sets . ................................. 2–10 2.2 User-Supplied Names ........................................ 2–11 2.2.1 Database Names ........................................ 2–19 2.2.1.1 Oracle Rdb Attach Specifications ......................... 2–20 2.2.1.2 Repository Path Names ................................ 2–23 2.2.2 Aliases ................................................ 2–25 iii 2.2.3 Names in Multischema Databases ........................... 2–26 2.2.4 Stored Names ........................................... 2–28 2.2.5 Authorization Identifiers .................................. 2–29 2.2.5.1 Authorization Identifiers and Stored Modules . ............. 2–29 2.2.5.2 Authorization Identifiers and Nonstored Modules ............ 2–33 2.2.6 Connection Names . ...................................... 2–33 2.2.7 Catalog Names .......................................... 2–33 2.2.8 Schema Names .......................................... 2–35 2.2.9 Table and View Names .................................... 2–36 2.2.10 Column Names . ...................................... 2–39 2.2.10.1 Correlation Names .................................... 2–41 2.2.10.2 Outer References ..................................... 2–43 2.2.11 Domain Names . ...................................... 2–44 2.2.12 Trigger Names .......................................... 2–45 2.2.13 Index Names ........................................... 2–46 2.2.14 Cursor Names .......................................... 2–47 2.2.15 Constraint Names . ...................................... 2–47 2.2.16 Storage Area Names ..................................... 2–47 2.2.17 Storage Map Names ...................................... 2–48 2.2.18 Statement Names (Dynamic SQL Only) . ...................... 2–49 2.2.19 Parameters, Routine Parameters, and SQL Variables ............ 2–49 2.2.19.1 Data Parameters and Indicator Parameters . ............. 2–51 2.2.19.2 Host Structures and Indicator Arrays ..................... 2–53 2.2.19.3 Multistatement Procedure Variables and Stored Routine Parameters . ...................................... 2–58 2.2.19.4 External Routine Parameters ............................ 2–58 2.2.20 Nonstored Module, Procedure, and Parameter Names (Module Language Only) . ...................................... 2–59 2.3 Data Types . .............................................. 2–60 2.3.1 Character Data Types .................................... 2–63 2.3.1.1 Calculating the Maximum Length of a CHAR or VARCHAR Column ............................................ 2–65 2.3.2 DECIMAL and NUMERIC Data Types . ...................... 2–66 2.3.3 Fixed-Point Numeric Data Types ............................ 2–67 2.3.4 Floating-Point Numeric Data Types .......................... 2–68 2.3.5 Date-Time Data Types .................................... 2–69 2.3.6 LIST OF BYTE VARYING Data Type . ...................... 2–75 2.3.6.1 On-Disk Format of Lists . .............................. 2–77 2.3.7 Data Type Conversions ................................... 2–80 2.3.7.1 Conversion from Unsupported Data Types .................. 2–81 2.3.7.2 Conversion Between Supported Data Types ................. 2–82 2.4 Literals .................................................. 2–87 2.4.1 Numeric Literals . ...................................... 2–88 iv 2.4.2 Character String Literals . ................................. 2–89 2.4.2.1 Quoted Character String Literals ......................... 2–90 2.4.2.1.1 Quoted Character String Literals Qualified by a Character Set............................................. 2–92 2.4.2.1.2 Quoted Character String Literals Qualified by the National Character Set ..................................... 2–92 2.4.2.2 Hexadecimal Character String Literals .................... 2–93 2.4.3 Date-Time Literals ....................................... 2–93 2.5 SQL and DATATRIEVE Formatting Clauses ...................... 2–98 2.5.1 QUERY HEADER Clause ................................. 2–99 2.5.2 EDIT STRING Clause . ................................. 2–100 2.6 Value Expressions . ......................................... 2–115 2.6.1 NULL Keyword Used as an Expression ....................... 2–121 2.6.2 Built-In Functions ....................................... 2–122 2.6.2.1 CHARACTER_LENGTH Function ........................ 2–123 2.6.2.2 OCTET_LENGTH Function ............................. 2–125 2.6.2.3 CAST Function ...................................... 2–126 2.6.2.4 UPPER Function ..................................... 2–128 2.6.2.5 LOWER Function ..................................... 2–129 2.6.2.6 TRANSLATE Function ................................. 2–130 2.6.2.7 SUBSTRING Function ................................. 2–133 2.6.2.8 EXTRACT Function . ................................. 2–134 2.6.2.9 USER Function ...................................... 2–137 2.6.2.10 CURRENT_USER Function ............................. 2–138 2.6.2.11 SESSION_USER Function .............................. 2–138 2.6.2.12 SYSTEM_USER Function .............................. 2–139 2.6.2.13 CURRENT_DATE Function ............................. 2–139 2.6.2.14 CURRENT_TIME Function ............................. 2–140 2.6.2.15 CURRENT_TIMESTAMP Function ....................... 2–140 2.6.2.16 TRIM Function ...................................... 2–143 2.6.2.17 POSITION Function . ................................. 2–145 2.6.3 Aggregate Functions ..................................... 2–147 2.6.3.1 COUNT Function ..................................... 2–148 2.6.3.2 SUM Function ....................................... 2–149 2.6.3.3 AVG Function ........................................ 2–150 2.6.3.4 MAX Function ....................................... 2–150 2.6.3.5 MIN Function ....................................... 2–151 2.6.4 External Routines ....................................... 2–151 2.6.5 Database Keys . ......................................... 2–153 2.6.6 String Concatenation Operator ............................. 2–156