Java DB

Apache Derby

Derby Reference Manual

Derby Getting Started
Derby Reference Manual
Derby Developer's Guide
Derby Performance Tuning
Derby Server and Admin Guide
Derby Tools and Utilities
Derby Reference Manual
-SQL language reference
-Capitalization and special characters
-SQL identifiers
-Rules for SQL92 identifiers
-SQL92Identifier
-column-Name
-correlation-Name
-new-table-Name
-schemaName
-Simple-column-Name
-synonym-Name
-table-Name
-view-Name
-index-Name
-constraint-Name
-cursor-Name
-TriggerName
-
-RoleName
-Interaction with the dependency system
-ALTER TABLE
-CALL (PROCEDURE)
-CREATE statements
-DECLARE GLOBAL TEMPORARY TABLE
-DELETE
-DROP statements
-GRANT
-INSERT
-LOCK TABLE
-RENAME statements
-REVOKE
-SET statements
-SELECT
-UPDATE
-SQL clauses
-SQL expressions
-JOIN operations
-SQL queries
-Built-in functions
-Standard built-in functions
-Aggregates (set functions)
-ABS or ABSVAL function
-ACOS function
-ASIN function
-ATAN function
-ATAN2 function
-AVG function
-BIGINT function
-CASE expressions
-CAST function
-CEIL or CEILING function
-CHAR function
-COALESCE function
-Concatenation operator
-COS function
-COSH function
-COT function
-COUNT function
-COUNT(*) function
-CURRENT DATE function
-CURRENT_DATE function
-CURRENT ISOLATION function
-CURRENT_ROLE function
-CURRENT SCHEMA function
-CURRENT TIME function
-CURRENT_TIME function
-CURRENT TIMESTAMP function
-CURRENT_TIMESTAMP function
-CURRENT_USER function
-DATE function
-DAY function
-DEGREES function
-DOUBLE function
-EXP function
-FLOOR function
-HOUR function
-IDENTITY_VAL_LOCAL function
-INTEGER function
-LCASE or LOWER function
-LENGTH function
-LN or LOG function
-LOG10 function
-LOCATE function
-LTRIM function
-MAX function
-MIN function
-MINUTE function
-MOD function
-MONTH function
-NULLIF expressions
-PI function
-RADIANS function
-RANDOM function
-RAND function
-ROW_NUMBER function
-RTRIM function
-SECOND function
-SESSION_USER function
-SIGN function
-SIN function
-SINH function
-SMALLINT function
-SQRT function
-SUBSTR function
-SUM function
-TAN function
-TANH function
-TIME function
-TIMESTAMP function
-TRIM function
-UCASE or UPPER function
-USER function
-VARCHAR function
-XMLEXISTS operator
-XMLPARSE operator
-XMLQUERY operator
-XMLSERIALIZE operator
-YEAR function
-Built-in system functions
-Built-in system procedures
-SYSCS_B ACKUP_D ATABASE
-SYSCS_BAC KUP_DATAB ASE_NOWAIT
-SYSCS_BACKUP_DAT ABASE_AND_ENABLE _LOG_ARCHIVE_MODE
-SYSCS_BACKUP_DATAB ASE_AND_ENABLE_LOG ARCHIVE_MODE_NOWAIT
-SYSCS_EMP TY_STATEM ENT_CACHE
-SYSCS_CH ECKPOINT _DATABASE
-SYSCS_COMPRESS_TABLE
-SYSCS_INP LACE_COMP RESS_TABLE
-SYSCS_DISA BLE_LOG_AR CHIVE_MODE
-SYSCS_EXPORT_TABLE
-SYSCS_EXPOR T_TABLE_LOB S_TO_EXTFILE
-SYSCS_EXPORT_QUERY
-SYSCS_EXPOR T_QUERY_LOB S_TO_EXTFILE
-SYSCS_IMPORT_DATA
-SYSCS_IMPOR T_DATA_LOBS FROM_EXTFILE
-SYSCS_IMPORT_TABLE
-SYSCS_IMPORT _TABLE_LOBS_ FROM_EXTFILE
-SYSCS_F REEZE_D ATABASE
-SYSCS_U NFREEZE DATABASE
-SYSCS_REL OAD_SECUR ITY_POLICY
-SYSCS_SET _DATABASE _PROPERTY
-SYSCS_SET _RUNTIMES TATISTICS
-SYSCS_SET _STATISTI CS_TIMING
-SYSCS_S ET_XPLA N_SCHEMA
-SYSCS_S ET_XPLA IN_MODE
-SYSCS_S ET_USER _ACCESS
-SYSCS_U PDATE_S ATISTICS
-SYSCS_DIAG diagnostic tables and functions
-Data types
-Argument matching
-SQL reserved words
-Derby support for SQL-92 features
-Derby system tables
-XPLAIN style tables
-Derby exception messages and SQL states
-JDBC reference
-java.sql.Driver interface
-java. sql. DriverManager. getConnection method
-java.sql.Connection interface
-java. sql. DatabaseMetaData interface
-java.sql.Statement interface
-java. sql. CallableStatement interface
-java. sql. PreparedStatement interface
-java.sql.ResultSet interface
-java. sql. ResultSetMetaData interface
-java.sql.SQLException class
-java.sql.SQLWarning class
-java.sql.Savepoint interface
-Mapping of java. sql. Types to SQL types
-JDBC Package for Connected Device Configuration/Foundation Profile (JSR 169)
-JDBC 4.0-only features
-Setting attributes for the database connection URL
-bootPassword= key attribute
-collation= collation attribute
-create= true attribute
-createFrom= path attribute
-databaseName= nameofDatabase attribute
-dataEncryption= true attribute
-drop= true attribute
-encryptionKey= key attribute
-encryptionProvider= providerName attribute
-encryptionAlgorithm= algorithm attribute
-failover= true attribute
-logDevice= logDirectoryPath attribute
-newEncryptionKey= key attribute
-newBootPassword= newPassword attribute
-password= userPassword attribute
-restoreFrom= path attribute
-rollForwardRecoveryFrom= path attribute
-securityMechanism= value attribute
-shutdown= true attribute
-slaveHost= hostname attribute
-slavePort= portValue attribute
-startMaster= true attribute
-startSlave= true attribute
-stopMaster= true attribute
-stopSlave= true attribute
-territory= ll_CC attribute
-traceDirectory= path attribute
-traceFile= path attribute
-traceFileAppend= true attribute
-traceLevel= value attribute
-upgrade= true attribute
-user= userName attribute
-ssl= sslMode attribute
-Creating a connection without specifying attributes
-Derby property reference
-Scope of Derby properties
-Dynamic and static properties
-Derby properties
-derby. authentication. builtin. algorithm
-derby. authentication. ldap. searchAuthDN
-derby. authentication. ldap. searchAuthPW
-derby. authentication. ldap. searchBase
-derby. authentication. ldap. searchFilter
-
-
-derby. connection. requireAuthentication
-derby. database. defaultConnectionMode
-derby. database. forceDatabaseLock
-
-
-
-derby. database. readOnlyAccessUsers
-derby. database. sqlAuthorization
-derby.infolog.append
-derby. jdbc. xaTransactionTimeout
-
-derby. language. logStatementText
-
-
-derby. locks. escalationThreshold
-derby.locks.monitor
-
-derby. replication. logBufferSize
-derby. replication. maxLogShippingInterval
-derby. replication. minLogShippingInterval
-
-
-derby. storage. minimumRecordSize
-
-derby. storage. pageReservedSpace
-
-
-
-
-
-
-derby. stream. error. logSeverityLevel
-derby.system.bootAll
-
-derby.system.home
-derby.user.UserName
-J2EE Compliance: Java Transaction API and javax. sql Interfaces
-Derby API
-Supported territories
-Derby limitations

 

