Language Reference
Total Page:16
File Type:pdf, Size:1020Kb
InterBase 6 Language Reference Borland/INPRISE 100 Enterprise Way, Scotts Valley, CA 95066 http://www.interbase.com Inprise/Borland may have patents and/or pending patent applications covering subject matter in this document. The furnishing of this document does not convey any license to these patents. Copyright 1999 Inprise/Borland. All rights reserved. All InterBase products are trademarks or registered trademarks of Inprise/Borland. All Borland products are trademarks or registered trademarks of Inprise/Borland. Other brand and product names are trademarks or registered trademarks of their respective holders. 1INT0055WW21004 6E1R0699 Table of Contents List of Tables.....................................xi CHAPTER 1 Using the InterBase Language Reference Who should use this book .....................13 Topics covered in this book .....................14 CHAPTER 2 SQL Statement and Function Reference Database object naming conventions ...............16 Statement list .............................17 Function list .............................18 Datatypes ...............................19 Error handling ............................20 Using statement and function definitions .............21 ALTER DATABASE ..........................22 ALTER DOMAIN ...........................23 ALTER EXCEPTION .........................25 ALTER INDEX ............................26 ALTER PROCEDURE .........................27 ALTER TABLE .............................28 ALTER TRIGGER ...........................35 AVG( ) .................................36 BASED ON ..............................38 BEGIN DECLARE SECTION .....................39 CAST( ) ................................39 CLOSE .................................40 CLOSE (BLOB) ............................41 COMMIT ...............................42 CONNECT ...............................44 COUNT( ) ...............................48 CREATE DATABASE .........................49 CREATE DOMAIN ..........................52 iii CREATE EXCEPTION ........................57 CREATE GENERATOR ........................58 CREATE INDEX ............................59 CREATE PROCEDURE ........................61 CREATE ROLE ............................69 CREATE SHADOW ..........................69 CREATE TABLE ............................72 CREATE TRIGGER ..........................80 CREATE VIEW ............................87 DECLARE CURSOR .........................90 DECLARE CURSOR (BLOB) .....................92 DECLARE EXTERNAL FUNCTION .................93 DECLARE FILTER ..........................95 DECLARE STATEMENT .......................97 DECLARE TABLE ...........................97 DELETE ................................98 DESCRIBE ............................. 100 DISCONNECT ............................ 102 DROP DATABASE ......................... 102 DROP DOMAIN .......................... 103 DROP EXCEPTION ......................... 104 DROP EXTERNAL FUNCTION .................. 105 DROP FILTER ........................... 106 DROP INDEX ............................ 107 DROP PROCEDURE ........................ 108 DROP ROLE ............................ 108 DROP SHADOW .......................... 109 DROP TABLE ............................ 110 DROP TRIGGER .......................... 111 DROP VIEW ............................ 112 END DECLARE SECTION ..................... 112 EVENT INIT ............................. 113 EVENT WAIT ............................ 114 iv INTERBASE 6 EXECUTE .............................. 115 EXECUTE IMMEDIATE ...................... 117 EXECUTE PROCEDURE ...................... 118 FETCH ................................ 119 FETCH (BLOB) ........................... 121 GEN_ID( ) .............................. 122 GRANT ............................... 123 INSERT ............................... 127 INSERT CURSOR (BLOB) ..................... 129 MAX( ) ............................... 130 MIN( ) ................................ 131 OPEN ................................ 131 OPEN (BLOB) ........................... 132 PREPARE .............................. 133 REVOKE ............................... 135 ROLLBACK ............................. 138 SELECT ............................... 139 SET DATABASE ........................... 146 SET GENERATOR ......................... 148 SET NAMES ............................. 149 SET SQL DIALECT ......................... 150 SET STATISTICS .......................... 151 SET TRANSACTION ........................ 152 SHOW SQL DIALECT ....................... 155 SUM( ) ................................ 156 UPDATE ............................... 156 UPPER( ) .............................. 158 WHENEVER ............................. 159 CHAPTER 3 Procedures and Triggers Creating triggers and stored procedures ............ 162 Nomenclature conventions .................... 163 Assignment statement ....................... 163 BEGIN … END ........................... 164 LANGUAGE REFERENCE v Comment .............................. 165 DECLARE VARIABLE ........................ 166 EXCEPTION ............................. 166 EXECUTE PROCEDURE ...................... 167 EXIT ................................. 169 FOR SELECT…DO ......................... 170 IF…THEN … ELSE ......................... 171 Input parameters ......................... 172 NEW context variables ...................... 173 OLD context variables ....................... 174 Output parameters ......................... 175 POST_EVENT ............................ 176 SELECT ............................... 176 SUSPEND .............................. 177 WHEN … DO ............................ 179 Handling exceptions ..................... 180 Handling SQL errors ..................... 180 Handling InterBase error codes .............. 181 WHILE … DO ............................ 182 CHAPTER 4 Keywords InterBase keywords ........................ 184 CHAPTER 5 User-Defined Functions A brief overview .......................... 189 UDF library ............................. 190 abs ............................... 190 acos .............................. 190 ascii_char ........................... 191 ascii_val ............................ 191 asin .............................. 191 atan .............................. 191 atan2 ............................. 192 bin_and ............................ 192 vi INTERBASE 6 bin_or ............................. 192 bin_xor ............................ 192 ceiling ............................. 193 cos ............................... 193 cosh .............................. 193 cot ............................... 193 div ............................... 194 floor .............................. 194 ln................................ 194 log ............................... 194 log10.............................. 195 lower ............................. 195 ltrim .............................. 195 mod .............................. 195 pi................................ 196 rand .............................. 196 rtrim.............................. 196 sign .............................. 196 sin ............................... 197 sinh .............................. 197 sqrt .............................. 197 strlen ............................. 197 substr ............................. 198 tan ............................... 198 tanh .............................. 198 CHAPTER 6 Error Codes and Messages Error sources ............................ 199 Error reporting and handling .................. 200 Trapping errors with WHENEVER ............. 200 Checking SQLCODE value directly ............. 201 InterBase status array .................... 201 For more information .................... 203 SQLCODE error codes and messages .............. 203 LANGUAGE REFERENCE vii SQLCODE error messages summary ............ 204 SQLCODE codes and messages ............... 204 InterBase status array error codes ................ 220 CHAPTER 7 System Tables and Views Overview .............................. 241 System tables ............................ 242 RDB$CHARACTER_SETS ..................... 243 RDB$CHECK_CONSTRAINTS ................... 244 RDB$COLLATIONS ......................... 244 RDB$DATABASE .......................... 245 RDB$DEPENDENCIES ....................... 246 RDB$EXCEPTIONS ........................ 247 RDB$FIELD_DIMENSIONS .................... 248 RDB$FIELDS ............................ 248 RDB$FILES ............................. 253 RDB$FILTERS ........................... 254 RDB$FORMATS .......................... 254 RDB$FUNCTION_ARGUMENTS ................. 255 RDB$FUNCTIONS ......................... 256 RDB$GENERATORS ........................ 257 RDB$INDEX_SEGMENTS ..................... 258 RDB$INDICES ........................... 258 RDB$LOG_FILES .......................... 259 RDB$PAGES ............................ 260 RDB$PROCEDURE_PARAMETERS ................ 261 RDB$PROCEDURES ........................ 262 RDB$REF_CONSTRAINTS ..................... 263 RDB$RELATION_CONSTRAINTS ................. 263 RDB$RELATION_FIELDS ..................... 264 RDB$RELATIONS ......................... 266 RDB$ROLES ............................ 267 RDB$SECURITY_CLASSES .................... 268 RDB$TRANSACTIONS ....................... 268 viii INTERBASE 6 RDB$TRIGGER_MESSAGES .................... 269 RDB$TRIGGERS .......................... 269 RDB$TYPES ............................ 271 RDB$USER_PRIVILEGES ..................... 272 RDB$VIEW_RELATIONS ..................... 273 System views ............................ 273 CHECK_CONSTRAINTS ...................... 275 CONSTRAINTS_COLUMN_USAGE ...............