Skip to main content

skip to main content

developerWorks  >  Information Management  >

Selected common SQL features for developers of portable DB2 applications

developerWorks
Document options

Document options requiring JavaScript are not displayed


Rate this page

Help us improve this content


Level: Introductory

IBM staff (dwinfo@us.ibm.com), Staff, IBM

12 Sep 2006

Are you writing SQL applications that need to be portable across platforms? Here's the information you need to make sure your applications are portable. The tables in this article summarize the common SQL application features and make it easy for you to develop applications using SQL that is portable across the DB2® family, including DB2 for z/OS® , DB2 for i5/OS® , and DB2 for Linux®, UNIX®, and Windows® .

Introduction

IBM is committed to delivering SQL features that are important to our customers on all platforms in a way that is common and portable and supports the ANSI/ISO SQL standards. A feature may not be available on all DB2 products on exactly the same date. In some cases, this is only because the different DB2 products ship on slightly different schedules. In other cases, this is because customer requirements may accelerate development of an SQL feature on a specific DB2 product.

Many of IBM's database customers and independent software vendors have expressed interest in writing portable applications across multiple platforms. Others prefer to develop using, say DB2 for Windows, and then deploy the application on DB2 for z/OS. These application developers have asked us to provide them with a list of common SQL language capabilities as a quick reference.

This summary version of the common SQL application features is intended to be a quick reference and includes the frequently used features and functions across the platforms. For more detailed information, please consult the SQL Reference for Cross-Platform Development (PDF 2.7 MB) and the respective DB2 product SQL Reference books.

Please read the disclaimer before using the tables.



Back to top


Products included

  • DB2 9 for Linux, UNIX, and Windows
  • DB2 V9.1 for z/OS
  • DB2 V5 R4 for i5/OS


Back to top


Contents


Key
Y Product includes full support.
P Product includes partial support; check product information.

Basic elements
Language elementLUWz/OSi5/OSNotes
Identifiers -OrdinaryYYY
Identifiers -DelimitedYYY
Identifiers with support of lowercase letters and trailing underscoresYYY
Casting of Data Types -ImplicitYYY
Automatic data conversion based on code pageYYY
ConstantsYYY
Hex specification of character constantsYYY
Null valuesYYY
Column referencesYYY
Host Variable ReferencesYYY
Indicator variablesYYY
Host StructuresYYY
"Friendly" arithmetic and conversionYYY
Arithmetic operatorsYYY
String ConcatenationYYY
Scalar subselect as expressionYYY
Scalar fullselect as expressionYYY
Date/Time ArithmeticYYY
CASE expressionYYY
CAST specificationYYY
Sequence reference (NEXT VALUE and PREVIOUS VALUE)YYY
OLAP ranking specification (RANK, DENSE_RANK)YYY
OLAP numbering specification (ROW_NUMBER)YYY
Diagnostic AreaYYY


Data types
Language elementLUWz/OSi5/OSNotes
SMALLINTYYY
INTEGERYYY
BIGINTYYY
DECIMALYYY
NUMERICYYYNUMERIC is defined as zoned decimal on DB2 for i5/OS and packed decimal on other platforms.
REALYYYFor portability across platforms, do not use FLOAT(n).
DOUBLE or FLOATYYYFor portability across platforms, do not use FLOAT(n).
CHARACTERYYY
VARCHARYYY
FOR BIT DATA with CHAR or VARCHARYYY
CLOBYYY
FOR SBCS or MIXED DATA with CHAR, VARCHAR, or CLOBPYY
BLOBYYY
GRAPHICYYY
VARGRAPHICYYY
DBCLOBYYY
DATEYYY
TIMEYYY
TIMESTAMPYYY
User-defined distinct typesYYY

Special registers
Language elementLUWz/OSi5/OSNotes
CURRENT DATEYYY
CURRENT_DATEYYY
CURRENT DEGREEYYY
CURRENT PATHYYY
CURRENT_PATHYYY
CURRENT SCHEMAYYY
CURRENT_SCHEMAYYY
CURRENT SERVERYYY
CURRENT TIMEYYY
CURRENT_TIMEYYY
CURRENT TIMESTAMPYYY
CURRENT_TIMESTAMPYYY
CURRENT TIMEZONEYYY
SESSION_USERYYY
USERYYY

