mariadb/mysql-test/suite/compat/oracle/t
Michael Widenius 311ec6bbc0 MDEV-19683 Add support for Oracle TO_DATE()
Syntax:
TO_DATE(string_expression [DEFAULT string_expression ON CONVERSION ERROR],
        format_string [,NLS_FORMAT_STRING])
The format_string has the same format elements as TO_CHAR(), except a
few elements that are not supported/usable for TO_DATE().
TO_DATE() returns a datetime or date value, depending on if the format
element FF is used.

Allowed separators, same as TO_CHAR():
space, tab and any of !#%'()*+,-./:;<=>

'&' can also be used if next character is not a character a-z or A-Z
"text' indicates a text string that is verbatim in the format. One cannot
use " as a separator.

Format elements supported by TO_DATE():
AD          Anno Domini ("in the year of the Lord")
AD_DOT      Anno Domini ("in the year of the Lord")
AM          Meridian indicator (Before midday)
AM_DOT      Meridian indicator (Before midday)
DAY         Name of day
DD          Day (1-31)
DDD         Day of year (1-336)
DY          Abbreviated name of day
FF[1-6]     Fractional seconds
HH          Hour (1-12)
HH12        Hour (1-12)
HH24        Hour (0-23)
MI          Minutes (0-59)
MM          Month (1-12)
MON         Abbreviated name of month
MONTH       Name of Month
PM          Meridian indicator (After midday)
PM_DOT      Meridian indicator (After midday)
RR          20th century dates in the 21st century. 2 digits
            50-99 is assumed from 2000, 0-49 is assumed from 1900.
RRRR        20th century dates in the 21st century. 4 digits
SS          Seconds
SYYYY       Signed 4 digit year; MariaDB only supports positive years
Y           1 digit year
YY          2 digits year
YYY         3 digits year
YYYY        4 digits year

Note that if there is a missing part of the date, the current date is used!
For example if 'MM-DD HH-MM-SS' then the current year will be used.
(Oracle behaviour)

Not supported options:
- BC, D, DL, DS, E, EE, FM, FX, RM, SSSSS, TS, TZD, TZH, TZR, X,SY
  BC is not supported by MariaDB datetime.
- Most of the other are exotic formats does not make sence in MariaDB as
   we return datetime or datetime with fractions, not string.
- D (day-of-week) is not supported as it is not clear exactly how it would
  map to MariaDB. This element depends on the NLS territory of the session.
- RR only works with 2 digit years (In Oracle RR can also work with 4
  digit years in some context but the rules are not clear).