JDBC escape syntax for fn keyword

You can specify functions in JDBC escape syntax by using the fn keyword.

Syntax

{fn functionCall}

where functionCall is the name of one of the scalar functions listed below. The functions are of the following types:

  • Numeric functions
  • String functions
  • Date and time functions
  • System function

Numeric functions

abs
Returns the absolute value of a number.
abs(NumericExpression)

The JDBC escape syntax {fn abs(NumericExpression)} is equivalent to the built-in syntax ABS(NumericExpression). For more information, see ABS or ABSVAL function.

acos
Returns the arc cosine of a specified number.
acos(number)

The JDBC escape syntax {fn acos(number)} is equivalent to the built-in syntax ACOS(number). For more information, see ACOS function.

asin
Returns the arc sine of a specified number.
asin(number)

The JDBC escape syntax {fn asin(number)} is equivalent to the built-in syntax ASIN(number). For more information, see ASIN function.

atan
Returns the arc tangent of a specified number.
atan(number)

The JDBC escape syntax {fn atan(number)} is equivalent to the built-in syntax ATAN(number). For more information, see ATAN function.

atan2
Returns the arc tangent in radians of y/x.
atan2(y, x)

The JDBC escape syntax {fn atan2(y, x)} is equivalent to the built-in syntax ATAN2(y, x). For more information, see ATAN2 function.

