SQL (Structured Query Language) statement acquisition method, medium and equipment

Through a large language model, searching for similar field names and performing vector conversion and filtering, the problem of difficulty in obtaining SQL statements in database structure changes is solved, and the SQL statements are accurately adjusted and adapted, ensuring the accuracy of query results.

CN119862199AActive Publication Date: 2025-04-22ZHEJIANG MEIRI HUDONG NETWORK TECH CO LTD +1

Patent Information

Application Number
CN202411969381.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-04-22
Estimated Expiration
2044-12-30

AI Technical Summary

Technical Problem

In database applications, it is difficult to write accurate and meet the needs of SQL statements, especially when the database structure changes, it is difficult to accurately obtain new SQL statements.

Method used

By obtaining the target user's initial statement, target scenario, target table and initial SQL statement, using the large language model to find similar field names, and filtering the target field names through vector transformation and similarity calculation, replacing the keywords in the initial SQL statement to adapt to database field changes.

Benefits of technology

It realizes accurate acquisition and adjustment of SQL statements, ensuring that the replaced target field name conforms to the original semantic logic, and avoids logical errors caused by arbitrary replacement of field names or the query results do not meet expectations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119862199A_ABST
    Figure CN119862199A_ABST
Patent Text Reader

Abstract

The invention relates to the field of data processing, in particular to an SQL (Structured Query Language) statement acquisition method, a medium and equipment, aiming at a field name change condition, similar field names are searched by means of a large language model, reference keywords and middle field names are converted into vectors, the similarity degree is calculated, and a target field name is obtained through screening. Therefore, the SQL statement can be adjusted in time along with the change of the database field, and it is ensured that the target field name replaced into the initial SQL statement conforms to the original semantic logic, so that the situation that the SQL statement has a logic error or a query result does not conform to the expectation due to random replacement of the field name is avoided; the corresponding data operation can still be accurately executed in a new field environment, and the adaptability and accuracy of the generated SQL statement to the actual structure of the database are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing, and in particular to a method, medium and device for obtaining SQL statements. Background Art

[0002] In the field of database applications, SQL (Structured Query Language) statements are the key language used to interact with databases and manipulate data. However, for many users, especially non-professional database operators, it is difficult to write accurate SQL statements that meet the requirements. On the one hand, the SQL syntax rules are relatively complex, and you need to be familiar with the specific syntax structures corresponding to various operations such as query, insert, update, and other operations, as well as detailed information such as table structure and field names in the database. On the other hand, with the continuous changes in business needs and the continuous expansion of database content, the fields in the table may be adjusted, added, or renamed, so that the existing SQL statements need to be modified accordingly to adapt to the new database structure.

[0003] At the same time, a large number of initial SQL statements accumulated in actual applications are written based on previous business needs and database status. When the database changes or you want to query and operate data in a different way, it is difficult to accurately obtain new SQL statements that meet current needs.

[0004] Therefore, how to improve the accuracy of SQL statement acquisition becomes an urgent problem to be solved. Summary of the invention

[0005] In view of the above technical problem, the technical solution adopted by the present invention is a method for obtaining SQL statements, which includes the following steps:

[0006] S100, obtaining an initial statement input by a target user, a target scenario corresponding to the initial statement, a target table and an initial SQL statement, several initial field names corresponding to the target table, and a target vector conversion model corresponding to the target scenario.

[0007] S200: Input each initial field name into a preset large language model, and obtain a number of similar field names and the number of similar field names corresponding to each initial field name.

[0008] S300: determining initial field names whose corresponding similar field names are within a preset number threshold as reference field names, and determining each similar field name corresponding to each reference field name as an intermediate field name.

[0009] S400: extract keywords from the initial SQL statement to obtain a number of reference keywords corresponding to the initial SQL statement.

[0010] S500: Convert each reference keyword and each intermediate field name according to a target vector conversion model to obtain a reference vector corresponding to each reference keyword and an intermediate vector corresponding to each intermediate field name.

[0011] S600, for any reference keyword, obtain the similarity between the current reference keyword and each intermediate field name based on the current reference keyword, the reference vector corresponding to the current reference keyword, each intermediate field name and the intermediate vector corresponding to each intermediate field name.

[0012] S700: Acquire a target field name corresponding to the current reference keyword according to the similarity between the current reference keyword and each intermediate field name.

[0013] S800, using the target field name corresponding to each reference keyword to replace the corresponding reference keyword in the initial SQL statement, and obtaining the target SQL statement corresponding to the initial statement.

[0014] The present invention also provides a non-transitory computer-readable storage medium, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement the above-mentioned SQL statement acquisition method.

[0015] The present invention also provides an electronic device, comprising a processor and the above-mentioned non-transitory computer-readable storage medium.

[0016] The present invention has at least the following beneficial effects: in response to field name changes, similar field names are found with the help of a large language model, and target field names are screened by converting reference keywords and intermediate field names into vectors and calculating the degree of similarity, so that SQL statements can be adjusted in time with changes in database fields, and it is ensured that the target field names replaced in the initial SQL statements conform to the original semantic logic, thereby avoiding logical errors in SQL statements or unexpected query results due to arbitrary field name replacement, ensuring that corresponding data operations can still be accurately performed in a new field environment, and enhancing the adaptability and accuracy of the generated SQL statements to the actual structure of the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0018] Figure 1A flowchart of a method for obtaining SQL statements provided in Embodiment 1 of the present invention;

[0019] Figure 2 A schematic diagram of the structure of a SQL statement acquisition device provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION

[0020] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It is understood that, where appropriate, the above-mentioned terms used to distinguish similar objects can be interchanged so that the present invention can also implement other embodiments other than the above-mentioned illustrated embodiments or described embodiments. In addition, the terms "including" and "having" and any variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0022] Embodiment 1

[0023] This embodiment provides a method for obtaining a SQL statement, and the method for obtaining a SQL statement includes the following steps: Figure 1 As shown:

[0024] S100, obtaining an initial statement input by a target user, a target scenario corresponding to the initial statement, a target table and an initial SQL statement, several initial field names corresponding to the target table, and a target vector conversion model corresponding to the target scenario.

[0025] The initial statement input by the user is a data operation requirement expressed by the user in natural language. The target scenario is a classification definition of the business or operation type in which the initial statement is located. The target table refers to a specific data table in the database related to the requirement expressed by the user through the initial statement.

[0026] For example, the target scenarios can be divided into sales business scenarios, financial business scenarios, human resources business scenarios, etc. according to the business field. They can also be divided into query scenarios, insert scenarios, update scenarios, etc. according to the operation type. In an enterprise management database, the target tables may include employee information tables, sales data tables, department information tables, etc. The description text of the employee information table may introduce "the table contains fields such as employee number, name, department, and entry time. The employee number is the primary key and uniquely identifies each employee."

[0027] The initial SQL statement is an existing SQL statement that was previously obtained based on the business requirements corresponding to the initial statement. It is the basis for subsequent adjustments and optimizations to obtain SQL statements with higher accuracy.

[0028] Each target table contains multiple fields. The initial field name is the specific name of each field in the target table. It can be used as a specific identifier for storing data in the database, as well as an object that needs to be explicitly referenced when querying and operating SQL statements. It reflects the data structure details of the target table and plays a key role in accurately generating target SQL statements. For example, in the "employee information table", the initial field names may include "employee number", "name", "department", "entry date", etc. In the "sales data table", there may be field names such as "sales amount", "sales date", and "salesperson".