Predicates
Language elementLUWz/OSi5/OSNotes
Basic ( = <> < > <= >= ) excluding LOB typesYYY
Basic with scalar subselect right of comparison operatorYYY
Quantified (ALL, ANY or SOME) with single expression (no subquery) on left side and subselect on right sideYYY
BETWEEN (no scalar subqueries)YYY
EXISTS (subselect)YYY
IN followed by list of expressionsYYY
IN followed by single column subselectYYY
IS NULL (no scalar subquery)YYY
LIKE with host variable or string constant as patternYYY
LIKE with expression for pattern and escapeYYY

Aggregate functions
Language elementLUWz/OSi5/OSNotes
AVGYYY
COUNTYYY
COUNT_BIGYYY
MAXYYY
MINYYY
StdDEVYYY
SUMYYY
VARIANCE or VARYYY

Scalar functions
Language elementLUWz/OSi5/OSNotes
ABSVAL or ABSYYY
ACOSYYY
ASINYYY
ATANYYY
ATANHYYY
ATAN2YYY
BIGINTYYY
BLOBYYY
CEIL or CEILINGYYY
CHAR (no string units)YYY
CHARACTER_LENGTH or CHAR_LENGTH (no string units)PPYFor LUW and z/OS, the argument CODEUNITS16 is required to achieve equivalent functionality for most data.
CLOB (no string units)YYY
COALESCE (or VALUE)YYY
CONCATYYY
COSYYY
COSHYYY
DATEYYY
DAYYYY
DAYNAMEYPYz/OS supports function as a sample in schema DSN8.
DAYOFWEEKYYY
DAYOFWEEK_ISOYYY
DAYOFYEARYYY
DAYSYYY
DBCLOB (no string units)YYY
DECIMAL or DECYYY
DECRYPT_BITPYYLUW supports the function with name DECRYPT_BIN.
DECRYPT_CHARPYY
DEGREESYYY
DIFFERENCEYYY
DIGITSYYY
DOUBLE or DOUBLE_PRECISIONYYY
ENCRYPTYYYSyntax for the ENCRYPT function is common but z/OS will use the ENCRYPT_tdES format for the result instead of ENCRYPT_RC2.
EXPYYY
FLOATYYY
FLOORYYY
GENERATE_UNIQUEYYY
GETHINTYYY
GRAPHIC (no string units)PYY
HEXYYY
HOURYYY
IDENTITY_VAL_LOCALYYY
INSERT (no string units)YYY
INTEGER or INTYYY
JULIAN_DAYYYY
LCASEYYY
LEFT (no string units)PYY
LENGTH (no string units)YYY
LNYYY
LOCATE (no string units)YYY
LOG10YYY
LOWERYYY
LtrIMPPYLUW does not support a CLOB argument. z/OS does not support a CLOB argument.
MICROSECONDYYY
MIDNIGHT_SECONDSYYY
MINUTEYYY
MODPYY
MONTHYYY
MONTHNAMEYPYz/OS supports function as a sample in schema DSN8.
MULTIPLY_ALTYYY
NULLIFPPYLUW does not support LOB arguments. z/OS does not support LOB arguments.
POSITION (no string units)PPYFor LUW and z/OS, the argument CODEUNITS16 is required to achieve equivalent functionality for most data.
POSSTRYYY
POWERYYY
QUARTERYYY
RADIANSYYY
RAISE_ERRORYYY
RANDYYY
REALYYY
REPEATPPYLUW does not support graphic types. z/OS does not support LOB arguments.
REPLACEPPYLUW does not support graphic types. z/OS does not support LOB arguments.
RIGHT (no string units)PYYLUW does not support graphic types.
ROUNDYYY
RTRIMPPYLUW does not support a CLOB argument. z/OS does not support a CLOB argument.
SECONDYYY
SIGNYYY
SINYYY
SINHYYY
SMALLINTYYY
SOUNDEXYYY
SPACEPYY
SQRTPYY
STRIPYYY
SUBSTRYYY
SUBSTRING (no string units)PPYFor LUW and z/OS, the argument CODEUNITS16 is required to achieve equivalent functionality for most data.
TANYYY
TANHYYY
TIMEYYY
TIMESTAMPYYY
TIMESTAMP_ISOYYY
TIMESTAMPDIFFYYY
TRANSLATEYYY
TRUNCATE or trUNCYYY
UCASE or UPPERYYY
VALUEYYY
VARCHAR (no string units)PYY
VARCHAR_FORMAT or TO_CHARPYP
VARGRAPHIC (no string units)YYY
WEEKYYY
WEEK_ISOYYY
YEARYYY

