Method and device for converting natural language into SQL (Structured Query Language)

By responding to database changes in real time through managed cloud platform services, the update cost in the natural language to SQL conversion method is reduced, and flexible database adaptation and efficient SQL generation are achieved.

CN120723801APending Publication Date: 2025-09-30INSPUR ENTERPRISE CLOUD TECHNOLOGY (SHANDONG) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510874158.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-27
Publication Date
2025-09-30

AI Technical Summary

Technical Problem

Existing natural language to SQL conversion methods require frequent model retraining when the database structure changes, resulting in high update costs.

Method used

Database information is stored through a hosted cloud platform service, and changes in the database are responded to in real time, eliminating the need to frequently retrain the model. SQL statements are generated using data preprocessing, key information extraction, and contextual information fusion.

Benefits of technology

It effectively reduces update costs and improves system flexibility and response speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120723801A_ABST
    Figure CN120723801A_ABST
Patent Text Reader

Abstract

The invention discloses a method and device for converting a natural language into an SQL (Structured Query Language), and the method comprises the steps: carrying out the data preprocessing of a to-be-converted natural language when the to-be-converted natural language is received, and obtaining the preprocessed to-be-converted natural language; extracting key information and entity information from the preprocessed to-be-converted natural language; data information, example data and access control information corresponding to the key information and the entity information are screened out from hosting cloud platform services through a hosting cloud platform service protocol; fusing the data information, the example data, the access control information and a preset structured query language (SQL) example to obtain context information; and generating an SQL statement based on the natural language to be converted and the context information. The hosting cloud platform service stores database information and can respond to changes in real time when the database changes. Therefore, the model does not need to be retrained frequently, and the updating cost is effectively reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of natural language processing technology, and in particular to a method and device for converting natural language to SQL. Background Art

[0002] With the widespread adoption of database applications, natural language processing (NLP) technology is becoming increasingly important in database query and management. By converting natural language into Structured Query Language (SQL), users can interact with databases more conveniently.

[0003] Existing natural language-to-SQL conversion methods typically train and model based on a fixed database structure. For example, training data is generated based on fixed structures such as database tables and fields. When the database structure changes, the original trained model may not recognize these changes. Because natural language-to-SQL models are typically trained on static data, changes in the database schema are not automatically reflected in the original training data. Therefore, every time the database changes, the model must be retrained using the updated database structure data, increasing update costs.

[0004] Therefore, how to reduce the update cost has become an urgent problem to be solved in this field. Summary of the Invention

[0005] The present application provides a natural language to SQL conversion method and device, the purpose of which is to reduce update costs.

[0006] In order to achieve the above objectives, this application provides the following technical solutions:

[0007] A natural language to SQL conversion method, comprising:

[0008] When receiving the natural language to be converted, performing data preprocessing on the natural language to be converted to obtain the preprocessed natural language to be converted;

[0009] Extracting key information and entity information from the preprocessed natural language to be converted;

[0010] Filtering data information, sample data, and access control information corresponding to the key information and the entity information from the hosted cloud platform service through the hosted cloud platform service agreement;

[0011] Merging the data information, the sample data, the access control information, and a preset structured query language SQL example to obtain context information;

[0012] Generate an SQL statement based on the natural language to be converted and the context information.

[0013] Optionally, performing data preprocessing on the natural language to be converted to obtain preprocessed natural language to be converted includes:

[0014] performing a cleaning process on the natural language to be converted to obtain a cleaned natural language to be converted;

[0015] performing standardization processing on the cleaned natural language to be converted to obtain standardized natural language to be converted;

[0016] The standardized natural language to be converted is subjected to text normalization processing to obtain the preprocessed natural language to be converted.

[0017] Optionally, before filtering out the data information, sample data, and access control information corresponding to the key information and the entity information from the hosted cloud platform service, the method further includes:

[0018] Create and parse the configuration file to obtain connection information;

[0019] connecting to a database according to the connection information;

[0020] When the database is successfully connected, extracting data information, sample data and access control information from the database;

[0021] The data information, the sample data, and the access control information are stored in a hosted cloud platform service.

[0022] Optionally, generating an SQL statement based on the natural language to be converted and the context information includes:

[0023] Inputting the natural language to be converted and the context information into a large language model to obtain an initial SQL statement;