[0029] The function of the vector conversion model is to convert natural language text into vector representation. Due to the different language characteristics, data relationships and other factors in different preset scenarios, a vector conversion model that is adapted to them is needed to more accurately measure the relationship between natural language text and vector representation, and provide a suitable vector data foundation for the subsequent generation of SQL statements.

[0030] In a specific implementation, S100 includes the following steps:

[0031] S101, obtaining an initial vector conversion model, description text samples corresponding to a number of preset tables, preset scenes and description vector samples corresponding to each description text sample, and a preset sampling ratio corresponding to each preset scene.

[0032] S102, determining a preset sampling ratio as a target sampling ratio, determining each preset scene as an initial scene, and initializing the number of repetitions N=1.

[0033] S103, sampling from a plurality of description text samples according to a target sampling ratio corresponding to each initial scene, to obtain an Nth description text training sample set, an Nth description text verification sample set, and an Nth number of description text samples corresponding to each initial scene in the Nth description text training sample set.

[0034] S104, training the initial vector conversion model according to the Nth description text training sample set, the Nth description text verification sample set and the description vector sample corresponding to each description text sample, and obtaining the Nth vector conversion model and the Nth accuracy of each initial scene in the Nth vector conversion model.

[0035] S105 , obtaining an Nth degree of adaptation between each initial scene and the Nth vector conversion model according to the Nth number and the Nth accuracy rate corresponding to each initial scene.

[0036] S106, for any initial scene, determine the adaptation result corresponding to the current initial scene according to the comparison result of the Nth adaptation degree corresponding to the current initial scene and the preset degree threshold, wherein the adaptation result includes adaptation, non-matching and to be determined.

[0037] S107: If the adaptation result corresponding to the current initial scene is adaptation, the current initial scene is determined as the first scene, and the Nth vector conversion model is determined as the target vector conversion model corresponding to the current first scene.

[0038] S108: If the adaptation result corresponding to the current initial scene is not suitable, the current initial scene is determined as the second scene.

[0039] S109: If the adaptation result corresponding to the current initial scene is to be determined, the current initial scene is determined as the third scene.

[0040] S110, traverse all initial scenes, obtain all first scenes and the target vector conversion model corresponding to each first scene, all second scenes, all third scenes and the number of scenes corresponding to the third scenes.

[0041] S111, acquiring a target description text sample set corresponding to each second scene according to the preset scene and the description vector sample corresponding to each description text sample.

[0042] S113, training the initial vector conversion model according to the target description text sample set corresponding to each second scene and the description vector sample corresponding to each description text sample, to obtain the target vector conversion model corresponding to each second scene.

[0043] S114, if the number of scenes is greater than 0, update the preset sampling ratio corresponding to each third scene and determine the updated preset sampling ratio as the target sampling ratio, determine each third scene as the initial scene, update N=N+1, and repeat step S103 until the updated number of scenes is equal to 0, and obtain the target vector conversion model corresponding to each preset scene.

[0044] S115, acquiring a target vector conversion model corresponding to the target scene according to the target vector conversion model corresponding to each preset scene.

[0045] The description text sample is used to describe in detail the structure, field meaning, data range and other information of each preset table, which helps to understand the specific composition of the table so as to accurately build the association between the SQL statement and the table.

[0046] The initial vector conversion model is a general vector conversion model that is not optimized for specific scenarios. In the future, training and adjustment will be carried out based on the initial vector conversion model combined with specific data to enable it to adapt to the text-to-vector conversion requirements in different preset scenarios.

[0047] The description vector sample is the correct vector representation of the corresponding description text sample, which is used to guide the model to learn how to accurately convert the description text into a vector. The description vector sample can be obtained by converting the description text sample based on a known vector conversion technology. Among them, those skilled in the art know that any vector conversion technology in the prior art falls within the protection scope of the present invention, and will not be repeated here. For example, the vector conversion technology can be Word2Vec technology.

[0048] During the training process of the initial vector conversion model, the description text samples in the Nth description text training sample set as training samples are input into the initial vector conversion model to assist the initial vector conversion model in learning how to convert the description text samples into vectors, and then the description text samples in the Nth description text verification sample set as verification samples are used for verification, and the difference between the vector output by the model and the corresponding description vector sample is compared. The accuracy of the model conversion in each initial scenario is measured by evaluation indicators such as cosine similarity, and finally the Nth vector conversion model and the Nth accuracy of each initial scenario in the Nth vector conversion model are obtained to reflect the accuracy of the current model in converting text into vectors in the corresponding initial scenario.

[0049] For any initial scene, the corresponding Nth degree of adaptation is compared with the preset degree threshold. If the Nth degree of adaptation is higher than the preset degree threshold, it means that the Nth vector conversion model performs well in the initial scene and the adaptation is ideal. If it is lower than the preset degree threshold, it is considered that the Nth vector conversion model is not very suitable for the initial scene. If it is just near the critical point of the preset degree threshold, it is determined to be in a pending state, and the vector conversion model adapted to the initial scene needs to be further updated and matched.

[0050] For the situation determined as the first scene, the target vector conversion model corresponding to each first scene is determined to complete the work of determining the appropriate model in some scenes.

[0051] For the cases determined to be the second scene, a target description text sample set suitable for retraining is collected and sorted out, and the initial vector conversion model corresponding to each second scene is trained separately to obtain the target vector conversion model corresponding to each second scene.

[0052] For the situation judged as the third scene, the vector conversion model is continuously optimized by updating the sampling ratio, repeating training and other operations until all preset scenes have clear model adaptation judgment results, and finally the target vector conversion model corresponding to each preset scene is obtained.

[0053] The above method of finding a suitable vector conversion model for different preset scenarios through multiple iterative training and evaluation aims to improve the accuracy and effectiveness of subsequent SQL statement conversion so that it can better adapt to diverse business scenarios and natural language input situations.

[0054] By acquiring basic data including the initial vector conversion model, descriptive text samples and their related preset scenarios and description vector samples, preset sampling ratios, etc., and through multiple rounds of iterative operations, each preset scenario and related sample data and vector conversion model are sampled, trained, evaluated and classified, and each initial scenario is divided into an adapted first scenario and its target vector conversion model is determined, an unsuitable second scenario is to be retrained, and a third scenario to be judged is to be further analyzed and optimized, until all preset scenarios obtain an adapted target vector conversion model, which lays a precise and adaptable vector conversion foundation for the subsequent natural language and SQL statement conversion based on the target vector conversion model, improves the depth and accuracy of the understanding of the initial statements corresponding to each scenario in the vector conversion process, thereby improving the accuracy of SQL statement generation and reducing the risk of data errors or business process interference caused by the execution of erroneous SQL statements.

[0055] In a specific implementation, the preset sampling ratio corresponding to each preset scene includes a training sample sampling ratio and a verification sample sampling ratio, and S103 includes the following steps:

[0056] S1031, for any initial scene, according to the sampling ratio of training samples corresponding to the current initial scene, a number of description text samples are sampled from all description text samples corresponding to the current initial scene as training samples, and the Nth number of description text samples corresponding to the current initial scene as training samples is obtained.