ceiling
Rounds the specified number up, and returns the smallest number that is greater than or equal to the specified number.
ceiling(number)

The JDBC escape syntax {fn ceiling(number)} is equivalent to the built-in syntax CEILING(number). For more information, see CEIL or CEILING function.

cos
Returns the cosine of a specified number.
cos(number)

The JDBC escape syntax {fn cos(number)} is equivalent to the built-in syntax COS(number). For more information, see COS function.

cot
Returns the cotangent of a specified number.
cot(number)

The JDBC escape syntax {fn cot(number)} is equivalent to the built-in syntax COT(number). For more information, see COT function.

degrees
Converts a specified number from radians to degrees.
degrees(number)

The JDBC escape syntax {fn degrees(number)} is equivalent to the built-in syntax DEGREES(number). For more information, see DEGREES function.

exp
Returns e raised to the power of the specified number.
exp(number)

The JDBC escape syntax {fn exp(number)} is equivalent to the built-in syntax EXP(number). For more information, see EXP function.

floor
Rounds the specified number down, and returns the largest number that is less than or equal to the specified number.
floor(number)

The JDBC escape syntax {fn floor(number)} is equivalent to the built-in syntax FLOOR(number). For more information, see FLOOR function.

log
Returns the natural logarithm (base e) of the specified number.
log(number)

The JDBC escape syntax {fn log(number)} is equivalent to the built-in syntax LOG(number). For more information, see LN or LOG function.

log10
Returns the base-10 logarithm of the specified number.
log10(number)

The JDBC escape syntax {fn log10(number)} is equivalent to the built-in syntax LOG10(number). For more information, see LOG10 function.

mod
Returns the remainder (modulus) of argument 1 divided by argument 2. The result is negative only if argument 1 is negative.
mod(integer_type, integer_type)

The JDBC escape syntax {fn mod(integer_type, integer_type)} is equivalent to the built-in syntax MOD(integer_type, integer_type). For more information, see MOD function.

pi
Returns a value that is closer than any other value to pi.
pi()

The JDBC escape syntax {fn pi()} is equivalent to the built-in syntax PI(). For more information, see PI function.

radians
Converts a specified number from degrees to radians.
radians(number)

The JDBC escape syntax {fn radians(number)} is equivalent to the built-in syntax RADIANS(number). For more information, see RADIANS function.

rand
Returns a random number given a seed number.
rand(seed)