[0024] Recognizing the natural language to be converted to obtain fuzzy information; the fuzzy information indicates unclear content in the natural language to be converted;

[0025] The initial SQL statement is adjusted according to the fuzzy information and the context information to obtain an SQL statement.

[0026] Optionally, also include:

[0027] Verify the SQL statement;

[0028] When the SQL statement passes verification, the SQL statement is executed in the target database to obtain the execution result;

[0029] When the execution result indicates that the SQL statement is successfully executed, feeding back the execution result;

[0030] When the execution result indicates that the SQL statement fails to execute, failure information is recorded.

[0031] A natural language to SQL conversion device, comprising:

[0032] a processing unit configured to, upon receiving a natural language to be converted, perform data preprocessing on the natural language to be converted to obtain preprocessed natural language to be converted;

[0033] An extraction unit, configured to extract key information and entity information from the preprocessed natural language to be converted;

[0034] a screening unit, configured to screen data information, sample data, and access control information corresponding to the key information and the entity information from the hosted cloud platform service through the hosted cloud platform service agreement;

[0035] a fusion unit, configured to fuse the data information, the sample data, the access control information, and a preset structured query language SQL example to obtain context information;

[0036] A generating unit is configured to generate an SQL statement based on the natural language to be converted and the context information.

[0037] Optionally, the processing unit is specifically configured to:

[0038] performing a cleaning process on the natural language to be converted to obtain a cleaned natural language to be converted;

[0039] performing standardization processing on the cleaned natural language to be converted to obtain standardized natural language to be converted;

[0040] The standardized natural language to be converted is subjected to text normalization processing to obtain the preprocessed natural language to be converted.

[0041] Optionally, also include:

[0042] Create a unit to create and parse the configuration file to obtain connection information;

[0043] a connection unit, configured to connect to a database according to the connection information;

[0044] An information extraction unit, configured to extract data information, sample data, and access control information from the database when the database connection is successful;

[0045] A storage unit is used to store the data information, the sample data and the access control information in a hosted cloud platform service.

[0046] Optionally, the generating unit is specifically configured to:

[0047] Inputting the natural language to be converted and the context information into a large language model to obtain an initial SQL statement;

[0048] Recognizing the natural language to be converted to obtain fuzzy information; the fuzzy information indicates unclear content in the natural language to be converted;

[0049] The initial SQL statement is adjusted according to the fuzzy information and the context information to obtain an SQL statement.

[0050] Optionally, also include:

[0051] A verification unit, configured to verify the SQL statement;

[0052] An execution unit, configured to execute the SQL statement in a target database to obtain an execution result after the SQL statement passes verification;

[0053] A first feedback unit, configured to feed back the execution result when the execution result indicates that the SQL statement is executed successfully;

[0054] The second feedback unit is configured to record failure information when the execution result indicates that the SQL statement execution fails.

[0055] The technical solution provided by this application performs data preprocessing on the natural language to be converted upon receiving it, obtaining preprocessed natural language to be converted; extracts key information and entity information from the preprocessed natural language to be converted; filters data information, sample data, and access control information corresponding to the key information and entity information from a hosted cloud platform service; fuses the data information, sample data, access control information, and preset structured query language (SQL) examples to obtain context information; and generates SQL statements based on the natural language to be converted and the context information. The hosted cloud platform service stores database information and can respond to changes in the database in real time. This eliminates the need for frequent model retraining, effectively reducing update costs. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0057] Figure 1 A flowchart of a natural language to SQL conversion method provided in an embodiment of the present application;

[0058] Figure 2 A flowchart of an information storage method provided in an embodiment of the present application;

[0059] Figure 3 A flowchart of a method for executing an SQL statement provided in an embodiment of the present application;

[0060] Figure 4 A schematic diagram of the architecture of a natural language to SQL conversion device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0061] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0062] In this application, the terms "comprises," "comprising," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not preclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.

[0063] like Figure 1 FIG. 1 is a flowchart of a natural language to SQL conversion method provided in an embodiment of the present application, comprising the following steps:

[0064] S101: When natural language to be converted is received, data preprocessing is performed on the natural language to be converted to obtain preprocessed natural language to be converted.

[0065] It is understandable that the purpose of data preprocessing for natural language is to convert the original text into a format that can be understood by the machine. By simplifying and standardizing the input, removing noise and inconsistencies, reducing computational complexity, and extracting key information, preprocessing can help the model better understand the text content.

