SQL (Structured Query Language) conversion method, system and equipment based on large model and storage medium
By identifying and mapping SQL skeleton components in the user's natural language to Python action functions, and combining detection tools for iterative correction, accurate SQL query statements are generated, solving the problem of low conversion accuracy in existing technologies and achieving higher generation accuracy and security.
Patent Information
- Application Number
- CN202511248021.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-02
- Publication Date
- 2026-01-06
AI Technical Summary
Existing technologies have unsatisfactory conversion accuracy when using large models to transform SQL query statements, and it is difficult to effectively verify and correct errors in the statements, resulting in low generation accuracy.
By identifying the SQL skeleton components in the user's natural language and mapping them to the corresponding Python action functions, detection tools are used for detection and correction. The process is iterated until there are no errors, and the final Python action sequence is generated and concatenated into an SQL query statement.
It improves the accuracy and security of SQL conversion, avoids potential damage to the database from unverified SQL queries, supports multiple tool calls and extensions, and adapts to different SQL query needs.
Smart Images

Figure CN121277962A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of large model technology, and in particular relates to a SQL conversion method, system, device and storage medium based on large models. Background Technology
[0002] With the rapid development of natural language processing technology, existing technologies use large language models (LLMs) to convert natural language text into structured query language (SQL) statements, enabling non-professional users to interact with databases and thus more conveniently obtain and analyze massive database data.
[0003] In existing technologies, the generated SQL query statement is typically executed in a real database management system (DBMS), and the execution results and feedback information returned by the system (such as execution status, error codes, error descriptions, query result sets, etc.) are obtained as important criteria for judging the executability of the SQL query statement. When the system feedback indicates that the SQL query statement has syntax parsing errors, semantic invalidity, or execution failure, or although the statement is executable but returns an empty result (which may mean logical errors or inaccurate query conditions), this feedback information is extracted in a structured manner and sent back to the Large Language Model (LLM). Based on this contextual information, the system further guides the LLM to analyze and correct the original SQL query statement, such as fixing syntax errors, adjusting table join logic, optimizing query conditions, or correcting field references, thereby achieving automatic iterative optimization and secondary generation of the SQL query statement.
[0004] The existing technology has the following technical problems: 1. Existing methods apply simple techniques to the task of converting natural language into SQL query statements for large models, but the conversion accuracy is not ideal.
[0005] 2. Existing technologies struggle to effectively verify and correct errors in SQL queries when using large models to transform them, resulting in low accuracy in SQL transformation generation. Summary of the Invention
[0006] This invention provides a method, system, device, and storage medium for SQL conversion based on a large model. It aims to solve the technical problems in the prior art, such as the fact that applying simple techniques to large models to convert natural language into SQL query statements results in unsatisfactory conversion accuracy, and that it is difficult to effectively verify and correct errors in SQL query statements when using large models to convert SQL query statements, thus causing low accuracy in SQL conversion generation.
[0007] The technical solution of this invention to solve the above-mentioned technical problems is as follows: A SQL transformation method based on a large model, the method comprising: The user's natural language is captured and parsed to obtain parsed data; Based on the parsing results, SQL skeleton components in the user's natural language are identified, and the SQL skeleton components are mapped to corresponding Python action functions to obtain an initial Python action sequence; wherein, the Python action function corresponding to each SQL skeleton component is predefined; Use detection tools to examine the initial Python action sequence to determine if any error messages are present: If an error message is found, the error message and the corresponding initial Python action sequence are fed back to the large model. The large model corrects the initial Python action sequence based on the error message, calls the detection tool again to detect the corrected initial Python action sequence, and repeats this step until the corrected initial Python action sequence is successfully detected, or the number of iterations reaches the maximum number, and outputs the final Python action sequence. If no error message is found, define the initial Python action sequence as the final Python action sequence and output it. The execution mode of the final Python action sequence output is switched to obtain the switched Python action sequence; Execute the switching Python action sequence, collect the SQL clause fragments returned by each Python action function, and concatenate all the SQL clause fragments into a string to obtain the SQL query statement.
[0008] Furthermore, the SQL skeleton components mentioned above include: "SELECT", "FROM", "JOIN", "WHERE", "GROUPBY", "HAVING", "ORDER BY", "INTERSECT", "UNION", and "EXCEPT". The Python action function corresponding to "SELECT" is "add_select", the Python action function corresponding to "FROM" is "add_from", the Python action function corresponding to "JOIN" is "add_join", the Python action function corresponding to "WHERE" is "add_where", the Python action function corresponding to "GROUPBY" is "add_groupby", the Python action function corresponding to "HAVING" is "add_having", the Python action function corresponding to "ORDER BY" is "add_orderby", and the Python action function corresponding to "INTERSECT", "UNION", "EXCEPT", and "SELECT" is "add_merge".
[0009] Furthermore, the initial Python action sequence obtained above specifically includes: Each SQL skeleton component is processed sequentially using a large model, and mapped to the corresponding Python action function to form a corresponding Python action subsequence; When a SQL skeleton component contains a nested structure, a QA action is generated, where the sub-questions in the QA action are encapsulated in natural language; The large model is recursively called to process the sub-problems encapsulated in each QA action, thereby obtaining the corresponding Python action sub-sequence, and the Python action sub-sequence is substituted into the original position; By integrating all the Python action subsequences, we obtain the initial Python action sequence.
[0010] Furthermore, the aforementioned detection of the initial Python action sequence using detection tools specifically includes: The initial Python action is then sent to the Python interpreter for execution. When each Python action function is executed, a predefined detection tool is automatically invoked to monitor the semantic and structural legality of the Python action function.
[0011] Furthermore, the aforementioned detection tools include database retrieval tools. Specifically, using database retrieval tools to detect the initial Python action sequence includes: Extract field names and query values from the parameters of a Python action function; The database connection interface is used to obtain the set of actual values corresponding to the field names; The query value is matched with the set of actual values to determine whether a match is successful. If the match is successful, there will be no error message. If the match fails, a corresponding error message will be generated.
[0012] Furthermore, the aforementioned detection tool includes a strict constraint testing tool, and the specific steps for detecting the initial Python action sequence using the strict constraint testing tool include: Capture the parameter information of the initial Python action sequence and obtain metadata based on the parameter information; wherein, the metadata includes: field names of the data table, data types, primary key and foreign key relationships, and constraints; Based on metadata, perform multi-dimensional monitoring, including: Perform a data type compatibility check; Perform a validity check on the relationship between primary keys and foreign keys; Check the integrity of the SQL syntax structure; Check the keywords and semantic integrity; If any item fails to be detected, a corresponding error response will be generated.
[0013] Furthermore, the execution mode of the final Python action sequence output above is switched to obtain the switching Python action sequence, which specifically includes: Switch the code logic of each Python action function from "validation mode" to "SQL concatenation mode".
[0014] Secondly, in order to solve the above-mentioned technical problems, the present invention also provides a SQL conversion system based on a large model, comprising: The data acquisition module is used to acquire and parse the user's natural language to obtain parsed data; The Python action sequence generation module is used to identify SQL skeleton components in the user's natural language based on the parsing results, and map the SQL skeleton components to the corresponding Python action functions to obtain an initial Python action sequence; wherein, the Python action function corresponding to each SQL skeleton component is predefined; The iterative repair module is used to detect the initial Python action sequence using detection tools to determine if there are any error messages. If an error message is found, the error message and the corresponding initial Python action sequence are fed back to the large model. The large model corrects the initial Python action sequence based on the error message, calls the detection tool again to detect the corrected initial Python action sequence, and repeats this step until the corrected initial Python action sequence is successfully detected, or the number of iterations reaches the maximum number, and outputs the final Python action sequence. If no error message is found, define the initial Python action sequence as the final Python action sequence and output it. The mode switching module is used to switch the execution mode of the output final Python action sequence to obtain a switched Python action sequence; The SQL query statement generation module is used to execute the switching Python action sequence, collect the SQL clause fragments returned by each Python action function, and concatenate all the SQL clause fragments into strings to obtain the SQL query statement.
[0015] Thirdly, in order to solve the above-mentioned technical problems, the present invention also provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the SQL conversion method based on a large model of the present application.
[0016] Fourthly, in order to solve the above-mentioned technical problems, the present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the SQL conversion method based on a large model of the present application.
[0017] Compared with the prior art, the present invention has the following advantages: 1. This invention facilitates tool invocation by defining a set of Python action sequences for the SQL skeleton, enabling convenient invocation of validation tools to examine different syntactic components of SQL query statements. Furthermore, it supports the extension of the Python action sequences to adapt to new SQL languages or SQL operations.
[0018] 2. This invention facilitates tool expansion. By modularly modifying the function bodies in Python action sequences, it enables the rapid writing and embedding of relevant verification code based on the specific SQL query verification requirements of a domain, thereby supporting more tools.
[0019] 3. This invention offers enhanced security, eliminating the need to execute the converted SQL query statements within the database and preventing damage to the database schema or data caused by unverified SQL query statements.
[0020] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures pointed out in the description, claims and drawings. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 A flowchart illustrating a large-model-based SQL transformation method according to an embodiment of the present invention is shown. Figure 2 A schematic diagram of a Python action function according to an embodiment of the present invention is shown; Figure 3 A schematic diagram of the structure of a large-model-based SQL conversion system according to an embodiment of the present invention is shown; Figure 4 A schematic diagram of an electronic device structure according to an embodiment of the present invention is shown. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0024] Figure 1 A flowchart illustrating a large-model-based SQL transformation method according to an embodiment of the present invention is shown, such as... Figure 1 As shown, an embodiment of the present invention provides a SQL transformation method based on a large model, comprising: The user's natural language is captured and parsed to obtain parsed data; Based on the parsing results, SQL skeleton components in the user's natural language are identified, and the SQL skeleton components are mapped to corresponding Python action functions to obtain an initial Python action sequence; wherein, the Python action function corresponding to each SQL skeleton component is predefined; Use detection tools to examine the initial Python action sequence to determine if any error messages are present: If an error message is found, the error message and the corresponding initial Python action sequence are fed back to the large model. The large model corrects the initial Python action sequence based on the error message, calls the detection tool again to detect the corrected initial Python action sequence, and repeats this step until the corrected initial Python action sequence is successfully detected, or the number of iterations reaches the maximum number, and outputs the final Python action sequence. If no error message is found, define the initial Python action sequence as the final Python action sequence and output it. The execution mode of the final Python action sequence output is switched to obtain the switched Python action sequence; Execute the switching Python action sequence, collect the SQL clause fragments returned by each Python action function, and concatenate all the SQL clause fragments into a string to obtain the SQL query statement.
[0025] Optionally, the SQL skeleton components include: "SELECT", "FROM", "JOIN", "WHERE", "GROUP BY", "HAVING", "ORDER BY", "INTERSECT", "UNION", and "EXCEPT". The Python action function corresponding to "SELECT" is "add_select", the Python action function corresponding to "FROM" is "add_from", the Python action function corresponding to "JOIN" is "add_join", the Python action function corresponding to "WHERE" is "add_where", the Python action function corresponding to "GROUP BY" is "add_groupby", the Python action function corresponding to "HAVING" is "add_having", the Python action function corresponding to "ORDER BY" is "add_orderby", and the Python action function corresponding to "INTERSECT", "UNION", "EXCEPT", and "SELECT" is "add_merge".
[0026] In this embodiment, as Figure 2 As shown, Figure 2 The above is a schematic diagram of the Python action functions corresponding to the SQL skeleton components. At the same time, functions such as "MAX" and "AVG" will also appear as parameters of the above action sequence, ensuring the universality of the Python action sequence definition.
[0027] In this embodiment, the Python action functions can be extended according to common needs in practical applications, thereby enabling the handling of uncommon SQL skeleton components and new SQL query languages. By designing Python function actions corresponding to the SQL skeleton components, the large model agent can focus on directly generating Python action sequences representing SQL query statements. The process of generating Python action sequences includes all the information required for the final SQL query statement, while also enabling the large model to more easily invoke relevant tools.
[0028] Optionally, obtaining the initial Python action sequence specifically includes: Each SQL skeleton component is processed sequentially using a large model, and mapped to the corresponding Python action function to form a corresponding Python action subsequence; When a SQL skeleton component contains a nested structure, a QA action is generated, where the sub-questions in the QA action are encapsulated in natural language; The large model is recursively called to process the sub-problems encapsulated in each QA action, thereby obtaining the corresponding Python action sub-sequence, and the Python action sub-sequence is substituted into the original position; By integrating all the Python action subsequences, we obtain the initial Python action sequence.
[0029] In this embodiment, a "QA" action is defined to isolate potential nesting within the SQL skeleton. For example, the SQL clause "WHERE a IN (SELECT a FROM …)" will be converted into the Python action "add_where(a,'IN',QA('sub-question…'))". The corresponding "QA" sub-questions will be solved separately by the large model agent. This Python action reduces the complexity of the user's natural language questions and improves the accuracy of the SQL conversion and generation process.
[0030] Optionally, using detection tools to detect the initial Python action sequence specifically includes: The initial Python action is then sent to the Python interpreter for execution. When each Python action function is executed, a predefined detection tool is automatically invoked to monitor the semantic and structural legality of the Python action function.
[0031] In this embodiment, if a tool detects a problem with the parameters of a Python action sequence, it will provide corresponding error feedback. For example, if it detects that the large model agent used a non-existent data table field in the parameters, it will provide feedback such as, "For add_where(a, b, c), a does not exist in the data table.", to inform the large model agent to make targeted fixes. Feedback will be provided for problematic Python action sequences simultaneously to improve the agent's repair efficiency. If any tool detects any error in any action within an action sequence, the large model agent will receive corresponding feedback. The large model agent will then regenerate a new Python action sequence based on the reference repair sample information, database schema information, all error feedback from the tool, the erroneous Python action sequence, and the user's natural language.
[0032] Optionally, the detection tool includes a database retrieval tool, and the detection of the initial Python action sequence using the database retrieval tool specifically includes: Extract field names and query values from the parameters of a Python action function; The database connection interface is used to obtain the set of actual values corresponding to the field names; The query value is matched with the set of actual values to determine whether a match is successful. If the match is successful, there will be no error message. If the match fails, a corresponding error message will be generated.
[0033] In this embodiment, the target data table to which the field name belongs is determined, and the actual content of the corresponding field name in the target data table is obtained, thereby determining whether the SQL query clause matches any entity in the database.
[0034] Optionally, the detection tool includes a strict constraint testing tool, and the detection of the initial Python action sequence using the strict constraint testing tool specifically includes: Capture the parameter information of the initial Python action sequence and obtain metadata based on the parameter information; wherein, the metadata includes: field names of the data table, data types, primary key and foreign key relationships, and constraints; Based on metadata, perform multi-dimensional monitoring, including: Perform a data type compatibility check; Perform a validity check on the relationship between primary keys and foreign keys; Check the integrity of the SQL syntax structure; Check the keywords and semantic integrity; If any item fails to be detected, a corresponding error response will be generated.
[0035] In this embodiment, the tool replaces the commonly used database management system-based execution feedback verification techniques in related technologies, avoiding direct interaction between the SQL generated by the large model and the database system. At the same time, the tool can be extended according to actual needs, such as verifying the handling of special data like "NULL" in SQL statements, and can quickly adapt to new verification logic by writing relevant code.
[0036] Optionally, the execution mode of the final Python action sequence output can be switched to obtain a switched Python action sequence, specifically including: Switch the code logic of each Python action function from "validation mode" to "SQL concatenation mode".
[0037] Based on and Figure 1 Using the same principle as the method shown, this embodiment of the invention also provides a SQL conversion system based on a large model, such as... Figure 3 As shown, it includes: The data acquisition module is used to acquire and parse the user's natural language to obtain parsed data; The Python action sequence generation module is used to identify SQL skeleton components in the user's natural language based on the parsing results, and map the SQL skeleton components to the corresponding Python action functions to obtain an initial Python action sequence; wherein, the Python action function corresponding to each SQL skeleton component is predefined; The iterative repair module is used to detect the initial Python action sequence using detection tools to determine if there are any error messages. If an error message is found, the error message and the corresponding initial Python action sequence are fed back to the large model. The large model corrects the initial Python action sequence based on the error message, calls the detection tool again to detect the corrected initial Python action sequence, and repeats this step until the corrected initial Python action sequence is successfully detected, or the number of iterations reaches the maximum number, and outputs the final Python action sequence. If no error message is found, define the initial Python action sequence as the final Python action sequence and output it. The mode switching module is used to switch the execution mode of the output final Python action sequence to obtain a switched Python action sequence; The SQL query statement generation module is used to execute the switching Python action sequence, collect the SQL clause fragments returned by each Python action function, and concatenate all the SQL clause fragments into strings to obtain the SQL query statement.
[0038] The SQL conversion system based on a large model in this embodiment can execute the SQL conversion method based on a large model provided in this embodiment. The implementation principles are similar. The actions performed by each module and unit in the SQL conversion system based on a large model in each embodiment of this invention correspond to the steps in the SQL conversion method based on a large model in each embodiment of this invention. For detailed functional descriptions of each module in the SQL conversion system based on a large model, please refer to the descriptions in the corresponding SQL conversion methods based on large models shown above, which will not be repeated here.
[0039] The aforementioned SQL conversion system based on a large model can be a computer program (including program code) running on a computer device. For example, the SQL conversion system based on a large model is an application software. The application software can be used to execute the corresponding steps in the method provided in the embodiments of the present invention.
[0040] The modules described in the embodiments of the present invention can be implemented in software or hardware. The names of the modules are not, in some cases, limiting the scope of the module itself.
[0041] Based on the same principles as the methods shown in the embodiments of the present invention, the embodiments of the present invention also provide an electronic device, which may include, but is not limited to: a processor and a memory; the memory for storing computer programs; and the processor for executing the methods shown in any embodiment of the present invention by invoking the computer programs.
[0042] In one alternative embodiment, an electronic device is provided, such as Figure 4 As shown, Figure 4 The illustrated electronic device includes a processor and a memory. The processor and memory are connected, for example, via a bus. Optionally, the electronic device may also include a transceiver, which can be used for data interaction between the electronic device and other electronic devices, such as sending and / or receiving data. It should be noted that in practical applications, the transceiver is not limited to one unit, and the structure of this electronic device does not constitute a limitation on the embodiments of the present invention.
[0043] The memory stores application code (computer program) that executes the present invention, and its execution is controlled by a processor. The processor executes the application code stored in the memory to implement the content shown in the foregoing method embodiments.
[0044] Among these, electronic devices can also be terminal devices. Figure 4 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
[0045] This invention provides a computer-readable storage medium storing a computer program that, when run on a computer, enables the computer to execute the corresponding content in the aforementioned method embodiments.
[0046] According to another aspect of the present invention, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in the various embodiments described above.
[0047] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the method shown in the above embodiments.
[0048] The above description is merely a preferred embodiment of the present invention and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this invention is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this invention.
Claims
1. A large model-based SQL conversion method, characterized by, The method comprises: acquiring and parsing user natural language to obtain parsed data; based on the parsed results, identifying SQL skeleton components in the user natural language and mapping the SQL skeleton components to corresponding Python action functions to obtain an initial Python action sequence; wherein the Python action function corresponding to each SQL skeleton component is predefined; detecting the initial Python action sequence using a detection tool to determine whether there is error information: if there is error information, the error information and the corresponding initial Python action sequence are fed back to a large model, the large model corrects the initial Python action sequence based on the error information, the detection tool is called again to detect the corrected initial Python action sequence, and the step is repeated until the corrected initial Python action sequence is successfully detected, or the number of iterations reaches a maximum iteration number, and a final Python action sequence is output; if there is no error information, the initial Python action sequence is defined as the final Python action sequence and is output; switching the execution mode of the output final Python action sequence to obtain a switched Python action sequence; execute the switched Python action sequence, collect SQL clause fragments returned by each Python action function, and concatenate all the SQL clause fragments to obtain a SQL query statement.
2. The large model-based SQL conversion method of claim 1, wherein, The SQL skeleton components include "SELECT", "FROM", "JOIN", "WHERE", "GROUP BY", "HAVING", "ORDER BY", "INTERSECT", "UNION", and "EXCEPT", the Python action function corresponding to "SELECT" is "add_select", the Python action function corresponding to "FROM" is "add_from", the Python action function corresponding to "JOIN" is "add_join", the Python action function corresponding to "WHERE" is "add_where", the Python action function corresponding to "GROUP BY" is "add_groupby", the Python action function corresponding to "HAVING" is "add_having", the Python action function corresponding to "ORDER BY" is "add_orderby", and the Python action function corresponding to "INTERSECT", "UNION", and "EXCEPT" is "add_merge".
3. The large model-based SQL conversion method of claim 1, wherein, The initial Python action sequence is obtained in particular as follows: using a large model to process each SQL skeleton component in turn, mapping it to a corresponding Python action function to form a corresponding Python action sub-sequence; When a certain SQL skeleton component contains a nested structure, a QA action is generated, in which the sub-questions in the QA action are encapsulated in natural language; The large model is recursively called to process the sub-questions encapsulated in each QA action to obtain a corresponding Python action sub-sequence, and the Python action sub-sequence is substituted into the original position; All Python action sub-sequences are integrated to obtain an initial Python action sequence.
4. The large model-based SQL conversion method of claim 1, wherein, Detecting the initial Python action sequence using a detection tool specifically includes: Executing the initial Python action in a Python interpreter; When executing each Python action function, a predefined detection tool is automatically called to monitor the legality of the semantics and structure of the Python action function.
5. The large model-based SQL conversion method of claim 4, wherein, The detection tool includes a database retrieval tool, and detecting the initial Python action sequence using the database retrieval tool specifically includes: Reading the field name and query value extracted from the parameters of the Python action function; Through a predefined database connection interface, an actual value set corresponding to the field name is obtained; Matching the query value with the actual value set to determine whether the matching is successful: If the matching is successful, there is no error information; If the matching is not successful, a corresponding error feedback is generated.
6. The large model-based SQL conversion method of claim 1, wherein, The detection tool includes a strict constraint verification tool, and detecting the initial Python action sequence using the strict constraint verification tool specifically includes: Capturing parameter information of the initial Python action sequence and obtaining metadata based on the parameter information; wherein the metadata includes: field name, data type, primary key and foreign key relationship, constraint condition of the data table; Based on the metadata, multi-dimensional monitoring is performed, including: Checking the compatibility of the data type; Checking the legality of the primary key and foreign key relationship; Checking the integrity of the SQL syntax structure; Checking the integrity of the keywords and semantics; If any one item fails the detection, a corresponding error reaction is generated.
7. The large model-based SQL conversion method of claim 1, wherein, Switching the execution mode of the final Python action sequence output to obtain a switched Python action sequence specifically includes: Switching the code logic of each Python action function from "verification mode" to "SQL splicing mode".
8. A large model-based SQL conversion system, characterized by, Including: A data acquisition module for acquiring and parsing user natural language to obtain parsed data; A Python action sequence generation module for mapping the SQL skeleton components in the user natural language to corresponding Python action functions based on the parsed results to obtain an initial Python action sequence; wherein the Python action function corresponding to each SQL skeleton component is predefined; An iterative repair module for detecting the initial Python action sequence using a detection tool to determine whether there is error information: If the error information exists, the error information and the corresponding initial Python action sequence are fed back to the large model, the large model corrects the initial Python action sequence based on the error information, the detection tool is called again to detect the corrected initial Python action sequence, and the step is looped until the corrected initial Python action sequence is successfully detected, or the number of loops reaches a maximum iteration number, and a final Python action sequence is output; If the error information does not exist, the initial Python action sequence is defined as the final Python action sequence and is output; A mode switching module is configured to switch the execution mode of the output final Python action sequence to obtain a switched Python action sequence; A SQL query statement generation module is configured to execute the switched Python action sequence, collect SQL clause fragments returned by each Python action function, concatenate all the SQL clause fragments to obtain a SQL query statement.
9. An electronic device, comprising: The computer program stored on the computer storage medium is executed by the processor to implement the method in any one of claims 1-7.
10. A computer storage medium, characterized in that, The computer program stored on the computer storage medium is executed by the processor to implement the method in any one of claims 1-7.
