The differences in syntax between MySQL and Oracle and how to write date comparisons in xml

As we all know, the syntax of MySQL and Oracle are somewhat similar, but also somewhat different.

In MySQL and Oracle, the syntax differences are as follows:

  1. Data type: The data types supported by MySQL and Oracle are different. For example, the data types supported by MySQL include: integer, floating point, character, date, binary, etc., while Oracle supports more complex data types. Including object type, XML type, array type, nested table type, etc.

  2. Data table creation: The syntax for creating data tables in MySQL and Oracle is also different. For example, in MySQL, you can use the CREATE TABLE statement to create a data table, while in Oracle, you need to use CREATE TABLE or CREATE GLOBAL TEMPORARY TABLE to create a data table.

  3. SQL syntax: There are also some differences in some aspects between the SQL syntax of MySQL and Oracle. For example, when using LEFT JOIN to query data between two tables in MySQL, the syntax is: SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id; while in Oracle, LEFT JOIN should be written as LEFT OUTER JOIN.

  4. Stored Procedures: The syntax of MySQL and Oracle stored procedures also differs. In MySQL, you can use CREATE PROCEDURE to create a stored procedure, while in Oracle, you need to use the CREATE PROCEDURE or CREATE FUNCTION statement to create a stored procedure.

In general, although there are some differences in the syntax of MySQL and Oracle, they will not have much impact on most SQL query statements.
For date query:

<if test="completeTime != null">
            and TO_CHAR(TRUNC(t.COMPLETE_TIME), 'yyyy-MM-dd') = TO_CHAR(#{completeTime,jdbcType=DATE}, 'yyyy-MM-dd')
        </if>

The time statement comparison needs to be converted into a string or date format in the corresponding format before the size can be compared.
In Oracle, you can use XPath expressions and functions to compare dates in XML. Here's an example:

Suppose we have the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <item>
        <name>Item 1</name>
        <date>2020-01-01</date>
    </item>
    <item>
        <name>Item 2</name>
        <date>2021-02-01</date>
    </item>
</items>

To compare dates, you can use an XPath expression like this:

//item[date > '2020-12-31']

This expression will return all item elements with dates in 2021 and later. You can use this expression as a condition in a SQL query, for example:

SELECT *
FROM xml_table
WHERE XMLExists('//item[date > "2020-12-31"]' PASSING xml_column)

This query will return all XML document lines that meet the criteria.

Guess you like

Origin blog.csdn.net/gradonisis/article/details/133417245