[0066] Optionally, in another embodiment of the present application, the specific implementation method of performing data preprocessing on the natural language to be converted in step S101 to obtain the preprocessed natural language to be converted includes processes A1 to A3.

[0067] A1: Clean the natural language to be converted to obtain the cleaned natural language to be converted.

[0068] Among them, the natural language to be converted is cleaned to remove and filter out stop words that have no practical meaning, identify and delete redundant words that do not affect the semantics, and standardize irrelevant punctuation points, so as to obtain the cleaned natural language to be converted.

[0069] A2: Standardize the cleaned natural language to be converted to obtain standardized natural language to be converted.

[0070] The cleaned natural language to be converted is standardized, and a spelling correction algorithm is used to correct the spelling of the cleaned natural language to be converted to obtain a standardized natural language to be converted.

[0071] A3: Perform text normalization processing on the standardized natural language to be converted to obtain preprocessed natural language to be converted.

[0072] Among them, the standardized natural language to be converted is subjected to text normalization processing to clarify the subject-predicate-object structure of the query sentence, thereby obtaining the preprocessed natural language to be converted.

[0073] S102: Extract key information and entity information from the pre-processed natural language to be converted.

[0074] The entry information includes but is not limited to the data tables involved, field names, operation types (such as query, sorting, aggregation), and filtering conditions.

[0075] Optionally, entity information includes, but is not limited to, time intervals, geographic locations, and product names. This entity information can be used as filter conditions or aggregation fields in Structured Query Language (SQL).

[0076] It is understandable that by installing transformers, loading semantic-based models (such as BERT and RoBERTa) in transformers, and inputting the preprocessed natural language to be converted into the semantic-based model, key information can be obtained.

[0077] S103: Filtering data information, sample data, and access control information corresponding to the key information and entity information from the hosted cloud platform service through the hosted cloud platform service agreement.

[0078] Data information includes table names and table structure information. Table structure information includes at least field names, data types, and field comments. The meaning of each field can be understood through the field names, data types, and field comments.

[0079] Optionally, access control information includes but is not limited to: tenant ID, data access scope, and field-level permissions. Filter fields and data scopes based on access control information.

[0080] Optionally, before step S103, the data information, sample data and access control information need to be stored in the hosting cloud platform service first, so that the information corresponding to the natural language to be converted can be filtered out from the hosting cloud platform service later. Therefore, another embodiment of the present application provides an information storage method, such as Figure 2 As shown, the following steps are included:

[0081] S201: Create and parse a configuration file to obtain connection information.

[0082] The configuration file is database_connections.json, which includes but is not limited to: database type, connection string, and authentication information.

[0083] Among them, a configuration file is created in the configuration directory of the provider (ie, MCPProvider) of the Managed Cloud Platform service (MCP), the configuration file is parsed to obtain connection information, and the connection information is stored in the memory.

[0084] S202: Connect to the database according to the connection information.

[0085] The connection information includes at least the database type (such as MySQL, Oracle, PostgreSQL), user name, password, and authentication string. For example, the connection information is:

[0086] {

[0087] "connections": [

[0088] {

[0089] "name": "connection1",

[0090] "type": "postgresql",

[0091] "connection_string": "host=your_host port=5432 dbname=your_dbuser=your_user password=your_password"

[0092] },

[0093] {

[0094] "name": "connection2",

[0095] "type": "mysql",

[0096] "connection_string": "host=your_host port=3306 dbname=your_dbuser=your_user password=your_password"

[0097] } ]

[0099] }.

[0100] It can be understood that a database connection is established based on the connection information. For example, in Python, psycopg2 is used to connect to PostgreSQL.

[0101] S203: When the database connection is successful, extract data information, sample data and access control information from the database.

[0102] The data information is Schema metadata, which specifically includes information such as extracted table structure, field definition, and foreign key constraints.

[0103] Optionally, extract a certain amount of sample data from each table in the database, with different amounts selected for tables with different functions. For example, extract 10-50 sample data entries from the user table and more than 50 entries from the business table to cover all business scenarios. For the associated table, each master record corresponds to 1-5 child records, depending on the complexity of the relationships.

