Trusted Digital Transformation Partner
Oracle Database 23ai ships with a feature that sounds almost too good to be true: type a natural-language question directly in a SQL prompt, and Oracle translates it to valid SQL, executes it, and returns structured results — all without any middleware, Python, or external service call from your application. That feature is Select AI, powered by DBMS_CLOUD_AI. Here is a complete technical walkthrough for enterprise DBAs and developers.
Select AI does not send your data to an LLM. The flow is:
Your actual row data never leaves the database. Only the schema shape is shared with the LLM.
BEGIN
DBMS_CLOUD.CREATE_CREDENTIAL(
credential_name => 'OAI_CRED',
username => 'OPENAI',
password => 'sk-proj-YOUR_API_KEY_HERE'
);
END;
/
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'GPT4O_PROFILE',
attributes => '{
"provider" : "openai",
"model" : "gpt-4o",
"credential_name" : "OAI_CRED",
"object_list" : [
{"owner": "SALES", "name": "ORDERS"},
{"owner": "SALES", "name": "CUSTOMERS"},
{"owner": "SALES", "name": "PRODUCTS"}
]
}'
);
END;
/
The object_list controls which tables the LLM can see — a critical security boundary. Never include tables with PII or credentials in this list.
EXEC DBMS_CLOUD_AI.SET_PROFILE('GPT4O_PROFILE');
-- Natural language query
SELECT AI What were the top 10 products by revenue in Q1 2025, grouped by category?
-- Equivalent SQL that Oracle generates and executes:
SELECT p.category,
p.product_name,
SUM(o.quantity * o.unit_price) AS revenue
FROM sales.orders o
JOIN sales.products p ON p.id = o.product_id
WHERE o.order_date BETWEEN DATE '2025-01-01' AND DATE '2025-03-31'
GROUP BY p.category, p.product_name
ORDER BY revenue DESC
FETCH FIRST 10 ROWS ONLY;
Beyond Select AI, you can call any LLM from PL/SQL for text generation, classification, or summarisation:
DECLARE
l_response CLOB;
BEGIN
l_response := DBMS_CLOUD_AI.GENERATE(
prompt => 'Summarise this customer complaint in one sentence: ' || :complaint_text,
profile_name => 'GPT4O_PROFILE',
action => 'narrate'
);
DBMS_OUTPUT.PUT_LINE(l_response);
END;
/
Available action values: chat, narrate, summarize, runsql, showsql. The showsql action is invaluable for debugging — it shows the generated SQL without executing it.
If your Oracle DB is on OCI, you can use OCI GenAI (Cohere Command R+, Llama 3) at no additional LLM cost:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'OCI_GENAI_PROFILE',
attributes => '{
"provider" : "oci",
"model" : "cohere.command-r-plus",
"credential_name" : "OCI_CRED",
"oci_compartment_id": "ocid1.compartment.oc1..xxxxx"
}'
);
END;
/
The single most effective way to improve Select AI accuracy is to add COMMENT ON COLUMN statements. The LLM uses these as metadata:
COMMENT ON COLUMN orders.status IS
'Order lifecycle status. Values: PENDING, CONFIRMED, SHIPPED, DELIVERED, CANCELLED, RETURNED. Use DELIVERED for revenue reporting.';
COMMENT ON COLUMN orders.unit_price IS
'Price in INR at time of purchase. Does not include GST. Always use SUM(quantity * unit_price) for revenue calculations.';
With good column comments, Select AI accuracy on complex analytical queries reaches 85–95% without any fine-tuning.
object_list to reporting tables only. Never expose USERS, CREDENTIALS, or audit tables.AUDIT SELECT AI to log every natural-language query and the SQL it generated.ROSTAN Technologies implements Oracle 23ai Select AI for Oracle EBS and Oracle Fusion Cloud customers, enabling business analysts to query ERP data in plain English without SQL knowledge. Contact our Oracle team for a live demo.
Talk to our certified experts — free consultation, no commitment.
Powered by AI · Typically replies instantly