[0057] S1032 , according to the sampling ratio of verification samples corresponding to the current initial scene, sample a plurality of description text samples from all description text samples corresponding to the current initial scene as verification samples.

[0058] S1033, traverse all initial scenes, and obtain a number of description text samples as training samples and a number of description text samples as verification samples corresponding to each initial scene.

[0059] S1034: Determine a set of several description text samples corresponding to all initial scenes as training samples as the Nth description text training sample set.

[0060] S1035: Determine a set of several description text samples corresponding to all initial scenes as verification samples as the Nth description text verification sample set.

[0061] As mentioned above, from the descriptive text samples in each initial scenario, training samples and verification samples are reasonably divided according to the corresponding sampling ratios, and finally the overall training sample set and verification sample set are constructed, so as to provide the key data preparation and organizational basis for the subsequent training, verification and gradual optimization of the initial vector conversion model based on the training sample set and the verification sample set, thereby creating a suitable vector conversion model for different preset scenarios, and ensuring the scientificity and rationality of the entire model training process.

[0062] In a specific implementation, S105 includes the following steps:

[0063] S1051, normalize the Nth number corresponding to each initial scene to obtain the normalized Nth number corresponding to each initial scene.

[0064] S1052, input the normalized Nth number and Nth accuracy corresponding to each initial scene into a preset adaptation degree calculation model to obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model.

[0065] Among them, there may be large differences in the number of descriptive text samples extracted as training samples from different initial scenes. This embodiment uses a normalization operation to uniformly convert the quantitative values ​​of different magnitudes into a standard, comparable range, creating conditions for the subsequent accurate measurement of the degree of adaptation. The value range of the Nth number after normalization is [0, 1]. Those skilled in the art know that any normalization method in the prior art with a value range of [0, 1] falls within the protection scope of the present invention, and will not be repeated here. For example, the normalization method in this embodiment can be a Min-Max normalization method.

[0066] When the normalized Nth number corresponding to the initial scene is large, it means that there is relatively sufficient training data for the vector conversion model to learn the text conversion mode related to the initial scene. Correspondingly, the abundant data volume should help the vector conversion model to better capture the rules and improve the accuracy. However, when the Nth accuracy corresponding to the initial scene is low, it means that the vector conversion model cannot effectively extract features and understand semantics for the specific data features of the initial scene, so that the generated vector has a large deviation from the actual expected vector. Therefore, when the normalized Nth number corresponding to the initial scene is large and the Nth accuracy is low, it means that the structural design of the vector conversion model cannot fully adapt to the complexity and diversity of the initial scene data, and cannot effectively utilize the description text samples and corresponding description vector samples under the initial scene. Therefore, the Nth adaptation degree is inversely proportional to the corresponding normalized Nth number, and the Nth adaptation degree is proportional to the corresponding Nth accuracy.

[0067] Among them, the preset adaptation degree calculation model is a weighted sum model. The implementer can set the first weight corresponding to the normalized Nth number and the second weight corresponding to the Nth accuracy rate according to actual conditions, and obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model by weighted summing the normalized Nth number and the Nth accuracy rate.

[0068] As described above, normalization is used to allow the number of training samples to participate in the evaluation on a fair and comparable basis. Then, based on the preset relationship between the degree of adaptation and the normalized Nth number and the Nth accuracy, the degree of adaptation is obtained using the adaptation degree calculation model. This provides a scientific and quantitative basis for the entire process to accurately judge the adaptation status of each initial scenario and the vector conversion model, which helps to improve the accuracy and reliability of constructing a vector conversion model that adapts to different preset scenarios, thereby improving the accuracy of subsequent SQL statement conversion.

[0069] In a specific implementation, the preset degree threshold includes a first degree threshold and a second degree threshold, and S106 includes the following steps:

[0070] S1061: If the Nth adaptation degree corresponding to the current initial scene is less than or equal to the first degree threshold, determine that the adaptation result corresponding to the current initial scene is unmatched.

[0071] S1062: If the Nth adaptation degree corresponding to the current initial scene is greater than or equal to the second degree threshold, it is determined that the adaptation result corresponding to the current initial scene is not adapted.

[0072] S1063: If the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold, it is determined that the adaptation result corresponding to the current initial scene is to be determined.

[0073] Among them, if the Nth adaptation degree corresponding to the current initial scene is less than or equal to the pre-set first degree threshold, it means that the Nth vector conversion model in the initial scene has very poor sample utilization effect, scene semantic understanding accuracy, and the ability to generate expected vectors. In this case, it can be clearly determined that the adaptation result corresponding to the initial scene is unsuitable, that is, the vector conversion model trained together under multiple initial scenes is not suitable for the current initial scene. In this case, a target description text sample set suitable for retraining can be collected and sorted, and the initial vector conversion model corresponding to each second scene can be trained separately to obtain an adapted target vector conversion model.

[0074] If the Nth adaptation degree corresponding to the current initial scene is greater than or equal to the set second degree threshold, it means that the Nth vector conversion model has reached an ideal adaptation state in the current initial scene, and can effectively convert the initial sentence in the current initial scene into a suitable vector, and performs well in terms of accuracy, etc., then the current Nth vector conversion model can be used as the target vector conversion model for the current initial scene.

[0075] If the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold, the adaptation result corresponding to the current initial scene is determined to be pending, and more rounds of analysis and processing are required to determine the adaptability of the current initial scene and the current vector conversion model.

[0076] The specific values ​​of the first degree threshold and the second degree threshold can be set by the implementer according to actual conditions.

[0077] In the above, by setting the first degree threshold and the second degree threshold, the three adaptation results of unmatched, matched, and to be judged are clearly and reasonably divided, which provides a clear judgment standard and classification basis for the evaluation and screening of vector conversion models in different initial scenarios, and can classify and process many initial scenarios in an orderly manner, and adopt corresponding optimization strategies for different adaptation results, which helps to more accurately find a suitable target vector conversion model for each preset scenario, thereby ensuring the accuracy and effectiveness of subsequent SQL statement conversion work.

[0078] In a specific implementation, S100 further includes the following steps:

[0079] S1, obtaining a plurality of preset tables, a preset description text and a preset scene corresponding to each preset table.

[0080] S2, acquiring a description vector corresponding to each preset table according to a target vector conversion model corresponding to a preset scene corresponding to a preset description text corresponding to each preset table.

[0081] S3, converting the model according to the target vector corresponding to the target scene corresponding to the initial sentence, and obtaining the sentence vector corresponding to the initial sentence.

[0082] S4, obtaining the target matching degree between the initial sentence and each preset table according to the description vector corresponding to each preset table and the sentence vector corresponding to the initial sentence.

[0083] S5, according to the target matching degree between the initial statement and each preset table, the target table corresponding to the initial statement is screened out from all the preset tables.

[0084] According to the target vector conversion model corresponding to the preset scene corresponding to each preset table, the preset description text corresponding to each preset table is vector-converted to obtain the description vector corresponding to each preset table.

[0085] According to the target vector conversion model corresponding to the preset scenario corresponding to the initial sentence, the initial sentence is vector converted to obtain the sentence vector corresponding to the initial sentence.

[0086] In a specific implementation, S4 includes the following steps:

[0087] S41, calculating the similarity between the description vector corresponding to each preset table and the sentence vector corresponding to the initial sentence.