[0104] It should be noted that a permission configuration file (such as tenant_permission.json) is created first, and the permission information of each tenant is defined in the permission configuration file; the permission configuration file is loaded and parsed from the database to obtain the access control information.

[0105] S204: Storing the data information, sample data, and access control information in the hosted cloud platform service.

[0106] It is understandable that the data information is stored in the metadata storage of the hosted cloud platform service, the sample data is stored in the sample data storage of the hosted cloud platform service, and the access control information is stored in the permission storage of the hosted cloud platform service.

[0107] It should be noted that the managed cloud platform service supports dynamic access to different types of databases and can be expanded online to access heterogeneous data sources. At the same time, there is no need to train database information into large language models in advance.

[0108] In addition, the database's DDL event monitoring mechanism is used to monitor changes in the database structure and the message queue is used to monitor permission change events.

[0109] S104: The data information, sample data, access control information, and a preset structured query language SQL example are integrated to obtain context information.

[0110] Optionally, data information, sample data, access control information, and preset structured query language SQL samples may be integrated through a hosted cloud platform service.

[0111] Specifically, taking the following logical statement as an example, the fused logical statement is:

[0112] context = {

[0113] "table_structures": {

[0114] "orders": [

[0115] {"column_name": "order_id", "data_type": "integer", "column_comment": "Order ID"},

[0116] {"column_name": "amount", "data_type": "numeric", "column_comment": "Order Amount"},

[0117] {"column_name": "order_date", "data_type": "date", "column_comment": "Order Date"} ]

[0119] },

[0120] "column_comments": {

[0121] "orders": {

[0122] "order_id": "Order ID",

[0123] "amount": "Order amount",

[0124] "order_date": "Order Date"

[0125] }

[0126] },

[0127] "sample_data": {

[0128] "orders": [

[0129] {"order_id": 1, "amount": 1200, "order_date": "2024-01-15"},

[0130] {"order_id": 2, "amount": 800, "order_date": "2024-02-20"},

[0131] {"order_id": 3, "amount": 1500, "order_date": "2024-03-10"} ]

[0133] },

[0134] "access_control_info": {

[0135] "tenant_id": "tenant123", # Tenant ID

[0136] "allowed_columns": ["order_id", "amount", "order_date"], # Fields allowed to be accessed

[0137] "allowed_data_range": {"order_date": ["2024-01-01", "2024-12-31"]}, # Data access range

[0138] "field_level_permissions": { # Field-level permissions

[0139] "order_id": "read",

[0140] "amount": "read",

[0141] "order_date": "read"

[0142] }

[0143] }

[0144] }.

[0145] S105: Generate an SQL statement based on the natural language to be converted and the context information.

[0146] It is understood that based on the natural language to be converted and the context information, an SQL statement that conforms to the target database syntax is generated. For example, for a PostgreSQL database, the generated SQL statement will follow the query syntax rules of PostgreSQL.

[0147] Optionally, in another embodiment of the present application, the specific implementation of step S105 includes process B1 to process B3.

[0148] B1: Input the natural language to be converted and context information into the large language model to obtain the initial SQL statement.

[0149] It is understandable that the big language model will combine contextual information and use the big language model to convert natural language queries into query statements that conform to SQL syntax, and ensure that they comply with data access rules, permission restrictions and data security requirements.

[0150] In addition, when generating the initial SQL statement, the large language model will optimize it through optimization strategies, such as indexing, sorting, and limiting the number of returned results to improve query efficiency.

[0151] B2: Identify the natural language to be converted and obtain fuzzy information.

[0152] The fuzzy information indicates the unclear content in the natural language to be converted.

[0153] B3: Adjust the initial SQL statement according to the fuzzy information and context information to obtain an SQL statement.

[0154] Understandably, if the natural language query to be converted includes a data time range requirement, such as querying data from 2024, but the original SQL statement lacks a relevant time restriction, then the original SQL statement will need to be modified through code. Specifically, time range restrictions should be added to the original SQL statement based on the fuzzy information and context. For example, a WHERE clause can be added to the end of the original SQL statement, specifying the time range as BETWEEN, to ensure that the generated SQL statement fully meets the user's query intent.

[0155] Optionally, after step S105, it is also necessary to verify whether the generated SQL statement can be successfully executed. In order to ensure the validity of the SQL query, it is possible to confirm that it can run as expected and return the correct results by executing the SQL statement or performing a syntax check. Therefore, in another embodiment of the present application, a method for executing an SQL statement is provided, such as Figure 3 As shown, the following steps are included:

[0156] S301: Verify the SQL statement.

[0157] SQL statements are subject to syntax and permission verification. Specifically, the syntax checker verifies the basic structure of SQL statements, supporting verification of basic statements such as SELECT, INSERT, UPDATE, and DELETE. The permission verifier verifies whether the user in the SQL statement has permission to access relevant tables and fields and perform specific operations (such as SELECT and INSERT) based on the permission information registered in the database.

[0158] S302: After the SQL statement passes verification, the SQL statement is executed in the target database to obtain the execution result.

[0159] It is understood that once the SQL statement passes verification, it can be executed in the target database through mechanisms such as database connection pool and transaction management. These mechanisms can ensure the efficiency and stability of the execution process, thereby improving overall performance and reliability.

[0160] S303: When the execution result indicates that the SQL statement is executed successfully, the execution result is fed back.

[0161] For example, the natural language to be converted into a query instruction is executed at this time, and the execution result obtained is the query result (such as table data, statistical information). The query result includes a detailed explanation of each field, such as the field source and data type, and the query result is returned to the client or question-answering system.

[0162] S304: When the execution result indicates that the SQL statement execution fails, the failure information is recorded.

[0163] It is understandable that debugging tips and optimization suggestions can be provided based on the failure information and SQL statements, such as adding an order by to store the results.

[0164] It should be noted that when executing SQL statements, the MCP Trace ID records each step of the query process, including context injection, intent recognition, and SQL generation. Subsequently, the Trace ID is used to track the entire query process, analyze problems, and optimize the query generation process.

[0165] In summary, managed cloud platform services store database information and respond to changes in real time when the database changes. This eliminates the need to frequently retrain models, effectively reducing update costs.

[0166] like Figure 4 , which is a schematic diagram of the architecture of a natural language to SQL conversion device provided in an embodiment of the present application, the conversion device includes: a processing unit 100, an extraction unit 200, a screening unit 300, a fusion unit 400 and a generation unit 500.

[0167] The processing unit 100 is configured to perform data preprocessing on the natural language to be converted upon receiving the natural language to be converted, so as to obtain the preprocessed natural language to be converted.

[0168] The processing unit 100 is specifically used to: clean the natural language to be converted to obtain the cleaned natural language to be converted; standardize the cleaned natural language to be converted to obtain the standardized natural language to be converted; and perform text normalization on the standardized natural language to be converted to obtain the preprocessed natural language to be converted.

[0169] The extraction unit 200 is used to extract key information and entity information from the pre-processed natural language to be converted.

[0170] The screening unit 300 is used to screen out data information, sample data and access control information corresponding to key information and entity information from the hosted cloud platform service through the hosted cloud platform service agreement.

[0171] The fusion unit 400 is used to fuse the data information, sample data, access control information and the preset structured query language SQL example to obtain context information.

[0172] The generating unit 500 is configured to generate an SQL statement based on the natural language to be converted and the context information.

[0173] The generation unit 500 is specifically used to: input the natural language to be converted and context information into the large language model to obtain an initial SQL statement; identify the natural language to be converted to obtain fuzzy information; the fuzzy information indicates the unclear content in the natural language to be converted; and adjust the initial SQL statement according to the fuzzy information and context information to obtain an SQL statement.

[0174] In summary, managed cloud platform services store database information and respond to changes in real time when the database changes. This eliminates the need to frequently retrain models, effectively reducing update costs.

[0175] Combine Figure 4 The conversion device further comprises:

[0176] The creation unit is used to create and parse the configuration file to obtain the connection information.

[0177] The connection unit is used to connect to the database according to the connection information.

[0178] The information extraction unit is used to extract data information, sample data and access control information from the database when the database connection is successful.

[0179] A storage unit is used to store data information, sample data, and access control information in a hosted cloud platform service.

[0180] Combine Figure 4 The conversion device further comprises:

[0181] Verification unit, used to verify SQL statements.

[0182] The execution unit is used to execute the SQL statement in the target database and obtain the execution result after the SQL statement passes the verification.

[0183] The first feedback unit is configured to feed back the execution result when the execution result indicates that the SQL statement is executed successfully.