Queries
Language elementLUWz/OSi5/OSNotes
SELECT clauseYYY
AS sub-clause in SELECT clauseYYY
Qualified * or unqualified * in SELECT clauseYYY
Expressions other than scalar subquery in SELECT clauseYYY
Aggregate functions allowed in SELECT clause even if the result table is derived from a grouped viewYYY
FROM clause referencing a single table or viewYYY
FROM clause with implicit inner join (multiple comma separated table-references)YYY
FROM clause with nested table expression containing a subselectYYY
FROM clause with nested table expression preceded by TABLE keywordYYY
FROM clause with explicit INNER JOINYYY
FROM clause with LEFT OUTER JOINYYY
FROM clause with RIGHT OUTER JOINYYY
WHERE clauseYYY
GROUP BY referencing column namesYYY
GROUP BY referencing grouping expressionsYYY
HAVING clauseYYY
Fullselect with UNION or UNION ALLYYY
Fullselect with INTERSECT or INTERSECT ALLYYPi5/OS does not support INTERSECT ALL.
Fullselect with EXCEPT or EXCEPT ALLYYPi5/OS does not support EXCEPT ALL.
Select-statement starting with common table expressionYYY
Select-statement using recursive common table expressionYYY
ORDER BY clause over qualified column namesYYY
ORDER BY clause over sort-key expressionsYYY
ORDER BY clause over expressions not in the SELECT listYYY
ORDER BY ORDER OFYYY
FOR UPDATE clause with list of column namesYYY
FOR UPDATE clause with implicit column listYYY
FOR READ ONLY clauseYYY
OPTIMIZE clause with integer number of rowsYYY
Select-statement with isolation clause with CS, RR, or RSYYY
Select-statement with isolation clause with UR on read only select statementYYY
FETCH FIRST clauseYYY

Basic statements
Language elementLUWz/OSi5/OSNotes
Static CALL statementYYY
Static CALL statement with variable name for procedure nameYYY
SELECT INTO statement with optional WHERE, GROUP BY or HAVING clausesYYY
SELECT INTO statement with FETCH FIRST clauseYYY
SELECT INTO statement with isolation clauseYYY
VALUES INTO statementYYY

Data change statements
Language elementLUWz/OSi5/OSNotes
Searched DELETE statementYYY
INSERT statement with single row VALUES clauseYYY
INSERT statement with subselectYYY
Searched UPDATE statementYYY

Cursor-oriented operations
Language elementLUWz/OSi5/OSNotes
CLOSE statementYYY
DECLARE CURSOR statement (see other cursor elements)YYY
Declare INSENSITIVE SCROLL cursorPYYLUW only supports this capability through CLI or JDBC.
Declare WITH HOLD cursorYYY
Declare WITH RETURN cursor (implicit return to caller)YYY
Declare WITH RETURN TO CALLER cursorYYY
Positioned DELETE statementYYY
FETCH statement with no cursor orientation (implicit NEXT)YYY
FETCH statement with NEXT, PRIOR, FIRST, LAST, BEFORE, AFTER, CURRENT, or RELATIVEPYYLUW only supports these fetch features through CLI or JDBC.
FETCH statement with ABSOLUTEPYP
OPEN statementYYY
Positioned UPDATE statementYYY

