Use AI Keyword to Enter Prompts
Use AI
as the keyword in a SELECT
statement for interacting with the database using natural language prompts.
The AI
keyword in a SELECT
statement
instructs the SQL execution engine to use the LLM identified in the active AI profile to
process natural language and to generate SQL.
You can use the AI
keyword in a query with Oracle clients
such as SQL Developer, OML Notebooks, and third-party tools, to interact with database
in natural language.
You cannot run PL/SQL statements, DDL statements, or DML statements using the
AI
keyword.
Syntax
SELECT AI action natural_language_prompt
Parameters
Parameter | Description |
---|---|
|
Runs the underlying SQL command for the natural language prompt. This is the default action and it is optional to specify this parameter. |
|
Displays the SQL statement for a natural language prompt. |
|
Explains the generated SQL from the prompt in a natural language. This option sends the generated SQL to the AI provider to produce a natural language explanation. |
|
Sends the result of the SQL query run by the LLM back to the LLM to generate a natural language description of that result. This option forwards the SQL result to the AI provider to generate a natural language summary. When using a vector index for RAG, the system utilizes the specified transformer model to create vector embeddings for semantic similarity search against the vector store. The system then adds the retrieved content to the user prompt and sends it to the LLM to generate a response based on this information. |
|
Generates
a response directly from the LLM based on the prompt. If
|
Usage Notes
-
Select
AI
is not supported in Database Actions or APEX Service. You can use onlyDBMS_CLOUD_AI.GENERATE
function. -
The
AI
keyword is supported only in aSELECT
statement. -
You cannot run PL/SQL statements, DDL statements, or DML statements using the
AI
keyword. -
The sequence is
SELECT
followed byAI
. These keywords are not case-sensitive. After setting your AI profile usingDBMS_CLOUD_AI.SET_PROFILE
, the text afterSELECT AI
is a natural language prompt. If an AI profile is not set,SELECT
AI
reports the following error when running aSELECT AI
statement:ORA-00923: FROM keyword not found where expected 00923. 00000 - "FROM keyword not found where expected"
-
Special character usage rules apply according to Oracle guidelines. For example, use single quotes twice if you are using an apostrophe in a sentence.
select ai how many customers in SF don''t own their own home
-
LLMs are subject to hallucinations and results are not always correct:
-
It is possible that
SELECT AI
may not be able to run the generated SQL query for a specific natural language prompt. -
It is possible that
SELECT AI
may not be able to generate a SQL query for a specific natural language prompt. -
It is possible that the LLM may not generate a SQL query that produces a correct result given your natural language prompt.
In such a scenario,
SELECT AI
may respond with information to assist you in generating valid SQL. -
-
For better results with natural language to SQL generation, use database views or tables with contextual column names or consider adding column comments explaining values stored in the columns.
- Use the
explainsql
action, as inSELECT AI explainsql
, to get a more detailed explanation of the SQL statement, as compared toSELECT AI showsql
. -
To access DBA or USER views, see DBMS_CLOUD_AI Views.