[0088] S42, determining the similarity between the description vector corresponding to each preset table and the sentence vector corresponding to the initial sentence as the target matching degree between the initial sentence and each preset table.

[0089] Among them, the similarity between the description vector corresponding to each preset table and the statement vector corresponding to the initial statement can be used to measure the degree of association between the initial statement and each preset table, so as to obtain the target matching degree between the initial statement and each preset table, which serves as the basis for accurately screening out the target table that best matches the initial statement from many preset tables, thereby improving the accuracy and rationality of the generated SQL statement.

[0090] In a specific implementation, S5 includes the following steps:

[0091] S51, comparing the target matching degree between the initial statement and each preset table to obtain the maximum target matching degree.

[0092] S52, determining the preset table corresponding to the maximum target matching degree as the target table corresponding to the initial sentence.

[0093] As described above, by constructing corresponding target vector conversion models for different preset scenarios, whether converting the description text of the preset table into a description vector or converting the initial sentence input by the user into a sentence vector, accurate mapping can be performed based on the semantic characteristics and data association logic in the specific scenario, so that the vector can more accurately carry the key information in the text, provide data support for table screening and SQL statement generation, reduce erroneous conversions caused by problems such as semantic understanding deviation, and improve the accuracy of SQL statement conversion results in each preset scenario.

[0094] In a specific implementation, S100 further includes the following steps:

[0095] S10, obtain the historical input database and the preset keyword configuration table corresponding to the target scenario, wherein the historical input database includes several historical statements, the historical statement vector corresponding to each historical statement, and the historical SQL statement, and the preset keyword configuration table includes several custom keywords and the regular expression corresponding to each custom keyword.

[0096] S20, extracting keywords from the initial sentence to obtain a number of target keywords corresponding to the initial sentence.

[0097] S30, matching each target keyword with the preset keyword configuration table to obtain a matching result corresponding to each target keyword, wherein the matching result includes a set consisting of a corresponding custom keyword and a corresponding regular expression.

[0098] S40, obtaining several target regular expressions corresponding to the initial sentence according to the matching results of all target keywords.

[0099] S50, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence.

[0100] S60, obtaining the similarity between the initial sentence and each historical sentence according to the sentence vector and the historical sentence vector corresponding to each historical sentence.

[0101] S70, based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold, a plurality of reference sentences corresponding to the initial sentence are screened out from all historical sentences.

[0102] S80, input the sentence vector, the target table, several target regular expressions corresponding to the initial sentence, several reference sentences corresponding to the initial sentence, and the historical SQL statements corresponding to each reference sentence into the preset large language model to obtain the initial SQL statement corresponding to the initial sentence.

[0103] Among them, the historical input database is a collection that stores a large amount of past database interaction-related data, including several historical statements, each of which corresponds to a historical statement vector and a corresponding historical SQL statement. The historical statement vector is a digital, computer-friendly representation of the historical statement after vector conversion, which contains information such as the semantics of the historical statement. The historical SQL statement is the SQL code that has been successfully generated and executed based on the corresponding historical statement and conforms to the database syntax specification.

[0104] The preset keyword configuration table is a pre-set table containing several custom keywords and the regular expression corresponding to each custom keyword. Custom keywords are important words with specific meanings and database operation directions extracted from a business perspective, such as "entry time" and "leaving time" in human resource management scenarios. Regular expression is a tool for matching and standardizing text formats. The regular expression corresponding to each custom keyword specifies how to accurately identify the keyword and its related expression form in natural language. For example, the regular expression corresponding to "entry time" may be "entry\s+[\s+] time", which is used to match statement expressions such as "entry on January 1, 2024". In this way, key information can be accurately extracted and standardized from texts such as initial statements, assisting in the determination of the generation logic of subsequent SQL statements.

[0105] Among them, those skilled in the art know that any keyword extraction method in the prior art falls within the protection scope of the present invention, and will not be described in detail here.

[0106] As described above, by extracting keywords from the initial sentence and matching it with the preset keyword configuration table to obtain the target regular expression, it is possible to accurately capture the key semantic information in the natural language, standardize the fuzzy and diverse natural language expressions according to the established business rules, and avoid the large language model's incorrect interpretation of the user's intentions. At the same time, by screening out reference sentences that are highly similar to the initial sentence and have reference significance for the current SQL statement generation from many historical sentences, it helps the preset large language model to generate more accurate initial SQL statements that meet the user's intentions based on previous similar situations, thereby improving the accuracy of SQL statement generation.

[0107] In a specific implementation, S30 further includes the following steps:

[0108] S301, for any target keyword, perform word consistency matching between the current target keyword and each custom keyword in the preset keyword configuration table, and obtain word consistency matching results between the current target keyword and each custom keyword, wherein the word consistency matching results include word consistency and word inconsistency.

[0109] S302: For any custom keyword, if the word consistency matching result between the current target keyword and the current custom keyword is word consistency, a set consisting of the current custom keyword and the regular expression corresponding to the current custom keyword is determined as the matching result corresponding to the current target keyword.

[0110] S303, traversing all the custom keywords, if the word consistency matching results between the current target keyword and all the custom keywords are all word inconsistencies, determining an empty set as the matching result corresponding to the current target keyword.

[0111] In the above, by comparing the target keywords with the custom keywords in the preset keyword configuration table one by one, the matching of the target keywords and the custom keywords at the word level is judged, and on this basis, the matching results corresponding to each target keyword are obtained, which lays a solid foundation for the subsequent integration of the matching results of all target keywords, further guiding the SQL statement generation logic based on these results, and improving the accuracy and standardization of SQL statement generation.

[0112] S200: Input each initial field name into a preset large language model, and obtain a number of similar field names and the number of similar field names corresponding to each initial field name.

[0113] Among them, the preset large language model is also used to find other field names that are similar in semantics, functions or usage scenarios for each initial field name based on its powerful language understanding and semantic association capabilities, and count the number of similar field names.

[0114] The above lays a foundation for subsequently screening out suitable options that can be used to replace relevant field names in the initial SQL statement, and further ensuring that the SQL statement can still accurately perform corresponding operations when adapting to changes in the database structure, etc., which helps to improve the rationality and accuracy of SQL statement updates and optimizations.

[0115] S300: determining initial field names whose corresponding similar field names are within a preset number threshold as reference field names, and determining each similar field name corresponding to each reference field name as an intermediate field name.

[0116] In a specific implementation, the preset quantity threshold range includes a first quantity threshold and a second quantity threshold, and S300 further includes the following steps:

[0117] S310, according to the number of similar field names corresponding to each initial field name, obtain the distribution of the number of similar field names corresponding to all initial field names.

[0118] S320: Determine the first quartile corresponding to the quantity distribution of similar field names as the first quantity threshold.

[0119] S330: Determine the third quartile corresponding to the quantity distribution of similar field names as the second quantity threshold.

[0120] S340: For any initial field name, if the number of similar field names corresponding to the current initial field name is greater than or equal to the first number threshold and less than or equal to the second number threshold, the current initial field name is determined as a reference field name.

[0121] Among them, the quartile is the value of the split point after the number of similar field names is arranged in order from small to large and divided into four equal parts. The first quartile is the value in the top 25% of the data sorting position, and the third quartile is the value in the top 75% of the data sorting position. By using the statistical characteristics of data distribution, the first quantity threshold and the second quantity threshold can reasonably reflect the boundary conditions in the data set.

