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.

Note

You cannot run PL/SQL statements, DDL statements, or DML statements using the AI keyword.

Syntax

The syntax for running AI prompt is:
SELECT AI action natural_language_prompt

Parameters

The following are the parameters available for the action parameter:
Parameter Description

runsql

Runs the underlying SQL command for the natural language prompt. This is the default action and it is optional to specify this parameter.

showsql

Displays the SQL statement for a natural language prompt.

explainsql

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.

narrate

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.

chat

Generates a response directly from the LLM based on the prompt. If conversation in the DBMS_CLOUD_AI.CREATE_PROFILE function is set to true, this option includes content from prior interactions or prompts, potentially including schema metadata.

Usage Notes

  • Select AI is not supported in Database Actions or APEX Service. You can use only DBMS_CLOUD_AI.GENERATE function.

  • The AI keyword is supported only in a SELECT statement.

  • You cannot run PL/SQL statements, DDL statements, or DML statements using the AI keyword.

  • The sequence is SELECT followed by AI. These keywords are not case-sensitive. After setting your AI profile using DBMS_CLOUD_AI.SET_PROFILE, the text after SELECT AI is a natural language prompt. If an AI profile is not set, SELECT AI reports the following error when running a SELECT 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 in SELECT AI explainsql, to get a more detailed explanation of the SQL statement, as compared to SELECT AI showsql.
  • To access DBA or USER views, see DBMS_CLOUD_AI Views.