Extensions / differences compared to Oracle;
- MariaDB supports FF (fractional seconds).  If FF[#] is used,
  then TO_DATE will return a datetime with # of subseconds.
  If FF is not used a datetime will be returned.
  There is warning (no error) if string contains more digts than what
  is specified with F(#]
- Names can be shortened to it's unique prefix. For example January and Ja
  works fine.
- No error if the date string is shorter format_string and the next
  not used character is not a number.. This is useful to get a date
  from a mixed set of strings in date or datetime format.
  Oracle gives an error if date string is too short.
- MariaDB supports short locales as language names
- NLS_DATE_FORMAT can use both " and ' for quoting.
- NLS_DATE_FORMAT must be a constant string.
  - This is to ensure that the server knows which locale to use
    when executing the function.

New formats handled by TO_CHAR():
FF[1-6]     Fractional seconds
DDD         Daynumber 1-366
IW          Week 1-53 according to ISO 8601
I           1 digit year according to ISO 8601
IY          2 digit year according to ISO 8601
IYY         3 digit year according to ISO 8601
IYYY        4 digit year according to ISO 8601
SYYY        4 digit year according to ISO 8601 (Oracle can do signed)

Supported NLS_FORMAT_STRING options are:
NLS_CALENDAR=GREGORIAN
NLS_DATE_LANGUAGE=language

Support languages are:
- All MariaDB short locales, like en_AU.
- The following Oracle language names:
ALBANIAN, AMERICAN, ARABIC, BASQUE, BELARUSIAN, BRAZILIAN PORTUGUESE
BULGARIAN, CANADIAN FRENCH, CATALAN, CROATIAN, CYRILLIC SERBIAN CZECH,
DANISH, DUTCH, ENGLISH, ESTONIAN, FINNISH, FRENCH, GERMAN,
GREEK, HEBREW, HINDI, HUNGARIAN, ICELANDIC, INDONESIAN ITALIAN,
JAPANESE, KANNADA, KOREAN, LATIN AMERICAN SPANISH, LATVIAN,
LITHUANIAN, MACEDONIAN, MALAY, MEXICAN SPANISH, NORWEGIAN, POLISH,
PORTUGUESE, ROMANIAN, RUSSIAN, SIMPLIFIED CHINESE, SLOVAK, SLOVENIAN,
SPANISH, SWAHILI, SWEDISH, TAMIL, THAI, TRADITIONAL CHINESE, TURKISH,
UKRAINIAN, VIETNAMESE

Development bugs fixed:
MDEV-38403 Server crashes in Item_func_to_date::fix_length_and_dec upon
           using an invalid argument
MDEV-38400 compat/oracle.func_to_date fails with PS protocol and cursor
           protocol (Fixed by Serg)
MDEV-38404 TO_DATE: MTR coverage omissions, round 1
MDEV-38509 TO_DATE: AD_DOT does not appear to be supported
MDEV-38513 TO_DATE: NULL value for format string causes assertion failure
MDEV-38521 TO_DATE: Date strings with non-ASCII symbols cause warnings
           and wrong results
MDEV-38578 TO_DATE: Possibly unexpected results upon wrong input
MDEV-38582 TO_DATE: NLS_DATE_LANGUAGE=JAPANESE does not parse values
           which work in Oracle
MDEV-38584 TO_DATE: NLS_DATE_LANGUAGE=VIETNAMESE does not parse values
           which work in Oracle
MDEV-38703 TO_DATE: Quotation for multi-word NLS_DATE_LANGUAGE leads
           to syntax error in view definition
MDEV-38675 TO_DATE: MSAN/Valgrind/UBSAN errors in
           extract_oracle_date_time
MDEV-38635 TO_DATE: UBSAN errors in item_timefunc.h upon comparison with
           a view column
MDEV-38719 TO_DATE: Assertion `&my_charset_bin != charset()' failed in
           String::append_for_single_quote_using_mb_wc
MDEV-38756 TO_DATE: MSAN/Valgrind errors in
            Item_func_to_date::fix_length_and_dec upon PREPARE with
            parameters

Known issues:
- Format string character matches inside quotes are done
  one-letter-to-one-letter, like in LIKE predicate. That means things
  like expansions and contractions do not work.
  For example 'ss' does not match 'ß' in collations which treat them
  as equal for the comparison operator.
  Match is done taking into account case and accent sensitivity
  of the subject argument collation, so for example this now works:
  MariaDB [test]> SELECT TO_DATE('1920á12','YYYY"a"MM') AS c;
  +---------------------+
  | c                   |
  +---------------------+
  | 1920-12-17 00:00:00 |
  +---------------------+

Co-author and reviewer: Alexander Barkov <bar@mariadb.com>
2026-02-10 00:03:02 +01:00
..
anonymous_derived.test MDEV-19162 anonymous derived tables part 2020-11-17 20:11:39 +01:00
binlog_ptr_mysqlbinlog-master.opt MDEV-23108: Point in time recovery of binary log fails when sql_mode=ORACLE 2020-07-22 11:34:50 +05:30
binlog_ptr_mysqlbinlog.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
binlog_stm_ps.test
binlog_stm_sp.test
binlog_stm_sp_package.test
column_compression.test MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
custom_aggregate_functions.test
empty_string_literal.test
events.test fix tests for embedded 2022-05-18 01:22:29 +02:00
exception.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
func_add_months.test MDEV-20025: ADD_MONTHS() Oracle function 2021-05-19 22:54:12 +02:00
func_case.test
func_concat.test MDEV-31910 ASAN memcpy-param-overlap upon CONCAT in ORACLE mode 2024-11-06 11:39:50 +04:00
func_decode.test MDEV-31184 Remove parser tokens DECODE_MARIADB_SYM and DECODE_ORACLE_SYM 2023-10-24 01:45:47 +04:00
func_length.test
func_misc.test
func_months_between.test MDEV-37319 Oracle Compatibility - MONTHS_BETWEEN functions 2025-09-30 19:47:55 +03:00
func_pad.test
func_qualified.test MDEV-29095 REGEXP_REPLACE treats empty strings different than REPLACE in ORACLE mode 2024-01-24 10:59:17 +04:00
func_regexp_replace.test MDEV-29095 REGEXP_REPLACE treats empty strings different than REPLACE in ORACLE mode 2024-01-24 10:59:17 +04:00
func_replace.test
func_substr.test
func_time.test
func_to_char.test MDEV-19683 Add support for Oracle TO_DATE() 2026-02-10 00:03:02 +01:00
func_to_date-ucs2.test MDEV-19683 Add support for Oracle TO_DATE() 2026-02-10 00:03:02 +01:00
func_to_date.test MDEV-19683 Add support for Oracle TO_DATE() 2026-02-10 00:03:02 +01:00
func_trim.test
func_trunc.test MDEV-20023 Implement Oracle TRUNC() function 2025-09-30 17:37:12 +03:00
func_trunc_ucs2.test MDEV-20023 Implement Oracle TRUNC() function 2025-09-30 17:37:12 +03:00
gis-debug.test
gis.test
information_schema_parameters.test
keywords.test
lower_case_table_names.opt MDEV-31340 Remove MY_COLLATION_HANDLER::strcasecmp() 2024-04-18 15:22:10 +04:00
lower_case_table_names.test MDEV-31340 Remove MY_COLLATION_HANDLER::strcasecmp() 2024-04-18 15:22:10 +04:00
minus.test MDEV-20021 sql_mode="oracle" does not support MINUS set operator 2021-05-19 22:54:12 +02:00
misc.test An additional patch for MDEV-27690 Crash on CHARACTER SET csname COLLATE DEFAULT in column definition 2022-04-14 12:22:28 +04:00
mysqldump_restore.test
mysqldump_restore_func_qualified.test MDEV-32250 Enable --no-autocommit by default in mysqldump 2024-12-03 20:25:04 +05:30
ora_outer_join.test MDEV-36055 Allow left join reordering 2026-01-28 14:11:44 +02:00
ora_outer_join_err.test MDEV-13817 add support for oracle left join syntax - the ( + ) 2025-08-04 12:05:53 +02:00
parser.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
plugin.test
ps.test MDEV-20634 Report disallowed subquery errors as such (instead of parse error) 2019-09-20 10:36:20 +04:00
rpl_mariadb_date.test MDEV-19632 Replication aborts with ER_SLAVE_CONVERSION_FAILED upon CREATE ... SELECT in ORACLE mode 2020-08-01 07:43:50 +04:00
rpl_sp_package.test
rpl_sp_package_variables.test
sequence.test MDEV-31003: Second execution for ps-protocol 2023-07-26 17:15:00 +07:00
sp-anchor-row-type-table.test MDEV-12252 ROW data type for stored function return values 2024-10-21 07:59:29 +04:00
sp-anchor-type.test MDEV-12252 ROW data type for stored function return values 2024-10-21 07:59:29 +04:00
sp-anonymous.test
sp-cache-invalidate.inc
sp-code.test MDEV-10862: Stored procedures: default values for parameters (optional parameters) 2025-01-31 19:42:04 +04:00
sp-cursor-decl.test
sp-cursor-pkg-01.inc MDEV-36047 Package body variables are not allowed as FETCH targets 2025-02-09 13:56:19 +04:00
sp-cursor-pkg-02.inc MDEV-36047 Package body variables are not allowed as FETCH targets 2025-02-09 13:56:19 +04:00
sp-cursor-pkg-03.inc MDEV-36047 Package body variables are not allowed as FETCH targets 2025-02-09 13:56:19 +04:00
sp-cursor-rowtype.test MDEV-21998: Server crashes in st_select_lex::add_table_to_list upon mix of KILL and sequences 2020-07-28 08:23:57 +02:00
sp-cursor.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
sp-default-param.test Merge branch 'bb-12.1-release' into bb-12.2-release 2025-11-06 07:29:30 +01:00
sp-expr.test Adding more tests for IN/EXIST subqueries for better coverage 2018-04-20 23:15:27 +04:00
sp-goto-debug.test MDEV-20667 Server crash on pop_cursor 2019-12-12 16:25:16 +04:00
sp-goto.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
sp-inout.test MDEV-33616 Tests failing on macOS 2024-04-24 08:44:24 -04:00
sp-memory-leak.test MDEV-26186 280 Bytes lost in mysys/array.c, mysys/hash.c, sql/sp.cc, sql/sp.cc, sql/item_create.cc, sql/item_create.cc, sql/sql_yacc.yy:10748 when using oracle sql_mode 2023-07-18 12:19:16 +04:00
sp-package-code.test Merge branch '10.11' into 11.4 2026-01-28 21:52:18 +01:00
sp-package-concurrent-dml-db.test MDEV-11952 Oracle-style packages: stage#5 2018-02-25 21:08:19 +04:00
sp-package-concurrent-dml-package.test
sp-package-concurrent-dml-trigger.test
sp-package-concurrent-dml-view.test
sp-package-concurrent-dml.inc mariadb-test: wait on disconnect 2025-07-16 09:14:33 +07:00
sp-package-i_s.test MDEV-30662 SQL/PL package body does not appear in I_S.ROUTINES.ROUTINE_DEFINITION 2023-07-14 13:26:26 +04:00
sp-package-innodb.test MDEV-16708: fix in test failures(added --enable_prepared_warnings/--disable_prepared_warnings) 2021-06-17 19:30:24 +02:00
sp-package-mdl.test Fixed mtr --embedded compat/oracle.sp-package-mdl 2026-01-13 01:39:32 +04:00
sp-package-mysqldump.test Merge branch '10.2' into 10.3 2019-09-03 13:17:32 +03:00
sp-package-security.test
sp-package.test MDEV-36067 Assertion failure in TABLE_SHARE::init_from_sql_statement_string 2025-04-18 09:41:23 +02:00
sp-param.inc
sp-param.test MDEV-35229 NOCOPY has become reserved word bringing wide incompatibility 2024-10-30 13:58:20 +04:00
sp-record.test MDEV-37430 sql_mode=ORACLE: TYPE definitions in PACKAGE BODY 2025-08-28 13:45:29 +04:00
sp-row-vs-var.inc
sp-row.test MDEV-36716 A case expression with ROW arguments in THEN crashes 2025-05-05 19:44:04 +04:00
sp-security.test MDEV-37054: Implement INFORMATION_SCHEMA.PARAMETERS.PARAMETER_DEFAULT column 2025-10-15 22:04:28 +05:30
sp-sys_refcursor-alias.test MDEV-20034 Add support for the pre-defined weak SYS_REFCURSOR 2025-04-19 10:59:58 +04:00
sp-sys_refcursor-func_hybrid.test MDEV-20034 Add support for the pre-defined weak SYS_REFCURSOR 2025-04-19 10:59:58 +04:00
sp-sys_refcursor.test MDEV-20034 Add support for the pre-defined weak SYS_REFCURSOR 2025-04-19 10:59:58 +04:00
sp.test Fix typos in mysql-test/ 2025-04-29 13:53:16 +10:00
statement-expr.test MDEV-20634 Report disallowed subquery errors as such (instead of parse error) 2019-09-20 10:36:20 +04:00
table_value_constr.test Merge 10.11 into 11.4 2026-01-02 11:53:09 +02:00
trigger.test MDEV-36996: Implement INFORMATION_SCHEMA.TRIGGERED_UPDATE_COLUMNS table 2025-10-15 21:17:58 +05:30
trigger_notembedded.test MDEV-36996: Implement INFORMATION_SCHEMA.TRIGGERED_UPDATE_COLUMNS table 2025-10-15 21:17:58 +05:30
truncate.test
type_blob.test
type_clob.test
type_date.test MDEV-12252 ROW data type for stored function return values 2024-10-21 07:59:29 +04:00
type_number.test
type_raw.test
type_varchar.test
type_varchar2.test
update.test MDEV-27769 Assertion failed in Field::ptr_in_record upon UPDATE in ORACLE mode 2025-01-26 16:15:46 +01:00
update_innodb.test Merge 10.5 into 10.6 2024-10-03 09:31:39 +03:00
variables.test
vcol.test
vcol_innodb.test MDEV-27744 LPAD in vcol created in ORACLE mode makes table corrupted in non-ORACLE 2023-11-08 15:01:20 +04:00
versioning.test
win.test