[0184] The second feedback unit is configured to record failure information when the execution result indicates that the SQL statement execution fails.

[0185] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Ordinary technicians in this field can understand and implement it without expending creative work.

[0186] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0187] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A natural language to SQL conversion method, characterized in that: include: When receiving the natural language to be converted, performing data preprocessing on the natural language to be converted to obtain the preprocessed natural language to be converted; Extracting key information and entity information from the preprocessed natural language to be converted; Filtering data information, sample data, and access control information corresponding to the key information and the entity information from the hosted cloud platform service through the hosted cloud platform service agreement; Merging the data information, the sample data, the access control information, and a preset structured query language SQL example to obtain context information; Generate an SQL statement based on the natural language to be converted and the context information.

2. The method according to claim 1, characterized in that The performing data preprocessing on the natural language to be converted to obtain the preprocessed natural language to be converted includes: performing a cleaning process on the natural language to be converted to obtain a cleaned natural language to be converted; performing standardization processing on the cleaned natural language to be converted to obtain standardized natural language to be converted; The standardized natural language to be converted is subjected to text normalization processing to obtain the preprocessed natural language to be converted.

3. The method according to claim 1, characterized in that Before filtering out the data information, sample data, and access control information corresponding to the key information and the entity information from the hosted cloud platform service, the method further includes: Create and parse the configuration file to obtain connection information; connecting to a database according to the connection information; When the database is successfully connected, extracting data information, sample data and access control information from the database; The data information, the sample data, and the access control information are stored in a hosted cloud platform service.

4. The method according to claim 1, wherein The generating of SQL statements based on the natural language to be converted and the context information includes: Inputting the natural language to be converted and the context information into a large language model to obtain an initial SQL statement; Recognizing the natural language to be converted to obtain fuzzy information; the fuzzy information indicates unclear content in the natural language to be converted; The initial SQL statement is adjusted according to the fuzzy information and the context information to obtain an SQL statement.

5. The method according to claim 1, wherein Also includes: Verifying the SQL statement; When the SQL statement passes verification, the SQL statement is executed in the target database to obtain the execution result; When the execution result indicates that the SQL statement is successfully executed, feeding back the execution result; When the execution result indicates that the SQL statement fails to execute, failure information is recorded.

6. A natural language to SQL conversion device, characterized in that: include: a processing unit configured to, upon receiving a natural language to be converted, perform data preprocessing on the natural language to be converted to obtain preprocessed natural language to be converted; An extraction unit, configured to extract key information and entity information from the preprocessed natural language to be converted; a screening unit, configured to screen data information, sample data, and access control information corresponding to the key information and the entity information from the hosted cloud platform service through the hosted cloud platform service agreement; a fusion unit, configured to fuse the data information, the sample data, the access control information, and a preset structured query language SQL example to obtain context information; A generating unit is configured to generate an SQL statement based on the natural language to be converted and the context information.

7. The device according to claim 6, characterized in that The processing unit is specifically configured to: performing a cleaning process on the natural language to be converted to obtain a cleaned natural language to be converted; performing standardization processing on the cleaned natural language to be converted to obtain standardized natural language to be converted; The standardized natural language to be converted is subjected to text normalization processing to obtain the preprocessed natural language to be converted.

8. The device according to claim 6, characterized in that Also includes: Create a unit to create and parse the configuration file to obtain connection information; a connection unit, configured to connect to a database according to the connection information; An information extraction unit, configured to extract data information, sample data, and access control information from the database when the database connection is successful; A storage unit is used to store the data information, the sample data and the access control information in a hosted cloud platform service.

9. The device according to claim 6, characterized in that The generating unit is specifically configured to: Inputting the natural language to be converted and the context information into a large language model to obtain an initial SQL statement; Recognizing the natural language to be converted to obtain fuzzy information; The fuzzy information indicates the unclear content in the natural language to be converted; The initial SQL statement is adjusted according to the fuzzy information and the context information to obtain an SQL statement.

10. The device according to claim 6, characterized in that Also includes: A verification unit, configured to verify the SQL statement; An execution unit, configured to execute the SQL statement in a target database to obtain an execution result after the SQL statement passes verification; A first feedback unit, configured to feed back the execution result when the execution result indicates that the SQL statement is executed successfully; The second feedback unit is configured to record failure information when the execution result indicates that the SQL statement execution fails.