[0122] If the number of similar field names is too small, such as less than the preset first quantity threshold, it means that the initial field name and other field names may only be associated with the initial field name by chance in some very special situations, that is, the semantic association between the initial field name and other field names is not strong, and there is a lack of initial field names with sufficient alternative options. If the number of similar field names is too large, such as exceeding the preset second quantity threshold, it means that the association range of the initial field name may be too broad, which will make the subsequent determination of appropriate replacement field names complicated and difficult, and increase the risk of selecting inappropriate replacement items. Therefore, this embodiment determines the initial field name whose number of similar field names is greater than or equal to the first quantity threshold and less than or equal to the second quantity threshold as the reference field name.

[0123] As mentioned above, by understanding the distribution of the number of similar field names, determining the upper and lower thresholds based on the quartiles, and screening out reference field names according to the threshold range, the drawbacks of traditional manual subjective threshold setting or arbitrary screening of field names are avoided, making the screening process more objective and scientific, and being able to accurately select a subset of field names with relatively appropriate relevance and applicability from a large number of initial field names and their similar field names, laying a solid foundation for subsequent accurate replacement of field names in SQL statements and generation of target SQL statements that meet the requirements, thereby improving the accuracy and reliability of the entire SQL statement acquisition method.

[0124] S400: extract keywords from the initial SQL statement to obtain a number of reference keywords corresponding to the initial SQL statement.

[0125] Among them, those skilled in the art know that any keyword extraction method in the prior art falls within the protection scope of the present invention, and will not be described in detail here.

[0126] In the above, reference keywords are extracted from the initial SQL statement to grasp the core semantics and key operation information of the initial SQL statement, which serves as an important basis for subsequent operations such as semantic matching and field name replacement. This helps to accurately adjust and optimize the initial SQL statement according to database changes and current needs, so as to convert it into a target SQL statement that meets the requirements.

[0127] S500: Convert each reference keyword and each intermediate field name according to a target vector conversion model to obtain a reference vector corresponding to each reference keyword and an intermediate vector corresponding to each intermediate field name.

[0128] S600, for any reference keyword, obtain the similarity between the current reference keyword and each intermediate field name based on the current reference keyword, the reference vector corresponding to the current reference keyword, each intermediate field name and the intermediate vector corresponding to each intermediate field name.

[0129] In a specific implementation, S600 includes the following steps:

[0130] S610: Calculate the character overlap between the current reference keyword and each intermediate field name.

[0131] S620: Calculate the vector similarity between the reference vector corresponding to the current reference keyword and the intermediate vector corresponding to each intermediate field name.

[0132] S630, based on the character overlap between the current reference keyword and each intermediate field name, the first weight corresponding to the character overlap, the vector similarity between the reference vector corresponding to the current reference keyword and the intermediate vector corresponding to each intermediate field name, and the second weight corresponding to the vector similarity, obtain the similarity between the current reference keyword and each intermediate field name.

[0133] Among them, the character overlap can reflect the similarity between two words in text form. By calculating the character overlap between the current reference keyword and each intermediate field name, the degree of association can be intuitively measured at the character level, providing a dimension based on literal information for comprehensive evaluation of the overall similarity, and assisting in subsequent more comprehensive and accurate judgment of the matching relationship between the reference keyword and the intermediate field name.

[0134] Calculating the vector similarity between the reference vector and the intermediate vector and measuring the degree of association between the reference keyword and the intermediate field name from the perspective of digital representation of semantics can more accurately determine whether they are consistent in terms of semantic connotation, usage scenarios, etc., and provide a key dimension data based on semantic understanding for the final determination of the similarity, which complements the character overlap and jointly builds a more comprehensive similarity evaluation system.

[0135] A common way to calculate the character overlap is to calculate the ratio of the number of identical characters in two words to the total number of characters.

[0136] The specific values ​​of the first weight and the second weight can be set by the implementer according to actual conditions.

[0137] As mentioned above, by obtaining the overlap degree from the character level, obtaining the similarity from the perspective of semantic vectors, and finally performing weighted synthesis, the literal information and deep semantic information of the words are fully utilized, avoiding the limitations of a single measurement method, so that the calculated similarity can more accurately reflect the matching relationship between the two, laying a solid and scientific foundation for the subsequent selection of the most appropriate target field name based on the similarity, and then accurately replacing the reference keywords in the initial SQL statement and generating a target SQL statement that meets the requirements, thereby improving the accuracy and rationality of the entire SQL statement acquisition method.

[0138] S700: Acquire a target field name corresponding to the current reference keyword according to the similarity between the current reference keyword and each intermediate field name.

[0139] Among them, the middle field name corresponding to the maximum similarity is determined as the target field name corresponding to the current reference keyword.

[0140] S800, using the target field name corresponding to each reference keyword to replace the corresponding reference keyword in the initial SQL statement, and obtaining the target SQL statement corresponding to the initial statement.

[0141] Among them, the corresponding reference keywords in the initial SQL statement are replaced by the target field name corresponding to each reference keyword to complete the adjustment and optimization of the initial SQL statement, and finally obtain the target SQL statement that meets the current needs, so that the target SQL statement can adapt to the changes in the database structure, and at the same time still accurately reflect the database operations that the user wants to perform in terms of semantics and logic, so as to achieve the goal of quickly generating new and effective SQL statements by using existing SQL statement resources.

[0142] In the above, each initial field name is input into the preset large language model, and a number of similar field names and the number of similar field names corresponding to each initial field name are obtained. The initial field name whose number of corresponding similar field names is within the preset number threshold is determined as a reference field name, and each similar field name corresponding to each reference field name is determined as an intermediate field name. Keyword extraction is performed on the initial SQL statement to obtain a number of reference keywords corresponding to the initial SQL statement, and each reference keyword and each intermediate field name are converted according to the target vector conversion model to obtain a reference vector corresponding to each reference keyword and an intermediate vector corresponding to each intermediate field name. For any reference keyword, the similarity between the current reference keyword and each intermediate field name is obtained according to the current reference keyword, the reference vector corresponding to the current reference keyword, each intermediate field name and the intermediate vector corresponding to each intermediate field name, and the similarity between the current reference keyword and each intermediate field name is obtained according to the current reference keyword, the reference vector corresponding to the current reference keyword, each intermediate field name and the intermediate vector corresponding to each intermediate field name. The similarity between the previous reference keyword and each intermediate field name is used to obtain the target field name corresponding to the current reference keyword, and the target field name corresponding to each reference keyword is used to replace the corresponding reference keyword in the initial SQL statement to obtain the target SQL statement corresponding to the initial statement. According to the change of field names, similar field names are found with the help of a large language model, and the target field names are screened by converting the reference keywords and intermediate field names into vectors and calculating the similarity, so that the SQL statement can be adjusted in time with the changes of database fields, and ensure that the target field name replaced in the initial SQL statement conforms to the original semantic logic, avoiding logical errors in SQL statements or unexpected query results due to arbitrary replacement of field names, ensuring that the corresponding data operations can still be accurately performed in the new field environment, and enhancing the adaptability and accuracy of the generated SQL statement to the actual structure of the database.

[0143] Embodiment 2

[0144] This embodiment 2 provides a SQL statement acquisition device, the SQL statement acquisition device includes: Figure 2 As shown:

