Class ToCharFunction
java.lang.Object
org.h2.expression.Expression
org.h2.expression.OperationN
org.h2.expression.function.FunctionN
org.h2.expression.function.ToCharFunction
- All Implemented Interfaces:
ExpressionWithVariableParameters, NamedExpression, HasSQL, Typed
Emulates Oracle's TO_CHAR function.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRepresents a capitalization / casing strategy. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intThe AM / PM field.static final intThe beginning of the Julian calendar.static final intThe month field.private static String[][]private static final String[]private static final int[]static final intThe month field (short form).static final intThe weekday field (short form).static final intThe weekday field.Fields inherited from class OperationN
args, argsCount, typeFields inherited from class Expression
AUTO_PARENTHESES, MAP_IN_AGGREGATE, MAP_IN_WINDOW, MAP_INITIAL, WITH_PARENTHESES, WITHOUT_PARENTHESESFields inherited from interface HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddSign(StringBuilder output, int signum, boolean leadingSign, boolean trailingSign, boolean trailingMinus, boolean angleBrackets, boolean fillMode) private static intcalculateScale(String format, int separator) static voidUsed for testing.private static ToCharFunction.CapitalizationcontainsAt(String s, int index, String... substrings) Returns a capitalization strategy if the specified string contains any of the specified substrings at the specified index.private static intfindDecimalSeparator(String format) private static Currencystatic String[]getDateNames(int names) Get the date (month / weekday / ...) names.getName()Get the name.private static StringgetTimeZone(SessionLocal session, Value value, boolean tzd) Returns time zone display name or ID for the specified date-time value.getValue(SessionLocal session, Value v1, Value v2, Value v3) Returns the value of this function.optimize(SessionLocal session) Try to optimize the expression.static StringtoChar(BigDecimal number, String format, String nlsParam) Emulates Oracle's TO_CHAR(number) function.static StringtoCharDateTime(SessionLocal session, Value value, String format, String nlsParam) Emulates Oracle's TO_CHAR(datetime) function.private static StringtoHex(BigDecimal number, String format) private static StringtoRomanNumeral(int number) private static StringMethods inherited from class FunctionN
getUnenclosedSQL, getValueMethods inherited from class OperationN
addParameter, doneWithParameters, getCost, getSubexpression, getSubexpressionCount, getType, isEverything, mapColumns, optimizeArguments, setEvaluatable, updateAggregateMethods inherited from class Expression
addFilterConditions, createIndexConditions, getAlias, getBooleanValue, getColumnName, getColumnNameForView, getEnclosedSQL, getNonAliasExpression, getNotIfPossible, getNullable, getSchemaName, getSQL, getSQL, getSQL, getSQL, getTableAlias, getTableName, getWhenSQL, getWhenValue, isConstant, isIdentity, isNullConstant, isValueSet, isWhenConditionOperand, needParentheses, optimizeCondition, toString, writeExpressions, writeExpressionsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface HasSQL
getTraceSQL
-
Field Details
-
JULIAN_EPOCH
public static final int JULIAN_EPOCHThe beginning of the Julian calendar.- See Also:
-
ROMAN_VALUES
private static final int[] ROMAN_VALUES -
ROMAN_NUMERALS
-
MONTHS
public static final int MONTHSThe month field.- See Also:
-
SHORT_MONTHS
public static final int SHORT_MONTHSThe month field (short form).- See Also:
-
WEEKDAYS
public static final int WEEKDAYSThe weekday field.- See Also:
-
SHORT_WEEKDAYS
public static final int SHORT_WEEKDAYSThe weekday field (short form).- See Also:
-
AM_PM
static final int AM_PMThe AM / PM field.- See Also:
-
NAMES
-
-
Constructor Details
-
ToCharFunction
-
-
Method Details
-
toChar
Emulates Oracle's TO_CHAR(number) function.
See also TO_CHAR(number) and number format models in the Oracle documentation.TO_CHAR(number) function Input Output Closest DecimalFormatEquivalent, 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. - Parameters:
number- the number to formatformat- the format pattern to use (if any)nlsParam- the NLS parameter (if any)- Returns:
- the formatted number
-
getCurrency
-
zeroesAfterDecimalSeparator
-
addSign
private static void addSign(StringBuilder output, int signum, boolean leadingSign, boolean trailingSign, boolean trailingMinus, boolean angleBrackets, boolean fillMode) -
findDecimalSeparator
-
calculateScale
-
toRomanNumeral
-
toHex
-
getDateNames
Get the date (month / weekday / ...) names.- Parameters:
names- the field- Returns:
- the names
-
clearNames
public static void clearNames()Used for testing. -
getTimeZone
Returns time zone display name or ID for the specified date-time value.- Parameters:
session- the sessionvalue- valuetzd- iftruereturn TZD (time zone region with Daylight Saving Time information included), iffalsereturn TZR (time zone region)- Returns:
- time zone display name or ID
-
toCharDateTime
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 SimpleDateFormatEquivalent- / , . ; : "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- the sessionvalue- the date-time value to formatformat- the format pattern to use (if any)nlsParam- the NLS parameter (if any)- Returns:
- the formatted timestamp
-
containsAt
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 returnsnull.- Parameters:
s- the string to checkindex- the index to check atsubstrings- the substrings to check for within the string- Returns:
- a capitalization strategy if the specified string contains any of
the specified substrings at the specified index,
nullotherwise
-
getValue
Description copied from class:FunctionNReturns the value of this function. -
optimize
Description copied from class:ExpressionTry to optimize the expression.- Specified by:
optimizein classExpression- Parameters:
session- the session- Returns:
- the optimized expression
-
getName
-