CN-122019572-A - Method, system, equipment and storage medium for converting database SQL (structured query language) sentences
Abstract
The method for converting the SQL sentences of the database comprises the steps of constructing a database difference comparison library, automatically extracting the SQL sentences from items to be migrated, matching conversion rules of the database difference comparison library with the SQL sentences to obtain a matching result, automatically converting the SQL sentences based on the database difference comparison library to obtain target SQL sentences when the database difference comparison library contains conversion rules corresponding to the SQL sentences, analyzing the SQL sentences and generating conversion suggestions through a preset large language model when the database difference comparison library does not contain conversion rules corresponding to the SQL sentences, and automatically converting the SQL sentences to obtain the target SQL sentences. According to the invention, the conversion efficiency and accuracy under the conventional scene and the flexibility and intelligence of the complex scene are ensured through a synergistic mechanism of combining the automatic processing of the known differences of the database and the processing of the unknown differences of the large language model by the database difference comparison library.
Inventors
- CHEN DING
Assignees
- 中国建设银行股份有限公司湖南省分行
Dates
- Publication Date
- 20260512
- Application Date
- 20260203
Claims (10)
- 1. A method for converting a database SQL statement, comprising: Constructing a database difference comparison library for recording differences between a source database and a target database; Automatically extracting SQL sentences from the items to be migrated; Matching the conversion rule of the database difference comparison library with the SQL sentence to obtain a matching result; When the matching result is that the database difference comparison library contains a conversion rule corresponding to the SQL sentence, automatically converting the SQL sentence based on the database difference comparison library to obtain a target SQL sentence; And when the matching result is that the database difference comparison library does not contain the conversion rule corresponding to the SQL sentence, analyzing the SQL sentence through a preset large language model, generating a conversion suggestion, and automatically converting the SQL sentence based on the conversion suggestion to obtain the target SQL sentence.
- 2. The method for converting a database SQL statement according to claim 1, wherein the automatically extracting the SQL statement from the item to be migrated comprises: and automatically extracting SQL sentences from at least one file of a source code file, a configuration file, a database object and a script file in the item to be migrated through a preset extraction script, and carrying out standardized processing.
- 3. The method for converting a database SQL statement according to claim 1, wherein the matching the conversion rule based on the database difference comparison library to obtain a matching result comprises: Performing lexical analysis and grammar analysis on the SQL sentence to construct an abstract grammar tree; Traversing the nodes of the abstract syntax tree, and matching with the conversion rules in the database difference comparison library to obtain the matching result.
- 4. The method for converting a database SQL statement according to claim 1, further comprising, after said automatically converting said SQL statement: And evaluating the confidence coefficient of the SQL sentence after automatic conversion, and outputting the SQL sentence as the target SQL sentence when the confidence coefficient exceeds a preset threshold value.
- 5. The method for converting a database SQL statement according to claim 3, further comprising, before said analyzing said SQL statement by a preset large language model: Performing grammar checking on the SQL statement by using the grammar specification of the target database to obtain a grammar checking result; The SQL sentence is analyzed through a preset large language model, specifically, when the grammar checking result is that grammar errors exist, the corresponding SQL sentence and the corresponding grammar error information are provided as input data for the large language model to analyze.
- 6. The method for converting a database SQL statement according to claim 5, wherein analyzing the SQL statement and generating a conversion suggestion by a preset large language model comprises: Constructing a prompt word comprising SQL sentences, the source database type, the target database type and the grammar error information; and acquiring conversion suggestions generated by the large language model based on the prompt words.
- 7. The method for converting a database SQL statement according to claim 1, further comprising, after the obtaining the target SQL statement: And automatically replacing the SQL statement in the item to be migrated with the target SQL statement, and generating a migration report.
- 8. A system for converting a database SQL statement, comprising: The difference comparison library construction module is used for constructing a database difference comparison library for recording the difference between the source database and the target database; The SQL extraction module is used for automatically extracting SQL sentences from the items to be migrated; The conversion rule matching module is used for carrying out conversion rule matching on the SQL sentences based on the database difference comparison library to obtain a matching result; The comparison library conversion module is used for automatically converting the SQL sentence based on the database difference comparison library to obtain a target SQL sentence when the matching result is that the database difference comparison library contains conversion rules corresponding to the SQL sentence; And the model conversion module is used for analyzing the SQL sentence through a preset large language model and generating a conversion suggestion when the matching result is that the database difference comparison library does not contain the conversion rule corresponding to the SQL sentence, and automatically converting the SQL sentence based on the conversion suggestion to obtain the target SQL sentence.
- 9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the method of converting a database SQL statement according to any one of claims 1 to 7 when the computer program is executed.
- 10. A computer readable storage medium, characterized in that the computer readable storage medium stores a computer program which, when executed by a processor, implements the steps of the method of converting a database SQL statement according to any one of claims 1-7.
Description
Method, system, equipment and storage medium for converting database SQL (structured query language) sentences Technical Field The present invention relates to the field of database technologies, and in particular, to a method, a system, an apparatus, and a storage medium for converting a database SQL statement. Background With the advanced innovation of information technology applications, enterprise-level application systems are facing urgent demands for migration from foreign business databases (e.g., oracle, SQL SERVER, etc.) to domestic databases (e.g., TDSQL, dream of arrival, large-scale man Jin Cang, etc.). In the database migration process, because different database management systems have significant differences in terms of SQL dialects, data types, built-in functions, execution plan optimization and the like, SQL sentences in an application program cannot be directly and correctly operated on a target database. The current mainstream database migration method mainly relies on the following modes that all SQL sentences in an application program are manually modified one by a developer, grammar differences are modified one by one according to personal experience, the mode is extremely low in efficiency, one medium-scale project may contain thousands of SQL sentences, manual migration requires several months, simple keyword replacement is carried out by using a text search replacement tool based on simple replacement of tools, the method cannot handle complex grammar structure differences, for example, the ROWNUM paging of Oracle is completely different from the LIMIT paging of MySQL in grammar structure, simple text replacement can cause grammar errors, and a part of database provides a compatible mode, but has limited functions, cannot contain all grammar differences and can bring about performance problems. The prior art has the main defects of high dependence on manual experience, high personnel culture cost, difficult inheritance of experience, low migration efficiency, manual examination and modification of SQL sentences one by one, long migration period of a large project for several months, high error rate, easy omission or error modification of manual operation, particularly complicated nested query, storage process and the like, lack of a systematic method, and knowledge in the migration process is dispersed in the brains of all developers, and no reusable knowledge system is formed. In view of this, how to provide an automated method and system for converting database SQL statements to comprehensively improve the migration efficiency, accuracy and reliability of the database is a technical problem to be solved by those skilled in the art. Disclosure of Invention In order to solve the technical problems, the method and the device realize efficient, batched and accurate and consistent processing on the known grammar differences of the database by carrying out rule matching and automatic conversion based on the database difference comparison library, solve the automation problem of most conventional scenes, greatly improve the efficiency and quality of basic migration work, and provide an intelligent solving path for unknown SQL semantic differences which cannot be processed by the difference comparison library by introducing a mechanism for analyzing and generating conversion suggestions by calling a large language model when the conversion rules of the database difference comparison library do not contain conversion rules corresponding to SQL sentences, thereby effectively solving the technical contradiction that the automation coverage rate, the processing accuracy and the scene adaptability are difficult to be considered in the database migration as a whole, and comprehensively improving the migration efficiency, the accuracy and the reliability of the database. The invention aims to provide a conversion method of a database SQL sentence; The technical scheme provided by the invention is as follows: A method for converting a database SQL statement, comprising: Constructing a database difference comparison library for recording differences between a source database and a target database; Automatically extracting SQL sentences from the items to be migrated; based on the database difference comparison library, carrying out conversion rule matching on the SQL sentences to obtain a matching result; When the matching result is that the database difference comparison library contains a conversion rule corresponding to the SQL sentence, automatically converting the SQL sentence based on the database difference comparison library to obtain a target SQL sentence; And when the matching result is that the database difference comparison library does not contain the conversion rule corresponding to the SQL sentence, analyzing the SQL sentence through a preset large language model, generating a conversion suggestion, and automatically converting the SQL sentence based on the conversion suggestion to o