The invention discloses a method and a device for converting a
natural language into an
SQL (Structured
Query Language) statement based on a
large model. The method comprises the following steps: S1, performing
data governance on an
original data table; s2, constructing indexes for all the values in the
database, selecting correlation values from the
database based on the user problems, calculating the matching degree between the user problems and the correlation values based on a longest common
substring matching
algorithm, and selecting the correlation value with the highest matching degree; s3,
rewriting the problem of the user; s4, performing word segmentation matching on the user question; s5, storing the accumulated seed question and answer statements into a vector
database, performing weight assignment on different keywords in the user question, matching the user question with the accumulated seed question and answer statements, and selecting
SQL question and answer statements; and S6, optimizing the DDL statement to construct a Prompt statement, and calling the
large model to generate an
SQL statement. According to the method, the quality of the SQL statements generated by the
large model is greatly improved, and the flexibility of querying the statements by the user and the accuracy of generating the SQL statements are greatly improved.