Syntax Elements
Identifiers
Identifier is divided into an ordinary identifier and a delimited identifier. An ordinary identifier consists of letters or a combination of letters and numbers, and it is used by internally substituting all characters to uppercase letters. Therefore, an ordinary identifier is not case-sensitive.
The following is an example of an ordinary identifier.
GOLDILOCKS GoldiLocks
A delimited identifier consists of letters or a combination of letters and numbers enclosed in double quotes ("). All the characters are used as internally described. Therefore, a delimited identifier is case-sensitive.
The following is an example of a delimited identifier.
"GOLDILOCKS" "GoldiLocks"
Literals
Literals mean representation of non-null value.
Text Literals
Text literals mean representation of strings and binary strings.
Use single quote (') at the beginning and end of a string to write string of text literals.
Not only the double quotes (") string but also all strings except for the single quote (') string can be written within a single quote (').
Use a single quote twice without white spaces in between to write a single quote (') in a string.
A maximum of 4000 characters can be written in a string.The followings are examples of text literals for a string.
'GOLDILOCKS' 'Sunje''s DBMS'
A binary string of text literals is a string of hexadecimal numbers which starts with x'(X') and ends with '. Only the characters corresponding to 0 ~ 9, A (a) ~ F (f) can be written in each position of a hexadecimal string. The length of a hexadecimal string should always be an even number because its two digits mean one byte. A maximum of 4,000 characters can be written in a binary string.
The followings are examples of text literals for a binary string.
x'001f' X'FF0A' x'aF37BBc013'
Numeric Literals
Numeric literals mean literals of numeric type, and integers or the number with decimal point can be written. The syntax for numeric literals is as follows.
[ + | - ] <digits> [ . <digits> ] [ E | e [ + | - ] <digits> ] [ f | F | d | D ]
The first +/- means a positive or negative value of the entire number, and it can be omitted. If omitted, the default value is a positive value.
In <digits>, numbers from 0 to 9 can be listed without white space, the number with decimal point can be written by using decimal point (.).
An exponent form can be written after the first <digits>, and E or e is written, and it stands for exponent. Then +/- is written according to exponent sign, and <digits> is written. +/- of exponent can be omitted. If omitted, the default value is a positive value.
Lastly, character such as f, F, d, D can be written after numbers. It means that it is a number of BINARY_FLOAT, BINARY_DOUBLE. If the corresponding character is omitted, the number is considered as NUMBER type.
The followings are examples of numeric literals.
20 +123.45 0.03 +1.23E-02 -1.5 10f +123.45F 1.2E-3F -22d 123.45D -1.23E+05D
Datetime Literals
Datetime literals are representation of date/time type. Datetime value is specified using string literal, or by converting character or numeric value to datetime value using TO_*function (TO_DATE, etc).
Datetime data types are DATE, TIME, TIME WITH TIME ZONE, TIMESTAMP, TIMESTAMP WITH TIME ZONE.
Date Literals
Date literals are written in a form of DATE'string literal' or TO_DATE(string_literal [, format]).
DATE'string literal'
The format of date type is ' SYYYY-MM-DD'.
DATE'2002-07-15'
TO_DATE(string_literal [, format])
If the format is not specified, the format of date type is NLS_DATE_FORMAT by default.
If the format is specified, the specified format is applied.
The date type includes year, month, day, hour, minute, second (except for fractional seconds).
If the date is omitted, the default value is the first day of the current month.
If the hour, minute, second are omitted, the default value is midnight.
HH24 format: '00:00:00'
HH12 format: '12:00:00'
To set the hour, minute, second to the default value (midnight) when the date value includes hour, minute, second, then use the TRUNC(date) function.
For example, in TRUNC(SYSDATE), SYSDATE includes the values of the year, month, day, hour, minute, second.
To compare only the values of the year, month, day among date values, then set the values of the hour, minute, second are set to midnight using the TRUNC function.
For more information, refer to TO_DATE, Datetime Format String, NLS_DATE_FORMAT.
The following is an example of date literals.
DATE'2002-07-15'
The following is an example of when the format is not specified, so NLS_DATE_FORMAT is 'YYYY-MM-DD'.
TO_DATE( '2002-07-15' )
The followings are examples of when the format is specified.
TO_DATE( '15-JUL-02', 'DD-MON-RR' ) TO_DATE( '2002-07-15 00:00:00', 'YYYY-MM-DD HH24:MI:SS' ) TO_DATE( '2002-07-15 13:25:30', 'YYYY-MM-DD HH24:MI:SS' )
The following is an example of when the date is omitted. (It is set to the first day of the current month).
gSQL> SELECT TO_DATE( '2000-07', 'YYYY-MM' ) FROM DUAL; TO_DATE( '2000-07', 'YYYY-MM' ) ------------------------------- 2000-07-01
The following is an example of when the hour, minute, second are omitted. (It is set to the midnight).
gSQL> SELECT
TO_CHAR( DATE'2002-07-15', 'YYYY-MM-DD HH24:MI:SS' ) AS RESULT
FROM DUAL;
RESULT
-------------------
2002-07-15 00:00:00The following is an example of setting the hour, minute, second of DATE value (SYSDATE) to the default value (midnight).
gSQL> SELECT
TO_CHAR( SYSDATE,
'YYYY-MM-DD HH24:MI:SS' ) AS RESULT_SYSDATE,
TO_CHAR( TRUNC( SYSDATE ),
'YYYY-MM-DD HH24:MI:SS' ) AS RESULT_TRUNC_SYSDATE
FROM DUAL;
RESULT_SYSDATE RESULT_TRUNC_SYSDATE
------------------- --------------------
2014-08-19 10:06:49 2014-08-19 00:00:00The following is an example of comparing only the values of the year, month, day among date values.
gSQL> SELECT
TO_DATE( '2002-08-12' ) =
TRUNC( TO_DATE( '2002-08-12 23:59:59', 'YYYY-MM-DD HH24:MI:SS' ) )
AS RESULT FROM DUAL;
RESULT
------
TRUETime Literals
Time literals are written in a form of TIME'string literal' or TO_TIME(string_literal [, format]).
TIME'string literal'
The format of time type is 'HH24:MI:SS[.[FF6]]'.
TIME'15:30:59.999999'
TO_TIME(string_literal [, format])
If the format is not specified, the format of time type is NLS_TIME_FORMAT by default.
If the format is specified, the specified format is applied.
The time type includes hour, minute, second (fractional seconds). Fractional seconds can be specified to maximum six digits numbers format.
For more information, refer to TO_TIME, Datetime Format String, NLS_TIME_FORMAT.
The following is an example of time literals.
TIME'15:30:59.999999'
The following is an example of when the format is not specified, so NLS_TIME_FORMAT is 'HH24:MI:SS.FF6'.
TO_TIME( '15:30:59.999999' )
The following is an example of when the format is specified.
TO_TIME( '09.45.03.546873 AM', 'HH12.MI.SS.FF6 AM' ) TO_TIME( '09:45:03', 'HH12:MI:SS' )
Time with Time Zone Literals
Time with time zone literals is written in a form of TIME'string literal', TIME WITH TIME ZONE'string literal', TO_TIME_WITH_TIME_ZONE(string_literal [, format] ), or TO_TIME_TZ(string_literal [, format] ).
TIME'string literal' or TIME WITH TIME ZONE'string literal'
The format of time with time zone type is 'HH24:MI:SS[.[FF6]] TZH:TZM'.
TIME'15:30:59.999999 +09:00'
TIME WITH TIME ZONE'15:30:59.999999 +09:00'
TO_TIME_WITH_TIME_ZONE(string_literal [, format] )
If the format is not specified, the format of time with time zone type is NLS_TIME_WITH_TIME_ZONE_FORMAT by default.
If the format is specified, the specified format is applied.
Time with time zone type includes hour, minute, second (fractional seconds), and time zone offset (time zone hour, time zone minute). Fractional seconds can be specified to maximum six digits numbers format.
For more information, refer to TO_TIME_WITH_TIME_ZONE, Datetime Format String, NLS_TIME_WITH_TIME_ZONE_FORMAT.
The followings are examples of time with time zone literals.
TIME'15:30:59.999999 +09:00' TIME WITH TIME ZONE'15:30:59.999999 +09:00'
The following is an example of when the format is not specified, so NLS_TIME_WITH_TIME_ZONE_FORMAT is 'HH24:MI:SS.FF6 TZH:TZM'.
TO_TIME_WITH_TIME_ZONE( '15:30:59.999999 +09:00' ) TO_TIME_TZ( '15:30:59.999999 +09:00' )
The following is an example of when the format is specified.
TO_TIME_WITH_TIME_ZONE( '09.45.03.546873 +09:00 AM',
'HH12.MI.SS.FF6 TZH:TZM AM' )Timestamp Literals
Timestamp literals are written in a form of TIMESTAMP'string literal' or TO_TIMESTAMP(string_literal [, format] ).
TIMESTAMP'string literal'
The format of timestamp type is 'SYYYY-MM-DD HH24:MI:SS[.[FF6]]'.
TIMESTAMP'2002-07-15 15:39:59.999999'
TO_TIMESTAMP(string_literal [, format] )
If the format is not specified, the format of timestamp type is NLS_TIMESTAMP_FORMAT by default.
If the format is specified, the specified format is applied.
Timestamp type includes year, month, day, hour, minute, second (fractional seconds). Fractional seconds can be specified to maximum six digits numbers format.
For more information, refer to TO_TIMESTAMP, Datetime Format String, NLS_TIMESTAMP_FORMAT.
The following is an example of timestamp literals.
TIMESTAMP'2002-07-15 15:39:59.999999'
The following is an example of when the format is not specified, so NLS_TIMESTAMP_FORMAT is 'YYYY-MM-DD HH24:MI:SS.FF6'.
TO_TIMESTAMP( '2002-07-15 15:39:59.999999' )
The following is an example of when the format is specified.
TO_TIMESTAMP( '15-JUL-02 11.06.30.123456 AM',
'DD-MON-RR HH12.MI.SS.FF6 AM' )Timestamp with Time Zone Literals
Timestamp with time zone literals is written in a form of TIMESTAMP'string literal', TIMESTAMP WITH TIME ZONE'string literal', TO_TIMESTAMP_WITH_TIME_ZONE(string_literal [, formt] ), or TO_TIMESTAMP_TZ(string_literal [, format]).
TIMESTAMP'string literal' or TIMESTAMP WITH TIME ZONE'string literal'
The format of timestamp with time zone type is 'SYYYY-MM-DD HH24:MI:SS[.[FF6]] TZH:TZM'.
TIMESTAMP'2002-07-15 15:39:59.999999 +09:00'
TIMESTAMP WITH TIME ZONE'2002-07-15 15:39:59.999999 +09:00'
TO_TIMESTAMP_WITH_TIME_ZONE(string_literal [, formt] )
If the format is not specified, the format of timestamp with time zone type is NLS_TIMESTAMP_WITH_TIME_ZONE_FORMAT by default.
If the format is specified, the specified format is applied.
Timestamp with time zone type includes year, month, day, hour, minute, second (fractional seconds), time zone offset (time zone hour, time zone minute). Fractional seconds can be specified to maximum six digits numbers format.
For more information, refer to TO_TIMESTAMP_WITH_TIME_ZONE, Datetime Format String , NLS_TIMESTAMP_WITH_TIME_ZONE_FORMAT.
The following is an example of timestamp with time zone literals.
TIMESTAMP'2002-07-15 15:39:59.999999 +09:00' TIMESTAMP WITH TIME ZONE'2002-07-15 15:39:59.999999 +09:00'
The following is an example of when the format is not specified, so NLS_TIMESTAMP_WITH_TIME_ZONE_FORMAT is 'YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM'.
TO_TIMESTAMP_WITH_TIME_ZONE( '2002-07-15 15:39:59.999999 +09:00' ) TO_TIMESTAMP_TZ( '2002-07-15 15:39:59.999999 +09:00' )
The following is an example of when the format is specified.
TO_TIMESTAMP_WITH_TIME_ZONE( '15-JUL-02 11.06.30.123456 +09:00 AM',
'DD-MON-RR HH12.MI.SS.FF6 TZH:TZM AM' )
TO_TIMESTAMP_TZ( '15-JUL-02 11.06.30.123456 +09:00 AM',
'DD-MON-RR HH12.MI.SS.FF6 TZH:TZM AM' )Interval Literals
The interval literals specify the time interval.
Intervals are classified and expressed as follows.
Year-month INTERVAL values
It includes YEAR and MONTH.
Display string expression: 'year-month'
It can be written in a form as INTERVAL 'string literal' YEAR[leading precision] TO MONTH or NUMTOYMINTERVAL( num, interval_indicator )
Day-time INTERVAL values
It includes DAY, HOUR, MINUTE, SECOND (fractional seconds).
Display string expression: 'day hour:minute:second.fractional_seconds'
It can be written in a form as INTERVAL 'string literal' DAY[leading precision] TO SECOND[fractiona l seconds precision] or NUMTODSINTERVAL( num, interval_indicator ).
The interval value's sign is specified only once at the beginning of the string representation.
e.g. INTERVAL'+3 11:22:33.999999'DAY TO SECOND (O)
INTERVAL'-3 +11:22:33.999999'DAY TO SECOND (X)
The followings are the list of interval types.
INTERVAL YEAR (leading precision)
INTERVAL MONTH (leading precision)
INTERVAL YEAR (leading precision) TO MONTH
INTERVAL DAY (leading precision)
INTERVAL HOUR (leading precision)
INTERVAL MINUTE (leading precision)
INTERVAL SECOND (leading precision[, fractional seconds precision] )
INTERVAL DAY (leading precision) TO HOUR
INTERVAL DAY (leading precision) TO MINUTE
INTERVAL DAY (leading precision) TO SECOND (fractional seconds precision)
INTERVAL HOUR (leading precision) TO MINUTE
INTERVAL HOUR (leading precision) TO SECOND (fractional seconds precision)
INTERVAL MINUTE (leading precision) TO SECOND (fractional seconds precision)
Leading precision • It is the digit number of the field, it can be specified from 2 to 6. If it is not specified, the default value is set to 2. • If the leading field value exceeds the leading precision, then an error is returned.
Fractional seconds precision • It is the digit number of fractional seconds, and it can be specified from 0 to 6. If it is not specified, the default value is set to 6. • If the fractional second field value exceeds the fractional seconds precision, then it is rounded off.
For more information, refer to INTERVAL, Precisions and value range of the second or later field in INTERVAL * TO *, NUMTOYMINTERVAL, NUMTODSINTERVAL.
Examples of Using Interval Literals.
The followings are examples of using interval literals.
Interval YEAR
The followings are examples of using interval YEAR literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1'YEAR INTERVAL'01-00'YEAR | 1 year | +01-00 |
INTERVAL'100'YEAR | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'100'YEAR(3) | 100 year | +100-00 |
INTERVAL'+999999'YEAR(6) | 999999 year | +999999-00 |
INTERVAL'-999999'YEAR(6) | -(999999 year) | -999999-00 |
Interval MONTH
The followings are examples of using interval MONTH literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1'MONTH INTERVAL'00-01'MONTH | 1 month | +00-01 |
INTERVAL'100'MONTH | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'100'MONTH(3) | 8 year 4 month | +008-04 |
INTERVAL'+999999'MONTH(6) | 83333 year 3 month | +083333-03 |
INTERVAL'-999999'MONTH(6) | -(83333 year 3 month) | -083333-03 |
Interval YEAR TO MONTH
The followings are examples of using interval YEAR TO MONTH literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1-06'YEAR TO MONTH | 1 year 6 month | +01-06 |
INTERVAL'1-12'YEAR TO MONTH | The month value exceeded 11, so it returns the error. | - |
INTERVAL'100-11'YEAR TO MONTH | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'100-11'YEAR(3) TO MONTH | 100 year 11 month | +100-11 |
INTERVAL'+999999-11'YEAR(6) TO MONTH | 999999 year 11 month | +999999-11 |
INTERVAL'-999999-11'YEAR(6) TO MONTH | -(999999 year 11 month) | -999999-11 |
Interval DAY
The followings are examples of using interval DAY literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1'DAY INTERVAL'01 00:00:00'DAY | 1 day | +01 00:00:00 |
INTERVAL'100'DAY | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'100'DAY(3) | 100 day | +100 00:00:00 |
INTERVAL'+999999'DAY(6) | 999999 day | +999999 00:00:00 |
INTERVAL'-999999'DAY(6) | -(999999 day) | -999999 00:00:00 |
Interval HOUR
The followings are examples of using interval HOUR literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1'HOUR INTERVAL'00 01:00:00'HOUR | 1 hour | +00 01:00:00 |
INTERVAL'1000'HOUR(3) | It exceeds the leading precision 3, so it returns the error | - |
INTERVAL'1000'HOUR(4) | 41 day 16 hour | +0041 16:00:00 |
INTERVAL'+999999'HOUR(6) | 41666 day 15 hour | +041666 15:00:00 |
INTERVAL'-999999'HOUR(6) | -(41666 day 15 hour) | -041666 15:00:00 |
Interval MINUTE
The following are examples of using interval MINUTE literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1'MINUTE INTERVAL'00 00:01:00'MINUTE | 1 minute | +00 00:01:00 |
INTERVAL'12345'MINUTE(4) | It exceeds the leading precision 4, so it returns the error | - |
INTERVAL'12345'MINUTE(5) | 8 day 13 hour 45 minute | +00008 13:45:00 |
INTERVAL'+999999'MINUTE(6) | 694 day 10 hour 39 minute | +000694 10:39:00 |
INTERVAL'-999999'MINUTE(6) | -(694 day 10 hour 39 minute) | -000694 10:39:00 |
Interval SECOND
The followings are examples of using interval SECOND literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1'SECOND INTERVAL'00 00:00:01.000000'SECOND | 1 second | +00 00:00:01.000000 |
INTERVAL'100'SECOND | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'99.9999999'SECOND INTERVAL'99.9999999'SECOND(2,6) | The fractional seconds are rounded off to become 100 second, then it exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'99.9999999'SECOND(3) | 1 minute 40 second | +000 00:01:40.000000 |
INTERVAL'29.506167'SECOND(2, 2) | 29.51 second | +00 00:00:29.51 |
INTERVAL'999999.999999'SECOND(6,6) | 11day 13 hour 46 minute 39.999999 second | +000011 13:46:39.999999 |
INTERVAL'-999999.999999'SECOND(6,6) | -(11day 13 hour 46 minute 39.999999 second) | -000011 13:46:39.999999 |
Interval DAY TO HOUR
The followings are examples of using interval DAY TO HOUR literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1 23'DAY TO HOUR INTERVAL'01 23:00:00'DAY TO HOUR | 1 day 23 hour | +01 23:00:00 |
INTERVAL'1 24'DAY TO HOUR | The hour value exceeds 23 (invalid), so it returns the error. | - |
INTERVAL'100 23'DAY TO HOUR | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'100 23'DAY(3) TO HOUR | 100 day 23 hour | +100 23:00:00 |
INTERVAL'+999999 23'DAY(6) TO HOUR | 999999 day 23 hour | +999999 23:00:00 |
INTERVAL'-999999 23'DAY(6) TO HOUR | -(999999 day 23 hour) | -999999 23:00:00 |
INTERVAL'-999999 +23'DAY(6) TO HOUR | Invalid sign error | - |
Interval DAY TO MINUTE
The followings are examples of using interval DAY TO MINUTE literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'1 23:59'DAY TO MINUTE INTERVAL'01 23:59:00'DAY TO MINUTE | 1 day 23 hour 59 second | +01 23:59:00 |
INTERVAL'1 24:59'DAY TO MINUTE | The hour value exceeds 23 (invalid), so it returns the error. | - |
INTERVAL'1 23:60'DAY TO MINUTE | The minute value exceeds 59 (invalid), so it returns the error. | - |
INTERVAL'100 23:59'DAY TO MINUTE | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'100 23:59'DAY(3) TO MINUTE | 100 day 23 hour 59 minute | +100 23:59:00 |
INTERVAL'+999999 23:59'DAY(6) TO MINUTE | 999999 day 23 hour 59 minute | +999999 23:59:00 |
INTERVAL'-999999 23:59'DAY(6) TO MINUTE | -(999999 day 23 hour 59 minute) | -999999 23:59:00 |
Interval DAY TO SECOND
The followings are examples of using interval DAY TO SECOND literals.
Example | Description | display string |
|---|---|---|
INTERVAL '1 23:59:59.999999'DAY TO SECOND | 1 day 23 hour 59 minute 59.999999 second | +01 23:59:59.999999 |
INTERVAL '1 24:59:59.999999'DAY TO SECOND | The hour value exceeds 23, so it returns the error. | - |
INTERVAL '1 23:60:59.999999'DAY TO SECOND | The minute value exceeds 59, so it returns the error. | - |
INTERVAL '1 23:59:60.999999'DAY TO SECOND | The second value exceeds 60, so it returns the error. | - |
INTERVAL '99 23:59:59.9999999'DAY TO SECOND | The fractional seconds are rounded off to become 100 day, then it exceeds the leading precision 2, so it returns the error. | - |
INTERVAL '99 23:59:59.9999999'DAY(3) TO SECOND | 100 day | +100 00:00:00.000000 |
INTERVAL '1 11:22:33.567890'DAY(2) TO SECOND(2) | 1 day 11 hour 22 minute 33.57 second | +01 11:22:33.57 |
INTERVAL '+999999 23:59:59.999999'DAY(6) TO SECOND(6) | 999999 day 23 hour 59 minute 59.999999 hour | +999999 23:59:59.999999 |
INTERVAL '-999999 23:59:59.999999'DAY(6) TO SECOND(6) | -(999999 day 23 hour 59 minute 59.999999 hour) | -999999 23:59:59.999999 |
Interval HOUR TO MINUTE
The followings are examples of using interval HOUR TO MINUTE literals.
Example | Description | Display string |
|---|---|---|
INTERVAL'23:59'HOUR TO MINUTE INTERVAL'00 23:59:00'HOUR TO MINUTE | 23 hour 59 minute | +00 23:59:00 |
INTERVAL'23:60'HOUR TO MINUTE | The minute value exceeds 59, so it returns the error. | - |
INTERVAL'100:59'HOUR TO MINUTE | It exceeds the leading precision 2, so it returns the error. | - |
INTERVAL'100:59'HOUR(3) TO MINUTE | 4 day 4 hour 59 minute | +004 04:59:00 |
INTERVAL'+999999:59'HOUR(6) TO MINUTE | 41666 day 15 hour 59 minute | +041666 15:59:00 |
INTERVAL'-999999:59'HOUR(6) TO MINUTE | -(41666 day 15 hour 59 minute) | -041666 15:59:00 |
Interval HOUR TO SECOND
The followings are examples of using interval HOUR TO SECOND literals.
Example | Description | Display string |
|---|---|---|
INTERVAL '23:59:59.999999'HOUR TO SECOND INTERVAL '00 23:59:59.999999'HOUR TO SECOND | 23 hour 59 minute 59.999999 second | +00 23:59:59.999999 |
INTERVAL '23:60:59.999999'HOUR TO SECOND | The minute value exceeds 59, so it returns the error. | - |
INTERVAL '23:59:60.999999'HOUR TO SECOND | The second value exceeds 59, so it returns the error. | - |
INTERVAL '99:59:59.9999999'HOUR TO SECOND | The fractional seconds are rounded off to become 100 hour, then it exceeds the leading precision 2, so it returns the error. | - |
INTERVAL '99:59:59.9999999'HOUR(3) TO SECOND | 4 day 4 hour | +004 04:00:00.000000 |
INTERVAL '11:22:29.569'HOUR(3) TO SECOND(1) | 11 hour 22 minute 29.6 second | +000 11:22:29.6 |
INTERVAL '+999999:59:59.999999'HOUR(6) TO SECOND(6) | 41666 day 15 hour 59 minute 59.999999 second | +041666 15:59:59.999999 |
INTERVAL '-999999:59:59.999999'HOUR(6) TO SECOND(6) | -(41666 day 15 hour 59 minute 59.999999 second) | -041666 15:59:59.999999 |
Interval MINUTE TO SECOND
The followings are examples of using interval MINUTE TO SECOND literals.
Example | Description | Display string |
|---|---|---|
INTERVAL '15:23.123456'MINUTE TO SECOND INTERVAL '00 00:15:23.123456'MINUTE TO SECOND | 15 minute 23.123456 second | +00 00:15:23.123456 |
INTERVAL '15:60.123456'MINUTE TO SECOND | The second value exceeds 59, so it returns the error. | - |
INTERVAL '99:59.999999'MINUTE TO SECOND(2) | The fractional seconds are rounded off to become 100 minute, then it exceeds the leading precision 2, so it returns the error. | - |
INTERVAL '99:59.999999'MINUTE(3) TO SECOND(2) | 1 hour 40 minute | +000 01:40:00.00 |
INTERVAL '+999999:59.999999'MINUTE(6) TO SECOND(6) | 694 day 10 hour 39 minute 59.999999 second | +000694 10:39:59.999999 |
INTERVAL '-999999:59.999999'MINUTE(6) TO SECOND(6) | -(694 day 10 hour 39 minute 59.999999 second) | -000694 10:39:59.999999 |
Null Value
Null value is an unknown value or an undefined value. NULL value can be a value of any data type. The unknown value of the boolean type is represented as null value. Null value is defined as a keyword and it is not case-sensitive.
The following is an example of null value representation.
NULL Null
Comments
Single Line Comment
A single line comment is a comment which starts with -- or //. The single line comment processes a comment from the behind of the comment's symbol to the end of the line.
The following is an example of using a single line comment.
gSQL> SELECT I1, -- I2, I3, 2 I4, I5 3 FROM T1; I1 I4 I5 --------- --------- --------- column i1 column i4 column i5 1 row selected. gSQL> SELECT I1, // I2, I3, 2 I4, I5 3 FROM T1; I1 I4 I5 --------- --------- --------- column i1 column i4 column i5 1 row selected.
Multiple Line Comment
A multiple line comment is a comment which starts with /* and ends with */. Multiple line comments specify a comment from /* to */, and it can use multiple lines to represent comments.
The following is an example of using multiple line comment.
gSQL> SELECT I1, I2, I3, I4, I5 2 /* Output 3 all columns of TABLE T1 */ 4 FROM T1; I1 I2 I3 I4 I5 --------- --------- --------- --------- --------- column i1 column i2 column i3 column i4 column i5 1 row selected.
Hint Comment
A hint comment is a comment which starts with /*+ and ends with */. Hint comment is similar to multiple line comment, but the difference is that the hint comment has + at the beginning. Do not use a space between * and +. If so, it will be treated as multiple line comment.
Unlike other comments, a hint comment is specified to be used only at the location which is right after the SELECT keyword. The processing method which a user specified to GOLDILOCKS optimizer is described in the hint comment. For more information, refer to hint clause. The following is an example of using hint comment.
gSQL> SELECT /*+ FULL(T1) */ * FROM T1; I1 I2 I3 I4 I5 --------- --------- --------- --------- --------- column i1 column i2 column i3 column i4 column i5 1 row selected.
SQL Reserved Words and Keywords
SQL Reserved Words
GOLDILOCKS supports reserved words which are specified as SQL reserved words. The SQL reserved words can not be used other than specified location.
SQL reserved words can be used as identifiers by using double quotes ("), but it is not recommended to use it as follows, because readability decreases.
gSQL> CREATE TABLE "SELECT" ( "FROM" INTEGER ); Table created. gSQL> INSERT INTO "SELECT" ( "FROM" ) VALUES ( 1 ); 1 row created. gSQL> SELECT "FROM" FROM "SELECT"; FROM ---- 1 1 row selected.
The followings are SQL reserved words of GOLDILOCKS. * marked SQL reserved words are supported by the SQL standard. For more information about the list, refer to V$RESERVED_WORDS.
ABSOLUTE ACCESS ALL * ALLOCATE * ALTER * AND * ANY * ARE * AS * ASYMMETRIC * AT * AUTHORIZATION * BEGIN * BETWEEN * BOTH * BY * CALL * CASE * CHECK * CLOSE * COLUMN * COMMENT COMMIT * CONNECT * CONSTRAINT * CREATE * CROSS * CURRENT * CURRENT_CATALOG * CURRENT_DATE * CURRENT_DEFAULT_TRANSFORM_GROUP * CURRENT_PATH * CURRENT_ROLE * CURRENT_ROW * CURRENT_SCHEMA * CURRENT_TIME * CURRENT_TIMESTAMP * CURRENT_TRANSFORM_GROUP_FOR_TYPE * CURRENT_USER * DATABASE DEALLOCATE * DECLARE * DEFAULT * DELETE * DEREF * DESCRIBE * DETERMINISTIC * DISCONNECT * DISTINCT * DROP * ELSE * END * END_EXEC * ESCAPE * EXCEPT * EXEC * EXECUTE * EXISTS * FALSE * FETCH * FILTER * FIRST FOR * FOREIGN * FREE * FROM * FULL * FUNCTION * GET * GLOBAL * GRANT * GROUP * HAVING * HOLD * IDENTIFIED IF IMMEDIATE IN * INDICATOR * INNER * INOUT * INSERT * INTERSECT * INTO * IS * JOIN * LAST LEADING * LEFT * LIKE * LIMIT LOCAL * LOCALTIME * LOCALTIMESTAMP * MATCH * MEMBER * MERGE * MINUS NATURAL * NEW * NEXT NOT * NULL * OF * OFFSET * OLD * ON * OPEN * OR * ORDER * OUT * PREPARE * PRIMARY * PRIOR PROCEDURE * PROFILE REF * REFERENCES * RELATIVE RELEASE * RENAME RETURN * RETURNING RETURNS * REVOKE * RIGHT * ROLLBACK * ROW * ROWID ROWS * ROW_NUMBER * SAVEPOINT * SELECT * SESSION_USER * SET * SOME * SQL * SQLEXCEPTION * SQLSTATE * SQLWARNING * START * SYMMETRIC * SYNONYM SYSDATE SYSTEM * SYSTEM_USER * SYSTIME SYSTIMESTAMP TABLE * THEN * TO * TRAILING * TRIGGER * TRUE * TRUNCATE * UNION * UNIQUE * UNKNOWN * UPDATE * UPPER * USER * USING * VALUES * VIEW WHEN * WHENEVER * WHERE * WINDOW * WITH * WITHOUT *
SQL Keywords
GOLDILOCKS SQL keywords are not reserved words. However, they are keywords which are internally used by GOLDILOCKS. Therefore, it is not recommended to use GOLDILOCKS SQL keywords because it can decrease the readability of the results.
GOLDILOCKS SQL keywords list can be viewed through V$KEYWORDS.
Compatibility for Syntax Elements
The SQL standard compatibility for syntax element is as follows.
Feature ID | Description | Availability |
|---|---|---|
E021-03 | Character literals | O |
E131 | Null value support (nulls in lieu of values) | O |
E161 | SQL comments using leading double minus | O |
F051-01 | DATE data type (including support of DATE literal) | O |
F051-02 | TIME data type (including support of TIME literal) with fractional seconds precision of at least 0 | O |
F051-03 | TIMESTAMP data type (including support of TIMESTAMP literal) with fractional seconds precision of at least 0 and 6 | O |
F271 | Compound character literals | X |
F383 | Set column not null clause | O |
F391 | Long identifiers | X |
F392 | Unicode escapes in identifiers | X |
F393 | Unicode escapes in literals | X |
T023 | Compound binary literals | X |
T024 | Spaces in binary literals | X |
T101 | Enhanced nullability determination | X |
T351 | Bracketed comments | X |
T591 | UNIQUE constraints of possibly null columns | O |
X041 | Basic table mapping: null absent | X |
X042 | Basic table mapping: null as nil | X |
X051 | Advanced table mapping: null absent | X |
X052 | Advanced table mapping: null as nil | X |
X170 | XML null handling options | X |
X400 | Name and identifier mapping | X |
Data Type
Numeric Type
Numeric data types are classified according to the storage method and the fractional part representation.
Classification by the storage method
Decimal numeric type
It stores decimal numbers in 100 digits basis.
Types: NUMBER, NUMERIC, FLOAT
Binary numeric type
It stores numbers of C language as it is.
Types: NATIVE_INTEGER, NATIVE_DOUBLE
Classification by fractional part representation
Fixed point data type (exact numeric)
It is a numeric type whose scale is fixed.
Types: NUMERIC(precision, scale), NATIVE_INTEGER
Floating point data type (approximate numeric)
It is a numeric type whose scale is not fixed.
Types: FLOAT(precision), NATIVE_DOUBLE
Decimal Numeric Type
This type's precision and scale are based on decimal number. The precision indicates accuracy of the valid digits, and the scale indicates the range of fraction.
Decimal Fixed Point Number Type
The decimal fixed point number type is defined in SQL.
Type | Decimal precision | Decimal scale | Refer to |
|---|---|---|---|
NUMBER( p ) | p | 0 | |
NUMBER( p, s ) | p | s | |
NUMERIC( p ) | p | 0 | |
NUMERIC( p, s ) | p | s | |
DECIMAL( p ) | p | 0 | NUMERIC type alias |
DECIMAL( p, s ) | p | s | NUMERIC type alias |
DEC( p ) | p | 0 | NUMERIC type alias |
DEC( p, s ) | p | s | NUMERIC type alias |
SMALLINT | 5 | 0 | NUMBER type alias |
INTEGER | 10 | 0 | NUMBER type alias |
BIGINT | 19 | 0 | NUMBER type alias |
INT2 | 5 | 0 | NUMBER type alias |
INT4 | 10 | 0 | NUMBER type alias |
INT8 | 19 | 0 | NUMBER type alias |
Decimal Floating Point Number Type
The decimal floating point number type is defined in SQL.
Type | Decimal precision | Decimal scale | Refer to |
|---|---|---|---|
NUMBER | 38 | N/A | |
FLOAT( p ) | ceil( log10 2p ) | N/A | |
REAL | ceil( log10 224 ) = 8 | N/A | FLOAT type alias |
DOUBLE | ceil( log10 253 ) = 16 | N/A | FLOAT type alias |
FLOAT4 | ceil( log10 224 ) = 8 | N/A | FLOAT type alias |
FLOAT8 | ceil( log10 253 ) = 16 | N/A | FLOAT type alias |
Binary Number Type
This type's precision and scale are based on binary number. The precision indicates accuracy of the valid digits, and the scale indicates the range of fraction.
Binary Fixed Point Number Type
The binary fixed point number type refers to the signed integer data type of C language. 1 bit is used to represent the sign bit, and other bits are used to represent the precision, but not any bit is used to represent the scale.
Type | Binary precision | Binary scale | Refer to |
|---|---|---|---|
NATIVE_SMALLINT | 15 | 0 | |
NATIVE_INTEGER | 31 | 0 | |
NATIVE_BIGINT | 63 | 0 |
Binary Floating Point Number Type
The binary floating point type refers to the float and double data type in C language. 1 bit is used to represent the sign bit, and other bits are used to represent the precision and scale.
Type | Binary precision | Binary scale | Refer to |
|---|---|---|---|
NATIVE_REAL | 23 | 8 | |
NATIVE_DOUBLE | 52 | 11 |
The precision and scale of binary floating point type is subject to change depending on the influence of the compiler and OS.
CHARACTER STRING Type
CHARACTER STRING data types are classified according to whether it is a variable length string and the maximum length of string.
Classification by whether it is a variable length string
Fixed length string
Refer to CHARACTER.
Variable length string
Refer to CHARACTER VARYING, CHARACTER LONG VARYING.
Classification by the maximum length of a string
2000 [ characters or bytes ]
Refer to CHARACTER.
4000 [ characters or bytes ]
Refer to CHARACTER VARYING.
100 megabytes
Refer to CHARACTER LONG VARYING.
BINARY STRING Type
BINARY STRING data types are classified according to whether it is a variable length binary string and the maximum length of binary string.
Classification by whether it is a variable length binary string
Fixed length binary string
Refer to BINARY.
Variable length binary string
Refer to BINARY VARYING, BINARY LONG VARYING.
Classification by the maximum length of binary string
2000
Refer to BINARY.
4000
Refer to BINARY VARYING.
100 Mega Bytes
Refer to BINARY LONG VARYING.
Date/ Time Type
Date/ time data type specifies the year, month, day, hour, minute, second, time zone offset in accordance with their representation method. Date/ time type has DATE, TIME, TIMESTAMP types.
INTERVAL Type
INTERVAL data type specifies the time interval. It specifies the time interval of the year, month, day, hour, minute, second in accordance with their representation method.
INTERVAL data types are classified to the YEAR TO MONTH family type and the DAY TO SECOND family type, according to the range of value representation.
BOOLEAN Type
The BOOLEAN data type stores truth value of TRUE, FALSE, UNKNOWN. UNKNOWN value is represented as a null value. All expressions used as conditions return the BOOLEAN value and the column or the value defined as a BOOLEAN data type can be used as a condition.
The following literals can be stored in the boolean data type.
TRUE
Keyword: TRUE
Literal: 't', 'true' , 'y', 'yes' , 'on' ,'1'
FALSE
Keyword: FALSE
Literal: 'f', 'false', 'n', 'no', 'off', '0'
UNKNOWN
Keyword: UNKNOWN, NULL
For more information, refer to BOOLEAN.
ROWID Type
All records stored in the database have unique location information. The record identifier (ROWID) is used to distinguish each record.
ROWID data type is used to store and manage the record identifier (ROWID). Record identifier (ROWID) is obtained by the query using the ROWID pseudo column.
For more information, refer to ROWID.
Type Comparison
Comparing two types is executed on the basis of one representative type. If the comparison target type is different from the representative type, then the comparison can go through a type conversion. The representative types for type comparison defines the representative type for comparing two types.
The following table describes target type conversion for comparison per each representative type.
The followings are abbreviations which are used for the type comparison.
"
VC": CHARACTER VARYING"
LC": CHARACTER LONG VARYING"
VB": BINARY VARYING"
LB": BINARY LONG VARYING"
NB": NATIVE_BIGINT"
ND": NATIVE_DOUBLE"
NU": NUMBER"
DA": DATE"
TI": TIME"
TZ": TIME WITH TIMEZONE"
TS": TIMESTAMP"
SZ": TIMESTAMP WITH TIMEZONE"
YM": INTERVAL YEAR TO MONTH"
DS": INTERVAL DAY TO SECOND"
BO": BOOLEAN"
RI": ROWID
In the type comparison table, the built-in data types are represented by an abbreviated word enclosed in double quotes ("").
"CHAR": CHARACTER
"VARCHAR": CHARACTER VARYING
"LONG VARCHAR": CHARACTER LONG VARYING
"VARBINARY": BINARY VARYING
"LONG VARBINARY": BINARY LONG VARYING
"TIME_TZ": TIME WITH TIMEZONE
"TIMESTAMP_TZ": TIMESTAMP WITH TIMEZONE
"INTERVAL_YM": INTERVAL YEAR TO MONTH
"INTERVAL_DS": INTERVAL DAY TO SECOND
Data type | C H A R | V A R C H A R | L O N G V A R C H A R | B I N A R Y | V A R B I N A R Y | L O N G V A R B I N A R Y | N A T I V E S M A L L I N T | N A T I V E I N T E G E R | N A T I V E B I G I N T | N A T I V E R E A L | N A T I V E D O U B L E | N U M B E R | N U M E R I C | F L O A T | D A T E | T I M E | T I M E T Z | T I M E S T A M P | T I M E S T A T M P T Z | I N T E R V A L Y M | I N T E R V A L D S | B O O L E A N | R O W I D |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CHAR |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |||
VARCHAR |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |||
LONG VARCHAR |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |||
BINARY |
|
|
| ||||||||||||||||||||
VARBINARY |
|
|
| ||||||||||||||||||||
LONG VARBINARY |
|
|
| ||||||||||||||||||||
NATIVE_SMALLINT |
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||
NATIVE_INTEGER |
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||
NATIVE_BIGINT |
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||
NATIVE_REAL |
|
|
|
|
|
|
|
|
|
|
| ||||||||||||
NATIVE_DOUBLE |
|
|
|
|
|
|
|
|
|
|
| ||||||||||||
NUMBER |
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||
NUMERIC |
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||
FLOAT |
|
|
|
|
|
|
|
|
|
|
|
|
| ||||||||||
DATE |
|
|
|
|
|
| |||||||||||||||||
TIME |
|
|
|
|
| ||||||||||||||||||
TIME_TZ |
|
|
|
|
| ||||||||||||||||||
TIMESTAMP |
|
|
|
|
|
| |||||||||||||||||
TIMESTAMP_TZ |
|
|
|
|
|
| |||||||||||||||||
INTERVAL_YM |
|
|
|
|
|
|
|
|
|
| |||||||||||||
INTERVAL_DS |
|
|
|
|
|
|
|
|
|
| |||||||||||||
BOOLEAN |
|
|
|
| |||||||||||||||||||
ROWID |
|
|
|
|
Source type | Converted type |
|---|---|
CHAR | CHAR (no conversion) |
VARCHAR | VARCHAR (no conversion) |
Source type | Converted type |
|---|---|
CHAR | CHAR (no conversion) |
VARCHAR | VARCHAR (no conversion) |
LONG VARCHAR | LONG VARCHAR (no conversion) |
Source type | Converted type |
|---|---|
BINARY | BINARY (no conversion) |
VARBINARY | VARBINARY (no conversion) |
Source type | Converted type |
|---|---|
BINARY | BINARY (no conversion) |
VARBINARY | VARBINARY (no conversion) |
LONG VARBINARY | LONG VARBINARY (no conversion) |
Source type | Converted type |
|---|---|
CHAR | NATIVE_BIGINT |
VARCHAR | NATIVE_BIGINT |
LONG VARCHAR | NATIVE_BIGINT |
NATIVE_SMALLINT | NATIVE_SMALLINT (no conversion) |
NATIVE_INTEGER | NATIVE_INTEGER (no conversion) |
NATIVE_BIGINT | NATIVE_BIGINT (no conversion) |
Source type | Converted type |
|---|---|
CHAR | NATIVE_DOUBLE |
VARCHAR | NATIVE_DOUBLE |
LONG VARCHAR | NATIVE_DOUBLE |
NATIVE_SMALLINT | NATIVE_SMALLINT (no conversion) |
NATIVE_INTEGER | NATIVE_INTEGER (no conversion) |
NATIVE_BIGINT | NATIVE_BIGINT (no conversion) |
NATIVE_REAL | NATIVE_REAL (no conversion) |
NATIVE_DOUBLE | NATIVE_DOUBLE (no conversion) |
NUMBER | NUMBER (no conversion) |
NUMERIC | NUMERIC (no conversion) |
FLOAT | FLOAT (no conversion) |
Source type | Converted type |
|---|---|
CHAR | NUMBER |
VARCHAR | NUMBER |
LONG VARCHAR | NUMBER |
NATIVE_SMALLINT | NATIVE_SMALLINT (no conversion) |
NATIVE_INTEGER | NATIVE_INTEGER (no conversion) |
NATIVE_BIGINT | NATIVE_BIGINT (no conversion) |
NATIVE_REAL | NATIVE_REAL (no conversion) |
NATIVE_DOUBLE | NATIVE_DOUBLE (no conversion) |
NUMBER | NUMBER (no conversion) |
NUMERIC | NUMERIC (no conversion) |
FLOAT | FLOAT (no conversion) |
Source type | Converted type |
|---|---|
CHAR | DATE |
VARCHAR | DATE |
LONG VARCHAR | DATE |
DATE | DATE (no conversion) |
Source type | Converted type |
|---|---|
CHAR | TIME |
VARCHAR | TIME |
LONG VARCHAR | TIME |
TIME | TIME (no conversion) |
Source type | Converted type |
|---|---|
CHAR | TIME_TZ |
VARCHAR | TIME_TZ |
LONG VARCHAR | TIME_TZ |
TIME | TIME_TZ |
TIME_TZ | TIME_TZ (no conversion) |
Source type | Converted type |
|---|---|
CHAR | TIMESTAMP |
VARCHAR | TIMESTAMP |
LONG VARCHAR | TIMESTAMP |
DATE | DATE (no conversion) |
TIMESTAMP | TIMESTAMP (no conversion) |
Source type | Converted type |
|---|---|
CHAR | TIMESTAMP_TZ |
VARCHAR | TIMESTAMP_TZ |
LONG VARCHAR | TIMESTAMP_TZ |
DATE | TIMESTAMP_TZ |
TIMESTAMP | TIMESTAMP_TZ |
TIMESTAMP_TZ | TIMESTAMP_TZ (no conversion) |
Source type | Converted type |
|---|---|
CHAR | INTERVAL_YM |
VARCHAR | INTERVAL_YM |
LONG VARCHAR | INTERVAL_YM |
NATIVE_SMALLINT | INTERVAL_YM |
NATIVE_INTEGER | INTERVAL_YM |
NATIVE_BIGINT | INTERVAL_YM |
NUMBER | INTERVAL_YM |
NUMERIC | INTERVAL_YM |
FLOAT | INTERVAL_YM |
INTERVAL_YM | INTERVAL_YM (no conversion) |
Source type | Converted type |
|---|---|
CHAR | INTERVAL_DS |
VARCHAR | INTERVAL_DS |
LONG VARCHAR | INTERVAL_DS |
NATIVE_SMALLINT | INTERVAL_DS |
NATIVE_INTEGER | INTERVAL_DS |
NATIVE_BIGINT | INTERVAL_DS |
NUMBER | INTERVAL_DS |
NUMERIC | INTERVAL_DS |
FLOAT | INTERVAL_DS |
INTERVAL_DS | INTERVAL_DS (no conversion) |
Source type | Converted type |
|---|---|
CHAR | BOOLEAN |
VARCHAR | BOOLEAN |
LONG VARCHAR | BOOLEAN |
BOOLEAN | BOOLEAN (no conversion) |
Source type | Converted type |
|---|---|
CHAR | ROWID |
VARCHAR | ROWID |
LONG VARCHAR | ROWID |
ROWID | ROWID (no conversion) |
Type Conversion
Type conversions are classified into implicit type conversion and explicit type conversion.
Implicit type conversion occurs in an expression, an operator, a function, a condition, for select, insert, delete, update.
Explicit type conversion occurs through the CAST operator.
The availability of type conversion describes the availability of data type conversion from a type to another type.
In the type conversion table, the built-in data types are represented by an abbreviated string enclosed in double quotes ("").
"CHAR": CHARACTER
"VARCHAR": CHARACTER VARYING
"LONG VARCHAR": CHARACTER LONG VARYING
"VARBINARY": BINARY VARYING
"LONG VARBINARY": BINARY LONG VARYING
"TIME_TZ": TIME WITH TIMEZONE
"TIMESTAMP_TZ": TIMESTAMP WITH TIMEZONE
"INTERVAL_YM": INTERVAL YEAR TO MONTH
"INTERVAL_DS": INTERVAL DAY TO SECOND
Data type | C H A R | V A R C H A R | L O N G V A R C H A R | B I N A R Y | V A R B I N A R Y | L O N G V A R B I N A R Y | N A T I V E S M A L L I N T | N A T I V E I N T E G E R | N A T I V E B I G I N T | N A T I V E R E A L | N A T I V E D O U B L E | N U M B E R | N U M E R I C | F L O A T | D A T E | T I M E | T I M E T Z | T I M E S T A M P | T I M E S T A T M P T Z | I N T E R V A L Y M | I N T E R V A L D S | B O O L E A N | R O W I D |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CHAR | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | |||
VARCHAR | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | |||
LONG VARCHAR | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | O | |||
BINARY | O | O | O | ||||||||||||||||||||
VARBINARY | O | O | O | ||||||||||||||||||||
LONG VARBINARY | O | O | O | ||||||||||||||||||||
NATIVE_SMALLINT | O | O | O | O | O | O | O | O | O | O | O | O | O | ||||||||||
NATIVE_INTEGER | O | O | O | O | O | O | O | O | O | O | O | O | O | ||||||||||
NATIVE_BIGINT | O | O | O | O | O | O | O | O | O | O | O | O | O | ||||||||||
NATIVE_REAL | O | O | O | O | O | O | O | O | O | O | O | ||||||||||||
NATIVE_DOUBLE | O | O | O | O | O | O | O | O | O | O | O | ||||||||||||
NUMBER | O | O | O | O | O | O | O | O | O | O | O | O | O | ||||||||||
NUMERIC | O | O | O | O | O | O | O | O | O | O | O | O | O | ||||||||||
FLOAT | O | O | O | O | O | O | O | O | O | O | O | O | O | ||||||||||
DATE | O | O | O | O | O | O | |||||||||||||||||
TIME | O | O | O | O | O | ||||||||||||||||||
TIME_TZ | O | O | O | O | O | ||||||||||||||||||
TIMESTAMP | O | O | O | O | O | O | O | ||||||||||||||||
TIMESTAMP_TZ | O | O | O | O | O | O | O | O | |||||||||||||||
INTERVAL_YM | O | O | O | O | O | O | O | O | O | O | |||||||||||||
INTERVAL_DS | O | O | O | O | O | O | O | O | O | O | |||||||||||||
BOOLEAN | O | O | O | O | |||||||||||||||||||
ROWID | O | O | O | O |
Conversion to CHARACTER type
When the source type is CHARACTER type:
If the source type precision is bigger than the CHARACTER type precision, then an error occurs.
If the source type precision is equal to the CHARACTER type precision, then the string is not changed.
If the source type precision is smaller than the CHARACTER type precision, then space characters are added to the string as many as the precision difference.
When the source type is CHARACTER VARYING type or CHARACTER LONG VARYING type:
If the source type string length is bigger than the CHARACTER type precision, then an error occurs.
If the source type string length is equal to the CHARACTER type precision, then the string is not changed.
If the source type string length is smaller than the CHARACTER type precision, then space characters are added to the string as many as precision difference.
When the source type is numeric type, date/time type, INTERVAL type, BOOLEAN type or ROWID type:
If the converted string length of the source type is bigger than the CHARACTER type precision, then an error occurs.
If the converted string length of the source type is equal to the CHARACTER type precision, the string is not changed.
If the converted string length of the source type is smaller than the CHARACTER type precision, then space characters are added to the string as many as precision difference.
Conversion to CHARACTER VARYING type
When the source type is CHARACTER type:
If the source type precision is bigger than the CHARACTER VARYING type precision, then an error occurs.
If the source type precision is equal or smaller than the CHARACTER VARYING type precision, then the string is not changed.
When the source type is CHARACTER VARYING type or CHARACTER LONG VARYING type:
If the source type string length is bigger than the CHARACTER VARYING type precision, then an error occurs.
If the source type string length is equal or smaller than the CHARACTER VARYING type precision, then the string is not changed.
When the source type is numeric type, date/time type, INTERVAL type, BOOLEAN type or ROWID type:
If the converted string length of the source type is bigger than the CHARACTER VARYING type precision, then an error occurs.
If the converted string length of the source type is equal or smaller than the CHARACTER VARYING type precision, then the string is not changed.
Conversion to CHARACTER LONG VARYING type
When the source type is CHARACTER STRING type:
The source type string is not changed.
When the source type is numeric type, date/time type, INTERVAL type, BOOLEAN type or ROWID type:
The converted string of the source type is not changed.
Conversion to BINARY type
When the source type is BINARY type:
If the source type precision is bigger than the BINARY type precision, then an error occurs.
If the source type precision is equal to the BINARY type precision, then the binary string is not changed.
If the source type precision is smaller than the BINARY type precision, the X'00' characters are added to the binary string as many as the precision difference.
When the source type is BINARY VARYING type or BINARY LONG VARYING type:
If the source type binary string length is bigger than the BINARY type precision, then an error occurs.
If the source type binary string length is equal to the BINARY type precision, then the binary string is not changed.
If the source type binary string length is smaller than the BINARY type precision, the X'00' characters are added to a binary string as many as precision difference.
Conversion to BINARY VARYING type
When the source type is BINARY type:
If the source type precision is bigger than the BINARY VARYING type precision, then an error occurs.
If the source type precision is equal or smaller than the BINARY VARYING type precision, then the binary string is not changed.
When the source type is BINARY VARYING type, BINARY LONG VARYING type:
If the source type binary string length is bigger than the BINARY VARYING type precision, then an error occurs.
If the source type binary string length is equal or smaller than the BINARY VARYING type precision, the binary string is not changed.
Conversion to BINARY LONG VARYING type
If the source type is BINARY STRING type, the source type binary string is not changed.
Conversion to numeric type
When the source type is CHARACTER STRING type:
If the string does not comply with the numeric format, then an error occurs.
An overflow or rounding can occur due to the precision and scale which is defined in the converted type.
When the source type is numeric type:
An overflow or rounding can occur due to the precision and scale which is defined in the converted type.
When the source type is INTERVAL type:
It can be converted to the numeric type only when the source type is the single field (YEAR, MONTH, DAY, HOUR, MINUTE, SECOND).
An overflow or rounding can occur due to the precision and scale which is defined in the converted type.
Conversion to DATE type
When the source type is CHARACTER STRING type:
If the string does not comply with the DATE type format, then an error occurs.
An overflow can occur due to a value range which is defined in the converted type.
When the source type is DATE type or TIMESTAMP type:
The error does not occur.
When the source type is TIMESTAMP WITH TIME ZONE type:
It is converted to the DATE type value upon consideration of the time zone offset.
Conversion to TIME type
When the source type is CHARACTER STRING type:
If the string does not comply with the TIME type format, then an error occurs.
A rounding can occur due to a value range which is defined in the converted type.
When the source type is TIME type or TIMESTAMP type:
The error does not occur.
When the source type is TIME WITH TIME ZONE type or TIMESTAMP WITH TIME ZONE type:
It is converted to the value of TIME type upon consideration of the time zone offset.
Conversion to TIME WITH TIME ZONE type
When the source type is CHARACTER STRING type:
If the string does not comply with the TIME WITH TIME ZONE type format, then an error occurs.
A rounding can occur due to a value range which is defined in the converted type.
When the source type is TIME type, TIME WITH TIME ZONE type or TIMESTAMP WITH TIME ZONE type:
It is converted to the value of TIME WITH TIME ZONE type upon consideration of the time zone offset.
Conversion to TIMESTAMP type
When the source type is CHARACTER STRING type:
If the string does not comply with the TIMESTAMP type format, then an error occurs.
An overflow or rounding can occur due to a value range which is defined in the converted type.
When the source type is DATE type or TIMESTAMP type:
The error does not occur.
When the source type is TIMESTAMP WITH TIME ZONE type:
It is converted to the TIMESTAMP type value upon consideration of the time zone offset.
Conversion to TIMESTAMP WITH TIME ZONE type
When the source type is CHARACTER STRING type:
If the string does not comply with the TIMESTAMP WITH TIME ZONE type format, then an error occurs.
An overflow or rounding can occur due to a value range which is defined in the converted type.
When the source type is DATE type, TIMESTAMP type or TIMESTAMP WITH TIME ZONE type:
It is converted to the value of TIMESTAMP WITH TIME ZONE type upon consideration of the time zone offset.
Conversion to INTERVAL YEAR TO MONTH family type
When the source type is CHARACTER STRING type:
If the string does not comply with the year-month interval literal format, then an error occurs.
For more information, refer to Interval Literals.
An overflow can occur due to a precision which is defined in the converted type.
When the source type is NATIVE_SMALLINT, NATIVE_INTEGER, NATIVE_BIGINT, NUMBER, NUMERIC or FLOAT type:
The converted type should be a single field (YEAR, MONTH).
An overflow can occur due to a precision which is defined in the converted type.
When the source type is INTERVAL YEAR TO MONTH family type:
An overflow can occur due to a precision which is defined in the converted type.
Conversion to INTERVAL DAY TO SECOND family type
When the source type is CHARACTER STRING type:
If the string does not comply with the day-time interval literal format, then an error occurs.
For more information, refer to Interval Literals.
An overflow or rounding can occur due to the precision which is defined in the converted type.
When the source type is NATIVE_SMALLINT, NATIVE_INTEGER, NATIVE_BIGINT, NUMBER, NUMERIC, or FLOAT type:
The converted type should be a single field (DAY, HOUR, MINUTE, SECOND)
An overflow or rounding can occur due to the precision which is defined in the converted type.
When the source type is INTERVAL DAY TO SECOND family type:
An overflow or rounding can occur due to the precision which is defined in the converted type.
Conversion to BOOLEAN type
When the source type is CHARACTER STRING type:
The conversion is available when the string is "TRUE" or "FALSE", and it is case-insensitive. (It is convertible even when the string includes a space before and after it.)
When the source type is BOOLEAN type:
The error does not occur.
Conversion to ROWID type
When the source type is CHARACTER STRING type:
If the string does not comply with the ROWID type format, then an error occurs.
When the source type is ROWID type:
The error does not occur.
Type Combination
When Type Combination Is Required
A CASE operator and a set operator have many expressions as a result of operation. Each expression can have different types each other as follows. In this case, the result type should be determined.
The following describes an execution result of a CASE operator.
SELECT CASE expr WHEN expr THEN char(3)
WHEN expr THEN char(5)
ELSE char(1)
END
FROM t1;The following describes an execution result of a set operator.
SELECT float_column FROM t1 UNION ALL SELECT number_precision_column FROM t2 UNION ALL SELECT native_integer_column FROM t3;
A rule is applied to determine the result type according to the type combination. The following is an example of applying the rule.
Result type combination rule
CASE operator
Result Type Combination Rule
Each expression's data type should be the same family type which is available to combine.
Examples of applying result type combination rule
CASE operator
The result types determined by result type combination rule are described in the following table.
The following abbreviations are used to describe the result type combination rule.
"VC": CHARACTER VARYING
"LC": CHARACTER LONG VARYING
"VB": BINARY VARYING
"LB": BINARY LONG VARYING
"NS": NATIVE_SMALLINT
"NI": NATIVE_INTEGER
"NB": NATIVE_BIGINT
"NR": NATIVE_REAL
"ND": NATIVE_DOUBLE
"FL": FLOAT
"NU": NUMBER
"DA": DATE
"TI": TIME
"TZ": TIME WITH TIMEZONE
"TS": TIMESTAMP
"SZ": TIMESTAMP WITH TIMEZONE
"YM": INTERVAL YEAR TO MONTH
"DS": INTERVAL DAY TO SECOND
"BO": BOOLEAN
"RI": ROWID
In result type combination table, the built-in data types are represented by an abbreviated word enclosed in double quotes ("").
"CHAR": CHARACTER
"VARCHAR": CHARACTER VARYING
"LONG VARCHAR": CHARACTER LONG VARYING
"BINARY": BINARY
"VARBINARY": BINARY VARYING
"LONG VARBINARY": BINARY LONG VARYING
"TIME_TZ": TIME WITH TIMEZONE
"TIMESTAMP_TZ": TIMESTAMP WITH TIMEZONE
"INTERVAL_YM": INTERVAL YEAR TO MONTH
"INTERVAL_DS": INTERVAL DAY TO SECOND
Data type | C H A R | V A R C H A R | L O N G V A R C H A R | B I N A R Y | V A R B I N A R Y | L O N G V A R B I N A R Y | N A T I V E S M A L L I N T | N A T I V E I N T E G E R | N A T I V E B I G I N T | N A T I V E R E A L | N A T I V E D O U B L E | N U M B E R | N U M E R I C | F L O A T | D A T E | T I M E | T I M E T Z | T I M E S T A M P | T I M E S T A T M P T Z | I N T E R V A L Y M | I N T E R V A L D S | B O O L E A N | R O W I D |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CHAR |
|
| |||||||||||||||||||||
VARCHAR |
|
| |||||||||||||||||||||
LONG VARCHAR |
| ||||||||||||||||||||||
BINARY |
|
| |||||||||||||||||||||
VARBINARY |
|
| |||||||||||||||||||||
LONG VARBINARY |
| ||||||||||||||||||||||
NATIVE_SMALLINT |
|
|
|
|
|
|
|
| |||||||||||||||
NATIVE_INTEGER |
|
|
|
|
|
|
|
| |||||||||||||||
NATIVE_BIGINT |
|
|
|
|
|
|
|
| |||||||||||||||
NATIVE_REAL |
|
|
|
|
|
|
|
| |||||||||||||||
NATIVE_DOUBLE |
|
|
|
|
|
|
|
| |||||||||||||||
NUMBER |
|
|
|
|
|
|
|
| |||||||||||||||
NUMERIC |
|
|
|
|
|
|
|
| |||||||||||||||
FLOAT |
|
|
|
|
|
|
|
| |||||||||||||||
DATE |
|
|
| ||||||||||||||||||||
TIME |
|
| |||||||||||||||||||||
TIME_TZ |
|
| |||||||||||||||||||||
TIMESTAMP |
|
|
| ||||||||||||||||||||
TIMESTAMP_TZ |
|
|
| ||||||||||||||||||||
INTERVAL_YM |
| ||||||||||||||||||||||
INTERVAL_DS |
| ||||||||||||||||||||||
BOOLEAN |
| ||||||||||||||||||||||
ROWID |
|
The result type of when all is CHAR type
If the lengths are different, then it is VARCHAR type.
If the lengths are equal, then it is CHAR type.
The result type of when all is BINARY type
If the lengths are different, then it is VARBINARY type.
If the lengths are equal, then it is BINARY type.
The result type of INTERVAL YEAR TO MONTH type
If YEAR type and MONTH type are mixed, then it is INTERVAL YEAR TO MONTH type.
If there is only YEAR type, then it is INTERVAL YEAR type.
If there is only MONTH type, then it is INTERVAL MONTH type.
The result type of INTERVAL DAY TO SECOND type
The start field is the biggest range field of each target expression.
The end field is the smallest range field of each target expression.
e.g. {INTERVAL DAY, INTERVAL HOUR} => INTERVAL DAY TO HOUR
The precision, scale of the result type
CHARACTER STRING type
The maximum character length of the target expression
BINARY STRING type
The maximum character length of the target expression
NUMERIC type
It specifies an acceptable maximum range of the type's value.
TIME/TIMESTAMP type
The maximum fractional seconds precision of the target expression
INTERVAL YEAR TO MONTH
The maximum leading precision of the target expression
INTERVAL DAY TO SECOND
Leading precision is the maximum leading precision of the start field
Fractional seconds precision is the maximum fractional seconds precision.
For more information, refer to Type Comparison.
Compatibility for Data Type
The SQL standard compatibility for data type is as follows.
Feature ID | Description | Availability |
|---|---|---|
B033 | Untyped SQL-invoked function arguments | X |
E011-01 | INTEGER and SMALLINT data types | O |
E011-02 | REAL, DOUBLE PRECISION, and FLOAT data types | O |
E011-03 | DECIMAL and NUMERIC data types | X |
E011-04 | Arithmetic operators | O |
E011-05 | Numeric comparison | O |
E011-06 | Implicit casting among the numeric data types | O |
E021-01 | CHARACTER data type | O |
E021-02 | CHARACTER VARYING data type | O |
E021-03 | Character literals | O |
E021-04 | CHARACTER_LENGTH function | O |
E021-05 | OCTET_LENGTH function | O |
E021-06 | SUBSTRING function | O |
E021-07 | Character concatenation | O |
E021-08 | UPPER and LOWER functions | O |
E021-09 | TRIM function | O |
E021-10 | Implicit casting among the fixed-length and variable-length character string types | O |
E021-11 | POSITION function | O |
E021-12 | Character comparison | O |
E071-05 | Columns combined via table operators need not have exactly the same data type | O |
F051-01 | DATE data type (including support of DATE literal) | O |
F051-02 | TIME data type (including support of TIME literal) with fractional seconds precision of at least 0 | O |
F051-03 | TIMESTAMP data type (including support of TIMESTAMP literal) with fractional seconds precision of at least 0 and 6 | O |
F051-04 | Comparison predicate on DATE, TIME, and TIMESTAMP data types | X |
F051-05 | Explicit CAST between datetime types and character string types | O |
F054 | TIMESTAMP in DATE type precedence list | X |
F382 | Alter column data type | O |
F611 | Indicator data types | X |
F741 | Referential MATCH types | X |
J521 | JDBC data types | X |
J622 | external Java types | X |
S011-01 | USER_DEFINED_TYPES view | X |
S023 | Basic structured types | X |
S024 | Enhanced structured types | X |
S025 | Final structured types | X |
S026 | Self-referencing structured types | X |
S041 | Basic reference types | X |
S043 | Enhanced reference types | X |
S051 | Create table of type | X |
S071 | SQL paths in function and type name resolution | X |
S091-01 | Arrays of built-in data types | X |
S091-02 | Arrays of distinct types | X |
S092 | Arrays of user-defined types | X |
S094 | Arrays of reference types | X |
S161 | Subtype treatment | X |
S162 | Subtype treatment for references | X |
S201-02 | Array as result type of functions | X |
S231 | Structured type locators | X |
S261 | Specific type method | X |
S272 | Multisets of user-defined types | X |
S274 | Multisets of reference types | X |
S281 | Nested collection types | X |
S401 | Distinct types based on array types | X |
S402 | Distinct types based on distinct types | X |
T021 | BINARY and VARBINARY data types | O |
T022 | Advanced support for BINARY and VARBINARY data types | O |
T031 | BOOLEAN data type | O |
T041 | Basic LOB data type support | X |
T042 | Extended LOB data type support | X |
T051 | Row types | X |
T071 | BIGINT data type | O |
T201 | Comparable data types for referential constraints | X |
T322 | Declared data type attributes | X |
X010 | XML type | X |
X011 | Arrays of XML type | X |
X012 | XMultisets of XML type | X |
X013 | Distinct types of XML type | X |
X014 | Attributes of XML type | X |
X015 | Fields of XML type | X |
X181 | XML(DOCUMENT(UNTYPED)) type | X |
X182 | XML(DOCUMENT(ANY)) type | X |
X190 | XML(SEQUENCE) type | X |
X191 | XML(DOCUMENT(XMLSCHEMA)) type | X |
X192 | XML(CONTENT(XMLSCHEMA)) type | X |
X231 | XML(CONTENT(UNTYPED)) type | X |
X232 | XML(CONTENT(ANY)) type | X |
X251 | Persistent XML values of XML(DOCUMENT(UNTYPED)) type | X |
X252 | Persistent XML values of XML(DOCUMENT(ANY)) type | X |
X253 | Persistent XML values of XML(CONTENT(UNTYPED)) type | X |
X254 | Persistent XML values of XML(CONTENT(ANY)) type | X |
X255 | Persistent XML values of XML(SEQUENCE) type | X |
X256 | Persistent XML values of XML(DOCUMENT(XMLSCHEMA)) type | X |
X257 | Persistent XML values of XML(CONTENT(XMLSCHEMA)) type | X |
X260 | XML type: ELEMENT clause | X |
X261 | XML type: NAMESPACE without ELEMENT clause | X |
X263 | XML type: NO NAMESPACE with ELEMENT clause | X |
X264 | XML type: schema location | X |
X410 | Alter column data type: XML type | X |
Format String
Format string defines the format which is used when a numeric type or date/time type is converted to a character string or when a character string is converted to a numeric types or date/time type.
When a numeric type or date/time type is converted to a character string type, the representation format of the string is as follows.
Refer to TO_CHAR( number )), TO_CHAR( datetime ).
Numeric type: TO_CHAR( 1234.56, 'S9,999.99' ) → '+1,234.56'
Date/time type: TO_CHAR( SYSDATE, 'YYYY-MM-DD' ) → '2012-07-15'
When a character string is converted to the numeric type or date/time type, the representation format of the string is as follows.
Refer to TO_NUMBER, TO_NATIVE_REAL, TO_NATIVE_DOUBLE.
Refer to TO_DATE.
Refer to TO_TIMESTAMP, TO_TIMESTAMP_WITH_TIME_ZONE.
Refer to TO_TIME, TO_TIME_WITH_TIME_ZONE.
Numeric type: TO_NUMBER( '+1,234.56', 'S9,999.99' ) → NUMBER TYPE
Date/time type: TO_DATE( '2012-07-15', 'YYYY-MM-DD' ) → DATE TYPE
Format strings are classified according to the type. • Numeric data type: Refer to Number Format String. • Date/time type: Refer to Datetime Format String.
Number Format String
Number format string defines the format which is used when a numeric type is converted to a character string type, or when a character string type is converted to a numeric type.
Number format string is used as an argument of the functions such as TO_CHAR( number ), TO_NATIVE_SMALLINT, TO_NATIVE_INTEGER, TO_NATIVE_BIGINT, TO_NUMBER, TO_NATIVE_REAL, TO_NATIVE_DOUBLE.
Number format string can specify multiple format elements according to the desired format.
All number format elements are rounded off to fit the format. If the number of digits before the decimal point of the value to be converted is bigger than the number of digits specified in the format string, then they are replaced with '#' character. If the format element representing the sign of MI, S, PR is not specified, a negative number returns - sign and a positive number returns a white space to the front of the number.
Format element | Example | Description |
|---|---|---|
, (comma) | 9,999 | It returns a comma to the specified position. Multiple commas can be specified. Format string can not begin with a comma, and it can not come after the decimal point (.). |
. (period) | 99.99 | It returns a decimal point (.) to the specified position. The decimal point in the format string can be specified only once. |
$ | $9999 | It returns the $ sign to the front of the number. |
0 | 0999 9990 | It returns zero (0) to the front of or to the end of the number. If the number of digits of the value to be converted is smaller than the number of digits to the zero position of the format string, then the gap is filled with zero (0)s and is returned. |
9 | 9999 | It returns a white space and numbers according to the sign and the number of specified 9. If the number of digits of the value to be converted is smaller than the number of the specified 9, then the gap is filled with white spaces and is returned. For a positive number, a white space is returned to the front of the number. For a negative number, '-' symbol is returned to the front of the number. If the value before the format string's decimal point is 0, then 0 is returned as a white space. e.g. TO_CHAR( 0.123, '9.999' ) → .123 e.g. TO_CHAR( 0, '9' ) → 0 |
B | B9999 | If the value is zero, it returns a white space. |
EEEE | 9.9EEEE | It returns in exponential notation. It can be at the end of format string or it can be in front of S, MI, PR. It can not be specified together with a comma (,). |
MI | 9999MI | For a positive number, a white space is returned to the end of the number. For a negative number, '-' symbol is returned to the end of the number. It can be specified only at the end of format string and it can not be specified together with S, PR. |
PR | 9999PR | For a positive number, white spaces are returned to the beginning and end of the number. For a negative number, it returns the number into the inside of angle brackets. <number> It can be specified only at the end of format string, and it can not be specified together with S, MI. |
RN rn | RN rn | Roman numerals are converted to uppercase and returned. (RN) Roman numerals are converted to lowercase and returned. (rn) Only the numbers between 1 ~ 3999 are returned. It can be specified together only with FM format element, but it can not be specified with any other format elements. It can not be used in TO_NUMBER function. |
S | S9999 9999S | For a positive number, '+' symbol is returned to the front of the number. For a negative number, '-' symbol is returned to the front of the number. (S9999 For a positive number, '+' symbol is returned to the end of the number. For a negative number, '-' symbol is returned to the end of the number. (9999S) It can be specified only at the beginning of format string or at the end of format string. It can not be specified together with MI, PR. |
V | 999V99 | 10n(n: the digit number of 9 after V format element) multiplied by the value is returned. It can not specified together with the decimal point (.). It can not be used in TO_NUMBER function. |
X | XXXX xxxx | It returns the white space and hexadecimal number according to the digit number of the specified X. It converts an integer value to the hexadecimal number, and returns it. (A non-integer value is rounded off to make it to an integer value) XXX returns hexadecimal uppercase letters and xxxx returns hexadecimal lowercase letters. If the number of the converted hexadecimal digit is smaller than the number of the specified X, then the gap is filled with white spaces and is returned. Only 0 and positive integers are processed, and negative numbers are replaced with '#'. It can be specified together only with format element 0 and FM, but it can not be specified with any other format elements. |
FM | FM | It removes the front and end white spaces, and returns left aligned effect. It removes the front and end white spaces of the number. It removes zero(0)s under the decimal point which are added by 9 format element. |
Followings are examples of using number format string.
TO_CHAR( 12345, '99,999' ) : ' 12,345' TO_CHAR( 123456789, '999,999,999' ) : ' 123,456,789' TO_CHAR( 12.345, '99.999' ) : ' 12.345' TO_CHAR( 1234.56, '$9,999.99' ) : ' $1,234.56' TO_CHAR( 123, '099999' ) : ' 000123' TO_CHAR( 0.2, '0.9' ) : ' 0.2' TO_CHAR( 123.45, '999999.99' ) : ' 123.45' TO_CHAR( -123.45, '999999.99' ) : ' -123.45' TO_CHAR( 123.45, 'FM999999.99' ) : '123.45' TO_CHAR( -123.45, 'FM999999.99' ) : '-123.45' TO_CHAR( 12345.67, '999.99' ) : '#######' TO_CHAR( 123.100567, '999.999' ) : ' 123.101' TO_CHAR( 0.2, '90.99' ) : ' 0.20' TO_CHAR( 0.2, '99.99' ) : ' .20' TO_CHAR( 0, '90.99' ) : ' 0.00' TO_CHAR( 0, 'B90.99' ) : ' ' TO_CHAR( 123.45, '9.9EEEE' ) : ' 1.2E+02' TO_CHAR( 123.45, '999.99MI' ) : '123.45 ' TO_CHAR( -123.45, '999.99MI' ) : '123.45-' TO_CHAR( 123.45, '999.99PR' ) : ' 123.45 ' TO_CHAR( -123.45, '999.99PR' ) : '<123.45>' TO_CHAR( 123, 'RN' ) : ' CXXIII' TO_CHAR( 123, 'rn' ) : ' cxxiii' TO_CHAR( 123, 'FMRN' ) : 'CXXIII' TO_CHAR( 4000, 'RN' ) : '###############' TO_CHAR( 123.45, 'S999.99' ) : '+123.45' TO_CHAR( -123.45, 'S999.99' ) : '-123.45' TO_CHAR( 123.45, '999.99S' ) : '123.45+' TO_CHAR( -123.45, '999.99S' ) : '123.45-' TO_CHAR( 123.45, '999V999' ) : ' 123450' TO_CHAR( 123, 'XX' ) : ' 7B' TO_CHAR( 123, 'xx' ) : ' 7b' TO_CHAR( 45678, 'XXXXXXX' ) : ' B26E' TO_CHAR( 45678, 'FMXXXXXXX' ) : 'B26E' TO_CHAR( 123.45, '99,999.999999' ) : ' 123.450000' TO_CHAR( 123.45, 'FM99,999.999999' ) : '123.45'
Datetime Format String
Datetime format string defines the format which is used when a date/time type is converted to a character string type, or when a character string type is converted to a date/time type.
Datetime format string is used as an argument of the functions such as TO_CHAR( datetime ), TO_DATE, TO_TIMESTAMP, TO_TIMESTAMP_WITH_TIME_ZONE, TO_TIME, TO_TIME_WITH_TIME_ZONE.
For datetime format string, if the format string is not specified, then the default value is used. The default value of each type is specified in the session property (NLS _ * _ FORMAT).
DATE: Refer to NLS_DATE_FORMAT.
TIMESTAMP: Refer to NLS_TIMESTAMP_FORMAT.
TIMESTAMP WITH TIME ZONE: Refer to NLS_TIMESTAMP_WITH_TIME_ZONE_FORMAT.
TIME: Refer to NLS_TIME_FORMAT.
TIME WITH TIME ZONE: Refer to NLS_TIME_WITH_TIME_ZONE_FORMAT.
NLS * _FORMAT values can be changed by using ALTER SESSION SET property_name.
In datetime format string, multiple format elements can be specified upon the desired representation.
Format element | Whether to use TO_* datetime | Description |
|---|---|---|
- / , . ; : "text" Special characters | Y | It returns the format element character to the specified location. |
AD A.D. | Y | AD with or without periods. |
AM A.M. | Y | AM with or without periods. |
BC B.C. | Y | BC with or without periods. |
CC | N | Century If the last two digits of the four digits year is 01~ 99, the value which is added by one to the first two digits is returned. (e.g. If the year is 2005, 21 is returned.) If the last two digits of the four digits year is 00, the first two digits value is returned. (e.g. If the year is 2000, 20 is returned.) |
D | Y | It returns the sequence of the day in a week. (1 ~ 7) Sunday is 1, saturday is 7, and so on. |
DAY Day day | Y | It returns the day of the week. (e.g. SUNDAY)
|
DD | Y | It returns the sequence of the day in a month. (1 ~ 31) |
DDD | Y | It returns the sequence of the day in a year. (1 ~ 366) |
DY Dy dy | Y | It returns the abbreviated word for the day of the week. (e.g. SUN)
|
FF[1..6] | Y | It returns fractional seconds as many as the number of the specified digits (1-6) after FF. If the number is not specified, the default value is 6. (FF is equal to FF6.) If the number of fractional seconds digit is bigger than the number specified after FF, then it is rounded down. If the number of fractional seconds digit is smaller than the number specified after FF, then zero(0) is added according to the specified number. It can not be used in DATE type. |
HH HH12 | Y | The hour (1 ~ 12) |
HH24 | Y | The hour (0 ~ 23) |
IW | N | The week containing the first thursday of the year designated as the calendar week by ISO 8601 standards (1 ~ 52 week or 1 ~ 53 weeks) becomes the first week.
|
IYYY | N | The 4 digits year embracing the calendar week defined by ISO 8601 standards. |
IYY IY I | N | The 3 digits year embracing the calendar week defined by ISO 8601 standards. The 2 digits year embracing the calendar week defined by ISO 8601 standards. The single digit year embracing the calendar week defined by ISO 8601 standards. |
J | Y | Julian day: The number of days since BC 4714-11-24 |
MI | Y | Minute (0 ~ 59) |
MM | Y | Month (01 ~ 12), January(01)~December(12) |
MON Mon mon | Y | The abbreviated word for the month. (e.g. JAN)
|
MONTH Month month | Y | The month name (e.g. JANUARY)
|
PM P.M. | Y | PM with or without periods. |
Q | N | The quarter of the year (1 ~ 4) January to March is 1 and October to December is 4. |
RM Rm rm | Y | It returns the roman numeral month. (e.g. I)
|
RR | Y | Adjusted two digit year The two digit year represented by RR can be converted to four digit year as follows.
|
RRRR | Y | Adjusted four digit year Two digit or four digit can be input. Two digit input is processed in the same way as RR. |
SS | Y | Second (0 ~ 59) |
SSSSS | Y | Seconds since last midnight (0 ~ 86399) |
TZH | Y | Time Zone Hour It can not be used in DATE, TIMESTAMP, TIME types. It is available in TIMESTAMP WITH TIME ZONE, TIME WITH TIME ZONE types. |
TZM | Y | Time Zone Minute It can not be used in DATE, TIMESTAMP, TIME types. It can be used only in TIMESTAMP WITH TIME ZONE, TIME WITH TIME ZONE types. |
WW | N | The sequence of the week in a year. (1~ 53) The first week 1 starts on the first day of the year and continues to the seventh day of the year. |
W | N | The sequence of the week in a month. (1 ~ 5) The first week 1 starts on the first day of the month and ends on the seventh day. |
Y,YYY | Y | It returns the year with comma in the Y,YYY form. |
YYYY SYYYY | Y | Four digit year. If it is BC, SYYYY returns '-' signal. |
YYY YY Y | Y |
|
The followings are examples of using datetime format string.
* - / , . ; : "text" Special character
• TO_CHAR( TO_DATE( '2012-07-15 03:30:30', 'YYYY-MM-DD HH12:MI:SS' ),
'YYYY/MM/DD HH12:MI:SS' )
==> '2012/07/15 03:30:30'
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ),
'YYYY"year" DDD"th day"' )
==> '2012year 197th day'* AD
• TO_CHAR( TO_DATE( '2012-07-15 AD', 'YYYY-MM-DD AD' ), 'YYYY AD' )
==> '2012 AD'
• TO_CHAR( TO_DATE( '0001-01-01 BC', 'YYYY-MM-DD AD'), 'YYYY AD' )
==> '0001 BC'
* BC
• TO_CHAR( TO_DATE( '0001-01-01 BC', 'YYYY-MM-DD BC'), 'YYYY BC' )
==> '0001 BC'
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'YYYY BC' )
==> '2012 AD'* AM
• TO_CHAR( TO_DATE( '2012-07-15 03:30:30 AM',
'YYYY-MM-DD HH12:MI:SS AM' ),
'HH12:MI:SS AM' )
==> '03:30:30 AM'
• TO_CHAR( TO_DATE( '2012-07-15 21:30:30', 'YYYY-MM-DD HH24:MI:SS' ),
'HH12:MI:SS AM' )
==> '09:30:30 PM'
* PM
• TO_CHAR( TO_DATE( '2012-07-15 03:30:30',
'YYYY-MM-DD HH24:MI:SS' ),
'HH12:MI:SS PM' )
==> '03:30:30 AM'
• TO_CHAR( TO_DATE( '2012-07-15 09:30:30 PM',
'YYYY-MM-DD HH12:MI:SS PM' ),
'HH12:MI:SS PM' )
==> '09:30:30 PM'* CC
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'CC' )
==> '21'* D
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'D' )
==> '1'
* DD
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'DD' )
==> '15'
* DDD
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'DDD' )
==> '197'* DAY
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'DAY' )
==> 'SUNDAY '
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'Day' )
==> 'Sunday '
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'day' )
==> 'sunday '
* DY
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'DY' )
==> 'SUN'
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'Dy' )
==> 'Sun'
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'dy' )
==> 'sun'* FF[1 ... 6]
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 03:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'FF' )
==> '123456'
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 03:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'FF5' )
==> '12345'
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 03:30:45.9',
'YYYY-MM-DD HH24:MI.SS.FF1' ) ,
'FF6' )
==> '900000'* HH HH12 HH24
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 03:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'HH12' )
==> '03'
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 23:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'HH12' )
==> '11'
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 23:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'HH24' )
==> '23'* IW
• TO_CHAR( DATE'2016-01-01', 'IW' )
==> 53
• TO_CHAR( DATE'2014-12-30', 'IW' )
==> 01* IYYY
• TO_CHAR( DATE'2016-01-01', 'IYYY' )
==> 2015
• TO_CHAR( DATE'2014-12-30', 'IYYY' )
==> 2015
* IYY
• TO_CHAR( DATE'2016-01-01', 'IYY' )
==> 015
* IY
• TO_CHAR( DATE'2016-01-01', 'IY' )
==> 15
* I
• TO_CHAR( DATE'2016-01-01', 'I' )
==> 5* J
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'J' )
==> '2456124'
• TO_CHAR( TO_DATE( '2456124', 'J' ), 'YYYY-MM-DD' )
==> '2012-07-15'* MI
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 23:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'MI' )
==> '30'* MM
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 23:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'MM' )
==> '07'* MON
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'MON' )
==> 'JUL'
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'Mon' )
==> 'Jul'
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'mon' )
==> 'jul'
* MONTH
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'MONTH' )
==> 'JULY '
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'Month' )
==> 'July '
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'month' )
==> 'july '* Q
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'Q' )
==> '3'* RM
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'RM' )
==> 'VII '
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'Rm' )
==> 'Vii '
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'rm' )
==> 'vii '* RR, RRRR ( The current year is 2014. )
• TO_CHAR( TO_DATE( '49-07-15', 'RR-MM-DD' ), 'RRRR' )
==> '2049'
• TO_CHAR( TO_DATE( '49-07-15', 'RR-MM-DD' ), 'YYYY' )
==> '2049'
• TO_CHAR( TO_DATE( '50-07-15', 'RR-MM-DD' ), 'RRRR' )
==> '1950'
• TO_CHAR( TO_DATE( '50-07-15', 'RR-MM-DD' ), 'YYYY' )
==> '1950'
• TO_CHAR( TO_DATE( '50-07-15', 'YY-MM-DD' ), 'RRRR' )
==> '2050'
• TO_CHAR( TO_DATE( '49-07-15', 'RRRR-MM-DD' ), 'YYYY' )
==> '2049'
• TO_CHAR( TO_DATE( '50-07-15', 'RRRR-MM-DD' ), 'YYYY' )
==> '1950'
* RR, RRRR ( The current year is 2051. )
• TO_CHAR( TO_DATE( '49-07-15', 'RR-MM-DD' ), 'RRRR' )
==> '2149'
• TO_CHAR( TO_DATE( '49-07-15', 'RR-MM-DD' ), 'YYYY' )
==> '2149'
• TO_CHAR( TO_DATE( '50-07-15', 'RR-MM-DD' ), 'RRRR' )
==> '2050'
• TO_CHAR( TO_DATE( '50-07-15', 'RR-MM-DD' ), 'YYYY' )
==> '2050'
• TO_CHAR( TO_DATE( '50-07-15', 'YY-MM-DD' ), 'RRRR' )
==> '2050'
• TO_CHAR( TO_DATE( '49-07-15', 'RRRR-MM-DD' ), 'YYYY' )
==> '2149'
• TO_CHAR( TO_DATE( '50-07-15', 'RRRR-MM-DD' ), 'YYYY' )
==> '2050'* SS
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 23:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'SS' )
==> '45'
* SSSSS
• TO_CHAR( TO_TIMESTAMP( '2012-07-15 23:30:45.123456',
'YYYY-MM-DD HH24:MI:SS.FF6' ),
'SSSSS' )
==> '84645'* TZH
• TO_CHAR( TO_TIMESTAMP_TZ( '2012-07-15 23:30:45.123456 +09:00',
'YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM' ),
'TZH' )
==> '+09'
* TZM
• TO_CHAR( TO_TIMESTAMP_TZ( '2012-07-15 23:30:45.123456 +09:00',
'YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM' ),
'TZM' )
==> '00'
• TO_CHAR( TO_TIMESTAMP_TZ( '2012-07-15 23:30:45.123456 +09:00',
'YYYY-MM-DD HH24:MI:SS.FF6 TZH:TZM' ),
'TZH:TZM' )
==> '+09:00'* WW
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'WW' )
==> '29'
* W
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'W' )
==> '3'* Y,YYY
• TO_CHAR( TO_DATE( '2,012-07-15', 'Y,YYY-MM-DD' ), 'Y,YYY' )
==> '2,012'
* YYYY
• TO_CHAR( TO_DATE( '2012-07-15', 'YYYY-MM-DD' ), 'YYYY' )
==> '2012'
* SYYYY
• TO_CHAR( TO_DATE( '-0001-01-01', 'SYYYY-MM-DD' ), 'SYYYY' )
==> '-0001'
* YYY
• TO_CHAR( TO_DATE( '012-07-15', 'YYY-MM-DD' ), 'YYY' )
==> '012'
• TO_CHAR( TO_DATE( '012-07-15', 'YYY-MM-DD' ), 'YYYY' )
==> '2012' ( (Current year / 1000) is 2 )
* YY
• TO_CHAR( TO_DATE( '12-07-15', 'YY-MM-DD' ), 'YY' )
==> '12'
• TO_CHAR( TO_DATE( '12-07-15', 'YY-MM-DD' ), 'YYYY' )
==> '2012' ( (Current year / 100) is 20 )
==> '2112' ( (Current year / 100) is 21 )
* Y
• TO_CHAR( TO_DATE( '2-07-15', 'Y-MM-DD' ), 'Y' )
==> '2'
• TO_CHAR( TO_DATE( '12-07-15', 'YY-MM-DD' ), 'YYYY' )
==> '2012' ( (Current year / 10 years) is 201 )
==> '2052' ( (Current year / 10 years) is 205 )Expressions
Expression is a combination of value, operator and function for getting data values.
The following is the position of the SQL commands in which expression can be used. • Target clause in SELECT • GROUP BY clause in SELECT • ORDER BY clause in SELECT • WHERE clause and HAVING clause in SELECT • INSERT VALUES clause • UPDATE SET clause • RETURN clause in INSERT, DELETE, UPDATE
Expression types are various as follows. • Simple expression • Compound expresssion • Boolean value expression • Case expression • Datetime expression • Scalar subquery expression • Sequence manipulation expression
Simple expressions are column, pseudo columns, literals, and null value. Compound expressions are combination of multiple expressions.
For more information, refer to the followings. • Null Value • Literals • Pseudo Columns • Operators • Functions
Boolean Value Expression
Syntax
<boolean value expression> ::=
<boolean term>
| <boolean value expression> OR <boolean term>
<boolean term> ::=
<boolean factor>
| <boolean term> AND <boolean factor>
<boolean factor> ::=
[ NOT ] <boolean test>
<boolean test> ::=
<boolean primary> [ IS [ NOT ] <truth value> ]
<truth value> ::=
TRUE
| FALSE
| UNKNOWN
<boolean primary> ::=
<column>
<condition>
| <boolean predicand>
<boolean predicand> ::=
<parenthesized boolean value expression>
| <nonparenthesized value expression primary>
<parenthesized boolean value expression> ::=
<left paren> <boolean value expression> <right paren>Description
<boolean value expression> describes a boolean value. <boolean primary> with boolean value are <column>, <condition>, and <boolean predicand>. <column> should be declared as BOOLEAN type, and it is allowed to return a boolean value using CAST.
<boolean value expression> can use logical operators such as AND, OR, NOT, and the dedicated operators of boolean value such as IS, IS NOT are also supported.
IS operator and IS NOT operator which are described in <boolean test> determine whether the boolean value described in <boolean primary> matches with one of the <truth value> (TRUE, FALSE, UNKNOWN).
For more information, refer to Conditions.
Example
gSQL> SELECT * FROM T1 WHERE CAST('TRUE' AS BOOLEAN);
I1
-----
TRUE
FALSE
null
3 rows selected.
gSQL> SELECT * FROM T1 WHERE I1;
I1
----
TRUE
1 row selected.
gSQL> SELECT * FROM T1 WHERE I1 IS TRUE;
I1
----
TRUE
1 row selected.
gSQL> SELECT * FROM T1 WHERE I1 IS NOT FALSE;
I1
----
TRUE
null
2 rows selected.
gSQL> SELECT * FROM T1 WHERE I1 IS UNKNOWN;
I1
----
null
1 row selected.CASE Expression
Syntax
<case expression> ::=
<simple case>
| <searched case>
<simple case> ::=
CASE expr WHEN comparison_expr THEN result
[ WHEN comparison_expr THEN result ... ]
[ ELSE result ]
END
<searched case> ::=
CASE WHEN condition THEN result
[ WHEN condition THEN result ... ]
[ ELSE result ]
ENDDescription
WHEN ... THEN clause is evaluated in the order of which is described in the CASE statement. If a comparison result is FALSE, the subsequent WHEN ... THEN clauses are evaluated until TRUE comes up. If a comparison result is TRUE, the result is returned, and the evaluation is not executed any more.
• Simple case The comparison_expr of CASE expr and WHEN ... THEN clause is evaluated as the equal operation. (expr = comparison_expr). • Searched case The condition of WHEN ... THEN clause is evaluated.
If all evaluation results of the WHEN clause are FALSE, then result of ELSE clause is returned. If ELSE clause is omitted, NULL is returned as a result.
If there are multiple types of THEN or ELSE clause results, the result type is determined by Result Type Combination Rule.
For more information, refer to the followings. • COALESCE • NULLIF
Example
Simple case
gSQL> SELECT I1,
CASE I1 WHEN 1 THEN 'ONE'
WHEN 2 THEN 'TWO'
ELSE 'NUMBER'
END AS CASE_RESULT1,
CASE I1 WHEN 1 THEN 'ONE'
WHEN 2 THEN 'TWO'
END AS CASE_RESULT2
FROM T1;
I1 CASE_RESULT1 CASE_RESULT2
-- ------------ -----------
1 ONE ONE
2 TWO TWO
3 NUMBER null
3 rows selected.Searched case
gSQL> SELECT I1,
CASE WHEN I1 = 1 THEN 'ONE'
WHEN I1 = 2 THEN 'TWO'
ELSE 'NUMBER'
END AS CASE_RESULT1,
CASE WHEN I1 = 1 THEN 'ONE'
WHEN I1 = 2 THEN 'TWO'
END AS CASE_RESULT2
FROM T1;
I1 CASE_RESULT1 CASE_RESULT2
-- ------------ ------------
1 ONE ONE
2 TWO TWO
3 NUMBER null
3 rows selected.CAST Specification
Syntax
CAST( expression AS data_type )
Description
CAST converts the expression data type to the data type of the specified data_type.
Example
gSQL> SELECT CAST( '1-2' AS INTERVAL YEAR TO MONTH ) AS RESULT FROM DUAL; RESULT ------ +01-02 1 row selected.
Scalar Subquery Expression
Scalar subquery expression is a subquery which returns a single row with one column as a result. The scalar subquery expression result is the values described in select list of the subquery.
If the subquery does not return any row, then the result value is NULL, and if it returns two or more rows, then an error occurs.
Scalar subquery expression can be described on most position which describes expression. The subquery should be enclosed in parentheses. Even when scalar subquery expression is used as a function argument and the scalar subquery expression is enclosed in parentheses, other parentheses for the subquery is required regardless of the function parentheses. Otherwise, an error occurs.
The following is an example of using scalar subquery expression.
gSQL> select * from dual where dummy = (select * from dual);
DUMMY
-----
X
1 row selected.
gSQL> select sum(select 1 from dual) from dual;
ERR-42000(40000): syntax error
select sum(select 1 from dual) from dual
...........^ ^
Error at line 1
gSQL> select sum((select 1 from dual)) from dual;
SUM((SELECT 1 FROM DUAL))
-------------------------
1
1 row selected.Compatibility
The SQL standard compatibility for expression is as follows.
Feature ID | Description | Availability |
|---|---|---|
E121-03 | Value expressions in ORDER BY clause | O |
F051-05 | Basic date and time Explicit CAST between datetime types and character string types | O |
F201 | CAST function | O |
F261-01 | Simple CASE | O |
F261-02 | Searched CASE | O |
F261-03 | NULLIF | O |
F261-04 | COALESCE | O |
F263 | Comma-separated predicates in simple CASE expression | X |
F301 | CORRESPONDING in query expressions | X |
F385 | Drop column generation expression clause | X |
F561 | Full value expressions | X |
F846 | Octet support in regular expression operators | X |
F847 | Nonconstant regular expressions | X |
F850 | Top-level <order by clause> in <query expression> | O |
F855 | Nested <order by clause> in <query expression> | O |
F856 | Nested <fetch first clause> in <query expression> | O |
F857 | Top-level <fetch first clause> in <query expression> | O |
F861 | Top-level <result offset clause> in <query expression> | O |
F863 | Nested <result offset clause> in <query expression> | O |
S091-03 | Arrays expressions | X |
S111 | ONLY in query expressions | X |
T121 | WITH (excluding RECURSIVE) in query expression | X |
T581 | Regular expression substring function | X |
Pseudo Columns
Pseudo column is not only similar to function, but also it is similar to table column because it can return different value in row unit every time the pseudo column is executed.
Name | Description | Refer to |
|---|---|---|
CURRVAL | It is a pseudo column which is related to a sequence. | |
NEXTVAL | It is a pseudo column which is related to a sequence. | |
ROWNUM | It is the row number which satisfies the condition. | |
ROWID | It returns the record identifier in database. | |
CLUSTER_GROUP_ID | It returns the group identifier in database. | |
CLUSTER_MEMBER_ID | It returns the member identifier in which the record is stored. | |
CLUSTER_GROUP_NAME | It returns the group name in which the record is stored. | |
CLUSTER_MEMBER_NAME | It returns the member name in which the record is stored. | |
CLUSTER_SHARD_ID | It returns the shard identifier in which the record is stored. |
ROWID Pseudo Column
ROWID pseudo column is a record identifier, and it returns the identification information of each database record.
ROWID has the following information to identify the location within the database depending on the system.
Standalone system • OBJECT_ID • TABLESPACE_ID • PAGE_ID • OFFSET in PAGE
Cluster system • GRID_BLOCK_SEQUENCE • GRID_BLOCK_ID • MEMBER_ID • SHARD_ID
The information stored inside in base 64 encoding is converted into the value such as A-Z, a-z, 0-9, +, / then output when querying ROWID.
Each information to identify the address within database stored in ROWID can be obtained using the ROWID-related functions.
The address of the deleted record can be newly reassigned to the record to be inserted.
ROWID pseudo column can be used only in SELECT operation, but it can not be used in INSERT, UPDATE, DELETE operations.
For more information, refer to ROWID, ROWID-related Functions.
The following is an example of querying ROWID pseudo column.
gSQL> SELECT ROWID FROM T1;
ROWID
-----------------------
AAAAAAAAFpEAACAAAEAkAAA
AAAAAAAAFpEAACAAAEAkAAB
AAAAAAAAFpEAACAAAEAkAAC
AAAAAAAAFpEAACAAAEAkAAD
AAAAAAAAFpEAACAAAEAkAAE
5 rows selected.CLUSTER_GROUP_ID Pseudo Column
CLUSTER_GROUP_ID pseudo column returns the group identifier of a server in which the record is stored.
CLUSTER_GROUP_ID pseudo column can perform the SELECT, but it can not perform the INSERT, UPDATE, or DELETE.
This information in valid in the cluster system.
The following is an example of retrieving CLUSTER_GROUP_ID pseudo column.
gSQL> SELECT T1.C1, T1.CLUSTER_GROUP_ID FROM T1; C1 T1.CLUSTER_GROUP_ID -- ------------------- A 1 B 2 C 3 3 rows selected.
CLUSTER_MEMBER_ID Pseudo Column
CLUSTER_MEMBER_ID pseudo column returns the member identifier of a server in which the record is stored.
CLUSTER_MEMBER_ID pseudo column can perform the SELECT, but it can not perform the INSERT, UPDATE, or DELETE.
This information in valid in the cluster system.
The following is an example of retrieving CLUSTER_MEMBER_ID pseudo column.
gSQL> SELECT T1.C1, T1.CLUSTER_MEMBER_ID FROM T1; C1 T1.CLUSTER_MEMBER_ID -- -------------------- A 1 B 3 C 5 3 rows selected.
CLUSTER_GROUP_NAME Pseudo Column
CLUSTER_GROUP_NAME pseudo column returns the group name of a server in which the record is stored.
CLUSTER_GROUP_NAME pseudo column can perform the SELECT, but it can not perform the INSERT, UPDATE, or DELETE.
This information in valid in the cluster system.
The following is an example of retrieving CLUSTER_GROUP_NAME pseudo column.
gSQL> SELECT T1.C1, T1.CLUSTER_GROUP_NAME FROM T1; C1 T1.CLUSTER_GROUP_NAME -- --------------------- A G1 B G2 C G3 3 rows selected.
CLUSTER_MEMBER_NAME Pseudo Column
CLUSTER_MEMBER_NAME pseudo column returns the member name of a server in which the record is stored.
CLUSTER_MEMBER_NAME pseudo column can perform the SELECT, but it can not perform the INSERT, UPDATE, or DELETE.
This information in valid in the cluster system.
The following is an example of retrieving CLUSTER_MEMBER_NAME pseudo column.
gSQL> SELECT T1.C1, T1.CLUSTER_MEMBER_NAME FROM T1; C1 T1.CLUSTER_MEMBER_NAME -- ---------------------- A G1N1 B G2N1 C G3N1 3 rows selected.
CLUSTER_SHARD_ID Pseudo Column
CLUSTER_SHARD_ID pseudo column returns the shard identifier in which the record is stored.
CLUSTER_SHARD_ID pseudo column is allowed for SELECT only, but it is not allowed for INSERT, UPDATE, or DELETE.
This information in valid in the cluster system.
The following is an example of retrieving CLUSTER_SHARD_ID pseudo column.
gSQL> SELECT T1.C1, T1.CLUSTER_SHARD_ID FROM T1; C1 CLUSTER_SHARD_ID -- ---------------- A 14 B 17 C 4 3 rows selected.
Compatibility
The SQL standard compatibility for pseudo column is as follows.
Feature ID | Description | Availability |
|---|---|---|
T176 | Sequence generator support | O |
T177 | Sequence generator support: simple restart option | O |
Operators
An operator is represented by one or more specific symbols or keywords, and it performs an operation using one or more arguments.
The operator types are various as follows. • Arithmetic operator • Concatenation operator • Set operator
Arithmetic Operator
Syntax
<arithmetic operator> ::=
<value term>
| <expression> + <value term>
| <expression> - <value term>
<value term> ::=
<value factor>
| <value term> * <value factor>
| <value term> / <value factor>
<value factor> ::=
<expression>
| + <expression>
| - <expression>Description
An arithmetic operator performs an arithmetic operation of the numeric types, date/time types or interval types.
The arithmetic operator precedence is as follows.
Concatenation Operator
Syntax
<concatenation operator> ::=
<expression> || <expression>Description
A concatenation operator returns strings which connect between values of CHARACTER STRING type or BINARY STRING type. For more information, refer to || (CONCATENATE), CONCATENATE.
Set Operator
Syntax
<set operator> ::=
<set operator term>
| <subquery> UNION [ ALL | DISTINCT ] <set operator term>
| <subquery> EXCEPT [ ALL | DISTINCT ] <set operator term>
| <subquery> MINUS [ ALL | DISTINCT ] <set operator term>
<set operator term> ::=
<subquery>
| <subquery> INTERSECT [ ALL | DISTINCT ] <set operator term>Description
set operator performs a set operation of the subquery results.
INTERSECT ALL/DISTINCT has a higher precedence than other set operators.
Operator | Description |
|---|---|
UNION ALL | It is the union which does not exclude duplicated rows of the subquery result. |
UNION DISTINCT | It is the union which excludes duplicated rows of the subquery result. |
EXCEPT ALL | It is the difference set which does not exclude duplicated rows of the subquery result. |
EXCEPT DISTINCT | It is the difference set which excludes duplicated rows of the subquery result. |
MINUS ALL | It is as same as EXCEPT ALL. |
MINUS DISTINCT | It is as same as EXCEPT DISTINCT. |
INTERSECT ALL | It is the intersection which does not exclude duplicated rows of the subquery result. |
INTERSECT DISTINCT | It is the intersection which excludes duplicated rows of the subquery result. |
Compatibility
The SQL standard compatibility for operator is as follows.
Feature ID | Description | Availability |
|---|---|---|
E011-04 | Arithmetic operators | O |
E021-07 | Character concatenation | O |
E071-01 | UNION DISTINCT table operator | O |
E071-02 | UNION ALL table operator | O |
E071-03 | EXCEPT DISTINCT table operator | O |
E071-05 | Columns combined via table operators need not have exactly the same data type | O |
E071-06 | Table operators in subqueries | O |
F041-08 | All comparison operators are supported (rather than just =) | O |
F302-01 | INTERSECT DISTINCT table operator | O |
F302-02 | INTERSECT ALL table operator | O |
F304 | EXCEPT ALL table operator | O |
F846 | Octet support in regular expression operators | X |
J571 | NEW operator | X |
Functions
Functions and operators are similar in features. However, to represent arguments, functions use parentheses after its name. A function can have zero or more arguments. The function has two types as follows. .• Single row function • Aggregate function
Single Row Function
Single row function creates a single result row for each row in the table or view.
The single row functions are as follows.
Numeric function
Character string function returning character values
Character string function returning number values
Datetime function
General comparison function
Conversion function
Conditional function
NULL-related function
ROWID-related function
Encryption function
System information function
Numeric Functions
A numeric value is input in numeric function, and the numeric function returns a numeric result.
For more information about the numeric function types, refer to the followings.
Character String Functions Returning Character Values
A character string type value is input in character string functions returning character values, and the function returns the result of character string type.
For more information about character string functions returning character values types, refer to the followings.
Character String Functions Returning Number Values
A character string type value is input in character string functions returning number values the value, and the function returns the result of number type.
For more information about character string functions returning number values types, refer to the followings.
Datetime Functions
The value of date/time/timestamp/interval type is input in datetime function, and the function returns the result of date/time/timestamp/interval type.
For more information about datetime functions types, refer to the followings.
General Comparison Functions
General comparison function returns a minimum value or a maximum value for the value set.
For more information about general comparison function types, refer to the followings.
Conversion Functions
Conversion function sets the value of a particular data type.
For more information about conversion function types, refer to the followings.
Conditional Functions
Conditional function returns a result of specific value depending on a condition.
For more information about conditional function types, refer to the followings.
NULL-related Functions
NULL-related function returns a result of specific value depending on whether the input value is a NULL value.
For more information about null-related function types, refer to the followings.
ROWID-related Functions
ROWID-related function is used to obtain information about the ROWID. For more information about ROWID-related function types, refer to the followings.
Valid functions in stand-alone
Valid functions in cluster
Encryption Functions
encryption function encrypts, decrypts, or hashes the given plain text by using the specific algorithm, then returns the result.
For more information about the encryption function, refer to DIGEST.
System Information Functions
System information function is used to obtain information about sessions and the system.
For more information about system information function type, refer to the followings.
Aggregate Function
Aggregate function creates a single result row for multiple rows.
For more information about aggregate function types, refer to the followings.
Compatibility
The SQL standard compatibility for function is as follows.
Feature ID | Description | Availability |
|---|---|---|
B033 | Untyped SQL-invoked function arguments | X |
E021-04 | CHARACTER_LENGTH function | O |
E021-05 | OCTET_LENGTH function | O |
E021-06 | SUBSTRING function | O |
E021-08 | UPPER and LOWER functions | O |
E021-09 | TRIM function | O |
E021-11 | POSITION function | O |
E091-01 | AVG | O |
E091-02 | COUNT | O |
E091-03 | MAX | O |
E091-04 | MIN | O |
E091-05 | SUM | O |
E091-06 | ALL quantifier | O |
E091-07 | DISTINCT quantifier | O |
F131-03 | Set functions supported in queries with grouped views | O |
F201 | CAST function | O |
F441 | Extended set function support | X |
F442 | Mixed column references in set functions | X |
F801 | Full set function | X |
F842 | OCCURRENCES_REGEX function | X |
F843 | POSITION_REGEX function | X |
S071 | SQL paths in function and type name resolution | X |
S201-02 | Array as result type of functions | X |
S211 | User-defined cast functions | X |
S241 | Transform functions | X |
T041-03 | POSITION, LENGTH, LOWER, TRIM, UPPER, and SUBSTRING functions for LOB data types | X |
T312 | OVERLAY function | O |
T321-01 | User-defined functions with no overloading | X |
T326 | Table functions | X |
T341 | Overloading of SQL-invoked functions and SQL-invoked procedures | X |
T433 | Multiargument GROUPING function | X |
T441 | ABS and MOD functions | O |
T571 | Array-returning external SQL-invoked functions | X |
T572 | Multiset-returning external SQL-invoked functions | X |
T581 | Regular expression substring function | X |
T614 | NTILE function | X |
T615 | LEAD and LAG functions | X |
T616 | Null treatment option for LEAD and LAG functions | X |
T617 | FIRST_VALUE and LAST_VALUE functions | X |
T618 | NTH_VALUE function | X |
T619 | Nested window functions | X |
T621 | Enhanced numeric functions | O |
Conditions
Condition
Condition is an expression which is evaluated as TRUE, FALSE, UNKNOWN.
Condition can be used in the following SQL statements. • WHERE clauses in DELETE, UPDATE statements • WHERE and HAVING clauses in SELECT statement • Where the BOOLEAN TYPE can be used
The condition types are as follows. • Comparison condition • Logical condition • Null condition • Compound condition • Pattern-matching condition • Between condition • In condition • Exists condition
Precedence | Condition type |
|---|---|
1 | Operators in condition clauses |
2 | =, !=, <, >, <=, >= |
3 | IS [NOT] NULL, [NOT] BETWEEN, [NOT] IN, LIKE, EXISTS |
4 | NOT |
5 | AND |
6 | OR |
Comparison Conditions
It compares both conditional expressions, and returns the boolean type of TRUE, FALSE, UNKNOWN values.
Condition | Description |
|---|---|
= | It checks if both conditions are equal. |
!=, <> | It checks if both conditions are not equal. |
> | It compares which one of both conditions is bigger. |
< | It compares which one of both conditions is smaller. |
>= | It compares which one of both conditions is bigger or equal. |
<= | It compares which one of both conditions is smaller or equal. |
ANY, SOME | If there is a condition whose left expr satisfies at least one of right expr_list (or subquery results), then it returns TRUE. If there is not right subquery result, then it returns FALSE. |
ALL | If there is a condition whose left expr satisfies all right expr_list (or subquery results), then it returns TRUE. If there is not right subquery result, then it returns TRUE. |
For more information, refer to Type Comparison.
< Simple Comparison Conditions >
Syntax
<simple_comparison_condition> ::=
<expr> <comparison_operator> <expr>
| <expr> <comparison_operator> ( <subquery> )
| ( <subquery> ) <comparison_operator> <expr>
| ( <subquery> ) <comparison_operator> ( <subquery> )
| ( <expr_list> ) <comparison_operator> ( <expr_list> )
| ( <expr_list> ) <comparison_operator> ( <subquery> )
| ( <subquery> ) <comparison_operator> ( <expr_list> )
| ( <subquery> ) <comparison_operator> ( <subquery> )
<comparison_operator> ::=
< = >
| < != >
| < < >
| < > >
| < <= >
| < >= >
<expr_list> ::=
<expr>
| <expr>, ... , <expr>
| ( <expr> )
| ( <expr> , ... , <expr> )For more information, refer to Scalar Subquery Expression.
Description
If the expr list or subquery comes to both left and right of comparison_operator, then the number of expr or subquery target to be compared should be same. If there is a subquery, the number of result records should be one.
Example
Conditional expression | Result |
|---|---|
'abc' = 'abc' | TRUE |
'abc' != 'abc' | FALSE |
'abc' < 'abc' | FALSE |
'abc' <= 'abc' | TRUE |
'abc' > 'abc' | FALSE |
'abc' >= 'abc' | TRUE |
( 1, 2, 3 ) = ( 1, 2, 3 ) | TRUE |
( 1, 2, 3 ) = ( 1, 2, 4 ) | FALSE |
( 1, 2, 3 ) != ( 4, 5, 6 ) | TRUE |
( 1, 2, 3 ) != ( 1, 2, 3 ) | FALSE |
( 1, 2, 3 ) < ( 1, 2, 4 ) | TRUE |
( 1, 2, 3 ) < ( 1, 2, 3 ) | FALSE |
( 1, 2, 3 ) <= ( 1, 2, 4 ) | TRUE |
( 1, 2, 3 ) <= ( 1, 2, 2 ) | FALSE |
( 1, 2, 3 ) > ( 1, 2, 2 ) | TRUE |
( 1, 2, 3 ) > ( 1, 2, 4 ) | FALSE |
( 1, 2, 3 ) >= ( 1, 2, 2 ) | TRUE |
( 1, 2, 3 ) >= ( 1, 2, 4 ) | FALSE |
<Group Comparison Conditions>
Syntax
<group_comparison_condition> ::=
<expr> <comparison_operator> <quantifier> ( <expr_list> )
| <expr> <comparison_operator> <quantifier> ( <subquery> )
| ( <expr_list> ) <comparison_operator> <quantifier> ( <expr_list_list> )
| ( <expr_list> ) <comparison_operator> <quantifier> ( <subquery> )
| ( <subquery> ) <comparison_operator> <quantifier> ( <expr_list> )
| ( <subquery> ) <comparison_operator> <quantifier> ( <expr_list_list> )
| ( <subquery> ) <comparison_operator> <quantifier> ( <subquery> )
<comparison_operator> ::=
< = >
| < != >
| < < >
| < > >
| < <= >
| < >= >
<quantifier> ::=
ALL
| ANY
| SOME
<expr_list> ::=
<expr>
| <expr>, ... , <expr>
| ( <expr> )
| ( <expr> , ... , <expr> )
<expr_list_list> ::=
<expr_list>
| <expr_list>, ... , <expr_list>For more information, refer to Scalar Subquery Expression.
Description
If the expr list or subquery comes to both left and right of comparison_operator, then the number of expr or subquery target to be compared should be same. If a subquery comes to the left of comparison_operator, the number of result records should be one. If a subquery comes to the right of comparison_operator, the number of result records can be multiple.
Example
Conditional expression | Result |
|---|---|
1 =any ( 1, 2, 3, 4, 5 ) | TRUE |
1 =any ( 1, 2, null, 4, 5 ) | TRUE |
1 =any ( 2, null, 4, 5 ) | NULL |
1 =any ( 100, 2, 3, 4, 5 ) | FALSE |
1 =all ( 1, +1, 1E+0 ) | TRUE |
1 =all ( 1, +1, 1E+0, null ) | NULL |
1 =all ( 1, 2, 3, 4, 5 ) | FALSE |
( 1, 2 ) =any ( ( 0, 1 ), ( 1, 2 ), ( 3, 4 ) ) | TRUE |
( 1, 2 ) =any ( ( 0, 1 ), ( 1, 2 ), ( null, null ) ) | TRUE |
( 1, 2 ) =any ( ( 0, 1 ), ( 2, 3 ), ( 3, 4 ) ) | FALSE |
( 1, 2 ) =all ( ( 1, 2 ), ( +1, +2 ), ( 1E+0, 2E+0 ) ) | TRUE |
( 1, 2 ) =all ( ( 1, 2 ), ( +1, +2 ), ( null, null ) ) | NULL |
( 1, 2 ) =all ( ( 0, 1 ), ( 2, 3 ), ( 3, 4 ) ) | FALSE |
When the result record of comparison_operator's right subquery is 0 | |
( 'X' ) =any ( select dummy from dual where dummy = 'Y' ) | FALSE |
( 'X' ) =all ( select dummy from dual where dummy = 'Y' ) | TRUE |
Logical Conditions
Logical conditions are such as AND, OR, NOT.
AND
Syntax
<boolean value expression> AND <boolean value expression>
Description
AND | True | False | Unknown |
|---|---|---|---|
True | True | False | Unknown |
False | False | False | False |
Unknown | Unknown | False | Unknown |
OR
Syntax
<boolean value expression> OR <boolean value expression>
Description
OR | True | False | Unknown |
|---|---|---|---|
True | True | True | True |
False | True | False | Unknown |
Unknown | True | Unknown | Unknown |
NOT
Syntax
NOT <boolean value expression>
Description
expr | NOT |
|---|---|
True | False |
False | True |
Unknown | Unknown |
Null Condition
Syntax
<expr> IS [NOT] NULL
Description
It checks whether the result value of expr is NULL.
expr | IS NULL | IS NOT NULL |
|---|---|---|
NULL | True | False |
NOT NULL | False | True |
Compound Conditions
It is a conditional expression in which multiple conditions are combined.
compound_condition ::=
( condition )
| NOT condition
| condition < AND | OR > conditionPattern-matching Conditions
Like Condition
Syntax
like_condition ::=
string [NOT] LIKE pattern [ ESCAPE escape_character ]Description
It checks if a string matches the specified pattern.
Arguments such as string, pattern, escape_character can be of a character type such as CHARACTER, CHARACTER VARYING, CHARACTER LONG VARYING, or of the type which is available to be converted to a character type. If string, pattern, escape_character are NULL, it returns NULL.
If escape_character is omitted, there is not a default value. If escape_character is specified, the escape_character should be one character.
If pattern does not include '_' nor '%', it is processed in the same way as equal operation(string = pattern). If pattern includes '_' or '%', the string checks if it matches as follows. • '_': If it corresponds to one arbitrary character. • '%': If it corresponds to the arbitrary character string which has zero or more characters.
Use ESCAPE syntax to compare '_' or '%' included in the pattern with characters. Specify escape_character, and describe the specified escape_character before the pattern's '_' or '%'.
Example
gSQL> SELECT 'hello%' LIKE 'h%o!%' ESCAPE '!' AS RESULT FROM DUAL; RESULT ------ TRUE • 'represent' LIKE 'represent' => TRUE • 'represent' LIKE ' represent ' => FALSE • 'represent' LIKE 'REPRESENT' => FALSE • 'represent' LIKE 'r_pr_s_nt' => TRUE • 'represent' LIKE 're%t' => TRUE • 'represent' LIKE 'rep' => FALSE • 'summer_vacation' LIKE 'summer\_vacation' ESCAPE '\' => TRUE • NULL LIKE 'summer\_vacation' ESCAPE '\' => NULL • 'summer_vacation' LIKE NULL ESCAPE '\' => NULL • 'summer_vacation' LIKE 'summer\_vacation' ESCAPE NULL => NULL
BETWEEN Condition
Syntax
<between condition> ::= <expr1> [ NOT ] BETWEEN [ ASYMMETRIC | SYMMETRIC ] <expr2> AND <expr3>
Description
It checks whether expr1 is within the range between expr2 and expr3.
If ASYMMETRIC or SYMMETRIC is omitted, the default is ASYMMETRIC. If data types among expr1, expr2, expr3 are different, they are converted. For more information, refer to Type Comparison, Type Conversion.
A | B |
|---|---|
X BETWEEN ASYMMETRIC Y AND Z | X BETWEEN Y AND Z |
X BETWEEN Y AND Z | X >= Y AND X <= Z |
X NOT BETWEEN Y AND Z | NOT( X BETWEEN Y AND Z ) |
X BETWEEN SYMMETRIC Y AND Z | ((X BETWEEN Y AND Z) OR (X BETWEEN Z AND Y) |
X NOT BETWEEN SYMMETRIC Y AND Z | NOT( X BETWEEN SYMMETRIC Y AND Z ) |
Example
Conditional expression | Result | |
|---|---|---|
BETWEEN [ ASYMMETRIC ] | 3 BETWEEN 1 AND 5 | TRUE |
NULL BETWEEN 1 AND 5 3 BETWEEN NULL AND 5 3 BETWEEN 1 AND NULL | NULL | |
3 BETWEEN 5 AND 1 | FALSE | |
BETWEEN SYMMETRIC | 3 BETWEEN SYMMETRIC 1 AND 5 | TRUE |
NULL BETWEEN SYMMETRIC 1 AND 5 3 BETWEEN SYMMETRIC NULL AND 5 3 BETWEEN SYMMETRIC 1 AND NULL | NULL | |
3 BETWEEN SYMMETRIC 5 AND 1 | TRUE | |
IN Condition
Syntax
<in_condition> ::=
<expr> [NOT] IN ( <expr_list> )
| <expr> [NOT] IN ( <subquery> )
| ( <expr_list> ) [NOT] IN ( <expr_list_list> )
| ( <expr_list> ) [NOT] IN ( <subquery> )
| ( <subquery> ) [NOT] IN ( <expr_list> )
| ( <subquery> ) [NOT] IN ( <expr_list_list> )
| ( <subquery> ) [NOT] IN ( <subquery> )
<expr_list> ::=
<expr>
| <expr>, ... , <expr>
| ( <expr> )
| ( <expr> , ... , <expr> )
<expr_list_list> ::=
<expr_list>
| <expr_list>, ... , <expr_list>Description
In condition returns the same result as = ANY. NOT IN condition returns the same result as !=ALL.
For more information, refer to Comparison Conditions.
Example
Conditional expression | Result |
|---|---|
1 IN ( 1, 2, 3, 4, 5 ) | TRUE |
1 IN ( 1, 2, null, 4, 5 ) | TRUE |
1 IN ( 2, null, 4, 5 ) | NULL |
1 IN ( 100, 2, 3, 4, 5 ) | FALSE |
NULL IN ( 1, 2, 3 ) | NULL |
1 NOT IN ( 2, 3, 4, 5 ) | TRUE |
1 NOT IN ( 2, null, 4, 5 ) | NULL |
1 NOT IN ( 1, 2, null, 4, 5 ) | FALSE |
1 NOT IN ( 100, 2, 3, 4, 5 ) | TRUE |
NULL NOT IN ( 1, 2, 3 ) | NULL |
EXISTS Condition
Syntax
exists_conditions ::=
EXISTS ( subquery )Description
It checks whether the result record of subquery exists. If the result record of subquery exists, it returns TRUE. Otherwise, it returns FALSE.
Example
gSQL> SELECT * FROM DUAL WHERE EXISTS ( SELECT * FROM DUAL );
DUMMY
-----
X
1 row selected.
gSQL> SELECT * FROM DUAL
WHERE EXISTS ( SELECT * FROM DUAL WHERE DUMMY = 'Y' );
no rows selected.Compatibility
The SQL standard compatibility for condition is as follows.
Feature ID | Description | Availability |
|---|---|---|
E061-01 | Comparison predicate | O |
E061-02 | BETWEEN predicate | O |
E061-03 | IN predicate with list of values | O |
E061-04 | LIKE predicate | O |
E061-05 | LIKE predicate: ESCAPE clause | O |
E061-06 | NULL predicate | O |
E061-07 | Quantified comparison predicate | O |
E061-08 | EXISTS predicate | O |
E061-09 | Subqueries in comparison predicate | O |
E061-11 | Subqueries in IN predicate | O |
E061-12 | Subqueries in quantified comparison predicate | O |
E061-13 | Correlated subqueries | O |
E061-14 | Search condition | O |
F051-04 | Comparison predicate on DATE, TIME, and TIMESTAMP data types | X |
F053 | OVERLAPS predicate | X |
F263 | Comma-separated predicates in simple CASE expression | X |
F291 | UNIQUE predicate | X |
F481 | Expanded NULL predicate | O |
F841 | LIKE_REGEX predicate | X |
P008 | Comma-separated predicates in a CASE statement Extended CASE | X |
S151 | Type predicate | X |
T141 | SIMILAR predicate | X |
T151 | DISTINCT predicate | X |
T152 | DISTINCT predicate with negation | X |
T461 | Symmetric BETWEEN predicate | O |
T501 | Enhanced EXISTS predicate | X |
T631 | IN predicate with one list element | X |
X090 | XML document predicate | X |
X091 | XML content predicate | X |
X141 | IS VALID predicate: data-driven case | X |
X142 | IS VALID predicate: ACCORDING TO clause | X |
X143 | IS VALID predicate: ELEMENT clause | X |
X144 | IS VALID predicate: schema location | X |
X145 | IS VALID predicate outside check constraints | X |
X151 | IS VALID predicate with DOCUMENT option | X |
X152 | IS VALID predicate with CONTENT option | X |
X153 | IS VALID predicate with SEQUENCE option | X |
X155 | IS VALID predicate: NAMESPACE without ELEMENT clause | X |
X157 | IS VALID predicate: NO NAMESPACE with ELEMENT clause | X |