Oracle database modification method and device, equipment and medium
By extracting and modifying SQL syntax units during the database migration process, the problem of inefficiency and error-prone manual conversion is solved, efficient and accurate database migration is achieved, and operation and maintenance costs are saved.
Patent Information
- Application Number
- CN202410725720.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-08-23
AI Technical Summary
During the database migration process, especially when migrating from Oracle database to MySQL database, manual conversion of sqlmapper files is inefficient and error-prone, wasting time and resources.
Extract the SQL syntax unit from the xml file in the mapper directory and modify it into the target syntax format. Use Document object parsing and deep traversal to find the SQL syntax unit, and then convert it according to the syntax rules of the target database to generate the target database corresponding XML file.
It improves the efficiency and accuracy of database migration, reduces dependence on manual operations, saves time and costs, avoids errors and missed modifications, and improves operation and maintenance efficiency.
Smart Images

Figure CN118536477A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to an Oracle database modification method, device, equipment and medium. Background Art
[0002] In the process of database application, sometimes it is necessary to migrate data between heterogeneous databases. For example, with the rapid development of business, the rapid growth of data volume in Oracle database will consume a large area of storage costs. At this time, it is necessary to modify it to MySQL database. However, migrating the previous Oracle database to MySQL database requires a lot of work, especially converting sqlmapper files to MySQL syntax sqlmapper files. If it relies on pure manual conversion, the efficiency is very low, and it is easy to make mistakes and miss changes, which wastes time and is inefficient. Summary of the invention
[0003] Based on the above technical problems, the present invention aims to solve the problems of low efficiency, error-proneness and omissions in relying on pure manual conversion by locking the xml file in the mapper directory, extracting SQL grammar units from the xml file, and then modifying the SQL grammar units to the target grammar format.
[0004] A first aspect of the present invention provides an Oracle database modification method, the method comprising:
[0005] Determine the Java project using Oracle database;
[0006] Get the storage directory of the Java project;
[0007] Read the XML files in the mapper directory of the Java project one by one in the storage directory;
[0008] Extracting SQL syntax units from the XML file;
[0009] The SQL syntax unit is modified into a target syntax format.
[0010] In some embodiments of the present invention, extracting the SQL syntax unit from the XML file includes:
[0011] Parse the XML file into a Document object;
[0012] Get the nodeList object through the get function of the Document object;
[0013] Finds a SQL syntax unit based on the nodeList object.
[0014] In some embodiments of the present invention, finding the SQL syntax unit based on the nodeList object includes:
[0015] Taking the nodeList object as a first-level node and taking the first-level node as a root node of a virtual syntax tree;
[0016] A deep traversal is performed starting from the root node to obtain secondary nodes, and the traversal is stopped when all SQL syntax units are found.
[0017] In some embodiments of the present invention, modifying the SQL grammar unit to a target grammar format includes:
[0018] The SQL grammar unit is modified into a target grammar format according to preset grammar rules of the target database.
[0019] In some embodiments of the present invention, modifying the SQL grammar unit to a target grammar format includes:
[0020] Parsing the SQL grammar unit to obtain the SQL grammar unit to be converted;
[0021] The SQL grammar unit to be converted is converted into a target grammar format using a grammar converter. In some embodiments of the present invention, after the SQL grammar unit is modified into the target grammar format, the method further includes:
[0022] Generate an XML file corresponding to the target database according to the target syntax format;
[0023] Set a symbol, and embed the symbol into an XML file corresponding to the target database.
[0024] In some embodiments of the present invention, after embedding the symbol into the XML file corresponding to the target database, the method further includes:
[0025] The XML file in which the symbol is embedded is stored in a preset directory.
[0026] A second aspect of the present invention provides an Oracle database modification device, the device comprising:
[0027] A determination module is configured to determine a Java project using an Oracle database;
[0028] An acquisition module is configured to acquire a storage directory of the Java project;
[0029] A reading module is configured to read the XML files in the mapper directory of the Java project one by one in the storage directory;
[0030] An extraction module is configured to extract SQL syntax units from the XML file;
[0031] The modification module is configured to modify the SQL grammar unit into a target grammar format.
[0032] A third aspect of the present invention provides a computer device, including a memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor performs the following steps:
[0033] Determine the Java project using Oracle database;
[0034] Get the storage directory of the Java project;
[0035] Read the XML files in the mapper directory of the Java project one by one in the storage directory;
[0036] Extracting SQL syntax units from the XML file;
[0037] The SQL syntax unit is modified into a target syntax format.
[0038] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the following steps:
[0039] Determine the Java project using Oracle database;
[0040] Get the storage directory of the Java project;
[0041] Read the XML files in the mapper directory of the Java project one by one in the storage directory;
[0042] Extracting SQL syntax units from the XML file;
[0043] The SQL syntax unit is modified into a target syntax format.
[0044] The technical solution provided in the embodiments of the present application has at least the following technical effects or advantages:
[0045] This application first determines the Java project using Oracle database, obtains the storage directory of the Java project, reads the xml files in the mapper directory of the Java project one by one in the storage directory, and then extracts the SQL syntax unit in the xml file, and modifies the SQL syntax unit to the target syntax format, which solves a series of problems such as a huge waste of operation and maintenance personnel, low efficiency, the need to arrange manpower on duty for the night shift, and the inability to detect abnormal situations in time. It avoids over-reliance on manual operations, saves time costs, is less likely to make mistakes and miss changes, and thus improves modification efficiency and accuracy.
[0046] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0048] Figure 1 A schematic diagram of the steps of an Oracle database modification method in an exemplary embodiment of the present application is shown;
[0049] Figure 2 A schematic diagram of a plug-in produced based on database conversion in an exemplary embodiment of the present application is shown;
[0050] Figure 3 A schematic diagram of the structure of an Oracle database modification device in an exemplary embodiment of the present application is shown;
[0051] Figure 4 A schematic structural diagram of a computer device provided by an exemplary embodiment of the present application is shown. DETAILED DESCRIPTION
[0052] Below, the embodiment of the present application will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present application. In addition, in the following description, the description of known structures and technologies is omitted to avoid unnecessary confusion of the concept of the present application. It is obvious to those skilled in the art that the present application can be implemented without one or more of these details. In other examples, in order to avoid confusion with the present application, some technical features known in the art are not described.
[0053] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should also be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of the features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0054] Now, exemplary embodiments according to the present application will be described in more detail with reference to the accompanying drawings. However, these exemplary embodiments may be implemented in a variety of different forms and should not be construed as being limited to the embodiments described herein. The accompanying drawings are not drawn to scale, and certain details may be magnified and certain details may be omitted for the purpose of clear expression. The shapes of the various regions and layers shown in the figures and the relative sizes and positional relationships therebetween are merely exemplary, and may deviate in practice due to manufacturing tolerances or technical limitations, and those skilled in the art may additionally design regions / layers with different shapes, sizes, and relative positions according to actual needs.
[0055] The following is attached to the instruction manual Figure 1 -Attached Figure 4 Several embodiments are given to describe exemplary implementations according to the present application. It should be noted that the following application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the implementations of the present application are not limited in this regard. On the contrary, the implementations of the present application can be applied to any applicable scenario.
[0056] In the process of database application, sometimes it is necessary to migrate data between heterogeneous databases. For example, with the rapid development of business, the amount of data in Oracle database increases rapidly, which will consume a large area of storage costs. At this time, it is necessary to modify it to MySQL database, or to perform O removal operation. However, there are a lot of modifications in the migration process, especially converting sqlmapper files to sqlmapper files in MySQL syntax. If it relies on pure manual conversion, the efficiency is very low, and it is also easy to make mistakes and miss changes, which wastes time and is inefficient.
[0057] Therefore, in some exemplary embodiments of the present application, an Oracle database modification method is provided, which is applied to an algorithm service processing system, such as Figure 1 As shown, the method includes:
[0058] S1. Determine the Java project using Oracle database;
[0059] S2. Obtain the storage directory of the Java project;
[0060] S3, reading the XML files in the mapper directory of the Java project one by one in the storage directory;
[0061] S4, extracting SQL syntax units from the XML file;
[0062] S5. Modify the SQL syntax unit into a target syntax format.
[0063] It should be noted that the xml files in the mapper directory belong to mapping files, which are very important files in the mybatis framework. The mapper.xml mapping file is mainly used to write SQL statements, some result set mapping relationships, and some cache configurations.
[0064] In a preferred implementation, the extracting of SQL syntax units from the xml file includes: parsing the xml file into a Document object; obtaining a nodeList object through a get function of the Document object; and finding SQL syntax units based on the nodeList object. Finding SQL syntax units based on the nodeList object includes: using the nodeList object as a first-level node and using the first-level node as the root node of a virtual syntax tree; performing a deep traversal from the root node to obtain a second-level node until all SQL syntax units are found and the traversal stops. The above-mentioned document object is a computer term, referring to an object in an HTML file. The document object can be used to check, modify or add content to an HTML document and process events within the document. On a Web page, the document object can be referenced through the document attribute of the window object, or directly referenced. The first-level node and the second-level node here are relative, and are intended to convert the syntax units involved in the XML file. For example, insert, update, and delete, the traversal converts the column value structure based on the table mode, and forms a corresponding database architecture based on the column value structure to build different types of databases.
[0065] Of course, in the process of traversing XML files, annotations will also be encountered, and text objects can also be parsed from the annotations to obtain text names and values. Therefore, during the specific implementation, the SQL statement syntax format matching strategy is configured according to the method of parsing files according to the common directory structure of Java projects. This strategy can select SQL statements from the file content. Knowing the syntax format of SQL, you can accurately find SQL statements from a file containing Java code, Chinese and English comments, XML tags and other interference items. Compared with the technical solutions of manually checking or collecting SQL statements in the form of keywords in the prior art, the method of node depth traversal provided in the embodiment of the present application can efficiently and accurately collect SQL statements in JAVA projects, and then obtain SQL syntax units, which is convenient for subsequent conversion operations.
[0066] In some embodiments of the present invention, different modification methods can be adopted when modifying the SQL grammar unit to the target grammar format. The SQL grammar unit can be modified to the target grammar format according to the preset grammar rules of the target database. In the embodiment of the present invention, the SQL grammar unit can be modified to the target grammar format according to the pre-configured SQL statement grammar format matching strategy of the target database. The acquisition, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations. The SQL grammar unit can also be parsed first to obtain the SQL grammar unit to be converted, and then the SQL grammar unit to be converted is converted to the target grammar format using a grammar converter. During conversion, for example, the OracleSysdateExpr time type needs to replace sysdate with now. That is, the different command formats at the bottom of the heterogeneous database are converted, and further, tabulation conversion can be performed. The corresponding SQL value is used as reference data, the reference data is tabulated and converted, and the corresponding relationship between the SQL value and the data in the target database is constructed, and the reference data is converted into a column value structure based on the table mode. This ensures the accuracy of data migration and avoids dependence on manual operations. It saves time and is less likely to cause errors and omissions, thereby improving modification efficiency.
[0067] In some embodiments of the present invention, after modifying the SQL grammar unit to the target grammar format, the method further includes: generating an XML file corresponding to the target database according to the target grammar format; setting a marker symbol, and embedding the marker symbol into the XML file corresponding to the target database. Further, after embedding the marker symbol into the XML file corresponding to the target database, the method further includes: storing the XML file embedded with the marker symbol into a preset directory.
[0068] In some other embodiments of the present invention, the above conversion operation command can be encapsulated into a plug-in to develop a self-developed framework sqlmapper-transform-1.3.jar, such as Figure 2 Schematic diagram, so you can get a Java dynamic mapper conversion tool. Through this tool class, you can convert Oralce**Mapper.xml to mysql**Mapper.xml by executing a command, where ** refers to other symbols that identify the name. Similarly, you can also encapsulate all these commands corresponding to the conversion into a plug-in, and directly execute the plug-in in the scenario where you need to migrate the Oracle database.
[0069] There are many business systems that need to modify the Oracle database in many cases. For example, during the use of the business system, the operation and maintenance personnel often need to query and compare the business data in order to monitor whether the business system is operating normally and determine whether the generated business data is correct. However, the common practice is that the operation and maintenance personnel manually query the business data regularly through the database client tool and manually determine the accuracy of the business data. This operation and maintenance method greatly wastes manpower and is not efficient. The night shift needs to arrange manpower on duty, and abnormal situations cannot be discovered in time. However, this application solves the problems of low efficiency, easy errors and omissions in relying on pure manual conversion. First, determine the Java project using the Oracle database, obtain the storage directory of the Java project, read the xml files in the mapper directory of the Java project one by one in the storage directory, and then extract the SQL syntax unit in the xml file, modify the SQL syntax unit to the target syntax format, avoid over-reliance on manual operation, save time cost, and is not prone to errors and omissions, thereby improving modification efficiency and accuracy.
[0070] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention.
[0071] In some exemplary embodiments of the present application, an Oracle database modification device is also provided to execute the Oracle database modification method described in each embodiment of the present application, such as Figure 3 As shown, the device comprises:
[0072] A determination module 301 is configured to determine a Java project using an Oracle database;
[0073] An acquisition module 302 is configured to acquire a storage directory of the Java project;
[0074] A reading module 303 is configured to read the XML files in the mapper directory of the Java project one by one in the storage directory;
[0075] An extraction module 304 is configured to extract SQL syntax units from the XML file;
[0076] The modification module 305 is configured to modify the SQL grammar unit into a target grammar format.
[0077] In a preferred implementation, when the extraction module 304 extracts the SQL syntax unit from the XML file, the following steps are specifically performed: parsing the XML file into a Document object; obtaining a nodeList object through a get function of the Document object; and finding the SQL syntax unit based on the nodeList object.
[0078] In another preferred implementation, the extraction module may be provided with a traversal module to find the SQL syntax unit based on the nodeList object. In a specific implementation, the nodeList object is used as a first-level node, and the first-level node is used as the root node of the virtual syntax tree; a deep traversal is performed from the root node to obtain the second-level node, and the traversal is stopped when all the SQL syntax units are found.
[0079] This device uses the Java project of the Oracle database, obtains the storage directory of the Java project, reads the xml files in the mapper directory of the Java project one by one in the storage directory, extracts the SQL grammar unit in the xml file, and modifies the SQL grammar unit to the target grammar format, thereby avoiding excessive reliance on manual operations, saving time costs, and being less prone to errors and omissions, thereby improving modification efficiency and accuracy. It solves a series of problems such as a huge waste of manpower for operation and maintenance personnel, low efficiency, the need to arrange manpower on duty for the night shift, and the inability to detect abnormal situations in a timely manner.
[0080] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application.
[0081] It should also be emphasized that the system provided in the embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system of simulating, extending and expanding human intelligence, perceiving the environment, acquiring knowledge and using knowledge to obtain the best results using digital computers or machines controlled by digital computers. Basic artificial intelligence technologies generally include technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. Artificial intelligence software technology mainly includes computer vision technology, robotics, biometrics, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0082] Please refer to the following Figure 4 , which shows a schematic diagram of a computer device provided by some embodiments of the present application. Figure 4 As shown, the computer device 2 includes: a processor 200, a memory 201, a bus 202 and a communication interface 203, wherein the processor 200, the communication interface 203 and the memory 201 are connected via the bus 202; the memory 201 stores a computer program that can be run on the processor 200, and when the processor 200 runs the computer program, the Oracle database modification method provided in any of the aforementioned embodiments of the present application is executed.
[0083] The memory 201 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 203 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0084] The bus 202 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 201 is used to store a program, and the processor 200 executes the program after receiving an execution instruction. The Oracle database modification method disclosed in any implementation of the embodiment of the present application may be applied to the processor 200 or implemented by the processor 200.
[0085] The processor 200 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 200. The above processor 200 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 201, and the processor 200 reads the information in the memory 201, and completes the steps of the above method in combination with its hardware. The method includes: determining a Java project using an Oracle database; obtaining a storage directory of the Java project; reading XML files in a mapper directory of the Java project one by one in the storage directory; extracting SQL syntax units from the XML files; and modifying the SQL syntax units to a target syntax format.
[0086] The embodiments of the present application also provide a computer-readable storage medium corresponding to the Oracle database modification method provided in the aforementioned embodiments, on which a computer program is stored. When the computer program is executed by a processor, the Oracle database modification method provided in any of the aforementioned embodiments is executed.
[0087] In addition, examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0088] The present application also provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the Oracle database modification method provided in any of the aforementioned embodiments are implemented, and the method includes: determining a Java project that uses an Oracle database; obtaining a storage directory for the Java project; reading XML files in a mapper directory of the Java project one by one in the storage directory; extracting SQL syntax units from the XML files; and modifying the SQL syntax units to a target syntax format.
[0089] It should be noted that the algorithms and displays provided herein are not inherently related to any particular computer, virtual device or other device. Various general devices can also be used together with the teachings based thereon. According to the above description, it is obvious that the structure required for constructing such devices is constructed. In addition, the present application is not directed to any specific programming language. It should be understood that the content of the present application described herein can be implemented using various programming languages, and the above description of specific languages is to disclose the best implementation mode of the present application. In the specification provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this specification.
[0090] Those skilled in the art will appreciate that the various component embodiments of the present application may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or digital signal processor (DSP) may be used in practice to implement some or all functions of some or all components of the virtual machine creation device according to the embodiments of the present application.
[0091] The above is only a preferred specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A method for modifying an Oracle database, characterized in that: The method comprises: Determine the Java project using Oracle database; Get the storage directory of the Java project; Read the XML files in the mapper directory of the Java project one by one in the storage directory; Extracting SQL syntax units from the XML file; The SQL syntax unit is modified into a target syntax format.
2. The Oracle database modification method according to claim 1, characterized in that: Extracting the SQL syntax unit from the XML file includes: Parse the XML file into a Document object; Get the nodeList object through the get function of the Document object; Finds a SQL syntax unit based on the nodeList object.
3. The Oracle database modification method according to claim 2, characterized in that: The finding the SQL syntax unit based on the nodeList object includes: Taking the nodeList object as a first-level node and taking the first-level node as a root node of a virtual syntax tree; A deep traversal is performed starting from the root node to obtain secondary nodes, and the traversal is stopped when all SQL syntax units are found.
4. The Oracle database modification method according to claim 1, characterized in that: The modifying the SQL grammar unit to a target grammar format includes: The SQL grammar unit is modified into a target grammar format according to preset grammar rules of the target database.
5. The Oracle database modification method according to claim 1, characterized in that: The modifying the SQL grammar unit to a target grammar format includes: Parsing the SQL grammar unit to obtain the SQL grammar unit to be converted; The SQL grammar unit to be converted is converted into a target grammar format using a grammar converter.
6. The Oracle database modification method according to any one of claims 1 to 5, characterized in that: After modifying the SQL grammar unit to the target grammar format, the method further includes: Generate an XML file corresponding to the target database according to the target syntax format; Set a symbol, and embed the symbol into an XML file corresponding to the target database.
7. The Oracle database modification method according to claim 6, characterized in that: After embedding the symbol into the XML file corresponding to the target database, the method further includes: The XML file in which the symbol is embedded is stored in a preset directory.
8. An Oracle database modification device, characterized in that: The device comprises: A determination module is configured to determine a Java project using an Oracle database; An acquisition module is configured to acquire a storage directory of the Java project; A reading module is configured to read the XML files in the mapper directory of the Java project one by one in the storage directory; An extraction module is configured to extract SQL syntax units from the XML file; The modification module is configured to modify the SQL grammar unit into a target grammar format.
9. A computer device comprising a memory and a processor, characterized in that: The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the method as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