The JDBC escape syntax {fn rand(seed)} is equivalent to the built-in syntax RAND(seed). For more information, see RAND function.

sign
Returns an integer that represents the sign of a specified number (+1 if the number is positive, -1 if it is negative, 0 if it is 0).
sign(number)

The JDBC escape syntax {fn sign(number)} is equivalent to the built-in syntax SIGN(number). For more information, see SIGN function.

sin
Returns the sine of a specified number.
sin(number)

The JDBC escape syntax {fn sin(number)} is equivalent to the built-in syntax SIN(number). For more information, see SIN function.

sqrt
Returns the square root of a floating-point number.
sqrt(FloatingPointExpression)

The JDBC escape syntax {fn sqrt(FloatingPointExpression)} is equivalent to the built-in syntax SQRT(FloatingPointExpression). For more information, see SQRT function.

tan
Returns the tangent of a specified number.
tan(number)

The JDBC escape syntax {fn tan(number)} is equivalent to the built-in syntax TAN(number). For more information, see TAN function.

String functions

concat
Returns the concatenation of character strings; that is, the character string formed by appending the second string to the first string. If either string is null, the result is NULL.
concat(CharacterExpression, CharacterExpression)

The JDBC escape syntax {fn concat(CharacterExpression, CharacterExpression)} is equivalent to the built-in syntax CharacterExpression || CharacterExpression. For more information, see Concatenation operator.

lcase
Returns a string in which all alphabetic characters in the argument have been converted to lowercase.
lcase(CharacterExpression)

The JDBC escape syntax {fn lcase(CharacterExpression)} is equivalent to the built-in syntax LCASE(CharacterExpression). For more information, see LCASE or LOWER function.

length
Returns the number of characters in a character string expression.
length(CharacterExpression)

The JDBC escape syntax {fn length(CharacterExpression)} is equivalent to the built-in syntax LENGTH(CharacterExpression). For more information, see LENGTH function.

locate
Returns the position in the second CharacterExpression of the first occurrence of the first CharacterExpression. Searches from the beginning of the second CharacterExpression, unless the startIndex parameter is specified.
locate(CharacterExpression,CharacterExpression [, startIndex] )

The JDBC escape syntax {fn locate(CharacterExpression, CharacterExpression [, startIndex] )} is equivalent to the built-in syntax LOCATE(CharacterExpression, CharacterExpression [, StartPosition] ). For more information, see LOCATE function.

ltrim
Removes blanks from the beginning of a character string expression.
ltrim(CharacterExpression)

The JDBC escape syntax {fn ltrim(CharacterExpression)} is equivalent to the built-in syntax LTRIM(CharacterExpression). For more information, see LTRIM function.

rtrim
Removes blanks from the end of a character string expression.
rtrim(CharacterExpression)

The JDBC escape syntax {fn rtrim(CharacterExpression)} is equivalent to the built-in syntax RTRIM(CharacterExpression). For more information, see RTRIM function.

substring
Forms a character string by extracting length characters from the CharacterExpression beginning at startIndex. The index of the first character in the CharacterExpression is 1.
substring(CharacterExpression, startIndex, length)

The JDBC escape syntax {fn substring(CharacterExpression, startIndex, length)} is equivalent to the built-in syntax SUBSTR(CharacterExpression, startIndex, length). For more information, see SUBSTR function.

ucase
Returns a string in which all alphabetic characters in the argument have been converted to uppercase.
ucase(CharacterExpression)

The JDBC escape syntax {fn ucase(CharacterExpression)} is equivalent to the built-in syntax UCASE(CharacterExpression). For more information, see UCASE or UPPER function.

Date and time functions

curdate
Returns the current date.
curdate()

The JDBC escape syntax {fn curdate()} is equivalent to the built-in syntax CURRENT_DATE. For more information, see CURRENT_DATE function.

curtime
Returns the current time.
curtime()

