The invention discloses a method for generating statements from natural languages to
SQL (Structured
Query Language) based on a large
language model agent. The method comprises the following steps of: constructing an LLM (Logical
Language Model) guide table mode index for a
target database; obtaining a user
natural language question and extracting a keyword; searching in an LLM guidance table mode index according to the keyword, and screening related data tables; splicing the table mode information and the keywords of the related data table into a user
natural language problem, and constructing an enhanced cue word; based on the large
language model intelligent agent, generating
SQL statements according to the enhanced cue words and verifying the
SQL statements, if the SQL statements succeed in
verification, obtaining the required SQL statements, and if the SQL statements fail in
verification, performing iterative closed-loop correction on the generated SQL statements through an SQL statement closed-loop correction
workflow; if the corrected SQL statement is successfully verified, the required SQL statement is obtained, and if the corrected SQL statement fails and the number of times of correction reaches a threshold value, the suggestions that the
natural language problem of the user has defects and is modified are output. According to the method, the accuracy and success rate of SQL statement generation can be improved.