[0145] The data acquisition module 21 is used to acquire the initial statement input by the target user, the target scenario corresponding to the initial statement, the target table and the initial SQL statement, several initial field names corresponding to the target table and the target vector conversion model corresponding to the target scenario.

[0146] The similar field name acquisition module 22 is used to input each initial field name into a preset large language model, and acquire a number of similar field names and the number of similar field names corresponding to each initial field name.

[0147] The field name screening module 23 is used to determine the initial field names whose corresponding similar field names are within a preset number threshold as reference field names, and determine each similar field name corresponding to each reference field name as an intermediate field name.

[0148] The keyword extraction module 24 is used to extract keywords from the initial SQL statement and obtain a number of reference keywords corresponding to the initial SQL statement.

[0149] The vector conversion module 25 is used to convert each reference keyword and each intermediate field name according to the target vector conversion model to obtain a reference vector corresponding to each reference keyword and an intermediate vector corresponding to each intermediate field name.

[0150] The similarity acquisition module 26 is used to obtain the similarity between the current reference keyword and each intermediate field name for any reference keyword based on the current reference keyword, the reference vector corresponding to the current reference keyword, each intermediate field name and the intermediate vector corresponding to each intermediate field name.

[0151] The target field name acquisition module 27 is used to acquire the target field name corresponding to the current reference keyword according to the similarity between the current reference keyword and each intermediate field name.

[0152] The SQL statement optimization module 28 is used to replace the corresponding reference keyword in the initial SQL statement with the target field name corresponding to each reference keyword, and obtain the target SQL statement corresponding to the initial statement.

[0153] In a specific implementation, the data acquisition module 21 includes:

[0154] The first data acquisition submodule is used to obtain an initial vector conversion model, description text samples corresponding to a number of preset tables, preset scenes and description vector samples corresponding to each description text sample, and a preset sampling ratio corresponding to each preset scene.

[0155] The data initialization submodule is used to determine the preset sampling ratio as the target sampling ratio, determine each preset scene as the initial scene, and initialize the number of repetitions N=1.

[0156] The first training data acquisition submodule is used to sample from a number of description text samples according to a target sampling ratio corresponding to each initial scene, to obtain the Nth description text training sample set, the Nth description text verification sample set, and the Nth number of description text samples corresponding to each initial scene in the Nth description text training sample set.

[0157] The first model training submodule is used to train the initial vector conversion model according to the Nth description text training sample set, the Nth description text verification sample set and the description vector sample corresponding to each description text sample, and obtain the Nth vector conversion model and the Nth accuracy of each initial scene in the Nth vector conversion model.

[0158] The adaptation degree acquisition submodule is used to obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model according to the Nth number and the Nth accuracy rate corresponding to each initial scene.

[0159] The adaptation result acquisition submodule is used to determine the adaptation result corresponding to the current initial scene for any initial scene based on the comparison result of the Nth adaptation degree corresponding to the current initial scene with the preset degree threshold, wherein the adaptation result includes adaptation, non-adaptation and pending judgment.

[0160] The first scene determination submodule is used to determine the current initial scene as the first scene if the adaptation result corresponding to the current initial scene is adaptation, and determine the Nth vector conversion model as the target vector conversion model corresponding to the current first scene.

[0161] The second scene determination submodule is used to determine the current initial scene as the second scene if the adaptation result corresponding to the current initial scene is not suitable.

[0162] The third scene determination submodule is used to determine the current initial scene as the third scene if the adaptation result corresponding to the current initial scene is to be determined.

[0163] The initial scene traversal submodule is used to traverse all initial scenes, obtain all first scenes and the target vector conversion model corresponding to each first scene, all second scenes, all third scenes and the number of scenes corresponding to the third scenes.

[0164] The second training data acquisition submodule is used to acquire a target description text sample set corresponding to each second scene according to the preset scene and description vector sample corresponding to each description text sample.

[0165] The second model training submodule is used to train the initial vector conversion model according to the target description text sample set corresponding to each second scene and the description vector sample corresponding to each description text sample, so as to obtain the target vector conversion model corresponding to each second scene.

[0166] The data updating submodule is used to update the preset sampling ratio corresponding to each third scene if the number of scenes is greater than 0 and determine the updated preset sampling ratio as the target sampling ratio, determine each third scene as the initial scene, update N=N+1, and repeatedly execute the first training data acquisition submodule until the updated number of scenes is equal to 0, and obtain the target vector conversion model corresponding to each preset scene.

[0167] In a specific implementation, the preset sampling ratio corresponding to each preset scene includes a training sample sampling ratio and a verification sample sampling ratio, and the first training data acquisition submodule includes:

[0168] The training sample acquisition unit is used to sample a number of description text samples as training samples from all description text samples corresponding to the current initial scene according to the training sample sampling ratio corresponding to the current initial scene for any initial scene, and obtain the Nth number of description text samples corresponding to the current initial scene as training samples.

[0169] The verification sample acquisition unit is used to sample a number of description text samples as verification samples from all description text samples corresponding to the current initial scene according to the verification sample sampling ratio corresponding to the current initial scene.

[0170] The scene traversal unit is used to traverse all the initial scenes and obtain a number of description text samples corresponding to each initial scene as training samples and a number of description text samples as verification samples.

[0171] The training sample set determination unit is used to determine a set of several description text samples corresponding to all initial scenes as training samples as the Nth description text training sample set.

[0172] The verification sample set determination unit is used to determine a set of several description text samples corresponding to all initial scenes as verification samples as the Nth description text verification sample set.

[0173] In a specific implementation, the adaptation degree acquisition submodule includes:

[0174] The data normalization unit is used to normalize the Nth quantity corresponding to each initial scene, and obtain the normalized Nth quantity corresponding to each initial scene.

[0175] The adaptation degree acquisition unit is used to input the normalized Nth number and Nth accuracy corresponding to each initial scene into a preset adaptation degree calculation model, and obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model, wherein the Nth adaptation degree is inversely proportional to the corresponding normalized Nth number, and the Nth adaptation degree is directly proportional to the corresponding Nth accuracy.

[0176] In a specific implementation, the preset degree threshold includes a first degree threshold and a second degree threshold, and the adaptation result acquisition submodule includes:

[0177] The first adaptation result obtaining unit is used to determine that the adaptation result corresponding to the current initial scene is not suitable if the Nth adaptation degree corresponding to the current initial scene is less than or equal to the first degree threshold.

[0178] The second adaptation result obtaining unit is configured to determine that the adaptation result corresponding to the current initial scene is not adapted if the Nth adaptation degree corresponding to the current initial scene is greater than or equal to a second degree threshold.

[0179] The third adaptation result obtaining unit is used to determine that the adaptation result corresponding to the current initial scene is to be determined if the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold.

[0180] In a specific implementation, the data acquisition module 21 further includes:

[0181] The first data acquisition submodule is used to acquire a plurality of preset tables, a preset description text and a preset scene corresponding to each preset table.

[0182] The description vector acquisition submodule is used to acquire the description vector corresponding to each preset table according to the target vector conversion model corresponding to the preset scene corresponding to the preset description text corresponding to each preset table.

[0183] The sentence vector acquisition submodule is used to convert the model according to the target vector corresponding to the target scene corresponding to the initial sentence, and obtain the sentence vector corresponding to the initial sentence.