The JDBC escape syntax {fn curtime()} is equivalent to the built-in syntax CURRENT_TIME. For more information, see CURRENT_TIME function.

hour
Returns the hour part of a time value.
hour(expression)

The JDBC escape syntax {fn hour(expression)} is equivalent to the built-in syntax HOUR(expression). For more information, see HOUR function.

minute
Returns the minute part of a time value.
minute(expression)

The JDBC escape syntax {fn minute(expression)} is equivalent to the built-in syntax MINUTE(expression). For more information, see MINUTE function.

month
Returns the month part of a date value.
month(expression)

The JDBC escape syntax {fn month(expression)} is equivalent to the built-in syntax MONTH(expression). For more information, see MONTH function.

second
Returns the seconds part of a time value.
second(expression)

The JDBC escape syntax {fn second(expression)} is equivalent to the built-in syntax SECOND(expression). For more information, see SECOND function.

TIMESTAMPADD
Use the TIMESTAMPADD function to add the value of an interval to a timestamp. The function applies the integer to the specified timestamp based on the interval type and returns the sum as a new timestamp. You can subtract from the timestamp by using negative integers.

TIMESTAMPADD is a JDBC escaped function and is accessible only by using the JDBC escape function syntax.

TIMESTAMPADD( interval, integerExpression, timestampExpression )

To perform TIMESTAMPADD on dates and times, it is necessary to convert the dates and times to timestamps. Dates are converted to timestamps by putting 00:00:00.0 in the time-of-day fields. Times are converted to timestamps by putting the current date in the date fields.

Do not put a datetime column inside a timestamp arithmetic function in WHERE clauses, because the optimizer will not use any index on the column.

TIMESTAMPDIFF
Use the TIMESTAMPDIFF function to find the difference between two timestamp values at a specified interval. For example, the function can return the number of minutes between two specified timestamps.

The TIMESTAMPDIFF is a JDBC escaped function and is accessible only by using the JDBC escape function syntax.

TIMESTAMPDIFF( interval, timestampExpression1, timestampExpression2 )

To perform TIMESTAMPDIFF on dates and times, it is necessary to convert the dates and times to timestamps. Dates are converted to timestamps by putting 00:00:00.0 in the time-of-day fields. Times are converted to timestamps by putting the current date in the date fields.

Do not put a datetime column inside a timestamp arithmetic function in WHERE clauses, because the optimizer will not use any index on the column.

year
Returns the year part of a date value.
year(expression)

The JDBC escape syntax {fn year(expression)} is equivalent to the built-in syntax YEAR(expression). For more information, see YEAR function.

Valid intervals for TIMESTAMPADD and TIMESTAMPDIFF

The TIMESTAMPADD and TIMESTAMPDIFF functions are used to perform arithmetic with timestamps. These two functions use the following valid intervals for arithmetic operations:
  • SQL_TSI_DAY
  • SQL_TSI_FRAC_SECOND
  • SQL_TSI_HOUR
  • SQL_TSI_MINUTE
  • SQL_TSI_MONTH
  • SQL_TSI_QUARTER
  • SQL_TSI_SECOND
  • SQL_TSI_WEEK
  • SQL_TSI_YEAR

Examples for the TIMESTAMPADD and TIMESTAMPDIFF escape functions

To return a timestamp value one month later than the current timestamp, use the following syntax:

{fn TIMESTAMPADD( SQL_TSI_MONTH, 1, CURRENT_TIMESTAMP)}

To return the number of weeks between now and the specified time on January 1, 2008, use the following syntax:

{fn TIMESTAMPDIFF(SQL_TSI_WEEK, CURRENT_TIMESTAMP, 
  timestamp('2008-01-01-12.00.00.000000'))}

System function

user
Returns the authorization identifier or name of the current user. If there is no current user, it returns APP.
user()

The JDBC escape syntax {fn user()} is equivalent to the built-in syntax USER. For more information, see USER function.

 

javadb@jdbcurl.com