09 / 14DBIntermediate4 min read

Oracle DB AI: Select AI & natural-language SQL

Ask your Oracle database questions in plain English with Select AI: set up the grants, credential and AI profile, then generate, inspect and run SQL. Includes where Select AI runs and what data it sends to the AI provider.

By Mohamed Harby · Verified against Oracle's Autonomous AI Database docs · Last verified

On this page
  1. 1. Grant access (as ADMIN)
  2. 2. Store the provider credential
  3. 3. Create an AI profile
  4. 4. Ask in natural language
  5. Stateless connections and APEX
  6. Ask AI on Table Hyperlinks
  7. What leaves the database
  8. Where the rest of DB AI fits
  9. Check your understanding

Select AI lets you type a question in plain English and get SQL back, generated by an AI provider you choose and limited to the schema objects you allow. This guide walks through the setup on Autonomous AI Database, shows how to inspect the SQL before you trust it, and explains how Select AI relates to AI Vector Search and JSON Relational Duality.

Where Select AI runs

Select AI is part of the DBMS_CLOUD_AI package. It is preinstalled on Oracle Autonomous AI Database (Serverless, Dedicated, Cloud@Customer). Oracle also lists Oracle AI Database 26ai and Oracle Database 19c, but on these customer-managed databases you must first install and configure the DBMS_CLOUD package family by hand (see Oracle's "Using the DBMS_CLOUD Family of Packages"). The stock Oracle AI Database 26ai Free container does not include it: DBMS_CLOUD_AI is not present until you install it. The steps below assume Autonomous AI Database.

1. Grant access (as ADMIN)

The user who runs Select AI needs EXECUTE on DBMS_CLOUD_AI and network access to the provider's API host. This example uses OpenAI and the HR sample schema; swap in your own user and provider host.

GRANT EXECUTE ON DBMS_CLOUD_AI TO HR;

BEGIN
  DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
    host => 'api.openai.com',
    ace  => xs$ace_type(privilege_list => xs$name_list('http'),
                        principal_name => 'HR',
                        principal_type => xs_acl.ptype_db));
END;
/

2. Store the provider credential

Store the API key as a database credential with DBMS_CLOUD.CREATE_CREDENTIAL. For OpenAI, password is your secret API key. Other providers (OCI Generative AI, Azure OpenAI, AWS…) use different credential types — check Oracle's provider examples.

BEGIN
  DBMS_CLOUD.CREATE_CREDENTIAL(
    credential_name => 'AI_CRED',
    username        => 'OPENAI',
    password        => '<your_api_key>');
END;
/

3. Create an AI profile

An AI profile names the provider, the credential and, through object_list, the tables and views whose metadata Select AI may use. provider and credential_name are required. Set model explicitly to a model from Oracle's "Select your AI Provider and LLMs" list for your provider (Oracle documents no default chat model for OpenAI; Azure OpenAI ignores model and uses your deployment). "comments": true adds your table and column comments to the metadata sent to the model.

BEGIN
  DBMS_CLOUD_AI.CREATE_PROFILE(
    profile_name => 'HR_AI',
    attributes   => '{"provider": "openai",
                      "credential_name": "AI_CRED",
                      "model": "gpt-5",
                      "comments": true,
                      "object_list": [{"owner": "HR", "name": "EMPLOYEES"},
                                      {"owner": "HR", "name": "DEPARTMENTS"}]}');
END;
/

4. Ask in natural language

Set the profile once per session (connection), then use SELECT AI <action> <prompt>. With no action, the default is runsql: the SQL is generated and executed.

EXEC DBMS_CLOUD_AI.SET_PROFILE('HR_AI');

SELECT AI how many employees per department earn above average;

-- see the generated SQL instead of running it
SELECT AI showsql how many employees per department earn above average;
  • runsql (default) — generate and run the SQL.
  • showsql — show the generated SQL without running it.
  • explainsql — explain the generated SQL in plain language.
  • narrate — run the SQL and return a prose answer (sends the result rows to the provider).
  • chat — send the prompt straight to the LLM, no SQL generation.

Review before you trust

LLMs can produce wrong SQL. Use showsql to inspect the query before relying on it, and give tables clear column names, or add column comments and set "comments": true in the profile so they reach the model.

Stateless connections and APEX

SET_PROFILE only lasts for the session. For stateless or pooled connections — and in APEX and Database Actions, where the SELECT AI keyword is not supported — call DBMS_CLOUD_AI.GENERATE and pass the profile on every call.

SELECT DBMS_CLOUD_AI.GENERATE(
         prompt       => 'how many employees per department earn above average',
         profile_name => 'HR_AI',
         action       => 'showsql')
FROM dual;

Since November 2026, Autonomous AI Database can put Select AI behind a Table Hyperlink: a pre-authenticated URL (it opens without a database login) to a table or view, created with DBMS_DATA_ACCESS.CREATE_URL. Whoever opens the link clicks Ask AI and asks in plain English. Select AI generates and runs the SQL and shows the result in the browser, and follow-up questions keep their context. Ask AI works only on links to a schema object, not on SQL_STATEMENT links or hyperlink groups.

-- A link on a narrow view, with Ask AI, a password, an allow-list and a 24-hour expiry
DECLARE
  status CLOB;
BEGIN
  DBMS_DATA_ACCESS.CREATE_URL(
    schema_name        => 'SALES',
    schema_object_name => 'REGION_SALES_V',
    password           => '<12+ chars: upper, lower, digit>',
    acl                => '["203.0.113.0/24"]',
    ai_profile_name    => 'SALES_NL2SQL',  -- on Oracle's feature page; not yet in the CREATE_URL reference
    expiration_minutes => 1440,
    result             => status);
END;
/

Oracle's feature page names ai_profile_name for attaching the AI profile, but the DBMS_DATA_ACCESS reference doesn't list it under CREATE_URL or UPDATE_URL yet, so check the reference for your database. The password can't be changed or reset after the link is created.

The link is a key

Anyone who holds the link can query that object. Point it at a narrow view with only the columns needed, and create it from a least-privilege schema: Oracle advises against running CREATE_URL as ADMIN. Add a password and an IP or VCN allow-list, and set a short expiry. 90 days is both the maximum and the default.

What leaves the database

To generate SQL, Oracle sends your prompt plus schema metadata only — table and column definitions, plus comments, annotations and constraints when you enable them in the profile (comments, annotations, constraints) — not row values. narrate is the exception: it sends the query result to the provider. Leave sensitive tables out of object_list, and add "enforce_object_list": true if generated SQL must stay within the listed objects.

Where the rest of DB AI fits

  • AI Vector Search — semantic similarity search over embeddings stored in the database; Select AI can use a vector index for RAG (see the Vector Search guide).
  • JSON Relational Duality views — the same data exposed as relational tables and as JSON documents, convenient for app backends.
  • Select AI narrate — a prose answer instead of rows, for chat-style apps.

Check your understanding

Check your understanding

0% · 0/3

What does SELECT AI showsql do?

What scopes which tables Select AI can see?

Which action sends query results (your data) to the AI provider?

Get the Oracle + AI digest

One email when a new tested guide, template or APEX release note lands — English or Arabic. No spam; unsubscribe anytime.

Need this delivered? Request a quote