Tài liệu SQL Clearly Explained- P10 doc

46 236 0
Tài liệu SQL Clearly Explained- P10 doc

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

414 Chapter 19: Object-Relational Support retrieve just the value of a single column, we use “dot” nota- tion. e rst portion— DEREF(related_ingredient) —actually performs the dereference. e portion to the right of the dot species the column in the referenced row. Some DBMSs provide a dereference operator (->) that can be used in place of the DEREF function. e preceding query might be written: SELECT related_ingredient->ingredient_name, amount FROM ingredient_amount; e UDTs that we have seen to this point have attributes, but not methods. It is certainly possible, however, to declare meth- ods as part of a UDT and then to use SQL programming to dene the body of the methods. Like classes used by OO pro- gramming languages such C++, SQL the body a method is dened separately from the declaration of the UDT. You declare a method after declaring the structure of a UDT. For example, we could add a method to display the instruc- tions of a recipe with CREATE TYPE recipe_type AS OBJECT (recipe_name CHAR (256), instruction_list instruction ARRAY[20], numb_servings INT) NOT INSTANTIABLE, NOT FINAL METHOD show_instructions (); is particular method does not return a value and the dec- laration therefore does not include the optional RETURNS clause. However, a method to compute the cost of a recipe (if we were to include ingredient costs in the database) could be declared as Methods Methods 415 Dening Methods Executing Methods CREATE TYPE recipe_type AS OBJECT (recipe_name CHAR (256), instruction_list instruction ARRAY[20], numb_servings INT) NOT INSTANTIABLE, NOT FINAL METHOD show_instructions () METHOD compute_cost () RETURNS DECIMAL (5,2)); Methods can accept input parameters within the parentheses following the method name. A method declared as METHOD scale_recipe (IN numb_servings INT): accepts an integer value as an input value. e parameter list can also contain output parameters (OUT) and parameters used for both input and output (INOUT). As mentioned earlier, although methods are declared when UDTs tables are declared, the bodies of methods are written separately. To dene a method, use the CREATE METHOD statement: CREATE METHOD method_name FOR UDT_name BEGIN // body of method END A SQL-only method is written using the language constructs discussed in Chapter 14. Random programming note: Like the C++ and Java “this,” SQL methods use SELF to refer to the object to which the method belongs. Executing a method uses the “dot” notation used in C++: typed_table_name.method_name (parameter_list); 416 Chapter 19: Object-Relational Support Such an expression can be, for example, included in an IN- SERT statement to insert the method’s return value into a column. It can also be included in another SQL method, trig- ger, or stored procedure. Its return value can then be captured across an assignment operator. Output parameters return their values to the calling routine, where they can be used as needed. Appendix A 419 Abbreviation/ Acronym Denition 1:1 One-to-one 1:M One-to-many ANSI American National Standards Institute API Application Program (or Programmer) Interface ASCII American Standard Code for Information Interchange CHAR Character CLI Command-line interface CTE Common table expression DBA Database administrator or Database administration DBMS Database management system DTD Document type denition ER Entity relationship ERD Entity relationship diagram FK or fk Foreign key GUI Graphic user interface HTML Hypertext markup language IE Information Engineering INT Integer Common Acronyms and Abbreviations 420 Appendix A: Common Acronyms and Abbreviations ISO International Standards Organization JDBC Java Database Connectivity M:M Many-to-many M:N Many-to-many NIST National Institute for Standards and Technology OO Object-oriented OODBMS Object-oriented database management system OOP Object-oriented programming OR Object-relational PK or pk Primary key PSM Persistent stored modules RDMBS Relational database management system SQL Structured query language UDF User-dened function UDT User-dened type; user-dened data type URI Uniform resource identier URL Uniform resource locator UML Unied modeling language VARCHAR Character varying XML Extended (Extensible) Markup Language Appendix B 421 SQLSTATE Return Codes is appendix contains a numeric listing of the SQLSTATE re- turn codes specied in the SQL standard (Table B-1). SQLSTATE is a ve-character string. e leftmost two characters represent the error class; the rightmost three characters represent the subclass. Because SQLSTATE is a string, an embedded SQL program will need to use a substring function if it needs to separate the two parts of the code. 422 Appendix B: SQLSTATE Return Codes Table B-1: SQLSTATE return codes Class Class denition Subclass Subclass denition 00 Successful completion 000 None 01 Warning 000 None 001 Cursor operation conict 002 Disconnect error 003 Null value eliminated in set function 004 String data, right truncation 005 Insucient item descriptor area 006 Privilege not revoked 007 Privilege not granted 008 Implicit zero-bit padding 009 Search expression too long for information schema 00A Query expression too long for information schema 00B Default value too long for information schema 00C Result sets returned 00D Additional result sets returned 00E Attempt to return too many result sets 00F Statement too long for information schema 010 Column cannot be mapped (XML) 011 SQL-Java path too long for information schema 02F Array data, right truncation 02 No data 000 None 001 No additional result sets returned 07 Dynamic SQL error 000 None 001 Using clause does not match dynamic parameter 002 Using clause does not match target specications 423 003 Cursor specication cannot be executed 004 Using clause required for dynamic parameters 005 Prepared statement not a cursor specication 006 Restricted data type attribute violation 007 Using clause required for result elds 008 Invalid descriptor count 009 Invalid descriptor index 00B Data type transform function violation 00C Undened DATA value 00D Invalid DATA target 00E invalid LEVEL value 00F Invalid DATETIME_INVERTVAL_CODE 08 Connection exception 000 None 001 SQL client unable to establish SQL connection 002 Connection name in use 003 Connection does not exist 004 SQL server rejected establishment of SQL connection 006 Connection failure 007 Transaction resolution unknown 09 Triggered action exception 000 None 0A Feature not supported 000 None 001 Multiple server transactions 0D Invalid target type specication 000 None 0E Invalid schema name list specication 000 None 0F Locator exception 000 None 001 Invalid specication 0K Resignal when handler not active 000 None 0L Invalid grantor 000 None 424 Appendix B: SQLSTATE Return Codes 0M Invalid SQL-invoked procedure reference 000 None 0N SQL/XML mapping error 000 None 001 Unmappable XML name 002 Invalid XML character 0P Invalid role specication 000 None 0S Invalid transform group name specication 000 None 0T Target table disagrees with cursor specication 000 None 0U Attempt to assign to non-updatable column 000 None 0V Attempt to assign to ordering column 000 None 0W Prohibited statement encountered during trigger execution 000 None 0X Invalid foreign server specication 000 None 0Y Pass-through specic condition 000 None 001 Invalid cursor option 002 Invalid cursor allocation 0Z Diagnostics exception 001 Maximum number of stacked diagnostics area exceeded 002 Stacked diagnostics accessed without active hander 10 XQuery error 000 None 20 Case not found for CASE statement 000 None 21 Cardinality violation 000 None 22 Data exception 000 None 001 String data, right truncation 002 Null value, no indicator 003 Numeric value out of range 004 Null value not allowed 005 Error in assignment 006 Invalid interval fomat 007 Invalid datetime format 425 008 Datetime eld overow 009 Invalid time zone displacement value 00B Escape character conict 00C Invalid use of escape character 00D Invalid escape octet 00E Null value in array target 00F Zero-length character string 00G Most specic type mismatch 00H Sequence generator limit exceeded 00J Nonidentical notations with the same name (XML) 00K Nonidentical unparsed entities with the same name (XML) 00L Not an XML document 00M Invalid XML document 00N Invalid XML content 00P Interval value out of range 00Q Multiset value overow 00R XML value overow 00S Invalid XML comment 00T Invalid XML processing instruction 00U Not an XQuery document node 00V Invalid XQuery context item 00W XQuery serialization error 010 Invalid indicator parameter value 011 Substring error 012 Division by zero 015 Interval eld overow 017 Invalid data specied for datalink 018 Invalid character value for cast 019 Invalid escape character [...]... Execute an embedded SQL statement EXEC SQL complete _SQL_ statement Execute a prepared dynamic SQL statement EXECUTE [ GLOBAL | LOCAL ] prepared_dynamic _SQL_ statement [ INTO { parameter, … } | { SQL DESCRIPTOR [ GLOBAL | LOCAL ] descriptor_name } ] [ USING { parameter, … } | { SQL DESCRIPTOR [ GLOBAL | LOCAL ] descriptor_name } ] 438  Appendix C: SQL Syntax Summary Execute a dynamic SQL statement immediately,... embedded SQL: Embedded SQL in which the entire SQL statement cannot be assembled prior to running the program The SQL statement is therefore completed and processed during the program run Dynamic parameter: A value given to an embedded SQL statement at runtime rather than when the program in which the statement is contained is compiled Embedded SQL: SQL statements placed within a host language, allowing SQL. .. rule violation in direct SQL statement 000 None 2B Dependent privilege descriptors still exist 000 None 2C Invalid character set name 000 None 2D Invalid transaction termination 000 None 2E Invalid connection name 000 None 2F SQL routine exception 000 None 002 Modifying SQL data not permitted 003 Prohibited SQL statement attempted 428  Appendix B: SQLSTATE Return Codes 004 Reading SQL data not permitted... Invalid SQL statement identifier 000 None 33 Invalid SQL descriptor name 000 None 34 Invalid cursor name 000 None 35 Invalid condition number 000 None 36 Cursor sensitivity exception 000 None 001 Request rejected 002 Request failed 37 Syntax error or access rule violation in dynamic SQL statement 000 None 38 External routine exception 000 None 001 Containing SQL not permitted 002 Modifying SQL not... needed are followed by an ellipsis (…) The second table (Table C.2) describes SQL built-in functions discussed in this book, including input data types In Table C.3 you will find SQL operators covered in the text 433 434  Appendix C: SQL Syntax Summary Table C.1: SQL statements Allocate space for a descriptor area for a dynamic SQL statement ALLOCATE DESCRIPTOR descriptor_name [ WITH MAX number_of_parameters... state 000 None 001 Active SQL transaction 002 Branch transaction already active 003 Inappropriate access mode for branch transaction 004 Inappropriate isolation level for branch transaction 005 No active SQL transaction for branch transaction 006 Read-only SQL transaction 007 Schema and data statement mixing not supported 008 Held cursor requires same isolation level 26 Invalid SQL statement name 000... executing the SELECT and positioning the cursor at the first row OPEN cursor_name [ { USING host_language_variable_or_literal, … } | { SQL DESCRIPTOR descriptor_name } ] Prepare a dynamic SQL statement for execution PREPARE [ GLOBAL | LOCAL ] prepared_dynamic _SQL_ statement_name FROM SQL_ statement_text_literal_or_variable Remove access rights from a user REMOVE [GRANT OPTION FOR ] { ALL PRIVILEGES } | SELECT... UPDATE [ OF column_name, … ] ) ] | prepared_dynamic _SQL_ statement_name Delete rows from a table DELETE FROM table_name [ { WHERE row_selection_predicate } | { WHERE CURRENT OF cursor_name } ]   437 Describe the dynamic parameters in a prepared dynamic SQL statement for a descriptor area DESCRIBE [ INPUT | OUTPUT ] Prepared_dyamic _SQL_ statement_name USING SQL DESCRIPTOR descriptor_name Disconnect from a... language: A set of special codes placed inside a text document to identify the elements of the document and optionally to give instructions to software using the document Message: Requests for data manipulation sent from one object to another Method (class): A program module that acts on objects created from a class in an object-oriented program Method (SQL) : A program module that is part of a user-defined... smallest unit of a SQL PSM Typically it performs a single action, such as updating a total or inserting a row in a table 452  Glossary Schema (relational database): In database design theory, the overall logical design of a database In a SQL DBMS, a group of tables and supporting elements such as views and indexes Schema (XML): A special type of XML document that contains definitions of document structure . Language Appendix B 421 SQLSTATE Return Codes is appendix contains a numeric listing of the SQLSTATE re- turn codes specied in the SQL standard (Table B-1). SQLSTATE. None 001 SQL client unable to establish SQL connection 002 Connection name in use 003 Connection does not exist 004 SQL server rejected establishment of SQL

Ngày đăng: 21/01/2014, 19:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan