Top Description Inners Fields Constructors Methods
org.h2.expression.function

public final Class ToCharFunction

extends FunctionN
Class Inheritance
Imports
java.math.BigDecimal, .RoundingMode, java.text.DateFormatSymbols, .DecimalFormat, .DecimalFormatSymbols, .SimpleDateFormat, java.util.Arrays, .Currency, .Locale, org.h2.api.ErrorCode, org.h2.engine.SessionLocal, org.h2.expression.Expression, .TypedValueExpression, org.h2.message.DbException, org.h2.util.DateTimeUtils, .StringUtils, .TimeZoneProvider, org.h2.value.TypeInfo, .Value, .ValueTimeTimeZone, .ValueTimestamp, .ValueTimestampTimeZone, .ValueVarchar

Emulates Oracle's TO_CHAR function.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ToCharFunction.Capitalization

Represents a capitalization / casing strategy.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
AM_PM

The AM / PM field.

public static final int
JULIAN_EPOCH

The beginning of the Julian calendar.

public static final int
MONTHS

The month field.

private static volatile String[][]
private static final String[]
private static final int[]
public static final int
SHORT_MONTHS

The month field (short form).

public static final int
SHORT_WEEKDAYS

The weekday field (short form).

public static final int
WEEKDAYS

The weekday field.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
addSign(StringBuilder output, int signum, boolean leadingSign, boolean trailingSign, boolean trailingMinus, boolean angleBrackets, boolean fillMode)

private static int
calculateScale(String format, int separator)

public static void
clearNames()

Used for testing.

private static ToCharFunction.Capitalization

Returns:

a capitalization strategy if the specified string contains any of the specified substrings at the specified index, null otherwise
containsAt
(String
the string to check
s
,
int
the index to check at
index
,
String...
the substrings to check for within the string
substrings
)

Returns a capitalization strategy if the specified string contains any of the specified substrings at the specified index.

private static int
private static Currency
public static String[]

Returns:

the names
getDateNames
(int
the field
names
)

Get the date (month / weekday / ...) names.

public String
private static String

Returns:

time zone display name or ID
getTimeZone
(SessionLocal
the session
session
,
Value
value
value
,
boolean
if true return TZD (time zone region with Daylight Saving Time information included), if false return TZR (time zone region)
tzd
)

Returns time zone display name or ID for the specified date-time value.

public Value
getValue(SessionLocal
the session
session
,
Value
the value of first argument, or null
v1
,
Value
the value of second argument, or null
v2
,
Value
the value of third argument, or null
v3
)

Overrides org.h2.expression.function.FunctionN.getValue.

Returns the value of this function.

public Expression
optimize(SessionLocal
the session
session
)

Implements abstract org.h2.expression.Expression.optimize.

Try to optimize the expression.

public static String

Returns:

the formatted number
toChar
(BigDecimal
the number to format
number
,
String
the format pattern to use (if any)
format
,
String
the NLS parameter (if any)
nlsParam
)

Emulates Oracle's TO_CHAR(number) function.

public static String

Returns:

the formatted timestamp
toCharDateTime
(SessionLocal
the session
session
,
Value
the date-time value to format
value
,
String
the format pattern to use (if any)
format
,
String
the NLS parameter (if any)
nlsParam
)

Emulates Oracle's TO_CHAR(datetime) function.

private static String
toHex(BigDecimal number, String format)

private static String
toRomanNumeral(int number)

private static String
Inherited from org.h2.expression.function.FunctionN:
getUnenclosedSQLgetValue

Field Detail

AM_PMback to summary
pack-priv static final int AM_PM

The AM / PM field.

JULIAN_EPOCHback to summary
public static final int JULIAN_EPOCH

The beginning of the Julian calendar.

MONTHSback to summary
public static final int MONTHS

The month field.

NAMESback to summary
private static volatile String[][] NAMES
ROMAN_NUMERALSback to summary
private static final String[] ROMAN_NUMERALS
ROMAN_VALUESback to summary
private static final int[] ROMAN_VALUES
SHORT_MONTHSback to summary
public static final int SHORT_MONTHS

The month field (short form).

SHORT_WEEKDAYSback to summary
public static final int SHORT_WEEKDAYS

The weekday field (short form).

WEEKDAYSback to summary
public static final int WEEKDAYS

The weekday field.

Constructor Detail

ToCharFunctionback to summary
public ToCharFunction(Expression arg1, Expression arg2, Expression arg3)

Method Detail

addSignback to summary
private static void addSign(StringBuilder output, int signum, boolean leadingSign, boolean trailingSign, boolean trailingMinus, boolean angleBrackets, boolean fillMode)
calculateScaleback to summary
private static int calculateScale(String format, int separator)
clearNamesback to summary
public static void clearNames()

Used for testing.

containsAtback to summary
private static ToCharFunction.Capitalization containsAt(String s, int index, String... substrings)

Returns a capitalization strategy if the specified string contains any of the specified substrings at the specified index. The capitalization strategy indicates the casing of the substring that was found. If none of the specified substrings are found, this method returns null .

Parameters
s:String

the string to check

index:int

the index to check at

substrings:String[]

the substrings to check for within the string

Returns:ToCharFunction.Capitalization

a capitalization strategy if the specified string contains any of the specified substrings at the specified index, null otherwise

findDecimalSeparatorback to summary
private static int findDecimalSeparator(String format)
getCurrencyback to summary
private static Currency getCurrency()
getDateNamesback to summary
public static String[] getDateNames(int names)

Get the date (month / weekday / ...) names.

Parameters
names:int

the field

Returns:String[]

the names

getNameback to summary
public String getName()

Implements org.h2.expression.function.NamedExpression.getName.

Doc from org.h2.expression.function.NamedExpression.getName.

Get the name.

Returns:String

the name in uppercase

Annotations
@Override
getTimeZoneback to summary
private static String getTimeZone(SessionLocal session, Value value, boolean tzd)

Returns time zone display name or ID for the specified date-time value.

Parameters
session:SessionLocal

the session

value:Value

value

tzd:boolean

if true return TZD (time zone region with Daylight Saving Time information included), if false return TZR (time zone region)

Returns:String

time zone display name or ID

getValueback to summary
public Value getValue(SessionLocal session, Value v1, Value v2, Value v3)

Overrides org.h2.expression.function.FunctionN.getValue.

Doc from org.h2.expression.function.FunctionN.getValue.

Returns the value of this function.

Parameters
session:SessionLocal

the session

v1:Value

the value of first argument, or null

v2:Value

the value of second argument, or null

v3:Value

the value of third argument, or null

Returns:Value

the resulting value

Annotations
@Override
optimizeback to summary
public Expression optimize(SessionLocal session)

Implements abstract org.h2.expression.Expression.optimize.

Doc from org.h2.expression.Expression.optimize.

Try to optimize the expression.

Parameters
session:SessionLocal

the session

Returns:Expression

the optimized expression

Annotations
@Override
toCharback to summary
public static String toChar(BigDecimal number, String format, String nlsParam)

Emulates Oracle's TO_CHAR(number) function.

TO_CHAR(number) function
Input Output Closest DecimalFormat Equivalent
, Grouping separator. ,
. Decimal separator. .
$ Leading dollar sign. $
0 Leading or trailing zeroes. 0
9 Digit. #
B Blanks integer part of a fixed point number less than 1. #
C ISO currency symbol. ¤
D Local decimal separator. .
EEEE Returns a value in scientific notation. E
FM Returns values with no leading or trailing spaces. None.
G Local grouping separator. ,
L Local currency symbol. ¤
MI Negative values get trailing minus sign, positive get trailing space. -
PR Negative values get enclosing angle brackets, positive get spaces. None.
RN Returns values in Roman numerals. None.
S Returns values with leading/trailing +/- signs. None.
TM Returns smallest number of characters possible. None.
U Returns the dual currency symbol. None.
V Returns a value multiplied by 10^n. None.
X Hex value. None.
See also TO_CHAR(number) and number format models in the Oracle documentation.
Parameters
number:BigDecimal

the number to format

format:String

the format pattern to use (if any)

nlsParam:String

the NLS parameter (if any)

Returns:String

the formatted number

toCharDateTimeback to summary
public static String toCharDateTime(SessionLocal session, Value value, String format, String nlsParam)

Emulates Oracle's TO_CHAR(datetime) function.

TO_CHAR(datetime) function
Input Output Closest SimpleDateFormat Equivalent
- / , . ; : "text" Reproduced verbatim. 'text'
A.D. AD B.C. BC Era designator, with or without periods. G
A.M. AM P.M. PM AM/PM marker. a
CC SCC Century. None.
D Day of week. u
DAY Name of day. EEEE
DY Abbreviated day name. EEE
DD Day of month. d
DDD Day of year. D
DL Long date format. EEEE, MMMM d, yyyy
DS Short date format. MM/dd/yyyy
E Abbreviated era name (Japanese, Chinese, Thai) None.
EE Full era name (Japanese, Chinese, Thai) None.
FF[1-9] Fractional seconds. S
FM Returns values with no leading or trailing spaces. None.
FX Requires exact matches between character data and format model. None.
HH HH12 Hour in AM/PM (1-12). hh
HH24 Hour in day (0-23). HH
IW Week in year. w
WW Week in year. w
W Week in month. W
IYYY IYY IY I Last 4/3/2/1 digit(s) of ISO year. yyyy yyy yy y
RRRR RR Last 4/2 digits of year. yyyy yy
Y,YYY Year with comma. None.
YEAR SYEAR Year spelled out (S prefixes BC years with minus sign). None.
YYYY SYYYY 4-digit year (S prefixes BC years with minus sign). yyyy
YYY YY Y Last 3/2/1 digit(s) of year. yyy yy y
J Julian day (number of days since January 1, 4712 BC). None.
MI Minute in hour. mm
MM Month in year. MM
MON Abbreviated name of month. MMM
MONTH Name of month, padded with spaces. MMMM
RM Roman numeral month. None.
Q Quarter of year. None.
SS Seconds in minute. ss
SSSSS Seconds in day. None.
TS Short time format. h:mm:ss aa
TZD Daylight savings time zone abbreviation. z
TZR Time zone region information. zzzz
X Local radix character. None.

See also TO_CHAR(datetime) and datetime format models in the Oracle documentation.

Parameters
session:SessionLocal

the session

value:Value

the date-time value to format

format:String

the format pattern to use (if any)

nlsParam:String

the NLS parameter (if any)

Returns:String

the formatted timestamp

toHexback to summary
private static String toHex(BigDecimal number, String format)
toRomanNumeralback to summary
private static String toRomanNumeral(int number)
zeroesAfterDecimalSeparatorback to summary
private static String zeroesAfterDecimalSeparator(BigDecimal number)
org.h2.expression.function back to summary

public final Enum ToCharFunction.Capitalization

extends Enum<ToCharFunction.Capitalization>
Class Inheritance

Represents a capitalization / casing strategy.

Field Summary

Modifier and TypeField and Description
public static final ToCharFunction.Capitalization
CAPITALIZE

The string is capitalized (first letter uppercased, subsequent letters lowercased).

public static final ToCharFunction.Capitalization
LOWERCASE

All letters are lowercased.

public static final ToCharFunction.Capitalization
UPPERCASE

All letters are uppercased.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the resultant string
apply
(String
the string to apply this strategy to
s
)

Applies this capitalization strategy to the specified string.

pack-priv static ToCharFunction.Capitalization

Returns:

the capitalization / casing strategy which should be used when the first and second letters have the specified casing
toCapitalization
(Boolean
whether or not the first letter is uppercased
up1
,
Boolean
whether or not the second letter is uppercased
up2
)

Returns the capitalization / casing strategy which should be used when the first and second letters have the specified casing.

public static ToCharFunction.Capitalization
public static ToCharFunction.Capitalization[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CAPITALIZEback to summary
public static final ToCharFunction.Capitalization CAPITALIZE

The string is capitalized (first letter uppercased, subsequent letters lowercased).

LOWERCASEback to summary
public static final ToCharFunction.Capitalization LOWERCASE

All letters are lowercased.

UPPERCASEback to summary
public static final ToCharFunction.Capitalization UPPERCASE

All letters are uppercased.

Constructor Detail

Capitalizationback to summary
private Capitalization()

Method Detail

applyback to summary
public String apply(String s)

Applies this capitalization strategy to the specified string.

Parameters
s:String

the string to apply this strategy to

Returns:String

the resultant string

toCapitalizationback to summary
pack-priv static ToCharFunction.Capitalization toCapitalization(Boolean up1, Boolean up2)

Returns the capitalization / casing strategy which should be used when the first and second letters have the specified casing.

Parameters
up1:Boolean

whether or not the first letter is uppercased

up2:Boolean

whether or not the second letter is uppercased

Returns:ToCharFunction.Capitalization

the capitalization / casing strategy which should be used when the first and second letters have the specified casing

valueOfback to summary
public static ToCharFunction.Capitalization valueOf(String name)
valuesback to summary
public static ToCharFunction.Capitalization[] values()