Connection and transaction control
Language elementLUWz/OSi5/OSNotes
Isolation Level Specification at package levelYYY
Isolation Level Specification at statement levelYYY
RR (SERIALIZABLE in SQL2003 Standard)YYY
RS (REPEATABLE READ in SQL2003 Standard)YYY
CS (READ COMMITTED in SQL2003 Standard)YYY
UR (READ UNCOMMITTED in SQL2003 Core Standard)YYY
Isolation clause with USE AND KEEP EXCLUSIVE LOCKSPPY
COMMIT statementYYY
CONNECT statement (1 site per transaction)YYY
CONNECT statement (2+ sites per transaction) (also referred to as Two Phase Commit)YYY
DISCONNECT statementYYY
RELEASE connection statementYYY
RELEASE SAVEPOINT statementYYY
ROLLBACK unit of work statementYYY
ROLLBACK TO SAVEPOINT statementYYY
SAVEPOINT statement - not nestedYYY
SAVEPOINT statement - nestedYYY
SET CONNECTION statementYYY

Dynamic facilities
Language elementLUWz/OSi5/OSNotes
DESCRIBE output statement without a USING clauseYYY
DESCRIBE INPUT statementYYY
EXECUTE statementYYY
EXECUTE IMMEDIATE statementYYY
PREPARE statementYYY
PREPARE statement that specifies cursor options (ATtrIBUTES clause)PYYLUW only supports this capability through CLI or JDBC.

Control statements
Language elementLUWz/OSi5/OSNotes
Control statements in SQL proceduresYYY
Control statements in SQL functionsPPYPartial support allows a single RETURN statement in SQL functions.
Assignment statementYYY
CASE statementYYY
Compound statementYYY
Nested not atomic compound statementYYY
FOR statementYYY
GET DIAGNOSTICS for ROW_COUNT statementYYY
GET DIAGNOSTICS for RETURN_STATUS statementYYY
GET DIAGNOSTICS for MESSAGE_TEXT statementYYY
GOTO statementYYY
IF statementYYY
ITERATE statementYYY
LEAVE statementYYY
LOOP statementYYY
REPEAT statementYYY
RESIGNAL statementYYY
RETURN statement from SQL procedureYYY
RETURN statement from SQL functionYYY
SIGNAL statementYYY
WHILE statementYYY

