Multi-database adaptation | Record a data source compatible switching process from Oracle to MySQL

Introduction: As written above, each excerpt is based on an actual case scenario, and spare time on weekends to record each mark process. In different actual business scenarios, according to the changes in the project stage, different plans are formulated. Technical solutions. No matter how small a technical solution is, it has a different meaning in its corresponding scene. Practice is the only criterion for testing the truth. Participating in the discussion after the real practice may give you some new discoveries. I hope that it will be a little different for readers to think about IDea. Comments and contributions at the end of the article are welcome, and I am keen to share->Translation every day Click on knowledge.

Below, the editor mainly uses Oracle->MySQL adaptation as an example->FAQ to explain:

Supplementary record: From high version -> low version , data export -> import will have the following exception

IMP-00010: not a valid export file, header failed verification

Next, query the current Oracle version through SQL,

select * from v$version

At this point, modify the version information in the dmp file through Notepad++ as,

Execute the imp command again ,

[oracle@localhost ~]$ imp yd_dev_tmp/user@ip/orcl file=/home/oracle/xxx.dmp ignore=y full=y;

The Data Pump .dmp file was successfully imported. (Among them, you can enter the oracle directory through su - oracle , and the dmp file can be uploaded to the /home/oracle path)

Some of the common functions are listed above .

1、COALESCE函数 && NVL函数MySQL:COALESCE()Oracle:COALESCE()、NVL()COALESCE函数在MySQL跟Oracle都适用,NVL函数在Oracle中适用,COALESCE可替换NVL。
2、STR_TO_DATE函数 && TO_DATE函数MySQL:STR_TO_DATE(field,'yyyy-mm-dd')Oracle:TO_DATE(field,'yyyy-mm-dd hh24:mi:ss')
3、CONVERT函数 && TO_CHAR函数MySQL:CONVERT(field,CHAR)Oracle:TO_CHAR(field)
4、DATE_FORMAT函数 && TO_CHAR函数MySQL:DATE_FORMAT(field,'%Y-%m-%d')Oracle:TO_CHAR(field,'yyyy-MM-dd')

MySQL date interval calculation,

Corresponds to the XML notation-SQL in Mybatis, a commonly used ORM mapping framework in Java, where the MySQL dialect can specify the databaseId as mysql, and the Oracle dialect can specify the databaseId as oracle .

Oracle date range calculation,

MySQL and Oracle regular expressions ,

Oracle function DECODE ,

DECODE(A.KLX,'01','居民身份证','02','居民户口簿','03','护照','04','军官证','05','驾驶证','06','港澳居民来往内地通行证','07','台湾居民来往内地通行证','其他')

The MySQL function IF can realize the DECODE effect in Oracle ,

IF(A.KLX='01','居民身份证',IF(A.KLX='02','居民户口簿',IF(A.KLX='03','护照',IF(A.KLX='04','军官证',IF(A.KLX='05','驾驶证',IF(A.KLX='06','港澳居民来往内地通行证',IF(A.KLX='07','港澳居民来往内地通行证','其他')))))))

Functions in MySQL views,

Functions in Oracle views ,

Based on the idea of ​​the Mybatis plug-in , according to the current database databaseId, SQL is intercepted, and the SQL dialect functions of the respective databases are added to be compatible, so there is no need for SQL writing in multiple sets of database XML. In the future, we will consider open-sourcing a SQL plug- in on GitHub , which supports pluggable-open when needed.

Can automatically fill complex SQL parameters , print SQL statements,

And print its execution plan and time-consuming , which helps analyze SQL in the production environment, troubleshoot problems, and optimize performance .

This leads to such a small scenario-thinking: When you need to do multi -database compatibility adaptation , you want to predict an order of magnitude in advance . If you need to write test cases for each SQL dialect in the database layer , calculate the success or failure rate Evaluation , then how to have a Java version, unit test case - code automatic generator , according to the class name configuration , you can know the success or failure rate of all SQL dialects in the current class ? ^_^

Of course, we can also look at other development languages, Php, Python, Go......

"Past Articles"

Database Online Training Platform-MySQL

Elasticsearch Advanced | Remember kibana's actual combat process of executing dsl scripts

Oracle optimization case | Locating SQL query problems from the execution plan

Kafka | Remember to repair the downtime failure of the broker where the Kafka partition is located-the thinking process that caused the current partition to be unavailable

Dameng | Remember a thought process of domestic database adaptation

Scan QR code

Get more exciting

Scan the QR code to follow the translation point

Guess you like

Origin blog.csdn.net/yxd179/article/details/121630628