Type 4 JDBC Drivers

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

SQL Escape Sequences for JDBC

Language features, such as outer joins and scalar function calls, are commonly implemented by database systems. The syntax for these features is often database-specific, even when a standard syntax has been defined. JDBC defines escape sequences that contain the standard syntax for the following language features:

The escape sequence used by JDBC is:

   {extension}

The escape sequence is recognized and parsed by the Type 4 JDBC drivers, which replace the escape sequences with data store-specific grammar.

 


Date, Time, and Timestamp Escape Sequences

The escape sequence for date, time, and timestamp literals is:

   {literal-type 'value'}

where literal-type is one of the following:

Table C-1 Literal Types for Date, Time, and Timestamp Escape Sequences
literal-type
Description
Value Format
d
Date
yyyy-mm-dd
t
Time
hh:mm:ss [1]
ts
Timestamp
yyyy-mm-dd hh:mm:ss[.f...]

Example:

   UPDATE Orders SET OpenDate={d '1995-01-15'} 
   WHERE OrderID=1023

 


Scalar Functions

You can use scalar functions in SQL statements with the following syntax:

   {fn scalar-function}

where scalar-function is a scalar function supported by the Type 4 JDBC drivers, as listed in Table C-2.

Example:

   SELECT id, name FROM emp WHERE name LIKE {fn UCASE('Smith')}

Table C-2 Scalar Functions Supported 
Data Store
String
Functions
Numeric
Functions
Timedate
Functions
System
Functions
SQL Server
ASCII
CHAR
CONCAT
DIFFERENCE
INSERT
LCASE
LEFT
LENGTH
LOCATE
LTRIM
REPEAT
REPLACE
RIGHT
RTRIM
SOUNDEX
SPACE
SUBSTRING
UCASE
ABS
ACOS
ASIN
ATAN
ATAN2
CEILING
COS
COT
DEGREES
EXP
FLOOR
LOG
LOG10
MOD
PI
POWER
RADIANS
RAND
ROUND
SIGN
SIN
SQRT
TAN
TRUNCATE
DAYNAME
DAYOFMONTH
DAYOFWEEK
DAYOFYEAR
EXTRACT
HOUR
MINUTE
MONTH
MONTHNAME
NOW
QUARTER
SECOND
TIMESTAMPADD
TIMESTAMPDIFF
WEEK
YEAR
DATABASE
IFNULL
USER

 


Outer Join Escape Sequences

JDBC supports the SQL92 left, right, and full outer join syntax. The escape sequence for outer joins is:

   {oj outer-join}

where outer-join is:

   table-reference {LEFT | RIGHT | FULL} OUTER JOIN 
   {table-reference | outer-join} ON search-condition

where:

   table-reference is a database table name.

   search-condition is the join condition you want to use for the tables.

Example:

   SELECT Customers.CustID, Customers.Name, Orders.OrderID, Orders.Status
      FROM {oj Customers LEFT OUTER JOIN
         Orders ON Customers.CustID=Orders.CustID}
      WHERE Orders.Status='OPEN'

Table C-3 lists the outer join escape sequences supported by Type 4 JDBC drivers for each data store.

Table C-3 Outer Join Escape Sequences Supported 
Data Store
Outer Join Escape Sequences
SQL Server
Left outer joins
Right outer joins
Full outer joins
Nested outer joins

 


LIKE Escape Character Sequence for Wildcards

You can specify the character to be used to escape wildcard characters (% and _, for example) in LIKE clauses. The escape sequence for escape characters is:

{escape 'escape-character'}

where escape-character is the character used to escape the wildcard character.

For example. the following SQL statement specifies that an asterisk (*) be used as the escape character in the LIKE clause for the wildcard character %:

SELECT col1 FROM table1 WHERE col1 LIKE '*%%' {escape '*'}

 


Procedure Call Escape Sequences

A procedure is an executable object stored in the data store. Generally, it is one or more SQL statements that have been precompiled. The escape sequence for calling a procedure is:

   {[?=]call procedure-name[([parameter][,parameter]...)]}

where:

   procedure-name specifies the name of a stored procedure.

   parameter specifies a stored procedure parameter.


  Back to Top       Previous  Next