Data definition
Language elementLUWz/OSi5/OSNotes
Allow DDL statements in SQL programsYYY
Support Transaction Semantics for DDLYYY
Support 18 byte object names (except schema name )YYYSome platforms support longer object names.
Support 10 byte schema namesYYYSome platforms support longer schema names.
ALTER PROCEDURE statementPPY
ALTER SEQUENCE statementYYY
ALTER TABLE statement (see other elements marked ALTAB)YPYz/OS does not allow the same clause to be specified more than once.
ALTER COLUMN (ALTAB)PPY
COMMENT statementYYY
CREATE ALIAS statementYYY
CREATE DISTINCT TYPE statementYYY
CREATE FUNCTION (External Scalar) statementYYY
CREATE FUNCTION (Sourced) statementYYY
CREATE FUNCTION (SQL Scalar) statementPPYNot all features of the statement are supported on each platform.
CREATE FUNCTION (External Table) statementYYY
CREATE INDEX over column listYYY
CREATE UNIQUE INDEX over column listYYY
CREATE PROCEDURE statement for external procedureYYY
CREATE PROCEDURE statement for SQL procedureYYY
CREATE SCHEMAYPYz/OS requires the statement to be processed by a special schema processor.
CREATE TABLE statement using column definition (see other elements marked CRTAB)YYY
CREATE TABLE statement LIKE other table/view (see other elements marked CRTAB)YYY
CREATE TABLE statement LIKE other table/view including identity (see other elements marked CRTAB)YYY
CREATE TABLE statement AS query (see other elements marked CRTAB)YYY
CHECK constraint clause (ALTAB, CRTAB)YYY
DATA CAPTURE clause (ALTAB, CRTAB)YYPi5/OS tables always capture changes - the clause is not supported.
DEFAULT clause with no specified value (ALTAB, CRTAB, DGTTAB)YYY
DEFAULT clause with specified value (ALTAB, CRTAB, DGTTAB)YYY
VOLATILE clause (ALTAB, CRTAB)YYY
IDENTITY clause (ALTAB, CRTAB, DGTTAB)YYY
PRIMARY KEY constraint clause (ALTAB, CRTAB)YYY
UNIQUE constraint clause (ALTAB, CRTAB)YYY
Automatic index generation for unique constraints (ALTAB, CRTAB)YYY
Referential constraint clause (ALTAB, CRTAB)YYY
REFERENCES clause specifying ON DELETE (ALTAB, CRTAB)PPYLUW does not support ON DELETE SET DEFAULT. z/OS does not support ON DELETE SET DEFAULT.
Self referencing tables can be specified without requiring use of ALTER TABLEYPY
User maintained MQT (CRTAB,ALTAB)YYY
CREATE SEQUENCE statementYYY
CREATE TRIGGER statement - BEFORE or AFTER trigger on a tableYYY
CREATE TRIGGER statement - INSTEAD OF trigger on a viewYPY
CREATE VIEW statement using subselect without CHECK OPTION clauseYYY
CREATE VIEW WITH CASCADED CHECK OPTIONYYY
CREATE VIEW WITH LOCAL CHECK OPTIONYYY
DECLARE GLOBAL TEMPORARY TABLE statement (see other elements marked DGTTAB)PYY
DROP statement with specified REStrICT or CASCADE behaviourPPY
DROP ALIAS statementYYY
DROP DISTINCT TYPE statementYYY
DROP FUNCTION statementYYY
DROP INDEX statementYYY
DROP PACKAGE statementYYY
DROP PROCEDURE statementYPY
DROP SEQUENCE statementYYY
DROP TABLE statementYYY
DROP TRIGGER statementYYY
DROP VIEW statementYYY
RENAME TABLE statementPPY

Authorization
Language elementLUWz/OSi5/OSNotes
GRANT Function or Procedure Privileges statementYYY
GRANT Package Privileges statement having no WITH GRANT OPTION clauseYYY
GRANT Package Privileges statement having a WITH GRANT OPTION clauseYYY
GRANT Sequence Privileges statementYYY
GRANT Table Privileges statementYYY
REVOKE Function Privileges statementYYY
REVOKE Procedure Privileges statementYPY
REVOKE Package Privileges statementYYY
REVOKE Sequence Privileges statementYYY
REVOKE Table Privileges statementYYY

Miscellaneous statements
Language elementLUWz/OSi5/OSNotes
BEGIN and END DECLARE SECTION statementYYY
DECLARE STATEMENT statementPYYLUW supports the statement only in SQL stored procedures.
FREE LOCATOR statementYYY
INCLUDE statementYYY
LOCK TABLE statementYYY
REFRESH TABLE statementYYY
SET CURRENT DEGREE statementYYY
SET ENCRYPTION PASSWORD statementYYY
SET PATH statementYYY
SET SCHEMA statementYYY
WHENEVER statementYYY

Host languages
Language elementLUWz/OSi5/OSNotes
C or C++YYY
COBOLYYY
FORTRANYYY
Java (SQLJ)YYY
PL/IYYY
REXXYYY


Back to top


Disclaimer

This list is not necessarily complete. Selected features are based on frequent customer interest. You may find more common features by examining the SQL language reference books for our products in detail.

This list is not intended to be a feature and function list for any of the DB2 products. A feature may already appear on one platform and be in the process of rolling out on other DB2 platforms because we are continuing to ship new functionality all the time. Because of differences in customers and marketplaces, not all platforms require the same features delivered at the same time.



Resources



About the author

This article brought to you by IBM staff.




Rate this page


Please take a moment to complete this form to help us better serve you.



 


 


Not
useful
Extremely
useful
 


Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!



Back to top