HP Neoview SQL Reference Manual
HP Neoview SQL Reference Manual

HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

Quick Links

HP Neoview SQL Reference Manual
HP Part Number: 61 1360-001
Published: July 2010
Edition: HP Neoview Release 2.5

Advertisement

Table of Contents
loading

Summary of Contents for HP Neoview SQL

  • Page 1 HP Neoview SQL Reference Manual HP Part Number: 61 1360-001 Published: July 2010 Edition: HP Neoview Release 2.5...
  • Page 2 The information contained herein is subject to change without notice. The only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein.
  • Page 3: Table Of Contents

    Rules for DML Statements.......................29 Effect of AUTOCOMMIT Option....................29 Concurrency............................29 Transaction Access Modes.......................31 Transaction Isolation Levels......................32 Transaction Rollback Mode......................33 ANSI Compliance and Neoview SQL Extensions................33 ANSI-Compliant Statements......................33 Statements That Are Neoview SQL Extensions................34 ANSI-Compliant Functions......................34 Neoview SQL Error Messages......................35 2 SQL Statements......................37 Categories.............................37...
  • Page 4 Syntax Description of ALTER MATERIALIZED VIEW..............40 Considerations for ALTER MATERIALIZED VIEW...............40 Example of ALTER MATERIALIZED VIEW...................41 ALTER MVGROUP Statement......................42 Syntax Description of ALTER MVGROUP..................42 Considerations for ALTER MVGROUP..................42 Examples of ALTER MVGROUP.....................42 ALTER SYNONYM Statement......................43 Syntax Description of ALTER SYNONYM..................43 Considerations for ALTER SYNONYM..................43 Example of ALTER SYNONYM......................43 ALTER TABLE Statement........................44...
  • Page 5 Limits for Tables..........................87 Calculating Row Size........................87 Creating Partitions Automatically....................87 Generating Values For an IDENTITY Column................88 Neoview SQL Extensions to CREATE TABLE................92 Considerations for DISK POOL.......................92 Examples of CREATE TABLE......................93 Examples of CREATE SET TABLE....................94 Example of CREATE SET VOLATILE TABLE.................94 Examples of CREATE TABLE AS....................94...
  • Page 6 Syntax Description of DROP TRIGGER..................119 Considerations for DROP TRIGGER.....................119 Example of DROP TRIGGER......................119 DROP VIEW Statement........................120 Syntax Description of DROP VIEW....................120 Considerations for DROP VIEW....................120 Example of DROP VIEW.......................120 EXECUTE Statement...........................121 Syntax Description of EXECUTE....................121 Considerations for EXECUTE......................122 Examples of EXECUTE........................122 EXPLAIN Statement..........................124 Syntax Description of EXPLAIN....................124 Considerations for EXPLAIN......................125...
  • Page 7 Syntax Description of REVOKE SCHEMA..................160 Considerations for REVOKE SCHEMA..................162 Examples of REVOKE SCHEMA....................162 ROLLBACK WORK Statement......................163 Syntax Description of ROLLBACK WORK...................163 Considerations for ROLLBACK WORK..................163 Example of ROLLBACK WORK....................163 SELECT Statement..........................164 Syntax Description of SELECT......................166 Considerations for SELECT......................173 Considerations for Select List......................175 Considerations for SEQUENCE BY....................175 Considerations for GROUP BY......................175 Considerations for ORDER BY......................176...
  • Page 8 Syntax Description of POPULATE INDEX..................220 Considerations for POPULATE INDEX..................220 Examples of POPULATE INDEX....................221 PURGEDATA Utility...........................222 Syntax Description of PURGEDATA.....................222 Considerations for PURGEDATA....................222 Example of PURGEDATA......................223 REPLICATE Command........................224 Syntax Description of REPLICATE ....................225 Considerations for REPLICATE ....................226 Examples of REPLICATE.......................230 4 SQL Language Elements...................233 Character Sets............................234 Columns..............................235 Column References........................235...
  • Page 9 Literals..............................274 Character String Literals........................274 Datetime Literals..........................275 Interval Literals..........................277 Numeric Literals..........................279 Materialized Views..........................281 Types of Materialized Views......................281 MVGROUPs ............................282 Null..............................283 Using Null Versus Default Values....................283 Defining Columns That Allow or Prohibit Null................283 Partitions.............................285 Hash Partition Keys........................285 Automatically Creating Partitions....................285 Predicates............................286 BETWEEN Predicate........................286 Comparison Predicates........................287 EXISTS Predicate..........................291 IN Predicate...........................292...
  • Page 10 Examples of SEQUENCE BY......................327 TRANSPOSE Clause...........................329 Considerations for TRANSPOSE....................330 Examples of TRANSPOSE......................331 6 SQL Functions and Expressions................337 Categories............................337 Standard Normalization........................337 Aggregate (Set) Functions......................337 Character String Functions......................338 Datetime Functions........................339 Mathematical Functions........................340 Sequence Functions........................341 Other Functions and Expressions....................343 ABS Function............................344 Example of ABS..........................344 ACOS Function...........................345 Examples of ACOS........................345 ADD_MONTHS Function........................346...
  • Page 11 Example of CODE_VALUE Function....................363 CONCAT Function..........................364 Concatenation Operator (||)......................364 Considerations for CONCAT......................364 Examples of CONCAT........................364 CONVERTTOHEX Function.......................366 Considerations for CONVERTTOHEX..................366 Examples of CONVERTTOHEX....................366 CONVERTTIMESTAMP Function......................368 Considerations for CONVERTTIMESTAMP.................368 Examples of CONVERTTIMESTAMP...................368 COS Function............................369 Example of COS..........................369 COSH Function...........................370 Example of COSH..........................370 COUNT Function..........................371 Considerations for COUNT......................371 Examples of COUNT........................371...
  • Page 12 Examples of DAYOFMONTH.......................389 DAYOFWEEK Function........................390 Example of DAYOFWEEK......................390 DAYOFYEAR Function........................391 Example of DAYOFYEAR......................391 DECODE Function..........................392 Considerations for DECODE......................392 Examples of DECODE........................393 DEGREES Function..........................395 Examples of DEGREES........................395 DIFF1 Function............................396 Considerations for DIFF1.......................396 Examples of DIFF1.........................396 DIFF2 Function............................398 Considerations for DIFF2.......................398 Examples of DIFF2.........................398 EXP Function............................400 Examples of EXP..........................400 EXPLAIN Function..........................401...
  • Page 13 Example of LTRIM.........................418 MAX/MAXIMUM Function........................419 Considerations for MAX/MAXIMUM...................419 Example of MAX/MAXIMUM.......................419 MIN Function............................420 Considerations for MIN.........................420 Example of MIN..........................420 MINUTE Function..........................421 Example of MINUTE........................421 MOD Function............................422 Example of MOD...........................422 MONTH Function..........................423 Example of MONTH........................423 MONTHNAME Function........................424 Considerations for MONTHNAME....................424 Example of MONTHNAME......................424 MOVINGAVG Function........................425 Example of MOVINGAVG......................425 MOVINGCOUNT Function........................426...
  • Page 14 Examples of RANK/RUNNINGRANK..................444 REPEAT Function..........................447 Example of REPEAT........................447 REPLACE Function..........................448 Example of REPLACE........................448 RIGHT Function..........................449 Examples of RIGHT........................449 ROUND Function..........................450 Examples of ROUND........................450 ROWS SINCE Function........................451 Considerations for ROWS SINCE....................451 Examples of ROWS SINCE......................451 ROWS SINCE CHANGED Function....................453 Considerations for ROWS SINCE CHANGED................453 Examples of ROWS SINCE CHANGED..................453 RPAD Function...........................454 Examples of RPAD Function......................454...
  • Page 15 Considerations for SUBSTRING/SUBSTR..................471 Examples of SUBSTRING/SUBSTR....................472 SUM Function.............................473 Considerations for SUM........................473 Example of SUM..........................473 TAN Function............................474 Example of TAN..........................474 TANH Function...........................475 Example of TANH.........................475 THIS Function.............................476 Considerations for THIS........................476 Example of THIS..........................476 TIMESTAMPADD Function........................477 Examples of TIMESTAMPADD.....................477 TIMESTAMPDIFF Function........................478 Examples of TIMESTAMPDIFF.....................478 TRANSLATE Function........................479 TRIM Function............................480 Considerations for TRIM.......................480...
  • Page 16 Examples of VARIANCE Window Function.................507 A Mapping Tables......................509 B Reserved Words......................519 Reserved Neoview SQL Identifiers ....................519 C Limits...........................523 D Standard SQL and Neoview SQL................525 ANSI SQL Standards...........................525 ISO Standards............................525 Neoview SQL Compliance........................526 Neoview SQL Extensions to Standard SQL..................529 Character Set Support.........................529 E Special Neoview Features—Enabled Upon Request..........531...
  • Page 17 List of Tables Concurrent DDL/Utility Operation and File Access Modes............29 Concurrent DDL/Utility and DML Operations................30 Concurrent DML and DDL Operations ..................30 Operations Effect on Table Timestamps ..................31 Precedence of Data Types During Suitable Key Searches.............80 Maximum Row Sizes Available.....................87 EXPLAIN Statement Options......................124 Plan Summary Information......................126 Node Listing Information ......................127 Cost Factors of DETAIL_COST column..................131...
  • Page 19: About This Document

    This manual describes reference information about the syntax of SQL statements, functions, and other SQL language elements supported by the Neoview database software. The Neoview SQL statements and utilities are entered interactively or from script files using one of these client-based utilities: •...
  • Page 20: Notation Conventions

    313), describes clauses used by Neoview SQL statements. • Chapter 6: “SQL Functions and Expressions” (page 337), describes specific functions and expressions that you can use in Neoview SQL statements. • Chapter 7: “OLAP Functions” (page 491), describes specific on line analytical processing functions.
  • Page 21 A group of items enclosed in brackets is a list from which you can choose one item or none. The items in the list can be arranged either vertically, with aligned brackets on each side of the list, or horizontally, enclosed in a pair of brackets and separated by vertical lines. For example: DROP SCHEMA schema [CASCADE] [RESTRICT]...
  • Page 22: Related Documentation

    — README for the HP Neoview Transporter Java Client • Management HP Database Manager (HPDM) Help topics that describe how to use the HP Database Manager client to monitor Online Help and manage a Neoview data warehousing platform. HP Database Manager (HPDM)
  • Page 23 Neoview Repository User Guide Information about using the Repository, including descriptions of Repository views and guidelines for writing Neoview SQL queries against the views. Neoview Workload Management Information about using Neoview Workload Management Services (WMS) to Services Guide manage workload and resources on a Neoview data warehousing platform.
  • Page 24: Publishing History

    HP Neoview Release 2.5 July 2010 HP Encourages Your Comments HP encourages your comments concerning this document. We are committed to providing documentation that meets your needs. Send any errors found or suggestions for improvement to docsfeedback@hp.com. Include the document title and part number, shown below: Document Title: Neoview SQL Reference Manual Part Number: 611360–001...
  • Page 25: Introduction

    1 Introduction The Neoview SQL database software allows you to use SQL statements, which comply closely to ANSI SQL:1999, to access SQL databases. This introduction describes: • “SQL Language” • “Security” • “Data Consistency and Access Options” • “Database Integrity and Locking”...
  • Page 26: Read Uncommitted

    To protect the integrity of the database, Neoview SQL provides locks on data. For example, Neoview SQL locks a row when an executing process accesses a row to modify it. The lock ensures that no other process simultaneously modifies the same row.
  • Page 27: Lock Duration

    READ COMMITTED or SERIALIZABLE access. Lock mode is sometimes determined by Neoview SQL. SQL ensures that an exclusive lock is in effect for write operations and usually acquires a shared lock for operations that access data without modifying it.
  • Page 28: Statement Atomicity

    • The AUTOCOMMIT option must be set to ON. If these conditions are not met, the transaction is aborted by Neoview SQL if a failure occurs. This behavior occurs for all INSERT, UPDATE, or DELETE statements in Neoview SQL. User-Defined and System-Defined Transactions User-Defined Transactions Transactions you define are called user-defined transactions.
  • Page 29: Rules For Dml Statements

    AUTOCOMMIT is an option that can be set in a SET TRANSACTION statement. It specifies whether Neoview SQL will commit automatically, or roll back if an error occurs, at the end of statement execution. This option applies to any statement for which the system initiates a transaction.
  • Page 30: Concurrent Ddl/Utility And Dml Operations

    Table 1-2 Concurrent DDL/Utility and DML Operations DML Operation in Progress DDL Operations You SELECT SELECT SHARE SELECT EXCLUSIVE UPDATE/ INSERT/ Can Start UNCOMMITTED DELETE ALTER TABLE Allowed Allowed Allowed Allowed attributes ALTER TABLE other Allowed Waits Waits Waits CREATE INDEX with Allowed Allowed Waits...
  • Page 31: Transaction Access Modes

    Table 1-3 Concurrent DML and DDL Operations (continued) DML Operations You Can Start DDL Operations in SELECT SELECT SHARE SELECT EXCLUSIVE UPDATE/ INSERT Progress UNCOMMITTED DELETE REVOKE Allowed Allowed Waits Waits UPDATE Allowed Allowed Allowed Allowed STATISTICS DDL operation aborts the DML operation. Allowed except during commit phase.
  • Page 32: Transaction Isolation Levels

    “READ COMMITTED”, “SERIALIZABLE or REPEATABLE READ ”. The Neoview SQL implementation for REPEATABLE READ and SERIALIZABLE is equivalent. You can set the isolation level of a transaction explicitly by using a SET TRANSACTION statement. See SET TRANSACTION Statement. The default isolation level is READ COMMITTED.
  • Page 33: Transaction Rollback Mode

    For these situations, Neoview SQL raises an error during compilation. When rollback mode is set to OFF, Neoview SQL sets the auto abort interval for the transaction to 0, indicating that this transaction should never abort for exceeding a predefined time interval.
  • Page 34: Statements That Are Neoview Sql Extensions

    LOCK TABLE statement • REVOKE SCHEMA statement • SET TABLE TIMEOUT statement • UPDATE STATISTICS statement ANSI-Compliant Functions These functions are ANSI compliant, but some might contain Neoview SQL extensions: • AVG function • CASE expression • CAST expression •...
  • Page 35: Neoview Sql Error Messages

    Neoview SQL Error Messages Neoview SQL reports error messages and exception conditions. When an error condition occurs, Neoview SQL returns a message number and a brief description of the condition. For example, Neoview SQL might display this error message: *** ERROR[1000] A syntax error occurred.
  • Page 37: Sql Statements

    • “Stored Procedure Statements” Data Definition Language (DDL) Statements Use these DDL statements to define, delete, or modify the definition of a Neoview SQL schema, or object, or the authorization to use an object. “ALTER MATERIALIZED VIEW Statement” (page 40) Changes materialized views.
  • Page 38: Data Manipulation Language (Dml) Statements

    Resource Control and Optimization Statements Use these statements to control access to a Neoview SQL table and its indexes on remote segments: “EXECUTE Statement” (page 121) Executes and SQL statement previously compiled by a PREPARE statement.
  • Page 39: Control Statements

    “PREPARE Statement” (page 154) Compiles an SQL statement for later use with the EXECUTE statement. “UPDATE STATISTICS Statement” (page 204) Updates statistics about the contents of a table and its indexes. Control Statements Use these statements to control the execution default options, plans, and performance of DML statements: “SET TABLE TIMEOUT Statement”...
  • Page 40: Alter Materialized View Statement

    ALTER MATERIALIZED VIEW Statement • “Syntax Description of ALTER MATERIALIZED VIEW” • “Considerations for ALTER MATERIALIZED VIEW” • “Example of ALTER MATERIALIZED VIEW” The ALTER MATERIALIZED VIEW statement changes a materialized view. ALTER {MATERIALIZED VIEW | MV} name mv-alter-action mv-alter-action is: MVATTRIBUTES[S] mv-attribute | {ADD | REMOVE} IGNORE CHANGES ON simple-table [,simple-table]...
  • Page 41: Example Of Alter Materialized View

    rows in the materialized view, an error will occur that indicates a REFRESH needs to be performed before altering the materialized view to add IGNORE CHANGES on the base table. Only a base table that is in the FROM clause of the query expression of the materialized view can be added to the IGNORE CHANGES list.
  • Page 42: Alter Mvgroup Statement

    ALTER MVGROUP Statement • “Syntax Description of ALTER MVGROUP” • “Considerations for ALTER MVGROUP” • “Examples of ALTER MVGROUP” The ALTER MVGROUP statement allows you to add or remove a member from the materialized view group (MVGROUP). The ADD clause should be used when adding one or more MVs to the MVGROUP.
  • Page 43: Alter Synonym Statement

    Syntax Description of ALTER SYNONYM alternate-name specifies the name of the synonym. See “Database Object Names” (page 242). object specifies the name of a Neoview SQL table, view, or materialized view. See “Database Object Names” (page 242). Considerations for ALTER SYNONYM •...
  • Page 44: Alter Table Statement

    • “Syntax Description of ALTER TABLE” • “Considerations for ALTER TABLE” • “Example of ALTER TABLE” The ALTER TABLE statement changes a Neoview SQL table. See “Database Object Names” (page 242). ALTER TABLE name alter-action ATTRIBUTE {NO INSERTLOG | INSERTLOG}...
  • Page 45: Syntax Description Of Alter Table

    SQL identifier. column-name must be unique among column names in the table. If the column name is a Neoview SQL reserved word, you must delimit it by enclosing it in double quotes. For example: "sql".myview. See “Identifiers”...
  • Page 46 (page 242). If you do not specify a constraint name, Neoview SQL constructs an SQL identifier as the name for the constraint in the schema for table. The identifier consists of the fully qualified table name concatenated with a system-generated unique identifier. For example, a constraint on table A.B.C might be assigned a name such as A.B.C_123..._01...
  • Page 47 “Database Object Names” (page 242). If you do not specify a constraint name, Neoview SQL constructs an SQL identifier as the name for the constraint in the schema for table. The identifier consists of the fully qualified table name concatenated with a system-generated unique identifier. For example, a constraint on table A.B.C might be assigned a name such as A.B.C_123..._01...
  • Page 48: Considerations For Alter Table

    new-name specifies the new name of the object after the RENAME TO operation occurs. CASCADE specifies that indexes and constraints on the renamed object will be renamed. sequence-generator options: INCREMENT BY signed-numeric-literal increments the current value to obtain the next value. Default is 1 (one). The INCREMENT BY value cannot be greater than the maximum value of the data type of the IDENTITY column.
  • Page 49: Recalibrating An Identity Column

    This allows for more available values in the cycle range for the internal sequence generator. Inserts will be successful until the new maxvalue is reached. NO MAXVALUE is not allowed. If you use NO MAXVALUE on the ALTER TABLE ALTER COLUMN specification, an error will be raised: >>alter table T115T002 alter column surrogate_key set NO MAXVALUE;...
  • Page 50 Recalibrate an IDENTITY Column Based on the INCREMENT BY Value This method always performs a SELECT on the base table containing the IDENTITY column to obtain the current maximum value of the IDENTITY column. This maximum value will be incremented using the value of the INCREMENT BY internal sequence generator option. It will be checked against the current numbering scheme of the INCREMENT BY option.
  • Page 51: Example Of Alter Table Alter Column

    • If the default specification type is GENERATED BY DEFAULT AS IDENTITY, a number less than the current maximum value of the IDENTITY column is allowed. • The user-specified recalibration value must not be less than the START WITH and MINVALUE options of the internal sequence generator.
  • Page 52: Example Of Alter Table

    insert into T1 values(default,3); --- 1 row(s) inserted. select * from T1; SURROGATE_KEY -------------------------------- ---- Example of ALTER TABLE • This example adds a column: ALTER TABLE persnl.project ADD COLUMN projlead NUMERIC (4) UNSIGNED SQL Statements...
  • Page 53: Alter Trigger Statement

    ALTER TRIGGER Statement • “Syntax Description of ALTER TRIGGER” • “Considerations for ALTER TRIGGER” • “Examples of ALTER TRIGGER” The ALTER TRIGGER statement is used to enable or disable triggers, individually or by SQL tables. ALTER TRIGGER { ENABLE trigger-name | ENABLE ALL OF table-name | DISABLE trigger-name | DISABLE ALL OF table-name}...
  • Page 54: Alter View Statement

    ALTER VIEW Statement • “Syntax Description of ALTER VIEW” • “Considerations for ALTER VIEW” • “Example of ALTER VIEW” The ALTER VIEW statement renames an object within the same schema. See “Database Object Names” (page 242). ALTER VIEW name alter-action alter-action is: RENAME TO new name Syntax Description of ALTER VIEW...
  • Page 55: Begin Work Statement

    “Transaction Management” (page 27). BEGIN WORK will raise an error if a transaction is currently active. BEGIN WORK is a Neoview SQL extension. BEGIN WORK Considerations for BEGIN WORK BEGIN WORK starts a transaction. COMMIT WORK or ROLLBACK WORK ends a transaction.
  • Page 56: Call Statement

    “Identifiers” (page 269) “Database Object Names” (page 242). If you do not fully qualify the procedure name, Neoview SQL qualifies it according to the schema of the current session. argument-list accepts arguments for IN, INOUT, or OUT parameters. The arguments consist of SQL expressions, including dynamic parameters, separated by commas: SQL-expression[{, SQL-expression}...]...
  • Page 57: Examples Of Call

    Neoview Guide to Stored Procedures in Java. Data Conversion of Parameter Arguments Neoview SQL performs an implicit data conversion when the data type of a parameter argument is compatible with but does not match the formal data type of the stored procedure. For stored procedure input values, the conversion is from the actual argument value to the formal parameter type.
  • Page 58 ORDERNUM NUM_PARTS AMOUNT ORDER_DATE LAST_NAME ---------- -------------- --------------- ---------- ------------------ 100210 19020.00 2006-04-10 HUGHES 100250 22625.00 2006-01-23 HUGHES 101220 45525.00 2006-07-21 SCHNABL 200300 52000.00 2006-02-06 SCHAEFFER 200320 9195.00 2006-02-17 KARAJAN 200490 1065.00 2006-03-19 WEIGL --- 13 row(s) selected. ORDERNUM PARTNUM UNIT_PRICE QTY_ORDERED PARTDESC ----------...
  • Page 59: Commit Work Statement

    COMMIT WORK Statement • “Considerations for COMMIT WORK” • “Example of COMMIT WORK” The COMMIT WORK statement commits any changes to objects made during the current transaction, releases all locks on objects held by the transaction, and ends the transaction. See “Transaction Management”...
  • Page 60: Create Index Statement

    • “Example of CREATE INDEX” The CREATE INDEX statement creates a Neoview SQL index based on one or more columns of a table. The CREATE VOLATILE INDEX statement creates a Neoview SQL index with a lifespan that is limited to the SQL session that the index is created. Volatile indexes are dropped automatically when the session ends.
  • Page 61: Considerations For Create Index

    Authorization and Availability Requirements An index always has the same security as the table it indexes, so roles authorized to access the table can also access the index. To create a Neoview SQL index, you must have one of the following privileges: •...
  • Page 62: Example Of Create Index

    occurs. If you want to access the data while populating the index, use the POPULATE INDEX utility. You cannot access an index directly. Limits on Indexes For nonunique indexes, the sum of the lengths of the columns in the index plus the sum of the length of the clustering key of the underlying table cannot exceed 2048 bytes.
  • Page 63: Create Materialized View Statement

    CREATE MATERIALIZED VIEW Statement • “Syntax Description of CREATE MATERIALIZED VIEW” • “Considerations for CREATE MATERIALIZED VIEW” • “Examples of CREATE MATERIALIZED VIEW” The CREATE MATERIALIZED VIEW statement creates a materialized view. See “Materialized Views” (page 281). CREATE {MATERIALIZED VIEW | MV} mv-name [column-name-list] { RECOMPUTE | REFRESH refresh-type } { INITIALIZE ON REFRESH | INITIALIZE ON CREATE }...
  • Page 64 refresh-type specifies the method that will be used to update the materialized view. ON REQUEST specifies that the materialized view has to be explicitly refreshed through the MAINTAIN command. RECOMPUTE a materialized view that is initialized every time the materialized view needs to be updated with changes to its base tables.
  • Page 65: Considerations For Create Materialized View

    • ON REQUEST and ON STATEMENT materialized views cannot be created on views. Types of Materialized Views Neoview SQL defines the following three types of materialized views: • Materialized Join View (MJV): An ON STATEMENT or ON REQUEST materialized view holds the results of a join query with inner equi-joins of several tables.
  • Page 66 Secondary indexes created by the system for incremental REFRESH of materialized views might be expensive to maintain. Neoview SQL allows users to remove indexes that were created by the system and to create alternative indexes. If you remove system-added indexes and do not replace them with alternative indexes, the performance of the REFRESH operation may be greatly hurt.
  • Page 67: Examples Of Create Materialized View

    You can create additional secondary indexes, which cannot be unique. Joins • An inner equi-join query is a query where rows from each table are matched to specific rows in other tables using equal predicates. • Outer joins include LEFT OUTER JOIN or FULL OUTER JOIN. •...
  • Page 68 AS SELECT PUBSCH.DETAIL_TABLE.ORDERNUM, SUM(PUBSCH.DETAIL_TABLE.QUANTITY) AS TOTAL_AVAIL FROM PUBSCH.DETAIL_TABLE WHERE PUBSCH.DETAIL_TABLE.ORDERNUM > 1 GROUP BY PUBSCH.DETAIL_TABLE.ORDERNUM; • This is an example of an MJV: CREATE MATERIALIZED VIEW sales_store REFRESH ON REQUEST INITIALIZE ON REFRESH AS SELECT price, partkey, timekey, store.nam FROM sales, store WHERE sales.storekey = store.storekey;...
  • Page 69: Create Mvgroup Statement

    CREATE MVGROUP Statement • “Considerations for MVGROUP” • “Example of CREATE MVGROUP” The CREATE MVGROUP statement groups together materialized views that are defined on a common table to preserve database consistency. For information on MVGROUPS, see “MVGROUPs ” (page 282) “MAINTAIN MVGROUP”...
  • Page 70: Create Schema Statement

    Considerations for CREATE SCHEMA Reserved Schema Names Schema names that begin with HP_ are reserved for use by HP. Schema names that begin with DEFINITION_SCHEMA_VERSION_ and the schema named PUBLIC_ACCESS_SCHEMA are reserved for SQL. You cannot create schemas with these names.
  • Page 71: Create Synonym Statement

    Syntax Description of CREATE SYNONYM alternate-name specifies the name of the synonym. See “Database Object Names” (page 242). object specifies Neoview SQL tables, views, and materialized views can be specified. See “Database Object Names” (page 242). Considerations for CREATE SYNONYM •...
  • Page 72: Create Table Statement

    The CREATE TABLE statement creates a Neoview SQL table. The CREATE VOLATILE TABLE statement creates a Neoview SQL table in a SQL session. The CREATE TABLE AS statement creates a table based on the data attributes of a SELECT query and populates the table using the data returned by the SELECT query.
  • Page 73: Syntax Description Of Create Table

    default is: literal | NULL | CURRENT_DATE | CURRENT_TIME | CURRENT_TIMESTAMP table-constraint is: PRIMARY KEY (key-column-list) | CHECK (condition) | FOREIGN KEY (column-list) REFERENCES ref-spec NOT ENFORCED identity-column-specification is: identity-type [(internal-sequence-generator-options)] identity-type is: GENERATED BY DEFAULT AS IDENTITY | GENERATED ALWAYS AS IDENTITY internal-sequence-generator-options is: internal-sequence-generator-option ...
  • Page 74 The value set by this option is mainly used by Neoview SQL to calculate the primary extent size and the secondary extent size and maximum extents of the table, based on internal rules.
  • Page 75 SQL identifier. column must be unique among column names in the table. If the name is a Neoview SQL reserved word, you must delimit it by enclosing it in double quotes. Such delimited parts are case-sensitive. For example: "join".
  • Page 76 If you omit the schema portions of the name you specify in constraint-name, Neoview SQL expands the constraint name by using the schema for table. See “Database Object Names”...
  • Page 77 You can specify PRIMARY KEY only once on any CREATE TABLE statement. Neoview SQL uses the primary key as the clustering key of the table in order to avoid creating a separate, unique index to implement the primary key constraint.
  • Page 78: Considerations For Create Table

    “Examples of CREATE TABLE” (page 93). LIKE source-table [include-option]... directs Neoview SQL to create a table like the existing table, source-table, omitting constraints (with the exception of the NOT NULL and PRIMARY KEY constraints), and partitions unless include-option clauses are specified. source-table is the ANSI logical name for the existing table and must be unique among names of tables, views, and procedures within its schema.
  • Page 79: Considerations For Create Volatile Table

    PARTITION BY clauses on columns that contain null values. • Neoview SQL does not require that the first column in a volatile table contain not null values and be the primary key. Instead, Neoview SQL attempts to partition the table, if possible, using an appropriate suitable key column as the primary and partitioning key.
  • Page 80: Precedence Of Data Types During Suitable Key Searches

    How Neoview SQL Selects Suitable Keys for Volatile Tables Neoview SQL searches for the first suitable column in the list of columns of the table being created. Once the column is located, the table is partitioned on it. The searched columns in the table might be explicitly specified (as in a CREATE TABLE statement) or implicitly created (as in a CREATE TABLE AS SELECT statement).
  • Page 81: Considerations For Create Table Like

    --- 0 row(s) inserted. Examples for Selecting Suitable Keys for Volatile Tables These examples show the order by which Neoview SQL selects a suitable key based on the precedence rules described in “How Neoview SQL Selects Suitable Keys for Volatile Tables”...
  • Page 82 For tables with IDENTITY columns, the target table inherits the IDENTITY property of a column along with the corresponding sequence generating properties from the source table. Neither Neoview SQL's CREATE TABLE LIKE support nor its behavior with respect to the IDENTITY column is ANSI compliant.
  • Page 83 Create table t2 like table t1. The CREATE TABLE LIKE target table t2 will inherit the internal sequence generator properties from the source table t1. The AS SELECT syntax will select all rows from table t1 and insert them into table t2. The IDENTITY column values will be user-specified values.
  • Page 84: Considerations For Create Table As

    The CREATE TABLE LIKE target table t2 will inherit the internal sequence generator properties from the source table t1. The AS SELECT syntax will select all rows from table t1 and insert them into table t2. The IDENTITY column values will be user-specified values. CREATE TABLE t2 LIKE t1 AS SELECT a,b FROM t1;...
  • Page 85 The NO LOAD option in a CREATE TABLE AS statement creates a table with the CREATE TABLE AS statement, but does not load data into the table. The option is useful if you need to create a table to review its structure and to analyze the SELECT part of the CREATE TABLE AS statement with the EXPLAIN statement.
  • Page 86: Reserved Table Names

    IDENTITY column of table t2. To avoid this problem, HP recommends that you determine a START WITH value that is greater than the largest value of the IDENTITY column of the source table. For example: SELECT MAX(a) FROM t1;...
  • Page 87: Limits For Tables

    If this clause is not specified, Neoview SQL will decide how to allocate the space for the table.
  • Page 88: Generating Values For An Identity Column

    If you specify GENERATED BY DEFAULT AS IDENTITY, values for the IDENTITY column are generated by default. If you specify a value for the IDENTITY column, Neoview SQL uses that value and does not generate a unique value for that row.
  • Page 89 • CREATE TABLE AS with GENERATED BY DEFAULT AS IDENTITY column is supported. Inserting values for a GENERATED ALWAYS AS IDENTITY column is not allowed. • CREATE TABLE LIKE with an IDENTITY column is supported. The target table will have the same column and sequence generating attributes as the source table.
  • Page 90 This example shows the IDENTITY column surrogate_key as the partitioning key. NOTE: In Neoview SQL, the partitioning key must be a subset of the clustering key. In the case of a table with a single column clustering key, the partitioning key must be the same as the clustering key.
  • Page 91 • This example shows that the values for the IDENTITY column Id_col will always be generated by the system. The following sequence generator options will take default values because they are not specified: MINVALUE, MAXVALUE, and NO CYCLE. CREATE TABLE tbl1 ( Id_col INTEGER UNSIGNED GENERATED ALWAYS AS IDENTITY START WITH 1 INCREMENT BY 2) NOT NULL,...
  • Page 92: Neoview Sql Extensions To Create Table

    Neoview SQL Extensions to CREATE TABLE This statement is supported for compliance with ANSI SQL:1999 Entry Level. Neoview SQL extensions to the CREATE TABLE statement are ASCENDING, DESCENDING, PARTITION, MAXTABLESIZE, ATTRIBUTE, and DISK POOL clauses. CREATE TABLE LIKE is also an extension.
  • Page 93: Examples Of Create Table

    Examples of CREATE TABLE • This example creates a table. The clustering key is the primary key. CREATE TABLE SALES.ODETAIL ( ordernum NUMERIC (6) UNSIGNED NO DEFAULT NOT NULL, partnum NUMERIC (4) UNSIGNED NO DEFAULT NOT NULL, unit_price NUMERIC (8,2) NO DEFAULT NOT NULL, qty_ordered...
  • Page 94: Examples Of Create Set Table

    • The row is returned in this example. Both sides are case sensitive. SELECT * FROM T WHERE a = 'A' (not casespecific); • A row is not returned in this example. A case sensitive comparison is done since column ‘b’ is case sensitive.
  • Page 95 Table t has 2 columns named (a,b) and the same data attributes as columns from table t1. • If the select list item is an expression, it must be renamed with an AS clause. An error is returned if expressions are not named. For example: create table no partition t as select a+1 as c from t1 Table t has 1 column named (c) and data attribute of (a+1) create table t no partition as select a+1 from t1...
  • Page 96: Create Trigger Statement

    CREATE TRIGGER Statement • “Syntax Description of CREATE TRIGGER” • “Considerations for CREATE TRIGGER” • “Examples of CREATE TRIGGER” The CREATE TRIGGER statement is used to create triggers on SQL tables. A trigger is a mechanism that sets up the database system to perform certain actions automatically in response to the occurrence of specified events.
  • Page 97: Considerations For Create Trigger

    old-new-alias is the list of correlation name of table aliases used by a trigger. correlation-name is the name of the old or new row acted upon by the trigger. table-alias is the name of the old or new table acted upon by the trigger. search-condition is the condition that, when true, activates this trigger.
  • Page 98 Trigger Types You can configure triggers as BEFORE or AFTER types. When a triggering statement occurs, this is the order of execution: BEFORE triggered statements Triggering statement AFTER triggered statements Execution of a statement is considered to be complete only when all cascaded triggers are complete.
  • Page 99 triggers are used to condition input data, while AFTER-type triggers encode actual application logic. Restrictions on Triggers • The trigger feature does not allow the use of: — Positioned deletes and updates as triggered statements. — Subqueries in search-condition for AFTER triggers (but they are allowed in search-condition for BEFORE triggers.) •...
  • Page 100: Examples Of Create Trigger

    As a workaround for this issue, change column c1 of table t1 from varchar(2040) to char(2000). The primary key length is now 2000 bytes, and the CREATE TRIGGER statement completes successfully. Examples of CREATE TRIGGER Before and After Triggers Suppose that you have a database to record patients’ vital signs and drugs prescribed for them. The database consists of these tables: •...
  • Page 101 ((SELECT sequence + 1 from prescription_seq), (SELECT pat_id FROM record WHERE sample.id = record.vital_id), (SELECT phys_id FROM record WHERE sample.id = record.vital_id), (SELECT record.id FROM record WHERE sample.id = record.vital_id), CURRENT_DATE, 'POUND OFF', '200 mg', '1 pill 1 hour before each meal', 0, 'Free sample no refills' CREATE TRIGGER Statement...
  • Page 102: Create View Statement

    • “Syntax Description of CREATE VIEW” • “Considerations for CREATE VIEW” • “Examples of CREATE VIEW” The CREATE VIEW statement creates a Neoview SQL view. See “Views” (page 312). CREATE VIEW view [(column-name ] [,column-name ...)] AS query-expr [order-by-clause] [WITH [CASCADED] CHECK OPTION]...
  • Page 103: Considerations For Create View

    Considerations for CREATE VIEW • You can specify GROUP BY using ordinals to refer to the relative position within the SELECT list. For example, GROUP BY 3, 2, 1. • Dynamic parameters are not allowed. Reserved View Names View names prefixed by the name of a user metadata table are reserved. You cannot create views with such names.
  • Page 104 The SELECT statement reads rows in table t in READ UNCOMMITTED access. The same behavior would occur with this SELECT statement: Select * from t for read uncommitted access; Multiple Tables in a View Create view v as select * from t1, t2 for serializable access; Select * from v;...
  • Page 105: Examples Of Create View

    Create view v as select a from t order by a; Select * from v x, v y; Or this INSERT statement: Insert into t1 select * from v; In these two examples, the ORDER BY clause is ignored during DML processing because the first appears as part of a derived table and the second as a subquery selects, both created after the view expansion.
  • Page 106 Suppose tables A and B denote generic tables. To check if the rule “every row from this child will match one and only one row from the other child” is true, Neoview SQL uses the fact that the join of Table A with table or subquery B preserves all the rows of A if the join predicate...
  • Page 107 select a, c from vp; -- reads vp0 and vp1 select d from vp; -- reads vp0 and vp2 CREATE VIEW Statement...
  • Page 108: Delete Statement

    Deleting rows from a view deletes the rows from the table on which the view is based. DELETE does not remove a table or view, even if you delete the last row in the table or view. Neoview SQL provides searched DELETE—deletes rows whose selection depends on a search condition.
  • Page 109 The data type of expression must be compatible with the data type of column-name. If expression refers to columns being updated, Neoview SQL uses the original values to evaluate the expression and determine the new value.
  • Page 110: Considerations For Delete

    SERIALIZABLE | REPEATABLE READ specifies that the DELETE statement and any concurrent process (accessing the same data) execute as if the statement and the other process had run serially rather than concurrently. SKIP CONFLICT enables transactions to skip rows locked in a conflicting mode by another transaction. The rows under consideration are the result of evaluating the search condition for the DELETE statement.
  • Page 111: Examples Of Delete

    DELETE WITH MULTI COMMIT FROM sales.orders WHERE salesrep = 220 AND custnum <> 1234; SET ON ROLLBACK Considerations The SET ON ROLLBACK expression is evaluated when each row is processed during execution of the DELETE statement. The results of the evaluation are applied when and if the transaction is rolled back.
  • Page 112 delete from table1 where a in (select a from table1 where b > 200) SQL Statements...
  • Page 113: Drop Index Statement

    “Syntax Description of DROP INDEX” • “Considerations for DROP INDEX” • “Example of DROP INDEX” The DROP INDEX statement drops a Neoview SQL index. See “Database Object Names” (page 242). DROP INDEX is a Neoview SQL extension. DROP [VOLATILE] INDEX index...
  • Page 114: Drop Materialized View Statement

    DROP MATERIALIZED VIEW Statement • “Syntax Description of DROP MATERIALIZED VIEW” • “Example of DROP MATERIALIZED VIEW” The DROP MATERIALIZED VIEW statement drops a materialized view. You cannot drop a materialized view that is used by other materialized views or by regular views unless the CASCADE option is used.
  • Page 115: Drop Mvgroup Statement

    DROP MVGROUP Statement • “Syntax Description of DROP MVGROUP” • “Considerations for DROP MVGROUP” • “Example of DROP MVGROUP” The DROP MVGROUP statement allows you to drop materialized view groups. For information on MVGROUPS, see “MVGROUPs ” (page 282). DROP MVGROUP mv-group-name Syntax Description of DROP MVGROUP mv-group-name specifies the materialized view group name to drop.
  • Page 116: Drop Schema Statement

    • “Syntax Description of DROP SCHEMA” • “Considerations for DROP SCHEMA” • “Example of DROP SCHEMA” The DROP SCHEMA statement deletes a Neoview SQL schema. See“Schemas” (page 304). DROP SCHEMA schema [RESTRICT|CASCADE] Syntax Description of DROP SCHEMA schema is the name of the schema to delete.
  • Page 117: Drop Synonym Statement

    DROP SYNONYM Statement • “Syntax Description of DROP SYNONYM ” • “Considerations for DROP SYNONYM” • “Example of DROP SYNONYM” The DROP SYNONYM statement allows you to drop synonyms for tables, views, or materialized views that can be used in queries. See “Synonyms”...
  • Page 118: Drop Table Statement

    “Syntax Description of DROP TABLE” • “Considerations for DROP TABLE” • “Examples of DROP TABLE” The DROP TABLE statement deletes a Neoview SQL table and its dependent objects such as indexes and constraints. See “Database Object Names” (page 242). DROP [VOLATILE] TABLE table [RESTRICT|CASCADE]...
  • Page 119: Drop Trigger Statement

    DROP TRIGGER Statement • “Syntax Description of DROP TRIGGER” • “Considerations for DROP TRIGGER” • “Example of DROP TRIGGER” The DROP TRIGGER statement is used to drop a trigger on an SQL table. See “Triggers” (page 311). DROP TRIGGER trigger-name Syntax Description of DROP TRIGGER trigger-name specifies the name of the trigger to be dropped.
  • Page 120: Drop View Statement

    • “Syntax Description of DROP VIEW” • “Considerations for DROP VIEW” • “Example of DROP VIEW” The DROP VIEW statement deletes a Neoview SQL view. See “Views” (page 312). DROP VIEW view [RESTRICT|CASCADE] Syntax Description of DROP VIEW view is the name of the view to delete.
  • Page 121: Execute Statement

    If there are fewer parameter values in the USING clause than there are unnamed parameters in the PREPARE statement, Neoview SQL returns an error. If there are more parameter values in the USING clause than there are unnamed parameters in the PREPARE statement, Neoview SQL issues warning 15019.
  • Page 122: Considerations For Execute

    Considerations for EXECUTE Scope of EXECUTE A statement must be compiled by PREPARE before you EXECUTE it, but after it is compiled, you can execute the statement multiple times without recompiling it. The statement must have been compiled during the same Neoview Command Interface session as its execution. Examples of EXECUTE •...
  • Page 123 --- 1 row(s) selected. SQL>execute findemp using 20000.00, 300; EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY ------ --------------- -------------- ------- ------- -------- 75 TIM WALKER 3000 300 32000.00 89 PETER SMITH 3300 300 37000.40 --- 13 row(s) selected. • Use SET PARAM to assign a value to a parameter name and specify both the parameter name and a literal value in the EXECUTE USING clause: SQL>prepare findemp from +>select * from persnl.employee...
  • Page 124: Explain Statement

    EXPLAIN Statement The EXPLAIN statement helps you to review query execution plans. You can use the EXPLAIN statement anywhere you can execute other Neoview database statements (for example, SELECT). For information about the Neoview Command Interface (NCI), see the Neoview Command Interface (NCI) Guide.
  • Page 125: Considerations For Explain

    Obtaining EXPLAIN Plans While Queries Are Running Neoview SQL provides the ability to capture an EXPLAIN plan for a query at any time while the query is running with the FOR QID option. By default, this behavior is disabled for a Neoview session.
  • Page 126: Plan Summary Information

    OPERATOR The operator type Query optimizations that were applied DESCRIPTION Additional information about the operator CARD Estimated number of rows returned by the plan. CARDINALITY and ROWS_OUT are the same. This example uses OPTIONS 'f ': >>explain options 'f' select * from region; OPERATOR DESCRIPTION CARD...
  • Page 127: Node Listing Information

    Table 2-5 Node Listing Information Field Description Operator name Current operator type, such as FILE_SCAN, HASH_JOIN, NESTED_JOIN, and so on. SEQ_NO Sequence number of the current operator in the query execution plan; indicates the sequence in which the query plan is generated. Children information Sequence number of the operator’s children (operators that feed data up to this operator).
  • Page 128 PARTITION_ACCESS ========================== SEQ_NO 2 ONLY CHILD 1 REQUESTS_IN ....(not found) ROWS_OUT ....100 EST_OPER_COST .... 0.01 EST_TOTAL_COST ... 0.01 DESCRIPTION max_card_est ..100 fragment_id .... 2 parent_frag .... 0 fragment_type ..dp2 buffer_size ..31,000 record_length ..306 space_usage .... 5:32:100:144 bottom_node_map ..
  • Page 129 ------------------------------------------------------------------ PLAN SUMMARY MODULE_NAME ....DYNAMICALLY COMPILED STATEMENT_NAME ... NOT NAMED PLAN_ID ....212141478299499838 ROWS_OUT ....100 EST_TOTAL_COST ... 0.01 STATEMENT ....select * from region; ------------------------------------------------------------------ NODE LISTING ROOT ====================================== SEQ_NO 3 ONLY CHILD 2 REQUESTS_IN ....(not found) ROWS_OUT ....
  • Page 130 key_columns .... R_KEY begin_key ....(R_KEY = <min> end_key ....(R_KEY = <max> ---SQL operation complete. Machine-Readable [OPTIONS 'm'] Considerations The machine-readable format also displays all of the plan data, but in a format easy to process by programs, one line per operator. This option provides the same output as the EXPLAIN function, but uses a different command to obtain the output.
  • Page 131: Cost Factors Of Detail_Cost Column

    Column Name Data Type Description DETAIL_COST VARCHAR (200) Cost vector of five items, which are described in detail in the next table. DESCRIPTION VARCHAR (3000) Additional information about the operator. For a detailed look at all operators, see the Neoview Query Guide.
  • Page 132: Example Of Explain Statement Using Odbc

    Example of EXPLAIN Statement Using ODBC Suppose an application prepares a SELECT statement: “SELECT * FROM ODBC_PERSNL.EMPLOYEE”. Use SQLGetCursorName to find the statement name. In this example, the returned statement name is "SQL_CUR_21". To get the plan for “SELECT * FROM ODBC_PERSNL.EMPLOYEE”, the application must allocate another statement handle and issue SQLExecDirect on “EXPLAIN options ‘f’...
  • Page 133 for (int i = 0; i < 10; i++) switch (i) case 0: System.out.println(""); stmt = connection.createStatement(); rs = stmt.executeQuery(sqlText); System.out.println(sqlText); break; default: rs = null; continue; ResultSetMetaData rsMD = rs.getMetaData(); System.out.println(""); for (int j = 1; j <= rsMD.getColumnCount(); j++) System.out.println(rsMD.getColumnName(j));...
  • Page 134: Get Service Statement

    GET SERVICE Statement • “Syntax Description of GET SERVICE” • “Considerations for GET SERVICE” • “Examples of GET SERVICE” The GET SERVICE statement returns the WMS service that is in effect for queries in the current session and provides some information about the service and the client session. Neoview Workload Management Services (WMS) manages queries associated with a service according to the priority, threshold limits, and rules of the service.
  • Page 135 SQL> By default, the query plan and SQL text are turned off (represented by 0 in the output) for HP_DEFAULT_SERVICE, and there is no connection rule in effect. This GET SERVICE statement shows that SALESQUERIES is the current service for the NCI session: SQL>get service;...
  • Page 136: Grant Statement

    “Considerations for GRANT” • “Examples of GRANT” The GRANT statement grants access privileges for a Neoview SQL table, view, or materialized view to specified roles or through a synonym of a table, view, or materialized view. See “Privileges” (page 301).
  • Page 137: Considerations For Grant

    grantee is authid authid specifies an authorization ID to whom you grant privileges. Authorization IDs identify roles during the processing of SQL statements. The authorization ID must be a valid role name enclosed in double quotes. authid is not case-sensitive. GRANT allows two special authorization IDs called PUBLIC and SYSTEM.
  • Page 138: Grant Execute Statement

    GRANT EXECUTE Statement • “Syntax Description of GRANT EXECUTE” • “Considerations for GRANT EXECUTE” • “Examples of GRANT EXECUTE” The GRANT EXECUTE statement grants privileges for executing a stored procedure in Java (SPJ) to one or more specified roles. See “Privileges”...
  • Page 139: Examples Of Grant Execute

    Examples of GRANT EXECUTE • The SPJ owner (or creator) grants the EXECUTE and WITH GRANT OPTION privileges on the ADJUSTSALARY procedure to the role ROLE.HR: GRANT EXECUTE ON PROCEDURE persnl.adjustsalary TO "ROLE.HR" WITH GRANT OPTION; • The role ROLE.HR grants the EXECUTE privilege on the ADJUSTSALARY procedure to other roles: GRANT EXECUTE ON PROCEDURE persnl.adjustsalary...
  • Page 140: Grant Schema Statement

    GRANT SCHEMA Statement • “Syntax Description of GRANT SCHEMA” • “Considerations for GRANT SCHEMA” • “Examples of GRANT SCHEMA” The GRANT SCHEMA statement grants access privileges for a schema to specified roles. See “Privileges” (page 301). GRANT {privilege [,privilege]... | all [PRIVILEGES] } ON SCHEMA schema-name TO {grantee [,grantee ]...
  • Page 141 Can create stored procedures in the schema. NOTE: To upload and create stored procedures on the Neoview platform, use HPDM. For more information, see the Neoview Guide to Stored Procedures in Java and the HP Database Manager (HPDM) User Guide. CREATE_SYNONYM Can create synonyms in the schema and become the owner of the synonyms.
  • Page 142: Considerations For Grant Schema

    TO {grantee [,grantee]... } specifies one or more roles to whom you grant privileges. grantee is authid authid specifies an authorization ID to whom you grant privileges. Authorization IDs identify roles during the processing of SQL statements. The authorization ID must be a valid role name enclosed in double quotes.
  • Page 143: Examples Of Grant Schema

    Examples of GRANT SCHEMA • This example grants SELECT and DELETE privileges on the sales schema to the two specified users: GRANT SELECT, DELETE ON SCHEMA sales TO "role.role1", "role.role2" WITH GRANT OPTION; GRANT SCHEMA Statement...
  • Page 144: Insert Statement

    INSERT Statement • “Syntax Description of INSERT” • “Considerations for INSERT” • “Examples of INSERT” The INSERT statement is a DML statement that inserts rows in a table or view. INSERT [NOMVLOG] [WITH NO ROLLBACK] INTO table [(target-col-list)] insert-source target-col-list is: colname [,colname]...
  • Page 145: Considerations For Insert

    188). Isolation Levels of Transactions and Access Options of Statements The isolation level of a Neoview SQL transaction defines the degree to which the operations on data within that transaction are affected by operations of concurrent transactions. When you specify access options for the DML statements within a transaction, you override the isolation level of the containing transaction.
  • Page 146: Examples Of Insert

    Inserting Date and Time Values Date, time, and timestamp are the three Neoview SQL datetime data types. A value with a datetime data type is compatible with another value with a datetime data type only if the values have the same datetime fields.
  • Page 147 --- 1 row(s) inserted. Unlike the previous example, the insert source of this statement does not contain a value for the CREDIT column, which has a default value. As a result, this INSERT must include the column name list. This SELECT statement shows the default value 'C1' for CREDIT: SELECT * FROM sales.customer WHERE custnum = 1120;...
  • Page 148 Examples of Self-Referencing Inserts • This is an example of a self-referencing insert: insert into table1 select pk+?, b, c from table1 • This is an example of a self-referencing insert where the target of the insert, table1, is also used in a subquery of the insert-source: insert into table1 select a+16, b, c from table2 where table2.b not in...
  • Page 149: Lock Table Statement

    Effect of AUTOCOMMIT Option At the start of a session, the AUTOCOMMIT option is ON by default. When this option is ON, Neoview SQL automatically commits any changes, or rolls back any changes, made to the database LOCK TABLE Statement...
  • Page 150: Examples Of Lock Table

    When you issue a LOCK TABLE statement without turning off AUTOCOMMIT, Neoview SQL locks the table temporarily, commits the transaction at the end of the LOCK TABLE statement and releases the locks. If you use LOCK TABLE, turn off AUTOCOMMIT by using the SET TRANSACTION statement.
  • Page 151: Merge Into Statement

    MERGE INTO Statement • “Syntax Description of MERGE INTO” • “Considerations for MERGE INTO” • “Example of MERGE INTO” The MERGE INTO statement:. • Updates a table if the row exists and inserts into a table if the row does not exist. This is upsert functionality.
  • Page 152 This example updates column b if a is found. If a is not found, nothing is done. MERGE INTO t ON a = 10 WHEN MATCHED THEN UPDATE SET b = 20 This example inserts values if a is not found. If a is found, nothing is done. MERGE INTO t ON a = 10 WHEN NOT MATCHED THEN INSERT VALUES (10, 30) Restrictions...
  • Page 153: Example Of Merge Into

    Example of MERGE INTO This query extracts derived columns 'a' and 'b' from the USING query as derived table 'z' and use each row to join to the merged table 't' based on the ON clause. For each matched row, column 'b' in table 't' is updated using column 'b' in derived table 'z'.
  • Page 154: Prepare Statement

    PREPARE Statement • “Syntax Description of PREPARE” • “Considerations for PREPARE” • “Examples of PREPARE” The PREPARE statement compiles an SQL statement for later use with the EXECUTE statement in a Neoview Command Interface (NCI) session. You can also use PREPARE to check the syntax of a statement without executing the statement in a Neoview Command Interface (NCI) session.
  • Page 155 32000.00 33000.50 40000.00 32000.00 45000.00 --- 5 row(s) selected. SQL> • Prepare a SELECT statement with a named parameter (?param-name) and later run EXECUTE on it: SQL>prepare findsal from +>select salary from persnl.employee +>where jobcode = ?job; --- SQL command prepared. SQL>set param ?job 450 SQL>execute findsal;...
  • Page 156: Revoke Statement

    “Considerations for REVOKE” • “Examples of REVOKE” The REVOKE statement revokes access privileges for a Neoview SQL table, view, or materialized view from specified roles or through a synonym of a table, view, or materialized view. See “Privileges” (page 301).
  • Page 157: Considerations For Revoke

    grantee is authid authid specifies an authorization ID to whom you revoke privileges. Authorization IDs identify roles during the processing of SQL statements. The authorization ID must be a valid role name enclosed in double quotes. authid is not case-sensitive. REVOKE allows two special authorization IDs called PUBLIC and SCHEMA: •...
  • Page 158: Revoke Execute Statement

    REVOKE EXECUTE Statement • “Syntax Description of REVOKE EXECUTE” • “Considerations for REVOKE EXECUTE” • “Examples of REVOKE EXECUTE” The REVOKE EXECUTE statement removes privileges for executing a stored procedure in Java (SPJ) from one or more specified roles. See “Privileges”...
  • Page 159: Considerations For Revoke Execute

    Considerations for REVOKE EXECUTE Authorization and Availability Requirements You can revoke the EXECUTE privilege from a role only if you have previously granted it to the role. If the privilege does not exist, the system returns a warning. To revoke privileges by using the CASCADE option, you must be the SPJ owner (that is, the schema owner or the creator of the stored procedure).
  • Page 160: Revoke Schema Statement

    “Syntax Description of REVOKE SCHEMA” • “Considerations for REVOKE SCHEMA” • “Examples of REVOKE SCHEMA” The REVOKE SCHEMA statement revokes access privileges for a Neoview SQL schema from specified roles. See “Privileges” (page 301). REVOKE [GRANT OPTION FOR] {privilege [,privilege ] ...| all [PRIVILEGES ]} ON SCHEMA schema-name FROM {grantee [,grantee]...} [drop-behavior]...
  • Page 161 privilege [,privilege]... | all [PRIVILEGES] specifies the privileges to revoke. You can specify each of these privileges for a schema. ALL_DDL Any table, view, materialized view, or procedure created in the schema after this privilege is granted will be able to perform any DDL privilege including CREATE, DROP, ALTER, and the REFRESH option of MAINTAIN.
  • Page 162: Considerations For Revoke Schema

    FROM {authid [,authid]} specifies one or more roles from whom you revoke privileges. grantee is authid authid specifies an authorization ID to whom you revoke privileges. Authorization IDs identify roles during the processing of SQL statements. The authorization ID must be a valid role name enclosed in double quotes.
  • Page 163: Rollback Work Statement

    ROLLBACK WORK Statement • “Syntax Description of REVOKE SCHEMA” • “Considerations for ROLLBACK WORK” • “Example of ROLLBACK WORK” The ROLLBACK WORK statement undoes all database modifications to objects made during the current transaction, releases all locks on objects held by the transaction, and ends the transaction.
  • Page 164: Select Statement

    SELECT Statement • “Syntax Description of SELECT” • “Considerations for SELECT” • “Considerations for Select List” • “Considerations for SEQUENCE BY” • “Considerations for GROUP BY” • “Considerations for ORDER BY” • “Considerations for UNION” • “Examples of SELECT” The SELECT statement is a DML statement that retrieves values from tables, views, and derived tables determined by the evaluation of query expressions, or joined tables.
  • Page 165 order-by-clause is: [ORDER BY {colname | colnum} [ASC[ENDING] | DESC[ENDING]] [,{colname | colnum} [ASC[ENDING] | DESC[ENDING]]]...] [access-clause] [mode-clause] access clause is: [FOR] access-option ACCESS access-option is: READ UNCOMMITTED | READ COMMITTED | SERIALIZABLE | REPEATABLE READ | SKIP CONFLICT mode-clause is: IN {SHARE | EXCLUSIVE} MODE select-list is: * | select-sublist [,select-sublist]...
  • Page 166: Syntax Description Of Select

    percent-size is: percent-result PERCENT [ROWS | {CLUSTERS OF number-blocks BLOCKS}] | BALANCE WHEN condition THEN percent-result PERCENT [ROWS] [WHEN condition THEN percent-result PERCENT [ROWS]]... [ELSE percent-result PERCENT [ROWS]] END rows-size is: number-rows ROWS | BALANCE WHEN condition THEN number-rows ROWS [WHEN condition THEN number-rows ROWS]...
  • Page 167 FROM table-ref [,table-ref]... specifies a list of tables, views, derived tables, or joined tables that determine the contents of an intermediate result table from which Neoview SQL returns the columns you specify in select-list. If you specify only one table-ref, the intermediate result table consists of rows derived from that table reference.
  • Page 168 (delete-statement [RETURN select-list]) [AS] corr [( col-expr-list)] enables an application to read and delete rows with a single operation. For the syntax of delete-statement, see the “DELETE Statement” (page 108). RETURN select-list specifies the columns or column expressions returned from the deleted row. The items in the select-list can be of these forms: [OLD.]* specifies the row from the old table exposed by the embedded delete.
  • Page 169 RIGHT, and FULL keywords. If you omit the optional OUTER keyword and use LEFT, RIGHT, or FULL in a join, Neoview SQL assumes the join is an outer join. If you specify a CROSS join as the join-type, you cannot specify a NATURAL join or a join-spec.
  • Page 170 FIRST rows-size [SORT BY colname [,colname]...] directs Neoview SQL to choose the first rows-size rows from the sorted result table. The sampling size is determined by using the specified number of rows.
  • Page 171 PERIODIC rows-size EVERY number-rows ROWS [SORT BY colname [,colname]...] directs Neoview SQL to choose the first rows from each block (period) of contiguous sorted rows. The sampling size is determined by using the specified number of rows chosen from each block.
  • Page 172 GROUP BY clause in the SELECT statement. To comply with ANSI standards, Neoview SQL does not move aggregate predicates from the WHERE clause to a HAVING clause and does not move non-aggregate predicates from the HAVING clause to the WHERE clause.
  • Page 173: Considerations For Select

    The select lists in the two SELECT statements of a union operation must have the same number of columns, and columns in corresponding positions within the lists must have compatible data types. The select lists must not be preceded by [ANY N] or [FIRST N]. The number of columns in the result table of the union operation is the same as the number of columns in each select list.
  • Page 174 Join Limits NOTE: HP recommends that you limit the number of tables in a join to a maximum of 64, which includes base tables of views referenced in joins. Queries with joins that involve a larger number of tables are not guaranteed to compile.
  • Page 175: Considerations For Select List

    • A union between embedded INSERT expressions is not supported. • Declaring a cursor on an embedded INSERT statement is not supported. DISTINCT Aggregate Functions An aggregate function can accept an argument specified as DISTINCT, which eliminates duplicate values before the aggregate function is applied. For a given grouping, multiple DISTINCT aggregates are allowed and can be used with non distinct aggregates.
  • Page 176: Considerations For Order By

    AGE is not a grouping column, you can refer to AGE only as the argument of a function, such as AVG (AGE). • The expression in the GROUP BY clause must be exactly the same as the expression in the select list.
  • Page 177 (The year-month fields are YEAR and MONTH. The day-time fields are DAY, HOUR, MINUTE, and SECOND.) For example, suppose that the column in TABLE1 has the data type INTERVAL HOUR TO MINUTE, and the column in TABLE2 has the data type INTERVAL DAY TO HOUR. The data type of the column resulting from the union operation is INTERVAL DAY TO MINUTE.
  • Page 178: Examples Of Select

    Use a table subquery to enclose the union, and apply the access mode to the main query. This statement receives a warning because Neoview SQL treats the access mode on the second SELECT as applicable only to that second SELECT:...
  • Page 179 1500 JONATHAN MITCHELL 32000.00 1500 JIMMY SCHNEIDER 26000.00 2500 MIRIAM KING 18000.00 1000 CRAMER 19000.00 . . . In this example, because of READ UNCOMMITTED access, the query does not wait for other concurrent processes to commit rows. • Display selected rows grouped by job code in ascending order: SELECT jobcode, AVG(salary) FROM persnl.employee WHERE jobcode >...
  • Page 180 Drop rows with unequal job codes. EMPLOYEE Table JOB Table EMPNUM ... JOBCODE ... SALARY JOBCODE JOBDESC 175500 MANAGER ....32000 SALESREP ..
  • Page 181 SECRETARY JOHN CHOU 28000.00 • Select from three tables, group the rows by job code and (within job code) by department number, and order the groups by the maximum salary of each group: SELECT E.jobcode, E.deptnum, MIN (salary), MAX (salary) FROM persnl.employee E, persnl.dept D, persnl.job J WHERE E.deptnum = D.deptnum AND E.jobcode = J.jobcode...
  • Page 182 SELECT * FROM job UNION SELECT * FROM job_corporate; JOBCODE JOBDESC ------- ------------------ MANAGER PRODUCTION SUPV ASSEMBLER SALESREP SYSTEM ANALYST ENGINEER PROGRAMMER ACCOUNTANT ADMINISTRATOR SECRETARY CORP MANAGER CORP SALESREP CORP SYSTEM ANALYS CORP ACCOUNTANT CORP ADMINISTRATOR CORP SECRETARY --- 16 row(s) selected. •...
  • Page 183 FROM sales.parts P, sales.odetail OD WHERE OD.partnum = P.partnum AND OD.ordernum IN (SELECT O.ordernum FROM sales.orders O WHERE custnum IN (SELECT custnum FROM sales.customer WHERE state = 'CALIFORNIA')) GROUP BY OD.ordernum; ORDERNUM (EXPR) ---------- --------------------- 200490 1030.00 300350 71025.00 300380 28560.00 --- 3 row(s) selected.
  • Page 184 select a from ( insert into identity_table values (DEFAULT,100,100), (DEFAULT,200,200) --------------- ------ ------ 216944652091640 216944652091641 • INSERT...SELECT statements are supported with embedded INSERT statements: insert into another_table values (300,300,300), (400,400,400), (500,500,500); select P.a, P.b, P.c from ( insert into identity_table select * from another_table where y <...
  • Page 185: Set Schema Statement

    SET SCHEMA Statement • “Syntax Description of SET SCHEMA” • “Consideration for SET SCHEMA” • “Examples of SET SCHEMA” The SET SCHEMA statement sets the default logical schema for unqualified object names for the current SQL session. SET SCHEMA default-schema-name Syntax Description of SET SCHEMA default-schema-name specifies the name of the schema.
  • Page 186: Set Table Timeout Statement

    Neoview SQL not to time out. A value of zero (0) directs Neoview SQL not to wait. If a table lock cannot be acquired or if a stream is empty, Neoview SQL immediately times out.
  • Page 187: Considerations For Set Table Timeout

    NOTE: Because of overhead processing by Neoview SQL after a timeout occurs on a locked table, the actual time is usually a few seconds longer than value. RESET removes the dynamic timeout value (if set) for the specified table, resetting the timeout value to the static values set during explicit Neoview SQL compilations.
  • Page 188: Set Transaction Statement

    SET TRANSACTION Statement • “Syntax Description of SET TRANSACTION” • “Considerations for SET TRANSACTION” • “Examples of SET TRANSACTION” The SET TRANSACTION statement sets attributes for transactions. It stays in effect until the end of the session or until the next SET TRANSACTION statement, whichever comes first. Therefore, the SET TRANSACTION statement can set the attributes of all subsequent transactions in the session.
  • Page 189 This option applies to any statement for which the system initiates a transaction. If this option is set to ON, Neoview SQL automatically commits any changes or rolls back any changes made to the database at the end of statement execution. AUTOCOMMIT is on by default at the start of a session.
  • Page 190: Considerations For Set Transaction

    The default setting is ON. If this option is set to OFF and Neoview SQL needs a transaction and one is not already running, an error is returned. The AUTOBEGIN option in a SET TRANSACTION can only be specified on one SET TRANSACTION command.
  • Page 191 Restrictions for the MULTI COMMIT option: • Not compatible with the READ UNCOMMITTED isolation level. • Not compatible with READ ONLY access mode. • Except for MULTI COMMIT, all of the SET TRANSACTION options are valid for the child transactions and not the logical parent transaction. •...
  • Page 192: Examples Of Set Transaction

    Effect on Utilities The SET TRANSACTION statement has no effect on the utility statements. The SET TRANSACTION statement does set attributes for transactions for UPDATE STATISTICS. Examples of SET TRANSACTION • Set the isolation level of a transaction that performs deletes, inserts, and updates: SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;...
  • Page 193: Showddl Statement

    SHOWDDL Statement • “Syntax Description of SHOWDDL” • “Considerations for SHOWDDL” • “Examples of SHOWDDL” The SHOWDDL statement describes details about objects in its display. SHOWDDL [TABLE] object-name} [, PRIVILEGES] object-name is: [schema-name.]object-name Syntax Description of SHOWDDL object-name specifies the ANSI name of a table, materialized view, or view. If object-name is not fully qualified, SHOWDDL uses the default schema for the session.
  • Page 194: Examples Of Showddl

    will be displayed as: GRANT SELECT ON TABLE sch.t1 TO "role_user1"; GRANT UPDATE ON TABLE sch.t1 TO "role_user1"; GRANT DELETE ON TABLE sch.t1 TO "role_user1"; GRANT INSERT ON TABLE sch.t1 TO "role_user1"; GRANT REFERENCES ON TABLE sch.t1 TO "role_user1"; GRANT SELECT ON TABLE sch.t1 TO "role_user2"; GRANT UPDATE ON TABLE sch.t1 TO "role_user21";...
  • Page 195 salary numeric (10,2) default 1000 hash partition by (empl_no) max table size 2000; create index empl_dept_no on empl (dept_no) hash partition by (dept_no); create mv empl_mv refresh on request initialize on refresh store by (dept_no) hash partition by (dept_no) as select max(salary) as salary, dept_no from empl group by dept_no;...
  • Page 196 -- showddl output -- Schema level privileges -- GRANT SELECT ON SCHEMA SCH TO “ROLE.READER”; CREATE TABLE SCH.DEPT DEPT_NO INT NO DEFAULT -- NOT NULL , DEPT_NAME VARCHAR(20) CHARACTER SET ISO88591 NO DEFAULT -- NOT NULL , CONSTRAINT SCH.DEPT_849937374_7746 PRIMARY KEY (DEPT_NO ASC) , CONSTRAINT SCH.DEPT_985137374_7746 CHECK (SCH.DEPT.DEPT_NO IS NOT NULL AND SCH.DEPT.DEPT_NAME IS NOT NULL) HASH PARTITION BY (DEPT_NO)
  • Page 197: Table Statement

    TABLE Statement • “Considerations for TABLE” • “Examples of TABLE” The TABLE statement is equivalent to the query specification SELECT * FROM table. TABLE table table names the user table or view. Considerations for TABLE Relationship to SELECT Statement The result of the TABLE statement is one form of a simple-table, which refers to the definition of a table reference within a SELECT statement.
  • Page 198: Update Statement

    UPDATE Statement • “Syntax Description of UPDATE” • “Considerations for UPDATE” • “Examples of UPDATE” The UPDATE statement is a DML statement that updates data in a row or rows in a table or updatable view. Updating rows in a view updates the rows in the table on which the view is based.
  • Page 199 The data type of expression must be compatible with the data type of column-name. If expression refers to columns being updated, Neoview SQL uses the original values to evaluate the expression and determine the new value.
  • Page 200: Considerations For Update

    ROLLBACK is encountered or an error occurs. Isolation Levels of Transactions and Access Options of Statements The isolation level of a Neoview SQL transaction defines the degree to which the operations on data within that transaction are affected by operations of concurrent transactions. When you...
  • Page 201 When an UPDATE completes successfully, Neoview SQL reports the number of times rows were updated during the operation. Under certain conditions, updating a table with indexes can cause Neoview SQL to update the same row more than once, causing the number of reported updates to be higher than the actual number of changed rows.
  • Page 202: Examples Of Update

    SET Clause Restrictions and Error Cases The SET clause has the following restrictions: • The number of columns on the left side of each assignment operator should match the number of values or SELECT list elements on the right side. The following examples are not allowed: UPDATE t SET (a,b)=(10,20,30) UPDATE t set (b,c)=(SELECT r,t,s FROM x)
  • Page 203 (SELECT deptnum FROM persnl.dept WHERE location = 'CHICAGO'); The subquery is evaluated for each row of the DEPT table and returns department numbers for departments located in Chicago. • Suppose that you want to change the employee number of a manager of a department. Because EMPNUM is a primary key of the EMPLOYEE table, you must delete the employee's record and insert a record with the new number.
  • Page 204: Update Statistics Statement

    UPDATE STATISTICS Statement NOTE: HP recommends that you update statistics by using the automated UPDATE STATISTICS stored procedures. The syntax for UPDATE STATISTICS is included here for reference. For information about automated UPDATE STATISTICS, see the Neoview Database Administrator's Guide.
  • Page 205: Syntax Description Of Update Statistics

    You must use the ON clause to generate statistics stored in histogram tables. If you omit it, physical statistics are generated for Neoview SQL tables, and SQL returns a warning message. See “Using Statistics”...
  • Page 206 1 percent of the rows in the table, with a maximum of 1 million rows. If you do not specify the SAMPLE clause, table has fewer rows than specified, or the sample size is greater than the system limit. Neoview SQL reads all rows from table. “SAMPLE Clause” (page 318).
  • Page 207: Considerations For Update Statistics

    (r > 0). RANDOM percent PERCENT directs Neoview SQL to choose rows randomly from the table. The value percent must be a value between zero and 100 (0 < percent < 100). In addition, only the first four digits to the right of the decimal point are significant.
  • Page 208 Authorization and Locking To run the UPDATE STATISTICS statement against SQL tables, you must have the authority to read the user table for which statistics are generated. Because the histogram tables are registered in the schema of table, you must have the authority to read and write to this schema. UPDATE STATISTICS momentarily locks the definition of the user table during the operation but not the user table itself.
  • Page 209: Examples Of Update Statistics

    --- SQL operation complete. • This example generates histogram statistics using the ON EVERY COLUMN option for the table DEPT. This statement performs a full scan, and Neoview SQL determines the default number of intervals. UPDATE STATISTICS FOR TABLE dept ON EVERY COLUMN;...
  • Page 210: Values Statement

    “SELECT Statement” (page 164). Relationship to INSERT Statement For a VALUES clause that is the direct source of an INSERT statement, Neoview SQL also allows the keyword DEFAULT in a VALUES clause, just like NULL is allowed. For more information, see the “INSERT Statement”...
  • Page 211: Sql Utilities

    3 SQL Utilities A utility is a tool that runs within Neoview SQL and performs such tasks as maintenance, loading indexes, purging data from tables, indexes, materialized views and reorganizing and reloading data in a table or index. This section describes the Neoview SQL utilities: “MAINTAIN Command”...
  • Page 212: Maintain Command

    The MAINTAIN command is a syntax-based utility that can be executed in the Neoview Command Interface (NCI) or in the SQL Whiteboard of the HP Database Manager (HPDM). The MAINTAIN command performs one or more table maintenance tasks, such as REORG, UPDATE STATISTICS, and REFRESH, on a specified database object.
  • Page 213: Syntax Description Of Maintain

    Not all tasks and options are available for each object type. The syntax for each object type is presented here. For single tables: MAINTAIN object-type object-name [,maintain-task ['task-options']...] [, other-options...][,control-options] object-type is: TABLE INDEX MVGROUP maintain-task is: REORG REORG ALL INDEXES UPDATE STATISTICS UPDATE STATISTICS ALL MVS REFRESH...
  • Page 214 — Update of mvlog statistics — Refresh of all materialized views on that table — Reorg of all materialized views on the table — Reorg of all indexes on the materialized views — Update of statistics for all materialized views referencing the table. •...
  • Page 215 other-options CONTINUE ON ERROR If any of the maintain tasks return an error, that error is returned, and execution continues to the next task. The default is to continue on error. STOP ON ERROR If any of the maintain tasks return an error, that error is returned, and execution stops. RETURN DETAIL OUTPUT displays a detailed message from each of the individual tasks.
  • Page 216 NOTE: The MAINTAIN command is not supported for use with volatile tables. RATE percentage specifies that the reorg operation should spend a percentage of its time doing the reorg and the rest of its time delaying. percentage is an integer in the range of 1 through 100. If this option is not specified, the default value of 40 is used.
  • Page 217: Maintain Mvgroup

    MVGROUP. NOTE: HP recommends that you gather all the materialized views to refresh at a specific time into one group and refresh them together. If for any reason the refresh of some materialized views in the MVGROUP fails, the utility reports the failures.
  • Page 218 maintain table t1_090, all, display; • Displays all tasks that are done on table t1_090 but shows the actual execution: maintain table t1_090, all; • Refreshes mvgroup MVG_090: maintain mvgroup MVG_090, refresh; • Reorganizes index T1_090_2: maintain index T1_090_2, reorg; •...
  • Page 219 Table001: CAT.SCH.T1 Table002: CAT.SCH.T2 Rate: Slack: Status: COMPLETED Completed: -001-00-00 00:00:00.000000 TableName: CAT.SCH.T1 Partition: NSK_SYSTEM_ZSDCNHM6_BSQJPG00 Location: \NSK.$SYSTEM.ZSDCNHM6.BSQJPG00 Status: NOT_INITIATED Segment: \NSK Cpu: PctDone: TableName: CAT.SCH.T2 Partition: NSK_SYSTEM_ZSDCNHM6_SFS6PG00 Location: \NSK.$SYSTEM.ZSDCNHM6.SFS6PG00 Status: NOT_INITIATED Segment: \NSK Cpu: PctDone: Total elapsed Time: 00:00:00.000 Task: REORG_TABLE Status: Ended ET: 00:00:00.031 --- SQL operation complete.
  • Page 220: Populate Index Utility

    If a lot of audit is generated and you perform many CREATE INDEX operations, Neoview SQL recommends that you avoid ONLINE operations because they can add more contention to the audit trail. The default is ONLINE.
  • Page 221: Examples Of Populate Index

    • If the POPULATE INDEX operation fails unexpectedly, you may need to drop the index again and recreate and repopulate, or run recover. Contact HP support for details on how to run recover. • Online POPULATE INDEX reads the audit trail to replay updates by allowing read/write access.
  • Page 222: Purgedata Utility

    “Considerations for PURGEDATA” • “Example of PURGEDATA” The PURGEDATA utility deletes all data from a Neoview SQL table and its related indexes. The PURGEDATA utility is a syntax-based utility that can be executed in the Neoview Command Interface (NCI). PURGEDATA object [IGNORE_TRIGGER] [NOLOG]...
  • Page 223: Example Of Purgedata

    the data. Error 8551 with an accompanying file system error 59 or error 1071 is returned in this case. Example of PURGEDATA • This example purges the data in the specified table. If the table has indexes, their data is also purged.
  • Page 224: Replicate Command

    REPLICATE Command • “Syntax Description of REPLICATE ” • “Considerations for REPLICATE ” • “Examples of REPLICATE” The REPLICATE command is a syntax-based utility that can be executed from any interface where an SQL command can be executed. The REPLICATE command allows an Neoview installation to replicate a table or an entire schema from one Neoview system to another.
  • Page 225: Syntax Description Of Replicate

    Syntax Description of REPLICATE name of the source table. schema name of the source schema. node target name in the format \node (backslash (\) followed by target system master segment name, for example, \NEO0101). query_id query ID of the replicate object. pattern pattern same as what is used in LIKE clause.
  • Page 226: Considerations For Replicate

    The target table must exist before you use the REPLICATE command. If the DDL for the target table does not match the source table, the REPLICATE fails. HP suggests that you use the COPY DDL option to create the target DDL and the dependent objects. A sample sequence of commands is REPLICATE ...
  • Page 227 In addition, the source and target tables must have the same number of physical partitions. If the source and target tables do not contain the same number of physical partitions, contact your HP support representative for assistance. DDL must exist for both source and target tables for the REPLICATE command to move data.
  • Page 228 Replicating Statistics Histogram statistics for objects in a schema can be replicated with the COPY STATISTICS option. All the relevant histogram statistics for the objects in the specified schema will be collected on the source system, copied to the target system, and then inserted into the histogram tables on the target system.
  • Page 229 replicate source schema neo.SCH, copy ddl, target system \tin0101; SrcSchema: TgtSchema: SrcSystem: EXE0201 TgtSystem: TIN0101 StartTime: 2010-05-05 17:16:48.601352 EndTime: 2010-05-05 17:18:39.907549 ElapsedTime: 00:01:51.306 *** ERROR[11205] Java class 'employee' was not found in external path '/home'. *** ERROR[1231] User-defined routine NEO.SCH.PROC_EMPLOYEE could not be created. *** ERROR[8659] BDR Listener process on TIN0101 received an error from CLI.
  • Page 230: Examples Of Replicate

    • A failed replicate operation on any partition will cause the REPLICATE command to abort. Restart after any failure will not be supported. A failed REPLICATE operation will purge data from all target partitions. You will need to reissue the REPLICATE command to replicate again.
  • Page 231 REPLICATE SOURCE SCHEMA sch, COPY STATISTICS, TARGET SYSTEM \exe0101; Copies statistics for the objects. • Return status of a replicate operation in progress: REPLICATE GET STATUS FOR QID 'MXID01123456789212131901967007490000000000204USER00_37'; SrcObject: NEO.SCH.T1 TgtObject: NEO.SCH.T1 ObjType: TABLE SrcSystem: \EXE0101 TgtSystem: \DOC0101 NumPartns: StartTime: 2010-02-11 15:40:16.302597 EndTime:...
  • Page 233: Sql Language Elements

    4 SQL Language Elements Neoview SQL language elements, which include data types, expressions, functions, identifiers, literals, and predicates, occur within the syntax of SQL statements. The statement and command topics support the syntactical and semantic descriptions of the language elements in this section.
  • Page 234: Character Sets

    Character Sets Each Neoview platform has a character set configuration that you choose when you order a new Neoview platform. The Neoview character set configuration determines how character data is sent back and forth between client applications and the Neoview database. Although you can specify only ISO88591 or UCS2 for a character column definition, the Neoview character set configuration permits you to store character string data encoded in other character sets.
  • Page 235: Columns

    Columns A column is a vertical component of a table and is the relational representation of a field in a record. A column contains one data value for each row of the table. A column value is the smallest unit of data that can be selected from or updated in a table. Each column has a name that is an SQL identifier and is unique within the table or view that contains the column.
  • Page 236: Column Default Settings

    Examples of Derived Column Names • These two examples show how to use names for derived columns. The first example shows (EXPR) as the column heading of the SELECT result table: SELECT AVG (salary) FROM persnl.employee; (EXPR) ---------------- 49441.52 --- 1 row(s) selected. The second example shows AVERAGE SALARY as the column heading: SELECT AVG (salary) AS "AVERAGE SALARY"...
  • Page 237: Constraints

    If you omit the schema portion of the name you specify, Neoview SQL expands the name by using the schema for the table.
  • Page 238: Correlation Names

    Correlation Names A correlation name is a name you can associate with a table reference that is a table, view, materialized view, or subquery in a SELECT statement to: • Distinguish a table or view from another table or view referred to in a statement •...
  • Page 239: Cursors

    ODBC or JDBC has retrieved all rows from the result set, the result set is discarded. After errors, Neoview SQL closes the cursor. Neoview SQL also closes the cursor if the transaction in which it is operating is rolled back.
  • Page 240 "WHERE salary > ? AND jobcode= ?" ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); To specify a non-holdable cursor in a JDBC client application, specify CLOSE_CURSORS_AT_COMMIT as a resultSetHoldability parameter to the createStatement or prepareStatement method. In Neoview SQL, the default is a non-holdable cursor. SQL Language Elements...
  • Page 241: Database Objects

    “Views” Ownership In Neoview SQL, the creator of a schema owns all the objects defined in the schema and has all privileges on the objects defined in the schema. In addition, you can use the GRANT and REVOKE statements to grant access privileges for a table or view to specified users.
  • Page 242: Database Object Names

    “Logical Names for SQL Objects” • “SQL Object Namespaces” DML statements can refer to Neoview SQL database objects. To refer to a database object in a statement, use an appropriate database object name. For information on the types of database objects see “Database Objects”...
  • Page 243: Data Types

    Data Types Neoview SQL data types are character, datetime, interval, or numeric (exact or approximate): “Character String Data Types” (page 248) Fixed-length and variable-length character data types. “Datetime Data Types” (page 250) DATE, TIME, and TIMESTAMP data types. “Interval Data Types” (page 251)
  • Page 244 Type SQL Designation Description Size or Range (1) REAL Floating point number (32 +/- 1.17549435e-38 through +/ bits) 3.40282347e+38; stored in 4 bytes DOUBLE PRECISION Floating-point numbers (64 +/- 2.2250738585072014e-308 bits) with 1 through 52 bits through of precision (52 bits of binary +/-1.7976931348623157e+308;...
  • Page 245: Comparable And Compatible Data Types

    Compatible data types are also comparable. Assignment and comparison are the basic operations of Neoview SQL. Assignment operations are performed during the execution of INSERT and UPDATE statements. Comparison operations are performed during the execution of statements that include predicates, aggregate (or set) functions, and GROUP BY, HAVING, and ORDER BY clauses.
  • Page 246 Extended Numeric Precision Neoview SQL provides support for extended numeric precision data type. Extended numeric precision is an extension to the NUMERIC(x,y) data type where no theoretical limit exists on precision. It is a software data type, which means that the underlying hardware does not support it and all computations are performed by software.
  • Page 247 NUMERIC(19,4) sum. But because there are no user-specified extended precision columns, the system casts the sum back to the user-specified type of NUMERIC(18,4). CREATE TABLE T(a NUMERIC(18,4), B NUMERIC(18,4); INSERT INTO T VALUES (1.1234, 2.1234); >> SELECT A+B FROM T; (EXPR) -------------- 3.246...
  • Page 248: Character String Data Types

    NO PARTITION --- SQL operation complete. >> Character String Data Types Neoview SQL includes both fixed-length character data and variable-length character data. You cannot compare character data to numeric, datetime, or interval data. character-type is: CHAR[ACTER] [(length [CHARACTERS])] [char-set] [UPSHIFT] [[NOT]CASESPECIFIC]...
  • Page 249 Neoview SQL compares the binary code values of the corresponding characters of s1 and s2 until it finds a difference. If Neoview SQL finds a difference and the differing character value of s1 is less than that of s2, s1 is considered to come before s2.
  • Page 250: Datetime Data Types

    “CAST Expression” (page 357). Neoview SQL accepts dates, such as October 5 to 14, 1582, that were omitted from the Gregorian calendar. This functionality is a Neoview SQL extension. The range of times that a datetime value can represent is: January 1, 1 A.D., 00:00:00.000000 (low value) December 31, 9999, 23:59:59.999999 (high value)
  • Page 251: Interval Data Types

    Interval Data Types Values of interval data type represent durations of time in year-month units (years and months) or in day-time units (days, hours, minutes, seconds, and fractions of a second). interval-type is: INTERVAL[-] { start-field TO end-field | single-field } start-field is: {YEAR | MONTH | DAY | HOUR | MINUTE} [(leading-precision)] end-field is:...
  • Page 252 SECOND(0) does not cause a loss of value. Provided that the value fits in the target column without a loss of precision, Neoview SQL does not return an overflow error. However, if the fractional value is > 0, an overflow occurs. Inserting value INTERVAL '1.000001' SECOND(6) causes a loss of value.
  • Page 253: Numeric Data Types

    Approximate numeric data types are types that do not necessarily represent a value exactly: FLOAT, REAL, and DOUBLE PRECISION. A column in a Neoview SQL table declared with a floating-point data type is stored in IEEE floating-point format and all computations on it are done assuming that. Neoview SQL tables can contain only IEEE floating-point data.
  • Page 254 FLOAT [( precision )] specifies an approximate numeric column. The column stores floating-point numbers and designates from 1 through 54 bits of precision. The range is from +/- 2.2250738585072014e-308 through +/-1.7976931348623157e+308 stored in 8 bytes. An IEEE FLOAT precision data type is stored as an IEEE DOUBLE, that is, in 8 bytes, with the specified precision.
  • Page 255: Expressions

    Expressions An SQL value expression, referred to as an expression, can evaluate to a value with one of these: “Character Value Expressions” (page 255) Operands can be combined with the concatenation operator (||). Example: 'HOUSTON,' ||' TEXAS' “Datetime Value Expressions” (page 257) Operands can be combined in specific ways with arithmetic operators.
  • Page 256: Examples Of Character Value Expressions

    Examples of Character Value Expressions These are examples of character value expressions: Expression Description Character string literal. 'ABILENE' The concatenation of two string literals. 'ABILENE ' ||' TEXAS' The concatenation of three string literals to form the literal: 'ABILENE ' ||' TEXAS ' || x’55 53 41' 'ABILENE TEXAS USA' The concatenation of a string literal with the value in 'Customer ' || custname...
  • Page 257: Datetime Value Expressions

    Datetime Value Expressions • “Considerations for Datetime Value Expressions” • “Examples of Datetime Value Expressions” The operands of a datetime value expression can be combined in specific ways with arithmetic operators. In this syntax diagram, the data type of a datetime primary is DATE, TIME, or TIMESTAMP. The data type of an interval term is INTERVAL.
  • Page 258 Considerations for Datetime Value Expressions Data Type of Result In general, the data type of the result is the data type of the datetime-primary part of the datetime expression. For example, datetime value expressions include: Datetime Expression Description Result Data Type The sum of the current date and an DATE CURRENT_DATE + INTERVAL '1'...
  • Page 259 (EXPR) ---------- 2007-03-12 --- 1 row(s) selected. The result of adding 20 days to 2008-02-21 is 2008-03-12. Neoview SQL correctly handles 2008 as a leap year. • Subtract an interval value qualified by HOUR TO MINUTE from a datetime value: SELECT ship_timestamp - INTERVAL '15:30' HOUR TO MINUTE FROM persnl.project...
  • Page 260 -------------------------- 2008-04-20 16:45:00.000000 The result of subtracting 15 hours and 30 minutes from 2007-04-21 08:15:00.00 is 2007-04-20 16:45:00.00. SQL Language Elements...
  • Page 261: Interval Value Expressions

    Interval Value Expressions • “Considerations for Interval Value Expressions” • “Examples of Interval Value Expressions” The operands of an interval value expression can be combined in specific ways with addition and subtraction operators. In this syntax diagram, the data type of a datetime expression is DATE, TIME, or TIMESTAMP;...
  • Page 262 the result of adding or subtracting two interval qualifiers, the interval qualifier of the result depends on the interval qualifier of the target column. Considerations for Interval Value Expressions Start and End Fields Within the definition of an interval range, the start-field and end-field can be any of the specified fields with these restrictions: •...
  • Page 263 INTERVAL '1' MONTH + INTERVAL '7' DAY • If you multiply or divide an interval value by a numeric value expression, Neoview SQL converts the interval value to its least significant subfield and then multiplies or divides it by the numeric value expression. The result has the same fields as the interval that was multiplied or divided.
  • Page 264 The next example uses these values in the PROJECT table: PROJCODE START_DATE SHIP_TIMESTAMP EST_COMPLETE 1000 2007-04-10 2007-04-21:08:15:00.0000 2000 2007-06-10 2007-07-21:08:30:00.0000 2500 2007-10-10 2007-12-21:09:00:00.0000 3000 2007-08-21 2007-10-21:08:10:00.0000 4000 2007-09-21 2007-10-21:10:15:00.0000 5000 2007-09-28 2007-10-28:09:25:01.1111 • Suppose that the CURRENT_TIMESTAMP is 2000-01-06 11:14:41.748703. Find the number of days, hours, minutes, seconds, and fractional seconds in the difference of the current timestamp and the SHIP_TIMESTAMP in the PROJECT table: SELECT projcode,...
  • Page 265: Numeric Value Expressions

    Numeric Value Expressions • “Considerations for Numeric Value Expressions” • “Examples of Numeric Value Expressions” The operands of a numeric value expression can be combined in specific ways with arithmetic operators. In this syntax diagram, the data type of a term, factor, or numeric primary is numeric. numeric-expression is: numeric-term | numeric-expression + numeric-term...
  • Page 266 REAL data type is approximately 7 decimal digits, and the maximum precision for the DOUBLE PRECISION data type is approximately 16 digits. When Neoview SQL encounters an arithmetic operator in an expression, it applies these rules (with the restriction that if the precision becomes greater than 18, the resulting precision is set to 18 and the resulting scale is the maximum of 0 and (18- (resulted precision - resulted scale)).
  • Page 267 Conversion of Numeric Types for Arithmetic Operations Neoview SQL automatically converts between floating-point numeric types (REAL and DOUBLE PRECISION) and other numeric types. All numeric values in the expression are first converted to binary, with the maximum precision needed anywhere in the evaluation.
  • Page 268: Examples Of Numeric Value Expressions

    Examples of Numeric Value Expressions These are examples of numeric value expressions: Numeric literal. The product of the values in the SALARY column and a salary * 1.10 numeric literal. The product of the values in the UNIT_PRICE and unit_price * qty_ordered QTY_ORDERED columns.
  • Page 269: Identifiers

    Delimited Identifiers Neoview has extended support within Neoview SQL to include the forward slash (/) character. The forward slash (/) is supported within delimited identifiers for DDL, DML, and SQL utility statements. The forward slash (/) character can be in any position with the delimited identifier string including the first character following the starting double quote.
  • Page 270 "table" "2006 SALES" "CUSTOMER-BILLING-INFORMATION" Because delimited identifiers are case-sensitive, Neoview SQL treats the identifier "mytable" as different from the identifiers "MYTABLE" or "MyTable". Trailing spaces in a delimited identifier are truncated. For example, "mytable " is equivalent to "mytable". You can use reserved words as delimited identifiers. For example, table is not allowed as a regular identifier, but "table"...
  • Page 271: Indexes

    Indexes are transparent to DML syntax. There is always a one-to-one correspondence between index rows and base table rows. SQL Indexes Each row in a Neoview SQL index contains: • The columns specified in the CREATE INDEX statement •...
  • Page 272: Keys

    Every table has a clustering key, which is the set of columns that determine the order of the rows on disk. Neoview SQL organizes records of a table or index by using a b-tree based on this clustering key. Therefore, the values of the clustering key act as logical row-ids.
  • Page 273: Hash Partition Keys

    Partitioned tables have a partitioning key (HASH PARTITION BY clause), chosen from the columns of the clustering key which Neoview SQL uses to distribute rows to different disks. The list of columns defined in the partitioning key is used to determine the hash partition key.
  • Page 274: Literals

    ISO88591 or UCS2. Although you can specify only ISO88591 or UCS2 for character column definitions and string literals in Neoview SQL, the character set configuration of your Neoview platform permits you to use character string data encoded in other character sets.
  • Page 275: Datetime Literals

    • Do not put a space between the character set qualifier and the character string literal. If you use this character string literal in a statement, Neoview SQL returns an error. • To specify a single quotation mark within a string literal, use two consecutive single quotation marks.
  • Page 276 the corresponding datetime data types. You cannot use leading or trailing spaces within a datetime string (within the single quotes). A datetime literal begins with the DATE, TIME, or TIMESTAMP keyword and can appear in default, USA, or European format. DATE 'date' | TIME 'time' | TIMESTAMP 'timestamp' date is: yyyy-mm-dd...
  • Page 277: Interval Literals

    Interval Literals • “Considerations for Interval Literals” • “Examples of Interval Literals” An interval literal is a constant of data type INTERVAL that represents a positive or negative duration of time as a year-month or day-time interval; it begins with the keyword INTERVAL optionally preceded or followed by a minus sign (for negative duration).
  • Page 278: Considerations For Interval Literals

    'year-month' | 'day:time' specifies the date and time components of an interval literal. The day and hour fields can be separated by a space or a colon. The interval literal strings are: Unsigned integer that specifies a number of years. years years can be up to 18 digits, or 16 digits if months is the end-field.
  • Page 279: Numeric Literals

    Examples of Interval Literals Interval of 1 month INTERVAL '1' MONTH Interval of 7 days INTERVAL '7' DAY Interval of 2 years, 7 months INTERVAL '2-7' YEAR TO MONTH Interval of 5 days, 2 hours, 15 minutes, and 36.33 seconds INTERVAL '5:2:15:36.33' DAY TO SECOND(2) Interval that subtracts 5 days INTERVAL - '5' DAY...
  • Page 280 Examples of Numeric Literals • These are all numeric literals, along with their display format: Literal Display Format 580.45 580.45 +005 -.3175 -.3175 1300000000 1300000000 -0.123456789012345678 -.123456789012345678 99E-2 9.9000000E-001 12.3e+5 1.2299999E+006 SQL Language Elements...
  • Page 281: Materialized Views

    Since summary tables are usually much smaller than the original tables, the queries are executed much faster. Types of Materialized Views Neoview SQL defines the following three types of materialized views: • Materialized Join View (MJV): An ON STATEMENT or ON REQUEST materialized view holds the results of a join query with inner equi-joins of several tables.
  • Page 282: Mvgroups

    MVGROUPs An MVGROUP is a group of materialized views that are refreshed together. One way to group MVs is by the frequency of the REFRESH (for example, each day, each week, each month). Another way is to create groups to preserve consistency, that is, to group all the MVs on common tables.
  • Page 283: Null

    Null is the default for a column (other than NOT NULL) unless the column definition includes a DEFAULT clause (other than DEFAULT NULL) or the NO DEFAULT clause. The default value for a column is the value Neoview SQL inserts in a row when an INSERT statement omits a value for a particular column.
  • Page 284: Null And Expression Evaluation Comparison

    Null and Expression Evaluation Comparison Expression Type Condition Result Boolean operators (AND, OR, NOT) Either operand is null. For AND, the result is null. For OR, the result is true if the other operand is true, or null if the other operand is null or false.
  • Page 285: Partitions

    Users may also specify the MAX TABLE SIZE clause that will be used to decide on the table extent sizes. If this option is not specified Neoview SQL will decide. If the table is partitioned then the table is partitioned across all the disk volumes on the system.
  • Page 286: Predicates

    Predicates A predicate determines an answer to a question about a value or group of values. A predicate returns true, false, or, if the question cannot be answered, unknown. Use predicates within search conditions to choose rows from tables or views. “BETWEEN Predicate”...
  • Page 287: Comparison Predicates

    Considerations for BETWEEN Logical Equivalents Using AND and OR The predicate expr1 BETWEEN expr2 AND expr3 is true if and only if this condition is true: expr2 <= expr1 AND expr1 <= expr3 The predicate expr1 NOT BETWEEN expr2 AND expr3 is true if and only if this condition is true: expr2 >...
  • Page 288 Predicate X<>Y is true if X=Y is false. If X1<>Y1, Neoview SQL does not look at all components. It stops and returns a value of false for the X=Y predicate and a value of true for the X<>Y predicate.
  • Page 289 X=Y. Predicate X<=Y is true if X<Y is true or X=Y is true. In this scenario, Neoview SQL might need to look through all components and return true if they are all equal. It stops at the first nonequal components, Xm<>Ym.
  • Page 290 Suppose that JOB1_TIME, defined as INTERVAL DAY TO MINUTE, is 2 days 3 hours, and JOB2_TIME, defined as INTERVAL DAY TO HOUR, is 3 days. To evaluate the predicate, Neoview SQL converts the two INTERVAL values to MINUTE. The comparison predicate is true.
  • Page 291: Exists Predicate

    --- 35 row(s) selected. The first subquery of this query determines the minimum salary of employees from other departments whose salary is greater than the average salary for department 1500. The main query then finds the names of employees who are not in department 1500 and whose salary is less than the minimum salary determined by the first subquery.
  • Page 292: In Predicate

    WHERE EXISTS (SELECT partnum FROM invent.partloc PL WHERE PS.partnum = PL.partnum AND qty_on_hand < 20); PARTNUM SUPPNUM ------- ------- 2001 2003 --- 18 row(s) selected. IN Predicate • “Considerations for IN” • “Examples of IN” The IN predicate determines if a sequence of values is equal to any of the sequences of values in a list of sequences.
  • Page 293 Both fixed-length and varying-length strings are padded in this way. For example, Neoview SQL considers the string ‘JOE’ equal to a value JOE stored in a column of data type CHAR or VARCHAR of width three or more. Similarly, Neoview SQL considers a value JOE stored in any column of the CHAR data type equal to the value JOE stored in any column of the VARCHAR data type.
  • Page 294: Like Predicate

    FROM invent.partloc); PARTNUM PARTDESC ------- ------------------ 186 MegaByte Disk --- 1 row(s) selected. • Find those items (and their suppliers) in PARTS that have a supplier in the PARTSUPP table: SELECT P.partnum, P.partdesc, S.suppnum, S.suppname FROM sales.parts P, invent.supplier S WHERE P.partnum, S.suppnum IN (SELECT partnum, suppnum FROM invent.partsupp);...
  • Page 295 Comparing the Pattern to CHAR Columns Columns of data type CHAR are fixed length. When a value is inserted into a CHAR column, Neoview SQL pads the value in the column with blanks if necessary. The value 'JOE' inserted Predicates...
  • Page 296: Null Predicate

    In double-byte SJIS characters, the second byte might be the hexadecimal value, 0x5C or 0x5F. In Neoview SQL, 0x5C corresponds to a back slash (\), which is often used as an escape character, and 0x5F corresponds to an underscore (_), which is one of the wild-card characters. In Neoview Release 2.3, if a LIKE pattern includes a double-byte SJIS character that uses 0x5C or 0x5F as the...
  • Page 297: Quantified Comparison Predicates

    If all of the expressions in the row-value-constructor are null, the IS NULL predicate is true. Otherwise, it is false. If none of the expressions in the row-value-constructor are null, the IS NOT NULL predicate is true. Otherwise, it is false. Considerations for NULL Summary of NULL Results Let rvc be the value of the row-value-constructor.
  • Page 298 row-value-constructor specifies the first operand of a quantified comparison predicate. The first operand can be either of: (expression [,expression ]...) is a sequence of SQL value expressions, separated by commas and enclosed in parentheses. expression cannot include an aggregate function unless expression is in a HAVING clause.
  • Page 299 FROM persnl.employee WHERE jobcode = 420); The inner query providing the comparison values yields these results: SELECT salary FROM persnl.employee WHERE jobcode = 420; SALARY ----------- 33000.00 36000.00 18000.10 --- 3 row(s) selected. The SELECT statement using this inner query yields these results. The salaries listed are greater than the salary of every employees with jobcode equal to 420—that is, greater than $33,000.00, $36,000.00, and $18,000.10: SELECT empnum, first_name, last_name, salary...
  • Page 300 The SELECT statement using this inner query yields these results. All of the order numbers listed have part number equal to any part number with more than five total units in stock—that is, equal to 2403, 5100, 5103, 6301, 6500, and so on: SELECT ordernum, partnum, qty_ordered FROM sales.odetail WHERE partnum = ANY (SELECT partnum...
  • Page 301: Privileges

    Privileges These privileges are used by the GRANT and REVOKE statements. For further information on GRANT, see “GRANT Statement” (page 136), “GRANT EXECUTE Statement” (page 138), or “GRANT SCHEMA Statement” (page 140). For further information on REVOKE, see “REVOKE Statement” (page 156), “REVOKE EXECUTE Statement”...
  • Page 302 DROP_MV_GROUP - Can drop MV groups. • DROP_PROCEDURE - Can drop any procedure in the schema. Procedures can only be created through HPDM. For more information, see the HP Database Manager (HPDM) User Guide. • DROP_SYNONYM - Can drop any synonym in the schema.
  • Page 303 • DROP_TABLE - Can drop any table (regular or volatile) in the schema. Indirectly allows the grantee to drop any dependent object on the table such as constraints, indexes, triggers, and synonyms. • DROP_TRIGGER - Can drop any trigger in the schema. •...
  • Page 304: Schemas

    The logical name of the form schema.object is an ANSI name. The part schema denotes the ANSI-defined schema. To be compliant with ANSI SQL:1999, Neoview SQL provides support for ANSI object names. By using these names, you can develop ANSI-compliant applications that access all SQL objects.
  • Page 305: Search Condition

    Search Condition A search condition is used to choose rows from tables or views, depending on the result of applying the condition to rows. The condition is a Boolean expression consisting of predicates combined together with OR, AND, and NOT operators. You can use a search condition in the WHERE clause of a SELECT, DELETE, or UPDATE statement, the HAVING clause of a SELECT statement, the searched form of a CASE expression, the ON clause of a SELECT statement that involves a join, a CHECK constraint, or a ROWS...
  • Page 306: Examples Of Search Condition

    Examples of Search Condition • Select rows by using a search condition composed of three comparison predicates joined by AND operators: select O.ordernum, O.deliv_date, OD.qty_ordered FROM sales.orders O, sales.odetail OD WHERE qty_ordered < 9 AND deliv_date <= DATE '2008-11-01' AND O.ordernum = OD.ordernum; ORDERNUM DELIV_DATE QTY_ORDERED...
  • Page 307: Subquery

    Subquery A subquery is a query expression enclosed in parentheses. Its syntactic form is specified in the syntax of a SELECT statement. For further information about query expressions, see “SELECT Statement” (page 164). A subquery is used to provide values for a BETWEEN, comparison, EXISTS, IN, or quantified comparison predicate in a search condition.
  • Page 308: Correlated Subqueries When Providing Comparison Values

    Correlated Subqueries When Providing Comparison Values In a subquery, when you refer to columns of any table or view defined in an outer query, the reference is called an outer reference. A subquery containing an outer reference is called a correlated subquery.
  • Page 309: Synonyms

    Synonyms A synonym is an alternate name that you create for a table, view, or materialized view to use in queries. You can write queries that reference the synonym and later alter the synonym to point to a different object with the same structure. The advantage of this is to change the object being referenced without changing the query.
  • Page 310: Tables

    (for example, the storage order of rows within the table) A Neoview SQL table is described in an SQL schema and stored in a physical file in the environment. An SQL table name can be a fully qualified ANSI name of the form schema-name.object-name.
  • Page 311: Triggers

    Triggers A trigger is a mechanism that resides in the database and specifies that when a particular action—an insert, delete, or update—occurs on a particular table, Neoview SQL should automatically perform one or more additional actions. For a complete description of triggers and their use, see the “CREATE TRIGGER Statement”...
  • Page 312: Views

    Views A view provides an alternate way of looking at data in one or more tables. A view is a named specification of a result table, which is a set of rows selected or generated from one or more base tables or other views.
  • Page 313: Sql Clauses

    5 SQL Clauses Clauses are used by Neoview SQL statements to specify default values, ways to sample or sort data, how to store physical data, and other details. This section describes: • “DEFAULT Clause” specifies a default value for a column being created.
  • Page 314: Default Clause

    DEFAULT Clause “Examples of DEFAULT” The DEFAULT option of the CREATE TABLE or ALTER TABLE table-name ADD COLUMN statement specifies a default value for a column being created. The default value is used when a row is inserted in the table without a value for the column. DEFAULT default | NO DEFAULT | identity-column-specification default is: literal...
  • Page 315: Examples Of Default

    identity-column-specification indicates that a particular column is a sequence-generating IDENTITY column. GENERATED BY DEFAULT AS IDENTITY indicates that the system will generate values for this column by default or values can be specified by the user. GENERATED ALWAYS AS IDENTITY indicates that the system will always generate values for this column by default.
  • Page 316: Format Clause

    FORMAT Clause • “Considerations for Date Formats” • “Considerations for Other Formats” • “Examples of FORMAT” The FORMAT clause specifies the output format for DATE values. It can also be used to specify the length of character output or to specify separating the digits of integer output with colons. Date Formats: (FORMAT 'format-string') | (DATE, FORMAT 'format-string')
  • Page 317: Considerations For Date Formats

    -99:99:99:99 specifies that the FORMAT clause output format is a timestamp. The input must be a numeric value. Considerations for Date Formats The expression preceding the (FORMAT ”format-string') clause must be a DATE value. The expression preceding the (DATE, FORMAT 'format-string') clause must be a quoted string in the USA, EUROPEAN, or DEFAULT date format.
  • Page 318: Sample Clause

    N. The number of rows picked follows a binomial distribution with mean equal to r * N/100. If you specify a sample size greater than 100 PERCENT, Neoview SQL returns all the rows in the result table plus duplicate rows. The duplicate rows are picked from the result table according to the specified sampling method.
  • Page 319: Considerations For Sample

    FIRST rows-size [SORT BY colname [ASC[ENDING] | DESC[ENDING]] [,colname [ASC[ENDING] | DESC[ENDING]]]...] directs Neoview SQL to choose the first rows from the result table. You can specify the order of the rows to sample. Otherwise, Neoview SQL chooses an arbitrary order. The sampling...
  • Page 320: Examples Of Sample

    Cluster Sampling Cluster sampling is an option supported by the SAMPLE RANDOM clause in a SELECT statement. A cluster, in this sense, is a logically contiguous set of disk blocks in the file in which a table is stored. The number of blocks in a cluster is specified in the CLUSTERS subclause of the SAMPLE RANDOM clause.
  • Page 321 136000.00 37000.40 --- 50 row(s) selected. • Return the SALARY of 50 sales people. In this case, the table is clustered on EMPID. If the optimizer chooses a plan to access rows using the primary access path, the result consists of salaries of the 50 sales people with the smallest employee identifiers.
  • Page 322 • Compute the average salary of a random 10 percent of the sales people using cluster sampling where each cluster is 4 blocks. You will get a different result each time you run this query because it is based on a random sample. SELECT AVG(salary) FROM salesperson SAMPLE RANDOM 10 PERCENT CLUSTERS OF 4 BLOCKS;...
  • Page 323 (EXPR) -------------------- 37000.000 --- 1 row(s) selected. Note that the results of this query and some of the results of previous queries might return null: SELECT AVG(salary) FROM ( SELECT salary, dnum FROM salesperson SAMPLE RANDOM 10 PERCENT ) AS S, department D WHERE S.DNUM = D.DNUM AND D.NAME = 'CORPORATE';...
  • Page 324 --- 88 row(s) selected. • The BALANCE option enables stratified sampling. Retrieve the age and salary of 1000 sales people such that 50 percent of the result are male and 50 percent female. SELECT age, sex, salary FROM salesperson SAMPLE FIRST BALANCE WHEN sex = 'male' THEN 15 ROWS WHEN sex = 'female' THEN 15 ROWS ORDER BY age;...
  • Page 325 GRAPHICPRINTER, M3 20000.00 LASERPRINTER, X1 42000.00 --- 30 row(s) selected. SAMPLE Clause...
  • Page 326: Sequence By Clause

    You must include a SEQUENCE BY clause if you include a sequence function in the select list of the SELECT statement. Otherwise, Neoview SQL returns an error. Further, you cannot include a SEQUENCE BY clause if there is no sequence function in the select list. See “Sequence Functions”...
  • Page 327: Examples Of Sequence By

    AS tab2 (ordernum, avg_price) SEQUENCE BY ordernum; • Like aggregate functions, sequence functions generate an intermediate result. If the query has a WHERE clause, its search condition is applied during the generation of the intermediate result. Therefore, you cannot use sequence functions in the WHERE clause of a SELECT statement.
  • Page 328 FROM orders o, odetail d WHERE o.ordernum=d.ordernum SEQUENCE BY o.order_date, o.ordernum, d.partnum ORDER BY o.order_date, o.ordernum, d.partnum; Order/Num MCOUNT Part/Num Order/Date AMOUNT ORDER_TOTAL TOTAL_SALES ---------- ----------- -------- ---------- ---------- -------------- -------------- 100250 2008-01-23 14000.00 14000.00 14000.00 100250 5103 2008-01-23 4000.00 18000.00 18000.00 100250...
  • Page 329: Transpose Clause

    The result table of the TRANSPOSE clause has all the columns of the source table plus, for each transpose item list, a value column or columns and an optional key column. TRANSPOSE is a Neoview SQL extension. TRANSPOSE transpose-set [transpose-set]... [KEY BY key-colname]...
  • Page 330: Considerations For Transpose

    parentheses must be equal for each list. The expressions in the same ordinal position within the parentheses must have compatible data types. For example, in the transpose set TRANSPOSE (A,X),(B,Y),(C,Z) AS (V1,V2), the expressions A,B, and C have compatible data types, and the expressions X,Y, and Z have compatible data types.
  • Page 331: Examples Of Transpose

    Data Type of the TRANSPOSE Result The data type of each of the value columns is the union compatible data type of the corresponding expressions in the transpose-item-list. You cannot have expressions with data types that are not compatible in a transpose-item-list. For example, in TRANSPOSE (A,X),(B,Y),(C,Z) AS (V1,V2), the data type of V1 is the union compatible type for A, B, and C, and the data type of V2 is the union compatible type for X, Y, and Z.
  • Page 332 The table MYTABLE has columns A, B, C, D, E, and F with related data. The columns A, B, and C are type INTEGER, and columns D, E, and F are type CHAR. • Suppose that MYTABLE has only the first three columns: A, B, and C. The result of the TRANSPOSE clause has three times as many rows (because there are three items in the transpose item list) as there are rows in MYTABLE: SELECT * FROM mytable...
  • Page 333 The result table of the TRANSPOSE query is: KEYCOL VALCOL COUNT(*) • This query shows how to use COUNT applied to VALCOL. The result table of the TRANSPOSE query shows the number of distinct values in VALCOL. SELECT COUNT(DISTINCT VALCOL) FROM mytable TRANSPOSE A, B, C AS VALCOL KEY BY KEYCOL GROUP BY KEYCOL;...
  • Page 334 KEYCOL1 VALCOL1 KEYCOL2 VALCOL2 • This query shows how a TRANSPOSE clause can contain multiple transpose sets—that is, multiple transpose-item-list AS transpose-col-list. The expressions A, B, and C are of type integer, and expressions D, E, and F are of type character. SELECT KEYCOL, VALCOL1, VALCOL2 FROM mytable TRANSPOSE A, B, C AS VALCOL1 D, E, F AS VALCOL2...
  • Page 335 KEYCOL VALCOL1 VALCOL2 (EXPR) • This query shows how an item in the transpose item list can contain a list of expressions and that the KEY BY clause is optional: SELECT * FROM mytable TRANSPOSE (1, A, 'abc'), (2, B, 'xyz') AS (VALCOL1, VALCOL2, VALCOL3);...
  • Page 337: Sql Functions And Expressions

    6 SQL Functions and Expressions This section describes the syntax and semantics of specific functions and expressions that you can use in Neoview SQL statements. The functions and expressions are categorized according to their functionality. Categories Use these types of functions within an SQL value expression: •...
  • Page 338: Character String Functions

    include a GROUP BY clause but you specify an aggregate function in the select list, all rows of the SELECT result table form the one and only group. See the individual entry for the function. Character String Functions These functions manipulate character strings and use a character value expression as an argument or return a result of a character data type.
  • Page 339: Datetime Functions

    “SUBSTRING/SUBSTR Function” (page 471) Extracts a substring from a character string. “TRANSLATE Function” (page 479) Translates a character string from a source character set to a target character set. “TRIM Function” (page 480) Removes leading or trailing characters from a character string.
  • Page 340: Mathematical Functions

    “DAYOFMONTH Function” (page 389) Returns an integer value in the range 1 through 31 that represents the corresponding day of the month. You can also use DAY. “DAYOFWEEK Function” (page 390) Returns an integer value in the range 1 through 7 that represents the corresponding day of the week.
  • Page 341: Sequence Functions

    “DEGREES Function” (page 395) Converts a numeric value expression expressed in radians to the number of degrees. “EXP Function” (page 400) Returns the exponential value (to the base e) of a numeric value expression. “FLOOR Function” (page 405) Returns the largest integer less than or equal to a numeric value expression.
  • Page 342 such operations may not be parallelized because the entire sorted result set must be available in order to compute the result of the sequence function. Difference sequence functions: “DIFF1 Function” (page 396) Calculates differences between values of a column expression in the current row and previous rows. “DIFF2 Function”...
  • Page 343: Other Functions And Expressions

    “ROWS SINCE CHANGED Function” (page 453) Returns the number of rows counted since the specified set of values last changed. “THIS Function” (page 476) Used in ROWS SINCE to distinguish between the value of the column in the current row and the value of the column in previous rows.
  • Page 344: Abs Function

    ABS Function The ABS function returns the absolute value of a numeric value expression. ABS is a Neoview SQL extension. ABS (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the ABS function. The result is returned as an unsigned numeric value if the precision of the argument is less than 10 or as a LARGEINT if the precision of the argument is greater than or equal to 10.
  • Page 345: Acos Function

    ACOS Function The ACOS function returns the arccosine of a numeric value expression as an angle expressed in radians. ACOS is a Neoview SQL extension. ACOS (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the ACOS function.
  • Page 346: Add_Months Function

    ADD_MONTHS Function The ADD_MONTHS function adds the integer number of months specified by int_expr to datetime_expr and normalizes the result. ADD_MONTHS is a Neoview extension. ADD_MONTHS (datetime_expr, int_expr [, int2 datetime_expr is an expression that evaluates to a datetime value of type DATE or TIMESTAMP. The return value is the same type as the datetime_expr.
  • Page 347: Ascii Function

    On a Neoview platform that has the SJIS or Unicode configuration, if the value of the first byte in the string is greater than 127, Neoview SQL returns this error message: ERROR[8428] The argument to function ASCII is not valid.
  • Page 348: Asin Function

    ASIN Function The ASIN function returns the arcsine of a numeric value expression as an angle expressed in radians. ASIN is a Neoview SQL extension. ASIN (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the ASIN function.
  • Page 349: Atan Function

    ATAN Function The ATAN function returns the arctangent of a numeric value expression as an angle expressed in radians. ATAN is a Neoview SQL extension. ATAN (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the ATAN function.
  • Page 350: Atan2 Function

    ATAN2 Function The ATAN2 function returns the arctangent of the x and y coordinates, specified by two numeric value expressions, as an angle expressed in radians. ATAN2 is a Neoview SQL extension. ATAN2 (numeric-expression-x,numeric-expression-y) numeric-expression-x, numeric-expression-y are SQL numeric value expressions that specify the value for the x and y coordinate arguments of the ATAN2 function.
  • Page 351: Avg Function

    AVG Function AVG is an aggregate function that returns the average of a set of numbers. AVG ([ALL | DISTINCT] expression) ALL | DISTINCT specifies whether duplicate values are included in the computation of the AVG of the expression. The default option is ALL, which causes duplicate values to be included. If you specify DISTINCT, duplicate values are eliminated before the AVG function is applied.
  • Page 352 --- 1 row(s) selected. • Return the average salary by department: SELECT deptnum, AVG (salary) AS "AVERAGE SALARY" FROM persnl.employee WHERE deptnum < 3000 GROUP BY deptnum; Dept/Num "AVERAGE SALARY" -------- --------------------- 1000 52000.17 2000 50000.10 1500 41250.00 2500 37000.00 --- 4 row(s) selected.
  • Page 353: Bitand Function

    BITAND Function The BITAND function performs an AND operation on corresponding bits of the two operands. If both bits are 1, the result bit is 1. Otherwise the result bit is 0. BITAND (expression, expression) expression The result data type is a binary number. Depending on the precision of the operands, the data type of the result can either be an INT (32-bit integer) or a LARGEINT (64-bit integer).
  • Page 354: Case (Conditional) Expression

    The CASE expression is a conditional expression with two forms: simple and searched. In a simple CASE expression, Neoview SQL compares a value to a sequence of values and sets the CASE expression to the value associated with the first match—if there is a match. If there is no match, Neoview SQL returns the value specified in the ELSE clause (which can be null).
  • Page 355: Considerations For Case

    CASE expression returns the value expression specified in the ELSE clause, or NULL if the ELSE value is not specified. Considerations for CASE Data Type of the CASE Expression The data type of the result of the CASE expression depends on the data types of the result expressions.
  • Page 356 WHEN 500 THEN 'ACCOUNTANT' WHEN 600 THEN 'ADMINISTRATOR ANALYST' WHEN 900 THEN 'SECRETARY' ELSE NULL FROM persnl.employee; LAST_NAME FIRST_NAME (EXPR) -------------------- --------------- ----------------- GREEN ROGER MANAGER HOWARD JERRY MANAGER RAYMOND JANE MANAGER CHOU JOHN SECRETARY CONRAD MANFRED PROGRAMMER HERMAN SALESREP CLARK LARRY ACCOUNTANT...
  • Page 357: Cast Expression

    10 characters consisting of the year, a hyphen, the month, another hyphen, and the day. • A date value to a character string or to a TIMESTAMP (Neoview SQL fills in the time part with 00:00:00.00). •...
  • Page 358 CAST (123.956 as INTERVAL DAY(18)) • This example returns the difference of two timestamps in minutes: CAST((d.step_end - d.step_start) AS INTERVAL MINUTE) • Suppose that your database includes a log file of user information. This example converts the current timestamp to a character string and concatenates the result to a character literal. Note the length must be specified.
  • Page 359: Ceiling Function

    CEILING Function The CEILING function returns the smallest integer, represented as a FLOAT data type, greater than or equal to a numeric value expression. CEILING is a Neoview SQL extension. CEILING (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the CEILING function.
  • Page 360: Char Function

    CHAR Function The CHAR function returns the character that has the specified code value, which must be of exact numeric with scale 0. CHAR is a Neoview SQL extension. CHAR(code-value, [,char-set-name]) code-value is a valid code value in the character set in use.
  • Page 361: Char_Length Function

    Considerations for CHAR_LENGTH CHAR and VARCHAR Operands For a column declared as fixed CHAR, Neoview SQL returns the maximum length of that column. For a VARCHAR column, Neoview SQL returns the actual length of the string stored in that column.
  • Page 362: Coalesce Function

    COALESCE Function The COALESCE function returns the value of the first expression in the list that does not have a NULL value or if all the expressions have NULL values, the function returns a NULL value. COALESCE (expr1, expr2, ...) expr1 an expression to be compared.
  • Page 363: Code_Value Function

    For more information on the Neoview character set configurations, see the Neoview Character Sets Administrator's Guide. CODE_VALUE is a Neoview SQL extension. CODE_VALUE(character-value-expression) _character-set character-value-expression is a character string.
  • Page 364: Concat Function

    CONCAT Function The CONCAT function returns the concatenation of two character value expressions as a character string value. You can also use the concatenation operator (||). CONCAT is a Neoview SQL extension. CONCAT (character-expr-1, character-expr-2) character-expr-1, character-expr-2 are SQL character value expressions (of data type CHAR or VARCHAR) that specify two strings of characters.
  • Page 365 INSERT INTO stats.logfile (user_key, user_info) VALUES (002, 'Executed at ' || CAST (CURRENT_TIMESTAMP AS CHAR(26))); CONCAT Function...
  • Page 366: Converttohex Function

    CONVERTTOHEX Function The CONVERTTOHEX function converts the specified value expression to hexadecimal for display purposes. CONVERTTOHEX is a Neoview SQL extension. CONVERTTOHEX (expression) expression is any numeric, character, datetime, or interval expression. The primary purpose of the CONVERTTOHEX function is to eliminate any doubt as to the exact value in a column.
  • Page 367 ----------- --------- ------------------------- ------------------------- 07D8040F 0E201E 07D8040F0E201E00000035 07D8040F0E201E00081ABB • Display the internal values for an INTERVAL YEAR column, an INTERVAL YEAR(2) TO MONTH column, and an INTERVAL DAY TO SECOND column: CREATE TABLE IVT ( IV1 interval year, IV2 interval year(2) to month, IV3 interval day to second) no partition;...
  • Page 368: Converttimestamp Function

    CONVERTTIMESTAMP Function The CONVERTTIMESTAMP function converts a Julian timestamp to a value with data type TIMESTAMP. CONVERTTIMESTAMP is a Neoview SQL extension. CONVERTTIMESTAMP (julian-timestamp) julian-timestamp is an expression that evaluates to a Julian timestamp, which is a LARGEINT value. Considerations for CONVERTTIMESTAMP The julian-timestamp value must be in the range from 148731163200000000 to 274927348799999999.
  • Page 369: Cos Function

    COS Function The COS function returns the cosine of a numeric value expression, where the expression is an angle expressed in radians. COS is a Neoview SQL extension. COS (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the COS function.
  • Page 370: Cosh Function

    COSH Function The COSH function returns the hyperbolic cosine of a numeric value expression, where the expression is an angle expressed in radians. COSH is a Neoview SQL extension. COSH (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the COSH function.
  • Page 371: Count Function

    COUNT Function The COUNT function counts the number of rows that result from a query or the number of rows that contain a distinct value in a specific column. The result of COUNT is data type LARGEINT. The result can never be NULL. COUNT {(*) | ([ALL | DISTINCT] expression)} COUNT (*)
  • Page 372 ----------- --- 1 row(s) selected. SELECT COUNT(*) FROM persnl.employee WHERE jobcode IS NOT NULL; (EXPR) ----------- --- 1 row(s) selected. • Count the number of distinct departments in the EMPLOYEE table: SELECT COUNT (DISTINCT deptnum) FROM persnl.employee; (EXPR) ----------- --- 1 row(s) selected. SQL Functions and Expressions...
  • Page 373: Current Function

    CURRENT Function The CURRENT function returns a value of type TIMESTAMP based on the current local date and time. The function is evaluated once when the query starts execution and is not reevaluated (even if it is a long running query). You can also use “CURRENT_TIMESTAMP Function”...
  • Page 374: Current_Date Function

    CURRENT_DATE Function The CURRENT_DATE function returns the local current date as a value of type DATE. The function is evaluated once when the query starts execution and is not reevaluated (even if it is a long running query). CURRENT_DATE The CURRENT_DATE function returns the current date, such as 2008-09-28. The value returned is a value of type DATE, not a string value.
  • Page 375: Current_Role Function

    CURRENT_ROLE Function The CURRENT_ROLE function returns the role (ROLE.name) that you logged in as. This function can be used anywhere in the query. The values returned are string datatype VARCHAR(64). CURRENT_ROLE Considerations for CURRENT_ROLE The CURRENT_ROLE function returns the role name in ISO8859-1 encoding on a Neoview platform that has the ISO88591 or SJIS configuration.
  • Page 376: Current_Time Function

    CURRENT_TIME Function The CURRENT_TIME function returns the current local time as a value of type TIME. The function is evaluated once when the query starts execution and is not reevaluated (even if it is a long running query). CURRENT_TIME [(precision)] precision is an integer value in the range 0 to 6 that specifies the precision of (the number of decimal places in) the fractional seconds in the returned value.
  • Page 377: Current_Timestamp Function

    CURRENT_TIMESTAMP Function The CURRENT_TIMESTAMP function returns a value of type TIMESTAMP based on the current local date and time. The function is evaluated once when the query starts execution and is not reevaluated (even if it is a long running query). You can also use the “CURRENT Function”...
  • Page 378: Current_User Function

    CURRENT_USER Function The CURRENT_USER function returns the user name that you logged in as. If you are logged in as the role, the role is returned. This function can be used anywhere in the query. The values returned are string datatype VARCHAR(64). CURRENT_USER The CURRENT_USER function is equivalent to the “USER Function”...
  • Page 379: Date_Add Function

    DATE_ADD Function The DATE_ADD function adds the interval specified by interval_expression to datetime_expr. If the specified interval is in years or months, DATE_ADD normalizes the result. See “Standard Normalization” (page 337). The type of the datetime_expr is returned, unless the interval_expression contains any time components, then a timestamp is returned. DATE_ADD is a Neoview extension.
  • Page 380: Date_Sub Function

    DATE_SUB Function The DATE_SUB function subtracts the specified interval_expression from datetime_expr. If the specified interval is in years or months, DATE_SUB normalizes the result. See “Standard Normalization” (page 337). The type of the datetime_expr is returned, unless the interval_expression contains any time components, then a timestamp is returned. DATE_SUB is a Neoview extension.
  • Page 381: Dateadd Function

    DATEADD Function The DATEADD function adds the interval of time specified by datepart and num_expr to datetime_expr. If the specified interval is in years or months, DATEADD normalizes the result. See “Standard Normalization” (page 337). The type of the datetime_expr is returned, unless the interval expression contains any time components, then a timestamp is returned.
  • Page 382: Datediff Function

    DATEDIFF Function The DATEDIFF function returns the integer value for the number of datepart units of time between startdate and enddate. If enddate precedes startdate, the return value is negative or zero. DATEDIFF is a Neoview extension. DATEDIFF (datepart, startdate, enddate) datepart is YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, QUARTER, WEEK, or one of the following abbreviations...
  • Page 383: Dateformat Function

    The DATEFORMAT function returns a datetime value as a character string literal in the DEFAULT, USA, or EUROPEAN format. The data type of the result is CHAR. DATEFORMAT is a Neoview SQL extension. DATEFORMAT (datetime-expression,{DEFAULT | USA | EUROPEAN}) datetime-expression is an expression that evaluates to a datetime value of type DATE, TIME, or TIMESTAMP.
  • Page 384: Date_Part Function (Of An Interval)

    DATE_PART Function (of an Interval) The DATE_PART function extracts the datetime field specified by text from the interval value specified by interval and returns the result as an exact numeric value. The DATE_PART function accepts the specification of 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', or 'SECOND' for text.
  • Page 385: Date_Part Function (Of A Timestamp)

    DATE_PART Function (of a Timestamp) The DATE_PART function extracts the datetime field specified by text from the datetime value specified by datetime_expr and returns the result as an exact numeric value. The DATE_PART function accepts the specification of 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', or 'SECOND' for text.
  • Page 386: Date_Trunc Function

    DATE_TRUNC Function The DATE_TRUNC function returns a value of type TIMESTAMP, which has all fields of lesser precision than text set to zero (or 1 in the case of months or days). DATE_TRUNC is a Neoview extension. DATE_TRUNC(text, datetime_expr) text specifies 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', or 'SECOND'.
  • Page 387: Day Function

    The DAY function converts a DATE or TIMESTAMP expression into an INTEGER value in the range 1 through 31 that represents the corresponding day of the month. The result returned by the DAY function is equal to the result returned by the DAYOFMONTH function. DAY is a Neoview SQL extension. DAY (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP.
  • Page 388: Dayname Function

    DAYNAME Function The DAYNAME function converts a DATE or TIMESTAMP expression into a character literal that is the name of the day of the week (Sunday, Monday, and so on). DAYNAME is a Neoview SQL extension. DAYNAME (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 389: Dayofmonth Function

    1 through 31 that represents the corresponding day of the month. The result returned by the DAYOFMONTH function is equal to the result returned by the DAY function. DAYOFMONTH is a Neoview SQL extension. DAYOFMONTH (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP.
  • Page 390: Dayofweek Function

    The DAYOFWEEK function converts a DATE or TIMESTAMP expression into an INTEGER value in the range 1 through 7 that represents the corresponding day of the week. The value 1 represents Sunday, 2 represents Monday, and so forth. DAYOFWEEK is a Neoview SQL extension. DAYOFWEEK (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP.
  • Page 391: Dayofyear Function

    DAYOFYEAR Function The DAYOFYEAR function converts a DATE or TIMESTAMP expression into an INTEGER value in the range 1 through 366 that represents the corresponding day of the year. DAYOFYEAR is a Neoview SQL extension. DAYOFYEAR (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 392: Decode Function

    DECODE Function The DECODE function compares expr to each test_expr value one by one in the order provided. If expr is equal to a test_expr, then the corresponding retval is returned. If no match is found, default is returned. If no match is found and default is omitted, NULL is returned.
  • Page 393: Examples Of Decode

    DECODE((?P1 || ?P2),(‘ ’ TRIM ?P1), ‘Hi’, ?P3, NULL) *** ERROR[8822] The statement was not prepared. The last ret-val is an explicit NULL. When Neoview SQL encounters this situation, it assumes that the return value will be NUMERIC(18,6). Once Neoview SQL determines that the return values are numeric, it determines that all possible return values must be numeric.
  • Page 394 When ‘Hi’ is encountered in a ret-val position, the error is produced because the CHAR(2) type argument is not comparable with a NUMERIC(18,6) type return value. This statement is equivalent and will not produce an error: SELECT decode( (?p1 || ?p2), trim(?p1), ‘Hi’ ) from emp; SQL Functions and Expressions...
  • Page 395: Degrees Function

    DEGREES Function The DEGREES function converts a numeric value expression expressed in radians to the number of degrees. DEGREES is a Neoview SQL extension. DEGREES (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the DEGREES function.
  • Page 396: Diff1 Function

    DIFF1 computation could result in a divisor of zero. Datetime Arguments In general, Neoview SQL does not allow division by a value of INTERVAL data type. However, to permit use of the two-argument version of DIFF1 with times and dates, Neoview SQL relaxes this restriction and allows division by a value of INTERVAL data type.
  • Page 397 --- 5 row(s) selected. Note that the first row retrieved displays null because the offset from the current row does not fall within the results set. • Retrieve the difference between the TS column in the current row and the TS column in the previous row: SELECT DIFF1 (TS) AS DIFF1_TS FROM mining.seqfcn...
  • Page 398: Diff2 Function

    DIFF1 computation could result in a divisor of zero. Datetime Arguments In general, Neoview SQL does not allow division by a value of INTERVAL data type. However, to permit use of the two-argument version of DIFF2 with times and dates, Neoview SQL relaxes this restriction and allows division by a value of INTERVAL data type.
  • Page 399 Note that the results are equal to the difference of DIFF1(I1) for the current row and DIFF1(I1) of the previous row. For example, in the third row of the output of this example, -31075 is equal to -9116 minus 21959. The value -9116 is the result of DIFF1(I1) for the current row, and the value 21959 is the result of DIFF1(I1) for the previous row.
  • Page 400: Exp Function

    EXP Function This function returns the exponential value (to the base e) of a numeric value expression. EXP is a Neoview SQL extension. EXP (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the EXP function.
  • Page 401: Explain Function

    Obtaining an EXPLAIN Plan While Queries Are Running Neoview SQL provides the ability to capture an EXPLAIN plan for a query at any time while the query is running with the QID option. By default, this behavior is disabled for a Neoview session.
  • Page 402 Statement name; truncated on the right if longer than 60 characters. PLAN_ID LARGEINT Unique system-generated plan ID automatically assigned by Neoview SQL; generated at compile time. SEQ_NUM Sequence number of the current operator in the operator tree; indicates the sequence in which the operator tree is generated.
  • Page 403: Examples Of Explain Function

    The DETAIL_COST column of the EXPLAIN function results contains these cost factors: CPU_TIME An estimate of the number of seconds of processor time it might take to execute the instructions for this operator. A value of 1.0 is 1 second. IO_TIME An estimate of the number of seconds of I/O time (seeks plus data transfer) to perform the I/O for this operator.
  • Page 404: Extract Function

    EXTRACT Function The EXTRACT function extracts a datetime field from a datetime or interval value expression. It returns an exact numeric value. EXTRACT (datetime-field FROM extract-source) datetime-field is: YEAR | MONTH | DAY | HOUR | MINUTE | SECOND extract-source is: datetime-expression | interval-expression “Datetime Value Expressions”...
  • Page 405: Floor Function

    FLOOR Function The FLOOR function returns the largest integer, represented as a FLOAT data type, less than or equal to a numeric value expression. FLOOR is a Neoview SQL extension. FLOOR (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the FLOOR function.
  • Page 406: Hour Function

    HOUR Function The HOUR function converts a TIME or TIMESTAMP expression into an INTEGER value in the range 0 through 23 that represents the corresponding hour of the day. HOUR is a Neoview SQL extension. HOUR (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type TIME or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 407: Insert Function

    Every character, including multibyte characters, is treated as one character. INSERT is a Neoview SQL extension. INSERT (char-expr-1, start, length, char-expr-2) char-expr-1, char-expr-2 are SQL character value expressions (of data type CHAR or VARCHAR) that specify two strings of characters.
  • Page 408: Isnull Function

    ISNULL Function The ISNULL function returns the value of the first argument if it is not null, otherwise it returns the value of the second argument. Both expressions must be of comparable types. ISNULL is a Neoview extension. ISNULL(ck_expr, repl_value) ck_expr an expression of any valid SQL data type.
  • Page 409: Juliantimestamp Function

    YEAR through SECOND, Neoview SQL extends the value before converting it to a Julian timestamp. Datetime fields to the left of the specified datetime value are set to current date fields. Datetime fields to the right of the specified datetime value are set to zero.
  • Page 410: Lastnotnull Function

    SEQUENCE BY clause in a SELECT statement. “SEQUENCE BY Clause” (page 326). LASTNOTNULL is a Neoview SQL extension. LASTNOTNULL (column-expression) column-expression specifies a derived column determined by the evaluation of the column expression. If only null values have been returned, LASTNOTNULL returns null.
  • Page 411: Lcase Function

    416). LCASE returns a string of fixed-length or variable-length character data, depending on the data type of the input string. LCASE is a Neoview SQL extension. LCASE (character-expression) character-expression is an SQL character value expression that specifies a string of characters to downshift. See “Character Value Expressions”...
  • Page 412: Left Function

    LEFT Function The LEFT function returns the leftmost specified number of characters from a character expression. Every character, including multibyte characters, is treated as one character. LEFT is a Neoview SQL extension. LEFT (character-expr, count) character-expr specifies the source string from which to return the leftmost specified number of characters.
  • Page 413: Locate Function

    NULL. See “Character Value Expressions” (page 255). Neoview SQL returns the result as a 2-byte signed integer with a scale of zero. If substring-expression is not found in source-expression, Neoview SQL returns 0. Considerations for LOCATE Result of LOCATE If the length of source-expression is zero and the length of substring-expression is greater than zero, Neoview SQL returns 0.
  • Page 414: Log Function

    LOG Function The LOG function returns the natural logarithm of a numeric value expression. LOG is a Neoview SQL extension. LOG (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the LOG function. The value of the argument must be greater than zero. See “Numeric Value...
  • Page 415: Log10 Function

    LOG10 Function The LOG10 function returns the base 10 logarithm of a numeric value expression. LOG10 is a Neoview SQL extension. LOG10 (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the LOG10 function.
  • Page 416: Lower Function

    LOWER Function • “Considerations for LOWER” • “Example of LOWER” The LOWER function downshifts alphanumeric characters. For non-alphanumeric characters, LOWER returns the same character. LOWER can appear anywhere in a query where a value can be used, such as in a select list, an ON clause, a WHERE clause, a HAVING clause, a LIKE predicate, an expression, or as qualifying a new value in an UPDATE or INSERT statement.
  • Page 417: Lpad Function

    LPAD Function The LPAD function pads the left side of a string with the specified string. Every character in the string, including multibyte characters, is treated as one character. LPAD is a Neoview extension. LPAD (str, len [,padstr]) can be an expression. See “Character Value Expressions”...
  • Page 418: Ltrim Function

    TRIM function and specify the value of the character. the“TRIM Function” (page 480). LTRIM is a Neoview SQL extension. LTRIM (character-expression) character-expression is an SQL character value expression and specifies the string from which to trim leading spaces.
  • Page 419: Max/Maximum Function

    MAX/MAXIMUM Function MAX is an aggregate function that returns the maximum value within a set of values. MAXIMUM is the equivalent of MAX wherever the function name MAX appears within a statement. The data type of the result is the same as the data type of the argument. MAX | MAXIMUM ([ALL | DISTINCT] expression) ALL | DISTINCT specifies whether duplicate values are included in the computation of the maximum of the...
  • Page 420: Min Function

    MIN Function MIN is an aggregate function that returns the minimum value within a set of values. The data type of the result is the same as the data type of the argument. MIN ([ALL | DISTINCT] expression) ALL | DISTINCT specifies whether duplicate values are included in the computation of the minimum of the expression.
  • Page 421: Minute Function

    MINUTE Function The MINUTE function converts a TIME or TIMESTAMP expression into an INTEGER value, in the range 0 through 59, that represents the corresponding minute of the hour. MINUTE is a Neoview SQL extension. MINUTE (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type TIME or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 422: Mod Function

    MOD Function The MOD function returns the remainder (modulus) of an integer value expression divided by an integer value expression. MOD is a Neoview SQL extension. MOD (integer-expression-1,integer-expression-2) integer-expression-1 is an SQL numeric value expression of data type SMALLINT, INTEGER, or LARGEINT that specifies the value for the dividend argument of the MOD function.
  • Page 423: Month Function

    MONTH Function The MONTH function converts a DATE or TIMESTAMP expression into an INTEGER value in the range 1 through 12 that represents the corresponding month of the year. MONTH is a Neoview SQL extension. MONTH (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 424: Monthname Function

    MONTHNAME Function The MONTHNAME function converts a DATE or TIMESTAMP expression into a character literal that is the name of the month of the year (January, February, and so on). MONTHNAME is a Neoview SQL extension. MONTHNAME (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 425: Movingavg Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). MOVINGAVG is a Neoview SQL extension. MOVINGAVG (column-expression,integer-expression [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 426: Movingcount Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). MOVINGCOUNT is a Neoview SQL extension. MOVINGCOUNT (column-expression,integer-expression [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 427: Movingmax Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). MOVINGMAX is a Neoview SQL extension. MOVINGMAX (column-expression,integer-expression [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 428: Movingmin Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). MOVINGMIN is a Neoview SQL extension. MOVINGMIN (column-expression,integer-expression [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 429: Movingstddev Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). MOVINGSTDDEV is a Neoview SQL extension. MOVINGSTDDEV (column-expression,integer-expression [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 430 -------------------- .000 15527.357 14802.016 15115.012 6036.275 --- 5 row(s) selected. SQL Functions and Expressions...
  • Page 431: Movingsum Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). MOVINGSUM is a Neoview SQL extension. MOVINGSUM (column-expression,integer-expression [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 432: Movingvariance Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). MOVINGVARIANCE is a Neoview SQL extension. MOVINGVARIANCE (column-expression,integer-expression [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 433 .000 241098840.500 219099697.000 228463602.333 36436621.000 --- 5 row(s) selected. MOVINGVARIANCE Function...
  • Page 434: Nullif Function

    NULLIF Function The NULLIF function compares the value of two expressions. Both expressions must be of comparable types. The return value is NULL when the two expressions are equal. Otherwise, the return value is the value of the first expression. NULLIF(expr1, expr2) expr1 an expression to be compared.
  • Page 435: Nullifzero Function

    NULLIFZERO Function The NULLIFZERO function returns the value of the expression if that value is not zero. It returns NULL if the value of the expression is zero. NULLIFZERO (expression) expression specifies a value expression. It must be a numeric data type. Examples of NULLIFZERO •...
  • Page 436: Nvl Function

    If operand is a null value, NVL returns new-operand. If operand is not a null value, NVL returns operand. The operand and new-operand can be a column name, subquery, Neoview SQL string functions, math functions, or constant values. Examples of NVL •...
  • Page 437: Octet_Length Function

    Considerations for OCTET_LENGTH CHAR and VARCHAR Operands For a column declared as fixed CHAR, Neoview SQL returns the length of that column as the maximum number of storage bytes. For a VARCHAR column, Neoview SQL returns the length of the string stored in that column as the actual number of storage bytes.
  • Page 438: Offset Function

    The OFFSET function is a sequence function that retrieves columns from previous rows of an intermediate result table ordered by a SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). OFFSET is a Neoview SQL extension. OFFSET (column-expression,number-rows [,max-rows]) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 439: Pi Function

    PI Function The PI function returns the constant value of pi as a floating-point value. PI is a Neoview SQL extension. PI() Example of PI This constant function returns the value 3.14159260000000000E+000: PI() PI Function...
  • Page 440: Position Function

    NULL. See “Character Value Expressions” (page 255). Neoview SQL returns the result as a 2-byte signed integer with a scale of zero. If substring-expression is not found in source-expression, Neoview SQL returns zero. Considerations for POSITION Result of POSITION If the length of source-expression is zero and the length of substring-expression is greater than zero, Neoview SQL returns 0.
  • Page 441: Power Function

    POWER Function The POWER function returns the value of a numeric value expression raised to the power of an integer value expression. You can also use the exponential operator **. POWER is a Neoview SQL extension. POWER (numeric-expression-1,numeric-expression-2) numeric-expression-1, numeric-expression-2 are SQL numeric value expressions that specify the values for the base and exponent arguments of the POWER function.
  • Page 442: Quarter Function

    The QUARTER function converts a DATE or TIMESTAMP expression into an INTEGER value in the range 1 through 4 that represents the corresponding quarter of the year. Quarter 1 represents January 1 through March 31, and so on. QUARTER is a Neoview SQL extension. QUARTER (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP.
  • Page 443: Radians Function

    RADIANS Function The RADIANS function converts a numeric value expression (expressed in degrees) to the number of radians. RADIANS is a Neoview SQL extension. RADIANS (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the RADIANS function.
  • Page 444: Rank/Runningrank Function

    RANK/RUNNINGRANK Function The RANK/RUNNINGRANK function is a sequence function that returns the rank of the given value of an intermediate result table ordered by a SEQUENCE BY clause in a SELECT statement. RANK is an alternative syntax for RANK/RUNNINGRANK. RANK/RUNNINGRANK is a Neoview extension. RUNNINGRANK(expression) | RANK(expression) expression specifies the expression on which to perform the rank.
  • Page 445 null • Return the rank of I1: SELECT I1, RUNNINGRANK (I1) AS RANK FROM cat.sch.seqfcn SEQUENCE BY I1; RANK ----------- -------------------- --- 8 row(s) selected. • Return the rank of I1 descending: SELECT I1, RUNNINGRANK (I1) AS RANK FROM cat.sch.seqfcn SEQUENCE BY I1 DESC;...
  • Page 446 --- 8 row(s) selected. Notice that the two NULL values received the same rank. • Return the rank of I2 descending, using the alternative RANK syntax: SELECT I2, RANK (I2) AS RANK FROM cat.sch.seqfcn SEQUENCE BY I2 DESC; RANK ----------- -------------------- --- 8 row(s) selected.
  • Page 447: Repeat Function

    REPEAT Function The REPEAT function returns a character string composed of the evaluation of a character expression repeated a specified number of times. REPEAT is a Neoview SQL extension. REPEAT (character-expr, count) character-expr specifies the source string from which to return the specified number of repeated strings.
  • Page 448: Replace Function

    All three character value expressions must be comparable types and must use the same character set. The return value is the VARCHAR type. REPLACE is a Neoview SQL extension. REPLACE (char-expr-1, char-expr-2, char-expr-3) char-expr-1, char-expr-2, char-expr-3 are SQL character value expressions.
  • Page 449: Right Function

    RIGHT Function The RIGHT function returns the rightmost specified number of characters from a character expression. Every character, including multibyte characters, is treated as one character. RIGHT is a Neoview SQL extension. RIGHT (character-expr, count) character-expr specifies the source string from which to return the rightmost specified number of characters.
  • Page 450: Round Function

    ROUND Function The ROUND function returns the value of numeric_expr rounded to num places to the right of the decimal point. ROUND is a Neoview extension. ROUND(numeric_expr [ , num ] ) numeric_expr is an SQL numeric value expression. specifies the number of places to the right of the decimal point for rounding. If num is a negative number, all places to the right of the decimal point and num places to the left of the decimal point are zeroed.
  • Page 451: Rows Since Function

    If a row is reached where the condition is true, ROWS SINCE returns the number of rows counted so far. Otherwise, if the condition is never true within the result table being considered, ROWS SINCE returns null. Neoview SQL then goes to the next row as the new current row. Examples of ROWS SINCE •...
  • Page 452 (EXPR) (EXPR) --------------- --------------- --- 5 row(s) selected. SQL Functions and Expressions...
  • Page 453: Rows Since Changed Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). ROWS SINCE CHANGED is a Neoview SQL extension. ROWS SINCE CHANGED (column-expression-list) column-expression-list is a comma-separated list that specifies a derived column list determined by the evaluation of the column expression list.
  • Page 454: Rpad Function

    RPAD Function The RPAD function pads the right side of a string with the specified string. Every character in the string, including multibyte characters, is treated as one character. RPAD is a Neoview extension. RPAD (str, len [,padstr]) can be an expression. See “Character Value Expressions”...
  • Page 455: Rtrim Function

    TRIM function and specify the value of the character. See the “TRIM Function” (page 480). RTRIM is a Neoview SQL extension. RTRIM (character-expression) character-expression is an SQL character value expression and specifies the string from which to trim trailing spaces.
  • Page 456: Runningavg Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). RUNNINGAVG is a Neoview SQL extension. RUNNINGAVG (column-expression) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 457: Runningcount Function

    SELECT statement. See “SEQUENCE BY Clause” (page 326). RUNNINGCOUNT is a Neoview SQL extension. RUNNINGCOUNT {(*) | (column-expression)} as an argument causes RUNNINGCOUNT(*) to return the number of rows in the intermediate result table up to and including the current row.
  • Page 458: Runningmax Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). RUNNINGMAX is a Neoview SQL extension. RUNNINGMAX (column-expression) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 459: Runningmin Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). RUNNINGMIN is a Neoview SQL extension. RUNNINGMIN (column-expression) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 460: Runningstddev Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). RUNNINGSTDDEV is a Neoview SQL extension. RUNNINGSTDDEV (column-expression) column-expression specifies a derived column determined by the evaluation of the column expression. RUNNINGSTDDEV returns the standard deviation of nonnull values of column-expression up to and including the current row.
  • Page 461: Runningsum Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). RUNNINGSUM is a Neoview SQL extension. RUNNINGSUM (column-expression) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 462: Runningvariance Function

    SEQUENCE BY clause in a SELECT statement. See “SEQUENCE BY Clause” (page 326). RUNNINGVARIANCE is a Neoview SQL extension. RUNNINGVARIANCE (column-expression) column-expression specifies a derived column determined by the evaluation of the column expression.
  • Page 463: Second Function

    SECOND Function The SECOND function converts a TIME or TIMESTAMP expression into an INTEGER value in the range 0 through 59 that represents the corresponding second of the hour. SECOND is a Neoview SQL extension. SECOND (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type TIME or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 464: Sign Function

    The SIGN function returns an indicator of the sign of a numeric value expression. If the value is less than zero, the function returns -1 as the indicator. If the value is zero, the function returns 0. If the value is greater than zero, the function returns 1. SIGN is a Neoview SQL extension. SIGN (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the SIGN function.
  • Page 465: Sin Function

    SIN Function The SIN function returns the sine of a numeric value expression, where the expression is an angle expressed in radians. SIN is a Neoview SQL extension. SIN (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the SIN function.
  • Page 466: Sinh Function

    SINH Function The SINH function returns the hyperbolic sine of a numeric value expression, where the expression is an angle expressed in radians. SINH is a Neoview SQL extension. SINH (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the SINH function.
  • Page 467: Space Function

    SPACE Function The SPACE function returns a character string consisting of a specified number of spaces, each of which is 0x20 or 0x0020, depending on the chosen character set. SPACE is a Neoview SQL extension. SPACE (length [,char-set-name]) length specifies the number of characters to be returned. The number count must be a value greater than or equal to zero of exact numeric data type and with a scale of zero.
  • Page 468: Sqrt Function

    SQRT Function The SQRT function returns the square root of a numeric value expression. SQRT is a Neoview SQL extension. SQRT (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the SQRT function. The value of the argument must not be a negative number. See “Numeric Value...
  • Page 469: Stddev Function

    Because the definition of variance has N-1 in the denominator of the expression (if weight is not specified), Neoview SQL returns a system-defined default setting of zero (and no error) if the number of rows in the table, or a group of the table, is equal to 1.
  • Page 470: Examples Of Stddev

    Examples of STDDEV • Compute the standard deviation of the salary of the current employees: SELECT STDDEV(salary) AS StdDev_Salary FROM persnl.employee; STDDEV_SALARY ------------------------- 3.57174062500000000E+004 --- 1 row(s) selected. • Compute the standard deviation of the cost of parts in the current inventory: SELECT STDDEV (price * qty_available) FROM sales.parts;...
  • Page 471: Substring/Substr Function

    SUBSTRING/SUBSTR Function The SUBSTRING function extracts a substring out of a given character expression. It returns a character string of data type VARCHAR, with a maximum length equal to the smaller of these two: • The fixed length of the input string (for CHAR-type strings) or the maximum variable length (for VARCHAR-type strings) •...
  • Page 472: Examples Of Substring/Substr

    • If the start position is greater than the length of the character expression, an empty string ('') is returned. • The resulting substring is always of type VARCHAR. If the source character string is an upshifted CHAR or VARCHAR string, the result is an upshifted VARCHAR type. Examples of SUBSTRING/SUBSTR •...
  • Page 473: Sum Function

    SUM Function SUM is an aggregate function that returns the sum of a set of numbers. SUM ([ALL | DISTINCT] expression) ALL | DISTINCT specifies whether duplicate values are included in the computation of the SUM of the expression. The default option is ALL, which causes duplicate values to be included. If you specify DISTINCT, duplicate values are eliminated before the SUM function is applied.
  • Page 474: Tan Function

    TAN Function The TAN function returns the tangent of a numeric value expression, where the expression is an angle expressed in radians. TAN is a Neoview SQL extension. TAN (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the TAN function.
  • Page 475: Tanh Function

    TANH Function The TANH function returns the hyperbolic tangent of a numeric value expression, where the expression is an angle expressed in radians. TANH is a Neoview SQL extension. TANH (numeric-expression) numeric-expression is an SQL numeric value expression that specifies the value for the argument of the TANH function.
  • Page 476: This Function

    If a row is reached where the condition is true, ROWS SINCE returns the number of rows counted so far. Otherwise, if the condition is never true within the result table being considered, ROWS SINCE returns null. Neoview SQL then goes to the next row as the new current row and the THIS constant is reevaluated.
  • Page 477: Timestampadd Function

    TIMESTAMPADD Function The TIMESTAMPADD function adds the interval of time specified by interval-ind and num_expr to datetime_expr. If the specified interval is in years, months, or quarters and the resulting date is not a valid date, the day will be rounded down to the last day of the result month.
  • Page 478: Timestampdiff Function

    TIMESTAMPDIFF Function The TIMESTAMPDIFF function returns the integer value for the number of interval-ind units of time between startdate and enddate. If enddate precedes startdate, the return value is negative or zero. TIMESTAMPDIFF (interval-ind, startdate, enddate) interval-ind is SQL_TSI_YEAR, SQL_TSI_MONTH, SQL_TSI_DAY, SQL_TSI_HOUR, SQL_TSI_MINUTE, SQL_TSI_SECOND, SQL_TSI_QUARTER, or SQL_TSI_WEEK startdate and enddate are each of type DATE or TIMESTAMP...
  • Page 479: Translate Function

    UCS2 character set no data loss is possible. However, when Neoview SQL translates a character-value-expression from UCS2, certain characters encoded in UTF16 cannot be converted to the target character set. Neoview SQL displays an error in this case.
  • Page 480: Trim Function

    TRIM Function The TRIM function removes leading and trailing characters from a character string. Every character, including multibyte characters, is treated as one character. TRIM ([[trim-type] [trim-char] FROM] trim-source) trim-type is: LEADING | TRAILING | BOTH trim-type specifies whether characters are to be trimmed from the leading end (LEADING), trailing end (TRAILING), or both ends (BOTH) of trim-source.
  • Page 481: Ucase Function

    483). UCASE returns a string of fixed-length or variable-length character data, depending on the data type of the input string. UCASE is a Neoview SQL extension. UCASE (character-expression) character-expression is an SQL character value expression that specifies a string of characters to upshift. See “Character Value Expressions”...
  • Page 482: Upper Function

    UPPER Function The UPPER function upshifts alphanumeric characters. For non-alphanumeric characters, UCASE returns the same character. UPPER can appear anywhere in a query where a value can be used, such as in a select list, an ON clause, a WHERE clause, a HAVING clause, a LIKE predicate, an expression, or as qualifying a new value in an UPDATE or INSERT statement.
  • Page 483: Upshift Function

    481). UPSHIFT returns a string of fixed-length or variable-length character data, depending on the data type of the input string. UPSHIFT is a Neoview SQL extension. UPSHIFT (character-expression) character-expression is an SQL character value expression that specifies a string of characters to upshift. See “Character Value Expressions”...
  • Page 484: User Function

    USER Function The USER function returns the user name that you logged in as. If you are logged in as the role, the role is returned. This function can be used anywhere in the query. The values returned are string datatype VARCHAR(64). USER The USER function is equivalent to the “CURRENT_USER Function”...
  • Page 485: Variance Function

    Because the definition of variance has N-1 in the denominator of the expression (when weight is not specified), Neoview SQL returns a default value of zero (and no error) if the number of rows in the table, or a group of the table, is equal to 1.
  • Page 486: Examples Of Variance

    where vi is the i-th value of expression, wi is the i-th value of weight, and N is the cardinality of the result table. Data Type of the Result The data type of the result is always DOUBLE PRECISION. Operands of the Expression The expression includes columns from the rows of the SELECT result table—but cannot include an aggregate function.
  • Page 487: Week Function

    Sunday of the year. The value 53 is returned for datetimes that occur in the last full or partial week of the year except for leap years that start on Saturday where December 31 is in the 54th full or partial week. WEEK is a Neoview SQL extension. WEEK (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP.
  • Page 488: Year Function

    YEAR Function The YEAR function converts a DATE or TIMESTAMP expression into an INTEGER value that represents the year. YEAR is a Neoview SQL extension. YEAR (datetime-expression) datetime-expression is an expression that evaluates to a datetime value of type DATE or TIMESTAMP. See “Datetime Value Expressions”...
  • Page 489: Zeroifnull Function

    ZEROIFNULL Function The ZEROIFNULL function returns a value of zero if the expression if NULL. Otherwise, it returns the value of the expression. ZEROIFNULL (expression) expression specifies a value expression. It must be a numeric data type. Example of ZEROIFNULL ZEROIFNULL returns the value of the column named salary whenever the column value is not NULL and it returns 0 whenever the column value is NULL.
  • Page 491: Olap Functions

    7 OLAP Functions This section describes the syntax and semantics of the On Line Analytical Process (OLAP) window functions. The OLAP window functions are ANSI compliant. Considerations for Window Functions These considerations apply to all window functions. inline-window-specification The window defined by the inline-window-specification consists of the rows specified by the window-frame-clause, bounded by the current partition.
  • Page 492: Limitations For Window Functions

    SELECT num, workgroupnum, annualsalary, SUM(AnnualSalary) OVER (ORDER BY SUM(annualsalary)*num ROWS UNBOUNDED PRECEDING), AVG(AnnualSalary) OVER (ORDER BY SUM(annualsalary)*num ROWS UNBOUNDED PRECEDING), MIN(AnnualSalary) OVER (ORDER BY SUM(annualsalary)*num ROWS UNBOUNDED PRECEDING), MAX(AnnualSalary) OVER (ORDER BY SUM(annualsalary)*num ROWS UNBOUNDED PRECEDING), VARIANCE(AnnualSalary) OVER (ORDER BY SUM(annualsalary)*num ROWS UNBOUNDED PRECEDING), STDDEV(AnnualSalary) OVER (ORDER BY SUM(annualsalary)*num ROWS UNBOUNDED PRECEDING),...
  • Page 493: Avg Window Function

    AVG Window Function AVG is a window function that returns the average of nonnull values of the given expression for the current window specified by the inline-window specification. AVG ([ALL] expression) OVER (inline-window-specification) inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] [ window-frame-clause ]...
  • Page 494 SELECT deptnum, empnum, AVG(SALARY) OVER (PARTITION BY deptnum ORDER BY empnum ROWS 3 PRECEDING) FROM persnl.employee; OLAP Functions...
  • Page 495: Count Window Function

    COUNT Window Function COUNT is a window function that returns the count of the non null values of the given expression for the current window specified by the inline-window-specification. COUNT {(*) | ([ALL] expression) } OVER inline-window-specification inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] [ window-frame-clause ]...
  • Page 496 SELECT deptnum, empnum, COUNT(salary) OVER (PARTITION BY deptnum ORDER BY empnum ROWS 3 PRECEDING) FROM persnl.employee; • Return the running count of employees within each department: SELECT deptnum, empnum, COUNT(*) OVER (PARTITION BY deptnum ORDER BY empnum ROWS UNBOUNDED PRECEDING) FROM persnl.employee;...
  • Page 497: Dense_Rank Window Funtion

    DENSE_RANK Window Funtion DENSE_RANK is a window function that returns the ranking of each row of the current partition specified by the inline-window-specification. The ranking is relative to the ordering specified in the inline-window-specification. The return value of DENSE_RANK starts at 1 for the first row of the window.
  • Page 498: Max Window Function

    MAX Window Function MAX is a window function that returns the maximum value of all non null values of the given expression for the current window specified by the inline-window-specification. MAX ([ALL] expression) OVER (inline-window-specification) inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] [ window-frame-clause ]...
  • Page 499 SELECT deptnum, empnum, MAX(salary) OVER (PARTITION BY deptnum ORDER BY empnum ROWS 3 PRECEDING) FROM persnl.employee; MAX Window Function...
  • Page 500: Min Window Function

    MIN Window Function MIN is a window function that returns the minimum value of all non null values of the given expression for the current window specified by the inline-window-specification. MIN ([ALL] expression) OVER (inline-window-specification) inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] [ window-frame-clause ]...
  • Page 501 SELECT deptnum, empnum, MIN(salary) OVER (PARTITION BY deptnum ORDER BY empnum ROWS 3 PRECEDING) FROM persnl.employee; MIN Window Function...
  • Page 502: Rank Window Function

    RANK Window Function RANK is a window function that returns the ranking of each row of the current partition specified by the inline-window-specification. The ranking is relative to the ordering specified in the inline-window-specification. The return value of RANK starts at 1 for the first row of the window. Values that are equal have the same rank.
  • Page 503: Row_Number Window Function

    ROW_NUMBER Window Function ROW_NUMBER is a window function that returns the row number of each row of the current window specified by the inline-window-specification. ROW_NUMBER () OVER (inline-window-specification) inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] inline-window-specification specifies the window over which the ROW_NUMBER is computed.
  • Page 504: Stddev Window Function

    STDDEV Window Function STDDEV is a window function that returns the standard deviation of non null values of the given expression for the current window specified by the inline-window-specification. STDDEV ([ALL] expression) OVER (inline-window-specification) inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] [ window-frame-clause ]...
  • Page 505: Sum Window Function

    SUM Window Function SUM is a window function that returns the sum of non null values of the given expression for the current window specified by the inline-window-specification. SUM ([ALL] expression) OVER (inline-window-specification) inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] [ window-frame-clause ]...
  • Page 506 SELECT deptnum, empnum, SUM (salary) OVER (PARTITION BY deptnum ORDER BY empnum ROWS 3 PRECEDING) FROM persnl.employee; OLAP Functions...
  • Page 507: Variance Window Function

    VARIANCE Window Function VARIANCE is a window function that returns the variance of non null values of the given expression for the current window specified by the inline-window-specification. VARIANCE ([ALL] expression) OVER (inline-window-specification) inline-window-specification is: [PARTITION BY expression [, expression]...] [ORDER BY expression [ASC[ENDING] | DESC[ENDING]] [,expression [ASC[ENDING] | DESC[ENDING]]]...] [ window-frame-clause ]...
  • Page 509: A Mapping Tables

    A Mapping Tables The following tables list mappings for the UCS2 character set. Characters not listed in these tables use themselves as their uppercase mappings. Table A-1 One-to-One Uppercase and Titlecase to Lowercase Mappings L (x) L(x) L(x) L(x) L(x) L(x) 0041 0061...
  • Page 510 Table A-1 One-to-One Uppercase and Titlecase to Lowercase Mappings (continued) L (x) L(x) L(x) L(x) L(x) L(x) 00C6 00E6 01B2 028B 0420 0440 0556 0586 1EA6 1EA7 1FBB 1F71 00C7 00E7 01B3 01B4 0421 0441 10A0 10D0 1EA8 1EA9 1FBC 1FB3 00C8 00E8...
  • Page 511 Table A-1 One-to-One Uppercase and Titlecase to Lowercase Mappings (continued) L (x) L(x) L(x) L(x) L(x) L(x) 0118 0119 0202 0203 0496 0497 10C3 10F3 1EEE 1EEF 216F 217F 011A 011B 0204 0205 0498 0499 10C4 10F4 1EF0 1EF1 24B6 24D0 011C 011D...
  • Page 512: One-To-One Ucs2 Mappings

    Table A-1 One-to-One Uppercase and Titlecase to Lowercase Mappings (continued) L (x) L(x) L(x) L(x) L(x) L(x) 0162 0163 03A4 03C4 04E6 04E7 1E42 1E43 1F48 1F40 FF2A FF4A 0164 0165 03A5 03C5 04E8 04E9 1E44 1E45 1F49 1F41 FF2B FF4B 0166 0167...
  • Page 513 Table A-2 One-to-One UCS2 Mappings (continued) U (x) U(x) U(x) U(x) U(x) U(x) 006F 004F 01A3 01A2 03EB 03EA 04F3 04F2 1E91 1E90 1F82 1F8A 0070 0050 01A5 01A4 03ED 03EC 04F5 04F4 1E93 1E92 1F83 1F8B 0071 0051 01A8 01A7 03EF 03EE...
  • Page 514 Table A-2 One-to-One UCS2 Mappings (continued) U (x) U(x) U(x) U(x) U(x) U(x) 00F9 00D9 01FB 01FA 044E 042E 0582 0552 1EE1 1EE0 2173 2163 00FA 00DA 01FD 01FC 044F 042F 0583 0553 1EE3 1EE2 2174 2164 00FB 00DB 01FF 01FE 0451 0401...
  • Page 515: Two-Character Ucs2 Mapping

    Table A-2 One-to-One UCS2 Mappings (continued) U (x) U(x) U(x) U(x) U(x) U(x) 013C 013B 03AD 0388 0497 0496 1E3F 1E3E 1F31 1F39 24E7 24CD 013E 013D 03AE 0389 0499 0498 1E41 1E40 1F32 1F3A 24E8 24CE 0140 013F 03AF 038A 049B 049A...
  • Page 516 Table A-3 Two-Character UCS2 Mapping (continued) Titlecase characters Two-character uppercase expansions 0x0587 0x0535 0x0552 0x1E96 0x0048 0x0331 0x1E97 0x0054 0x0308 0x1E98 0x0057 0x030A 0x1E99 0x0059 0x030A 0x1E9A 0x0041 0x02BE 0x1F50 0x03A5 0x0313 0x1F80 0x1F08 0x0399 0x1F81 0x1F09 0x0399 0x1F82 0x1F0A 0x0399 0x1F83 0x1F0B 0x0399 0x1F84...
  • Page 517 Table A-3 Two-Character UCS2 Mapping (continued) Titlecase characters Two-character uppercase expansions 0x1F9D 0x1F2D 0x0399 0x1F9E 0x1F2E 0x0399 0x1F9F 0x1F2F 0x0399 0x1FA0 0x1F68 0x0399 0x1FA1 0x1F69 0x0399 0x1FA2 0x1F6A 0x0399 0x1FA3 0x1F6B 0x0399 0x1FA4 0x1F6C 0x0399 0x1FA5 0x1F6D 0x0399 0x1FA6 0x1F6E 0x0399 0x1FA7 0x1F6F 0x0399 0x1FA8...
  • Page 518: Three-Character Ucs2 Mapping

    Table A-3 Two-Character UCS2 Mapping (continued) Titlecase characters Two-character uppercase expansions 0x1FFC 0x03A9 0x0399 0xFB00 0x0046 0x0046 0xFB01 0x0046 0x0049 0xFB02 0x0046 0x004C 0xFB05 0x0053 0x0054 0xFB06 0x0053 0x0054 0xFB13 0x0544 0x0546 0xFB14 0x0544 0x0535 0xFB15 0x0544 0x053B 0xFB16 0x054E 0x0546 0xFB17 0x0544 0x053D Table A-4...
  • Page 519: B Reserved Words

    B Reserved Words The words listed in this appendix are reserved for use by Neoview SQL. To prevent syntax errors, avoid using these words as identifiers in Neoview SQL. In Neoview SQL, if an HP operating system name contains a reserved word, you must enclose the reserved word in double quotes (") to access that column or object.
  • Page 520: Reserved Sql Identifiers - E

    Table B-5 Reserved SQL Identifiers — E EACH ELSE ELSEIF END-EXEC EQUALS ESCAPE EXCEPT EXCEPTION EXEC EXECUTE EXISTS EXTERNAL EXTRACT Table B-6 Reserved SQL Identifiers — F FALSE FETCH FIRST FLOAT FOREIGN FOUND FRACTION FREE FROM FULL FUNCTION Table B-7 Reserved SQL Identifiers — G GENERAL GLOBAL GOTO...
  • Page 521: Reserved Sql Identifiers - N

    SQL_DECIMAL SQL_DOUBLE SQL_FLOAT SQL_INT SQL_INTEGER SQL_REAL SQL_SMALLINT SQL_TIME SQL_TIMESTAMP SQL_VARCHAR SQLCODE SQLERROR SQLEXCEPTION SQLSTATE SQLWARNING STRUCTURE SUBSTRING SYNONYM SYSTEM_USER Table B-20 Reserved SQL Identifiers — T TABLE TEMPORARY TERMINATE TEST THAN THEN THERE TIME TIMESTAMP TIMEZONE_HOUR Reserved Neoview SQL Identifiers...
  • Page 522: Reserved Sql Identifiers - U

    Table B-20 Reserved SQL Identifiers — T (continued) TIMEZONE_MINUTE TRAILING TRANSACTION TRANSLATE TRANSLATION TRANSPOSE TREAT TRIGGER TRIM TRUE Table B-21 Reserved SQL Identifiers — U UNDER UNION UNIQUE UNKNOWN UNNEST UPDATE UPPER UPSHIFT USAGE USER USING Table B-22 Reserved SQL Identifiers — V VALUE VALUES VARCHAR...
  • Page 523: C Limits

    C Limits This appendix lists limits for various parts of Neoview SQL Column names 128 characters in length. Constraints The maximum combined length of the columns for a PRIMARY KEY constraint is 2048 bytes. Indexes The maximum combined length of the columns for an index is 2048 bytes.
  • Page 525: D Standard Sql And Neoview Sql

    D Standard SQL and Neoview SQL This appendix describes Neoview SQL conformance to the SQL standards established by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO). It describes: • “ANSI SQL Standards” • “ISO Standards”...
  • Page 526: Neoview Sql Compliance

    The ANSI and ISO SQL standards require conformance claims to state the type of conformance and the implemented facilities. Neoview SQL products provide full or partial conformance. This table lists the Core SQL:1999 features for which Neoview SQL offers full conformance:...
  • Page 527 • E141-07 Column defaults (Neoview SQL specifies a subset of datetime value functions that Core '99 allows to be specified. Neoview SQL does not enforce the conformance rule that “Without Feature F411 “Time zone specification”, CURRENT_TIME and CURRENT_TIMESTAMP shall not be specified.”) Neoview SQL does not support these subfeatures: •...
  • Page 528 • F311-03 CREATE VIEW (without WITH CHECK OPTION and without Feature F081 “UNION and EXCEPT in views” Neoview SQL views cannot refer to tables created in the same CREATE SCHEMA) • F311-04 CREATE VIEW: WITH CHECK OPTION (Without support for Feature F081 “UNION and EXCEPT in views”...
  • Page 529: Neoview Sql Extensions To Standard Sql

    Neoview SQL provides many features that enhance or supplement the functionality of standard SQL. In your Neoview SQL applications, you can use these extensions just as you can use Core SQL:1999. This table shows the Non-Core extensions that Neoview SQL supports:...
  • Page 530 Neoview SQL relaxes SQL:1999's data type matching rule for UCS2 character set host variables for ease of use and better performance. A UCS2 host variable is assignment and comparison compatible with an ISO88591 value expression. Neoview SQL allows various SQL:1999's NATIONAL CHARACTER syntax to denote a predesignated character set.
  • Page 531: E Special Neoview Features-Enabled Upon Request

    You might also be unaware of precision and rounding differences. To ease your transition to Neoview, HP packages a set of other DBMS features. This set of features is controlled by a Mode_Special_2 toggle, which can be enabled or disabled by HP at your request.
  • Page 532: Features Supported In Mode_Special_2

    Precision and Scale of Arithmetic Operations The maximum precision is limited to 18. If an arithmetic computation exceeds this precision, Neoview SQL returns an overflow error. The scale of the result is computed using the semantics of your previous DBMS.
  • Page 533 The “Ignore Duplicate Keys” feature simulates SET table support and provides the same semantics with one exception: Rows with duplicate keys are ignored during insert operations. To disable this feature, contact HP Support for assistance in setting the IGNORE_DUPLICATE_KEYS default to 'OFF.'...
  • Page 535: Index

    33 UPDATE statement use of, 200 names, schemas, 304 Access privileges SQL standards, 525 stored procedures, 138 standards, Neoview SQL compliance, 526 tables, 136, 140 ASCII function ACOS function examples of, 347 examples of, 345 syntax diagram of, 347...
  • Page 536 Bulk replicator SPACE, 467 REPLICATE command, 224 SUBSTRING/SUBSTR, 471 TRANSLATE, 479 TRIM, 480 CALL statement UCASE, 481 considerations for, 56 UPPER, 482 description for, 56 UPSHIFT, 483 examples of, 57 Character string literals, 274 required privileges, 56 Character value expression syntax diagram of, 56 examples of, 256 usage restrictions, 56...
  • Page 537 , 90, 93 examples of, 371 IDENTITY column, 76, 88 syntax diagram of, 371 limits, 87 COUNT window function Neoview SQL extensions, 92 examples of, 495 partitioning, 87 syntax diagram of, 495 reserved table names, 86 CREATE INDEX statement...
  • Page 538 nullable keys, 80 Data Manipulation Language (DML) statements restrictions, 79 summary of, 38 SET table, example of, 94 DELETE statement, 108 suitable keys, 80 INSERT statement, 144 syntax diagram of, 72 MERGE INTO, 151 CROSS JOIN, description of, 67, 169 SELECT statement, 164 CURRENT_DATE function TABLE statement, 197...
  • Page 539 examples of, 386 examples of, 388 syntax diagram of, 386 syntax diagram of, 388 DATEADD function DAYOFMONTH function examples of, 381 examples of, 389 syntax diagram of, 381 syntax diagram of, 389 DATEDIFF function DAYOFWEEK function examples of, 382 examples of, 390 syntax diagram of, 382 syntax diagram of, 390 DATEFORMAT function...
  • Page 540 DISK POOL examples of, 118 considerations for, 92 syntax diagram of, 118 description for, 75 examples of, 93 restrictions for, 92 Embedded INSERT DISTINCT clause examples of, 183 aggregate functions, 175, 337 restrictions on, 174 AVG function use of, 351 Error messages, 35 COUNT function use of, 371 EST_TOTAL_COST field, 128...
  • Page 541 Expression HOUR function character (or string) value, 255 examples of, 406 datetime value, 257, 258, 262 syntax diagram of, 406 description of, 255 interval value, 258, 262 numeric value, 265 Identifiers, 269 Extended numeric precision, 246 IDENTITY column Extensions, statements, 34 altering, 49 EXTRACT function altering MAXVALUE and INCREMENT BY, 48...
  • Page 542 415 Limits syntax diagram of, 415 constraints, 523 Logical name IN predicate, 292 Neoview SQL objects, 242 indexes, 62, 523 Logical operators number of tables joined, 174 NOT, AND, OR, 305 tables, 87, 523 search condition use of, 305...
  • Page 543 LOWER function SIGN, 464 examples of, 416 SIN, 465 syntax diagram of, 416 SINH, 466 LPAD function SQRT, 468 examples of, 417 TAN, 474 syntax diagram of, 417 TANH, 475 LTRIM function ZEROIFNULL, 489 examples of, 418 syntax diagram of, 418 definition of, 65, 281 restrictions for, 67 MAX function...
  • Page 544 NCHAR data type, 248 SUM window function, 505 NCHAR VARYING data type, 249 VARIANCE window function, 507 Neoview SQL objects, logical names, 242 Operators in query execution plan, 124 NOT CASESPECIFIC, 78 OPTIONS ’e’ on Explain statement, 124 NOT NULL constraint, 237 OPTIONS ’f’...
  • Page 545 ORDER BY clause, 176 syntax diagram of, 442 SAMPLE statement, cluster sampling, 320 Query execution plan updating rows, 200 displayed, 124 Persistent sample tables, 207 in running query, 125 PI function operators, 124 examples of, 439 reviewing, 124 syntax diagram of, 439 Query expression POPULATE INDEX utility SELECT statement use of, 167...
  • Page 546 Reserved syntax diagram of, 454 schemas for HP, 70 RTRIM function table names, 86 examples of, 455 words, Neoview SQL, 519 syntax diagram of, 455 Resource control statements , 38 RUNNINGAVG function EXECUTE statement, 121 equivalent definition, 456 LOCK TABLE statement, 149...
  • Page 547 467 RUNNINGAVG, 456 syntax diagram of, 467 RUNNINGCOUNT, 457 SQL statements RUNNINGMAX, 458 ANSI compliant, 33 RUNNINGMIN, 459 Neoview SQL extensions, 34 RUNNINGSTDDEV, 460 SQL Utilities RUNNINGSUM, 461 MAINTAIN command, 212 RUNNINGVARIANCE, 462 POPULATE INDEX utility, 220 THIS, 476...
  • Page 548 471 Statement atomicity syntax diagram of, 471 automatic, 28 Suitable keys description of, 28 Neoview SQL guidelines for selecting, 80 Statements, SQL SUM function ANSI compliant, 33 DISTINCT clause within, 473 Neoview SQL extensions, 34 examples of, 473...
  • Page 549 Transaction control statements considerations, 207 BEGIN WORK, 55 examples of, 209 COMMIT WORK, 59 histogram tables, 205 ROLLBACK WORK, 163 persistent sample tables, 207 SET TRANSACTION statement, 188 syntax diagram of, 204 Transaction isolation levels UPPER function READ COMMITTED, 32 examples of, 482 READ UNCOMMITTED, 32 syntax diagram of, 482...
  • Page 550 example of, 487 syntax diagram of, 487 window functions AVG , 493 considerations, 491 COUNT , 495 DENSE_RANK , 497 limitations, 492 MAX , 498 MIN , 500 ORDER BY clause, use of, 491 RANK , 502 ROW_NUMBER, 503 STDDEV, 504 SUM, 505 VARIANCE, 507 YEAR function...

Table of Contents