[0184] The target matching degree acquisition submodule is used to acquire the target matching degree between the initial sentence and each preset table according to the description vector corresponding to each preset table and the sentence vector corresponding to the initial sentence.

[0185] The target table acquisition submodule is used to filter out the target table corresponding to the initial statement from all preset tables according to the target matching degree between the initial statement and each preset table.

[0186] In a specific implementation, the data acquisition module 21 further includes:

[0187] The second data acquisition submodule is used to obtain the historical input database and the preset keyword configuration table corresponding to the target scenario, wherein the historical input database includes a number of historical statements, a historical statement vector corresponding to each historical statement, and a historical SQL statement, and the preset keyword configuration table includes a number of custom keywords and a regular expression corresponding to each custom keyword.

[0188] The keyword extraction submodule is used to extract keywords from the initial sentence and obtain several target keywords corresponding to the initial sentence.

[0189] The matching result acquisition submodule is used to match each target keyword with the preset keyword configuration table to obtain the matching result corresponding to each target keyword, wherein the matching result includes a set consisting of the corresponding custom keyword and the corresponding regular expression.

[0190] The target regular expression acquisition submodule is used to obtain several target regular expressions corresponding to the initial sentence according to the matching results of all target keywords.

[0191] The sentence vector acquisition submodule is used to convert the model according to the target vector corresponding to the target scene corresponding to the initial sentence, and obtain the sentence vector corresponding to the initial sentence.

[0192] The similarity acquisition submodule is used to obtain the similarity between the initial sentence and each historical sentence based on the sentence vector and the historical sentence vector corresponding to each historical sentence.

[0193] The sentence screening submodule is used to screen out several reference sentences corresponding to the initial sentence from all the historical sentences based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold.

[0194] The initial SQL statement acquisition submodule is used to input the statement vector, the target table, several target regular expressions corresponding to the initial statement, several reference statements corresponding to the initial statement, and the historical SQL statements corresponding to each reference statement into the preset large language model to obtain the initial SQL statement corresponding to the initial statement.

[0195] In a specific implementation, the preset quantity threshold range includes a first quantity threshold and a second quantity threshold, and the field name screening module 23 further includes:

[0196] The quantity distribution acquisition submodule is used to obtain the quantity distribution of similar field names corresponding to all initial field names based on the quantity of similar field names corresponding to each initial field name.

[0197] The first quantity threshold acquisition submodule is used to determine the first quartile corresponding to the quantity distribution of similar field names as the first quantity threshold.

[0198] The second quantity threshold acquisition submodule is used to determine the third quartile corresponding to the quantity distribution of similar field names as the second quantity threshold.

[0199] The reference field name acquisition submodule is used to determine, for any initial field name, the current initial field name as a reference field name if the number of similar field names corresponding to the current initial field name is greater than or equal to a first quantity threshold and less than or equal to a second quantity threshold.

[0200] It should be noted that the information interaction, execution process and other contents between the above modules are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0201] Embodiment 3

[0202] Embodiment 3 of the present invention provides a non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the non-transitory computer-readable storage medium, and the at least one instruction or at least one program is loaded and executed by a processor to implement the steps:

[0203] S100, obtaining an initial statement input by a target user, a target scenario corresponding to the initial statement, a target table and an initial SQL statement, several initial field names corresponding to the target table, and a target vector conversion model corresponding to the target scenario.

[0204] S200: Input each initial field name into a preset large language model, and obtain a number of similar field names and the number of similar field names corresponding to each initial field name.

[0205] S300: determining initial field names whose corresponding similar field names are within a preset number threshold as reference field names, and determining each similar field name corresponding to each reference field name as an intermediate field name.

[0206] S400: extract keywords from the initial SQL statement to obtain a number of reference keywords corresponding to the initial SQL statement.

[0207] S500: Convert each reference keyword and each intermediate field name according to a target vector conversion model to obtain a reference vector corresponding to each reference keyword and an intermediate vector corresponding to each intermediate field name.

[0208] S600, for any reference keyword, obtain the similarity between the current reference keyword and each intermediate field name based on the current reference keyword, the reference vector corresponding to the current reference keyword, each intermediate field name and the intermediate vector corresponding to each intermediate field name.

[0209] S700: Acquire a target field name corresponding to the current reference keyword according to the similarity between the current reference keyword and each intermediate field name.

[0210] S800, using the target field name corresponding to each reference keyword to replace the corresponding reference keyword in the initial SQL statement, and obtaining the target SQL statement corresponding to the initial statement.

[0211] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing related hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronization link DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0212] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0213] Embodiment 4

[0214] A fourth embodiment of the present invention provides an electronic device, which includes a processor and the non-transitory computer-readable storage medium in the third embodiment of the present invention.

[0215] The above are only preferred embodiments of the present invention, and are not intended to limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment as above, it is not intended to limit the present invention. Any technician familiar with the profession can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present invention. However, any simple modification, equivalent change and modification made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention still fall within the scope of the technical solution of the present invention.

Claims

1. A method for obtaining SQL statements, characterized in that: The SQL statement acquisition method comprises the following steps: S100, acquiring an initial statement input by a target user, a target scenario corresponding to the initial statement, a target table and an initial SQL statement, a plurality of initial field names corresponding to the target table, and a target vector conversion model corresponding to the target scenario; S200, inputting each initial field name into a preset large language model, and obtaining a number of similar field names and the number of similar field names corresponding to each initial field name; S300, determining the initial field names whose corresponding similar field names are within a preset number threshold as reference field names, and determining each similar field name corresponding to each reference field name as an intermediate field name; S400, extracting keywords from the initial SQL statement to obtain a number of reference keywords corresponding to the initial SQL statement; S500, converting each reference keyword and each intermediate field name according to the target vector conversion model to obtain a reference vector corresponding to each reference keyword and an intermediate vector corresponding to each intermediate field name; S600, for any reference keyword, according to the current reference keyword, the reference vector corresponding to the current reference keyword, each intermediate field name and the intermediate vector corresponding to each intermediate field name, obtain the similarity between the current reference keyword and each intermediate field name; S700, obtaining a target field name corresponding to the current reference keyword according to the similarity between the current reference keyword and each intermediate field name; S800, using the target field name corresponding to each reference keyword to replace the corresponding reference keyword in the initial SQL statement, and obtaining the target SQL statement corresponding to the initial statement.

2. The SQL statement acquisition method according to claim 1, characterized in that: S100 includes the following steps: S101, obtaining an initial vector conversion model, description text samples corresponding to a plurality of preset tables, preset scenes and description vector samples corresponding to each description text sample, and a preset sampling ratio corresponding to each preset scene; S102, determining a preset sampling ratio as a target sampling ratio, determining each preset scene as an initial scene, and initializing the number of repetitions N=1; S103, sampling from the plurality of description text samples according to a target sampling ratio corresponding to each initial scene, to obtain an Nth description text training sample set, an Nth description text verification sample set, and an Nth number of description text samples corresponding to each initial scene in the Nth description text training sample set; S104, training the initial vector conversion model according to the Nth description text training sample set, the Nth description text verification sample set, and the description vector sample corresponding to each description text sample, and obtaining the Nth vector conversion model and the Nth accuracy rate of each initial scene in the Nth vector conversion model; S105, obtaining an Nth degree of adaptation between each initial scene and the Nth vector conversion model according to the Nth number and the Nth accuracy rate corresponding to each initial scene; S106, for any initial scene, determining an adaptation result corresponding to the current initial scene according to a comparison result of the Nth adaptation degree corresponding to the current initial scene with a preset degree threshold, wherein the adaptation result includes adaptation, non-adaptation and pending; S107, if the adaptation result corresponding to the current initial scene is adaptation, the current initial scene is determined as the first scene, and the Nth vector conversion model is determined as the target vector conversion model corresponding to the current first scene; S108, if the adaptation result corresponding to the current initial scene is not suitable, the current initial scene is determined as the second scene; S109, if the adaptation result corresponding to the current initial scene is to be determined, the current initial scene is determined as the third scene; S110, traversing all initial scenes, obtaining all first scenes and a target vector conversion model corresponding to each first scene, all second scenes, all third scenes, and the number of scenes corresponding to the third scenes; S111, acquiring a target description text sample set corresponding to each second scene according to the preset scene and the description vector sample corresponding to each description text sample; S113, training the initial vector conversion model according to the target description text sample set corresponding to each second scene and the description vector sample corresponding to each description text sample, to obtain a target vector conversion model corresponding to each second scene; S114, if the number of scenes is greater than 0, then updating the preset sampling ratio corresponding to each third scene and determining the updated preset sampling ratio as the target sampling ratio, determining each third scene as the initial scene, updating N=N+1, and repeating step S103 until the updated number of scenes is equal to 0, and obtaining the target vector conversion model corresponding to each preset scene; S115, acquiring a target vector conversion model corresponding to the target scene according to the target vector conversion model corresponding to each preset scene.

3. The SQL statement acquisition method according to claim 2, characterized in that: The preset sampling ratio corresponding to each preset scene includes a training sample sampling ratio and a verification sample sampling ratio. S103 includes the following steps: S1031, for any initial scene, according to the sampling ratio of training samples corresponding to the current initial scene, a number of description text samples are sampled from all description text samples corresponding to the current initial scene as training samples, and the Nth number of description text samples corresponding to the current initial scene as training samples is obtained; S1032, according to the sampling ratio of the verification samples corresponding to the current initial scene, sampling from all the description text samples corresponding to the current initial scene to obtain a plurality of description text samples as verification samples; S1033, traversing all initial scenes, obtaining a number of description text samples as training samples and a number of description text samples as verification samples corresponding to each initial scene; S1034, determining a set of a plurality of description text samples corresponding to all initial scenes as training samples as an Nth description text training sample set; S1035: Determine a set of several description text samples corresponding to all initial scenes as verification samples as the Nth description text verification sample set.

4. The SQL statement acquisition method according to claim 2, characterized in that: S105 includes the following steps: S1051, normalizing the Nth number corresponding to each initial scene to obtain the normalized Nth number corresponding to each initial scene; S1052, inputting the normalized Nth number and Nth accuracy corresponding to each initial scene into a preset adaptation degree calculation model to obtain the Nth adaptation degree of each initial scene and the Nth vector conversion model.

5. The SQL statement acquisition method according to claim 2, characterized in that: The preset degree threshold includes a first degree threshold and a second degree threshold, and S106 includes the following steps: S1061, if the Nth adaptation degree corresponding to the current initial scene is less than or equal to the first degree threshold, determining that the adaptation result corresponding to the current initial scene is unmatched; S1062: If the Nth adaptation degree corresponding to the current initial scene is greater than or equal to the second degree threshold, determining that the adaptation result corresponding to the current initial scene is not suitable; S1063: If the Nth adaptation degree corresponding to the current initial scene is less than the second degree threshold and greater than the first degree threshold, it is determined that the adaptation result corresponding to the current initial scene is to be determined.

6. The SQL statement acquisition method according to claim 2, characterized in that: S100 also includes the following steps: S1, obtaining a number of preset tables, a preset description text and a preset scene corresponding to each preset table; S2, acquiring a description vector corresponding to each preset table according to a target vector conversion model corresponding to a preset scene corresponding to a preset description text corresponding to each preset table; S3, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence; S4, obtaining a target matching degree between the initial sentence and each preset table according to the description vector corresponding to each preset table and the sentence vector corresponding to the initial sentence; S5, according to the target matching degree between the initial statement and each preset table, filter out the target table corresponding to the initial statement from all the preset tables.

7. The SQL statement acquisition method according to claim 3, characterized in that: S100 also includes the following steps: S10, obtaining a history input database and a preset keyword configuration table corresponding to the target scenario, wherein the history input database includes a plurality of history sentences, a history sentence vector corresponding to each history sentence, and a history SQL statement, and the preset keyword configuration table includes a plurality of custom keywords and a regular expression corresponding to each custom keyword; S20, extracting keywords from the initial sentence to obtain a number of target keywords corresponding to the initial sentence; S30, matching each target keyword with the preset keyword configuration table to obtain a matching result corresponding to each target keyword, wherein the matching result includes a set consisting of a corresponding custom keyword and a corresponding regular expression; S40, obtaining a plurality of target regular expressions corresponding to the initial sentence according to the matching results of all target keywords; S50, acquiring a sentence vector corresponding to the initial sentence according to a target vector conversion model corresponding to a target scene corresponding to the initial sentence; S60, obtaining the similarity between the initial sentence and each historical sentence according to the sentence vector and the historical sentence vector corresponding to each historical sentence; S70, based on the comparison between the similarity between the initial sentence and each historical sentence and a preset similarity threshold, screening out a plurality of reference sentences corresponding to the initial sentence from all historical sentences; S80, input the sentence vector, the target table, several target regular expressions corresponding to the initial sentence, several reference sentences corresponding to the initial sentence, and historical SQL statements corresponding to each reference sentence into the preset large language model to obtain an initial SQL statement corresponding to the initial sentence.

8. The SQL statement acquisition method according to claim 1, characterized in that: The preset quantity threshold range includes a first quantity threshold and a second quantity threshold, and S300 further includes the following steps: S310, obtaining the number distribution of similar field names corresponding to all initial field names according to the number of similar field names corresponding to each initial field name; S320, determining the first quartile corresponding to the quantity distribution of similar field names as a first quantity threshold; S330, determining the third quartile corresponding to the quantity distribution of similar field names as a second quantity threshold; S340: For any initial field name, if the number of similar field names corresponding to the current initial field name is greater than or equal to the first number threshold and less than or equal to the second number threshold, the current initial field name is determined as a reference field name.

9. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the non-transitory computer-readable storage medium, characterized in that: The at least one instruction or the at least one program is loaded and executed by the processor to implement the SQL statement acquisition method as described in any one of claims 1-8.

10. An electronic device, characterized in that: The invention comprises a processor and the non-transitory computer-readable storage medium as claimed in claim 9.

Citation Information

Patent Citations

  • Data processing system for acquiring target task data set

    CN116561390A

  • SQL (Structured Query Language) statement generation method and device based on large language model

    CN119127922A

  • Method and system for building a report for execution against a data store

    US20050039033A1

  • Displaying results of keyword search over enterprise data

    US8484208B1

Cited By

  • Text-based SQL (Structured Query Language) statement acquisition method and equipment and medium

    CN121070962A