Use Select AI to Generate SQL from Natural Language Prompts
The Select AI feature allows Autonomous AI Database to use generative AI with Large Language Models (LLMs) to convert user's input text into Oracle SQL. Select AI processes the natural language prompt, supplements the prompt with metadata, and then generates and runs a SQL query.
Supported Platforms
Select AI is supported on Autonomous AI Database Serverless and Autonomous AI Database on Dedicated Exadata Infrastructure and Cloud at Customers.
- Autonomous AI Database Serverless
- Autonomous AI Database on Dedicated Exadata Infrastructure
- Autonomous AI Database on Dedicated Exadata Infrastructure Region
- Autonomous AI Database Cloud@Customer
About SQL Generation
Using natural language to interact with your database data is now achievable with LLMs. This means you can use natural language, for example plain English, to query the database.
When you use Select AI, Autonomous AI Database manages the process of converting natural language into SQL. This means you can provide a natural language prompt instead of SQL code to interact with your data. Select AI serves as a productivity tool for SQL users and developers and enables non-expert SQL users to derive useful insights from their data, without having to understand data structures or technical languages.
DBMS_CLOUD_AI package in Autonomous AI Database enables integration with a user-specified LLM for generating SQL code using natural language prompts. The package assists in supplying the LLM with knowledge of the database schema and instructing it to write a SQL query consistent with that schema. The DBMS_CLOUD_AI package works with AI providers like OpenAI, Cohere, Azure OpenAI Service, and Oracle Cloud Infrastructure Generative AI.
Note:
Users must have an account with the AI provider and provide their credentials throughDBMS_CLOUD_AI objects that the Autonomous AI Database uses.
Terminology
It is important to understand the various terms used with Select AI before using it.
The following are the terms related to Select AI feature:
| Term | Definition |
|---|---|
|
Database Credential |
Database Credentials are authentication credentials used to access and interact with databases. They typically consist of a user name and a password, sometimes supplemented by additional authentication factors like security tokens. These credentials are used to establish a secure connection between an application or user and a database, ensuring that only authorized individuals or systems can access and manipulate the data stored within the database. |
|
Hallucination in LLM |
Hallucination in the context of Large Language Models refers to a phenomenon where the model generates text that is incorrect, nonsensical, or unrelated to the input prompt. Despite being a result of the model's attempt to generate coherent text, these instances can contain information that is fabricated, misleading, or purely imaginative. Hallucination can occur due to biases in training data, lack of proper context understanding, or limitations in the model's training process. |
| IAM | Oracle Cloud Infrastructure Identity and Access Management (IAM) lets you control who has access to your cloud resources. You can control what type of access a group of users have and to which specific resources. To learn more, see Overview of Identity and Access Management. |
|
Natural Language Prompts |
Natural Language Prompts are human-readable instructions or requests provided to guide generative AI models, such as Large Language Models. Instead of using specific programming languages or commands, users can interact with these models by entering prompts in a more conversational or natural language form. The models then generate output based on the provided prompt. |
|
Network Access Control List (ACL) |
A Network Access Control List is a set of rules or permissions that define what network traffic is allowed to pass through a network device, such as a router, firewall, or gateway. ACLs are used to control and filter incoming and outgoing traffic based on various criteria such as IP addresses, port numbers, and protocols. They play a crucial role in network security by enabling administrators to manage and restrict network traffic to prevent unauthorized access, potential attacks, and data breaches. |
|
Similarity Search |
Similarity search identifies and retrieves data points that closely match a given query by comparing feature vectors in a vector store. |
|
Vector Distances |
Vector distances measure the similarity or dissimilarity between feature vectors by calculating the distance between them in a multidimensional space. |
|
Vector Index |
A vector index organizes and stores feature vectors to enable efficient similarity search and retrieval of related data. |
|
Vector Store |
A vector store includes systems that store, manage, and enable semantic similarity search involving vector embeddings. This includes standalone vector databases and Oracle Database 23ai AI Vector Search. |
Usage Guidelines
Provides usage guidelines that ensure effective and proper usage of natural language prompts for SQL generation to ensure an enhanced user experience.
Intended Use
This feature is intended for the generation and running of SQL queries resulting from user-provided natural language prompts. It automates what a user could do manually based on their schema metadata in combination with a large language model (LLM) of their choice.
While any prompt can be provided, including those that do not relate to the
production of SQL query results, Select AI focuses on SQL query generation. Select AI
enables submitting general requests with the chat action.
Prompt Augmentation Data
The database augments the user-specified prompt with database metadata to mitigate hallucinations from the LLM. The augmented prompt is then sent to the user-specified LLM to produce the query.
The database augments the prompt with schema metadata only. This metadata may include schema definitions, table and column comments, and content available from the data dictionary and catalog. For the purposes of SQL generation, the database does not provide table or view contents (actual row or column values) when augmenting the prompt.
The narrate action, however, does provide the result of the
query, which may contain database data, to the user-specified LLM from which to generate
natural language text describing the query results.
WARNING:
Large language models (LLMs) have been trained on a broad set of text documentation and content, typically from the Internet. As a result, LLMs may have incorporated patterns from invalid or malicious content, including SQL injection. Thus, while LLMs are adept at generating useful and relevant content, they also can generate incorrect and false information including SQL queries that produce inaccurate results and/or compromise security of your data.
The queries generated on your behalf by the user-specified LLM provider will be run in your database. Your use of this feature is solely at your own risk, and, notwithstanding any other terms and conditions related to the services provided by Oracle, constitutes your acceptance of that risk and express exclusion of Oracle’s responsibility or liability for any damages resulting from that use.
Select your AI Provider and LLMs
Choose an AI provider and LLM that meets your security standards and aligns with your specific needs, like text or code generation.
Different LLMs excel at various tasks based on their training data and intended purpose. Some models are excellent for text generation but may not perform well in code generation, while others are specifically optimized for coding tasks. Choose an LLM that best suits your needs.
| AI Provider | LLMs | Embedding Model for RAG | Purpose |
|---|---|---|---|
|
OCI Generative AI |
|
|
The OCI Generative AI Chat models are supported for
all The OCI Generate text models are supported only for
|
|
Azure OpenAI Service |
|
text-embedding-ada-002 |
Best suited for generating SQL from natural language
prompts, |
|
OpenAI |
|
text-embedding-ada-002 |
Best suited for generating SQL from natural language
prompts, |
|
OpenAI-Compatible |
Models from OpenAI-compatible providers such as:
|
Embedding models from OpenAI-compaitble providers. For example, see Fireworks AI embedding models. |
Supports a wide range of use cases. |
|
Cohere |
|
embed-english-v2.0 |
Best suited for |
|
|
|
text-embedding-004 (default) |
Best suited for generating SQL from natural language
prompts, |
|
Anthropic |
|
NA |
Best suited for generating SQL from natural language
prompts, |
|
Hugging Face |
|
NA |
Best suited for generating SQL from natural language
prompts, |
|
AWS |
|
Supports a wide range of use cases. |
Note:
-
Specify OpenAI-compatible provider through
provider_endpointinstead ofproviderparameter. See . -
For models that accept images, use
meta.llama-3.2-90b-vision-instruct. This model is specifically trained for vision and images. While it can be used for text and SQL generation, the model is best suited for images. To learn more, see Chat in OCI Generative AI.The
meta.llama-3.2-11b-vision-instructmodel provides robust multimodal capabilities. -
Embedding models are also known as transformer models.
About SQL Generation
Using natural language to interact with your database data is now achievable with LLMs. This means you can use natural language, for example plain English, to query the database.
When you use Select AI, Autonomous AI Database manages the process of converting natural language into SQL. This means you can provide a natural language prompt instead of SQL code to interact with your data. Select AI serves as a productivity tool for SQL users and developers and enables non-expert SQL users to derive useful insights from their data, without having to understand data structures or technical languages.
DBMS_CLOUD_AI package in Autonomous AI Database enables integration with a user-specified LLM for generating SQL code using natural language prompts. The package assists in supplying the LLM with knowledge of the database schema and instructing it to write a SQL query consistent with that schema. The DBMS_CLOUD_AI package works with AI providers like OpenAI, Cohere, Azure OpenAI Service, and Oracle Cloud Infrastructure Generative AI.
Note:
Users must have an account with the AI provider and provide their credentials throughDBMS_CLOUD_AI objects that the Autonomous AI Database uses.
Use DBMS_CLOUD_AI to Configure AI Profiles
Autonomous AI Database uses AI profiles to facilitate and configure access to an LLM and to setup for the generation of SQL statements from natural language prompts.
AI profiles include database objects that are the target for natural language queries. Metadata used from these targets can include database table names, column names, column data types, and comments. You create and configure AI profiles using the DBMS_CLOUD_AI.CREATE_PROFILE and DBMS_CLOUD_AI.SET_PROFILE procedures.
Requirements to Configure DBMS_CLOUD_AI Package
The following are required to run DBMS_CLOUD_AI:
- Access to an Oracle Cloud Infrastructure cloud account and to an Autonomous AI Database instance.
- A paid API account for a supported AI provider, one of:
-
OpenAI: To enable OpenAI to generate SQL from natural language prompts, obtain API keys from your OpenAI paid account.
You can find your secret API key in your User settings.
-
Cohere: To enable Cohere to generate SQL from natural language prompts, obtain API keys from your Cohere paid account.
Click Dashboard, and click API Keys on the left navigation. Copy the default API key or create another key. See API-Keys for more information.
-
Azure OpenAI Service: To enable Azure OpenAI Service to generate SQL from natural language prompts, configure and provide access to the AI provider.
To use Azure OpenAI Service, perform the following steps:
- Obtain your secret API keys. You can find your API keys in the Resource Management section of your Azure portal. On your Azure OpenAI Service Resource page, click Keys and Endpoint. You can copy either KEY1 or KEY2.
- Create an Azure OpenAI Service resource and deploy a model: Create and deploy an
Azure OpenAI Service resource.
Tip:
- Note the resource name and deployment
name as those parameters are used to provide network
access permission and creating your Azure OpenAI Service profile using the
DBMS_CLOUD_AI.CREATE_PROFILEprocedure. - To know more about rate limits for token per minute on a model, see Azure OpenAI Service quotas and limits.
- Note the resource name and deployment
name as those parameters are used to provide network
access permission and creating your Azure OpenAI Service profile using the
- Allow access to Azure OpenAI Service:
- OCI Generative AI: See How to Generate the API Signing Key.
- Google: To enable Google AI Studio to generate SQL and text responses to your natural language prompts, obtain API keys from your Google AI Studio paid account.
- Go to Google AI Studio.
- Click Sign In to Google AI Studio.
- Click Get API key on the prompt screen.
- Select all the applicable options on the next page.
- Click Create API key.
-
Click Create API key in new project.
The screen displays the progress and generates an API key. Copy the key and save it.
- Anthropic: To enable Anthropic Developer Console to generate SQL and text responses to your natural language prompts, obtain API keys from your Anthropic Developer Console paid account.
- Go to Anthropic Developer Console.
- Sign up for an account if you don't have one already.
- Once logged in, navigate to the API section or the dashboard.
- Look for an option to generate or view API keys.
- Click to create a new API key.
-
Copy the generated API key and save it.
The Claude API is a paid service. You'll need to add credits to your account before you can use the API key.
- Hugging Face: To enable Hugging Face as your AI provider to generate SQL and text responses to your natural language prompts, obtain API keys from your Hugging Face paid account.
- Go to Hugging Face.
- Sign up for an account if you don't have one already.
- Navigate to your account settings.
- In the navigation menu locate the Access Tokens.
- Click to create a new API key.
- Copy the generated API key and save it.
-
AWS: To enable AWS, obtain your API key and model ID.
Obtain your API key and use it to create credentials through
DBMS_CLOUD.CREATE_CREDENTIAL.Follow this process to obtain your API key and model name:
- Sign up for an AWS account if you don't have one already.
- Create your access keys and secret keys from AWS Bedrock Console.
- Copy the generated keys and save it.
- Request access to their foundation models. See Access Amazon Bedrock foundation models.
- Obtain the model ID. You require the model ID in
DBMS_CLOUD_AI.CREATE_PROFILEprocedure. Model ID depends on the resources that you use. If you use:- a base model, specify the model ID or its ARN(Amazon Resource Names). For a list of model IDs for base models, see Amazon Bedrock base model IDs
- an inference profile, specify the inference profile ID or its ARN. For a list of inference profile IDs, see Supported Regions and models for cross-region inference.
- a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see Run inference using a Provisioned Throughput.
- a custom model, purchase Provisioned Throughput for it. Then, specify the ARN of the resulting provisioned model. For more information, see Use a custom model in Amazon Bedrock.
- an Amazon Bedrock Marketplace model, specify the ID or ARN of the marketplace endpoint that you created, see Amazon Bedrock Marketplace.
Note:
Imported model is not supported with Bedrock Converse API.
To use AWS as your provider, see Example: Select AI with AWS.
-
- Network ACL privileges to access your external AI provider.
Note:
Network ACL is not applicable for OCI Generative AI. - A credential that provides access to the AI provider.
Configure DBMS_CLOUD_AI Package
Before you use Select AI, here are the steps to
enable DBMS_CLOUD_AI.
DBMS_CLOUD_AI:
-
Grant the
EXECUTEprivilege on theDBMS_CLOUD_AIpackage to the user who wants to use Select AI.By default, only ADMIN user is granted the
EXECUTEprivilege. The ADMIN user can grantEXECUTEprivilege to other users. -
Grant network ACL access to the user who wants to use Select AI and for the AI provider endpoint.
The ADMIN user can grant network ACL access. See APPEND_HOST_ACE Procedure in Oracle Database 19c PL/SQL Packages and Types Reference or Oracle Database 26ai PL/SQL Packages and Types Reference for more information.
- Create a credential to enable access to your AI provider.
See CREATE_CREDENTIAL Procedure for more information.
EXECUTE privilege to ADB_USER:grant execute on DBMS_CLOUD_AI to ADB_USER;The following example grants ADB_USER the privilege to use the api.openai.com endpoint.
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'api.openai.com',
ace => xs$ace_type(privilege_list => xs$name_list('http'),
principal_name => 'ADB_USER',
principal_type => xs_acl.ptype_db)
);
END;
/
APPEND_HOST_ACE Function Parameters
| Parameter | Description |
|---|---|
|
|
The host, which can be the name or the IP address of the host. You can use a wildcard to specify a domain or a IP subnet. The host or domain name is not case sensitive. For OpenAI, use api.openai.com. For Cohere, use api.cohere.ai. For Azure OpenAI Service, use <azure_resource_name>.openai.azure.com. See Profile Attributes to know more about For Google, use generativelanguage.googleapis.com. For Anthropic, use api.anthropic.com. For Hugging Face, use api-inference.huggingface.co. |
|
|
The access control entries (ACE). The |
Here is an example of how to create a credential to enable access to OpenAI.
EXEC DBMS_CLOUD.CREATE_CREDENTIAL('OPENAI_CRED', 'OPENAI', 'your_api_token');DBMS_CLOUD.CREATE_CREDENTIAL Parameters
| Parameter | Description |
|---|---|
|
|
The name of the credential to be stored. The |
|
|
The The |
|
|
The The |
Create and Set an AI Profile
Describes the steps to create and enable an AI profile.
Use DBMS_CLOUD_AI.CREATE_PROFILE to create an AI profile. Next start DBMS_CLOUD_AI.SET_PROFILE to enable the AI profile so that you can use SELECT AI with a natural language prompt.
Note:
You must run DBMS_CLOUD_AI.SET_PROFILE in each new database
session (connection) before you use SELECT
AI.
The following example with the OpenAI provider creates an
AI profile called OPENAI and sets the
OPENAI profile for the current user session.
-- Create AI profile
--
SQL> BEGIN
DBMS_CLOUD_AI.create_profile(
'OPENAI',
'{"provider": "openai",
"credential_name": "OPENAI_CRED",
"object_list": [{"owner": "SH", "name": "customers"},
{"owner": "SH", "name": "sales"},
{"owner": "SH", "name": "products"},
{"owner": "SH", "name": "countries"}]
}');
END;
/
PL/SQL procedure successfully completed.
--
-- Enable AI profile in current session
--
SQL> EXEC DBMS_CLOUD_AI.set_profile('OPENAI');
PL/SQL procedure successfully completed.
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 theAI keyword.
Syntax
SELECT AI action natural_language_promptParameters
| Parameter | Description |
|---|---|
|
|
Run the provided SQL command using a 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. |
|
|
The output of the prompt is explained in natural language. This option sends the SQL result to the AI provider to produce a natural language summary. |
|
|
Generates
a response directly from the LLM based on the prompt. If
|
|
|
The SQL generated from the prompt is explained in natural language. This option sends the generated SQL to the AI provider to produce a natural language explanation. |
Usage Notes
-
Select
AIis not supported in Database Actions or APEX Service. You can use onlyDBMS_CLOUD_AI.GENERATEfunction. -
The
AIkeyword is supported only in aSELECTstatement. -
You cannot run PL/SQL statements, DDL statements, or DML statements using the
AIkeyword. -
The sequence is
SELECTfollowed byAI. These keywords are not case-sensitive. After aDBMS_CLOUD_AI.SET_PROFILEis configured, the text afterSELECT AIis a natural language prompt. If an AI profile is not set,SELECTAIreports the following error: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 AImay not be able to run the generated SQL for a specific natural language prompt. -
It is possible that
SELECT AImay not be able to generate SQL for a specific natural language prompt.
In such a scenario,
SELECT AIresponds with information to assist you in generating valid SQL. -
-
Use the
chataction, withSELECT AI chat, to learn more about SQL constructs. For better results with thechataction, use database views or tables with contextual column names or consider adding column comments explaining values stored in the columns. -
To access DBA or USER views, see DBMS_CLOUD_AI Views.
Example: Select AI Actions
These examples illustrate common Select AI actions.
The following example illustrates actions such as
runsql (the default), showsql,
narrate, chat, explainsql,
feedback, and summarize that you
can perform with SELECT AI. These examples use the
sh schema with AI provider and profile attributes specified in
the DBMS_CLOUD_AI.CREATE_PROFILE function. Use Select AI actions after setting your AI profile
by using the DBMS_CLOUD_AI.SET_PROFILE procedure in the current
session.
To generate a
summary of your text, use SELECT AI SUMMARIZE <TEXT>.
SQL> select ai how many customers exist;
CUSTOMER_COUNT
--------------
55500
SQL> select ai showsql how many customers exist;
RESPONSE
----------------------------------------------------
SELECT COUNT(*) AS total_customers
FROM SH.CUSTOMERS
SQL> select ai narrate how many customers exist;
RESPONSE
------------------------------------------------------
There are a total of 55,500 customers in the database.
SQL> select ai chat how many customers exist;
RESPONSE
--------------------------------------------------------------------------------
It is impossible to determine the exact number of customers that exist as it con
stantly changes due to various factors such as population growth, new businesses
, and customer turnover. Additionally, the term "customer" can refer to individu
als, businesses, or organizations, making it difficult to provide a specific num
ber.
SQL> select ai explainsql how many customers in San Francisco are married;
RESPONSE
--------------------------------------------------------------------------------
SELECT COUNT(*) AS customer_count
FROM SH.CUSTOMERS AS c
WHERE c.CUST_STATE_PROVINCE = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married';
Explanation:
- We use the 'SH' table alias for the 'CUSTOMERS' table for better readability.
- The query uses the 'COUNT(*)' function to count the number of rows that match the given conditions.
- The 'WHERE' clause is used to filter the results:
- 'c.CUST_STATE_PROVINCE = 'San Francisco'' filters customers who have 'San Francisco' as their state or province.
- 'c.CUST_MARITAL_STATUS = 'Married'' filters customers who have 'Married' as their marital status.
The result of this query will give you the count of customers in San Francisco who are married, using the column alias 'customer_count' for the result.
Remember to adjust the table and column names based on your actual schema if they differ from the example.
Feel free to ask if you have more questions related to SQL or database in general.
-- Feedback on SQL Text
-- Negative feedback example:
SQL > select ai feedback for query "select ai showsql how many watch histories in total", please use sum instead of count;
-- Positive feedback example:
SQL > select ai feedback for query "select ai showsql how many watch histories in total", the sql query generated is correct;
-- Feedback on SQL ID
-- Negative feedback example:
SQL > select ai feedback please use sum instead of count for sql_id 1v1z68ra6r9zf;
-- Positive feedback example:
SQL > select ai feedback sql query result is correct for sql_id 1v1z68ra6r9zf;
-- If not specified, use default LASTAI SQL
-- To use default LASTAI sql, make sure that set server output off;
-- Negative feedback example:
SQL > select ai feedback please use ascending sorting for ranking;
-- Positive feedback example:
SQL > select ai feedback the result is correct;
SQL> SELECT AI SUMMARIZE
Like countless other people around the globe, I stream music, and like more
than six hundred million of them I mainly use Spotify. Streaming currently
accounts for about eighty per cent of the American recording industry’s
revenue, and in recent years Spotify’s health is often consulted as a measure
for the health of the music business over all. Last spring, the International
Federation of the Phonographic Industry reported global revenues of $28.6
billion, making for the ninth straight year of growth. All of this was
unimaginable in the two-thousands, when the major record labels appeared
poorly equipped to deal with piracy and the so-called death of physical media.
On the consumer side, the story looks even rosier. Adjusted for inflation, a
... (skipped 1000 rows in the middle)
Pelly writes of some artists, in search of viral fame, who surreptitiously use
social media to effectively beta test melodies and motifs, basically putting
together songs via crowdsourcing. Artists have always fretted about the
pressure to conform, but the data-driven, music-as-content era feels
different. “You are a Spotify employee at that point,” Daniel Lopatin, who
makes abstract electronic music as Oneohtrix Point Never, told Pelly. “If your
art practice is so ingrained in the brutal reality that Spotify has outlined
for all of us, then what is the music that you’re not making? What does the
music you’re not making sound like?” Listeners might wonder something similar.
What does the music we’re not hearing sound like?;
RESPONSE
------------------------------------------------------------------------------
The music streaming industry, led by Spotify, has revolutionized the way
people consume music, with streaming accounting for 80% of the American
recording industry's revenue. However, this shift has also complicated the
lives of artists, who struggle to survive in a hyper-abundant present where
music is often valued for its convenience rather than its artistic merit.
Spotify's algorithms prioritize popularity and profitability over artistic
diversity, leading to a homogenization of music and a devaluation of the
labor that goes into creating it. Meanwhile, the company's executives reap
enormous profits, with CEO Daniel Ek's net worth rivaling that of the
wealthiest musicians. As music critic Liz Pelly argues, the streaming economy
raises important questions about autonomy, creativity, and the value of art
in a world where everything is readily available and easily accessible.
Example: Select AI with AWS
The following example shows how to use AWS as the AI provider with Amazon Bedrock and its foundation models. The example shows creating AWS credentials, provide network access, creating an AI profile, and using Select AI actions to generate SQL queries from natural language prompts and chat using the AWS foundation models.
To use AWS, obtain access key, secret keys, and model ID. See . Use the model ID as the model attribute in the
DBMS_CLOUD_AI.CREATE_PROFILE procedure. You must
specify the model attribute explicitly, as no default model is
provided.
--Grant EXECUTE privilege to ADB_USER
GRANT EXECUTE on DBMS_CLOUD_AI to ADB_USER;
--
-- Create Credential for AI provider
--
BEGIN
DBMS_CLOUD.CREATE_CREDENTIAL(
credential_name => 'AWS_CRED',
username => '<your_AWS_access_key>',
password => '<your_AWS_secret_key>'
);
END;
/
PL/SQL procedure successfully completed.
--
-- Grant Network ACL for AWS
--
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'bedrock-runtime.us-east-1.amazonaws.com',
ace => xs$ace_type(privilege_list => xs$name_list('http'),
principal_name => 'ADB_USER',
principal_type => xs_acl.ptype_db)
);
END;
/
PL/SQL procedure successfully completed.
--
-- Create AI profile
--
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name =>'AWS',
attributes =>'{"provider": "aws",
"credential_name": "AWS_CRED",
"object_list": [{"owner": "SH", "name": "customers"},
{"owner": "SH", "name": "countries"},
{"owner": "SH", "name": "supplementary_demographics"},
{"owner": "SH", "name": "profits"},
{"owner": "SH", "name": "promotions"},
{"owner": "SH", "name": "products"}],
"model" : "anthropic.claude-v2",
"conversation" : "true"
}');
END;
/
PL/SQL procedure successfully completed.
--
-- Enable AI profile in current session
--
EXEC DBMS_CLOUD_AI.SET_PROFILE('AWS');
PL/SQL procedure successfully completed.
--
-- Use AI
--
SELECT AI how many customers exist;
"RESPONSE"
"COUNT(*)"
55500
SELECT AI how many customers in San Francisco are married;
"RESPONSE"
"COUNT(*)"
46
SELECT AI showsql how many customers in San Francisco are married;
"RESPONSE"
"SELECT COUNT(*) AS "Number of Married Customers in San Francisco"
FROM "SH"."CUSTOMERS" C
WHERE UPPER(C."CUST_CITY") = UPPER('San Francisco')
AND UPPER(C."CUST_MARITAL_STATUS") = UPPER('Married')"
SELECT AI explainsql how many customers in San Francisco are married;
"RESPONSE""SELECT
COUNT(*) AS "Number of Married Customers in San Francisco"
FROM "SH"."CUSTOMERS" C
WHERE C."CUST_CITY" = 'San Francisco'
AND C."CUST_MARITAL_STATUS" = 'Married'
Explanation:
- Used table alias C for CUSTOMERS table
- Used easy to read column names like CUST_CITY, CUST_MARITAL_STATUS
- Enclosed table name, schema name and column names in double quotes
- Compared string values in WHERE clause without UPPER() since the values are not in double quotes
- Counted number of rows satisfying the condition and aliased the count as "Number of Married Customers in San Francisco""
SELECT AI narrate what are the top 3 customers in San Francisco;
"RESPONSE"
The top 3 customers in San Francisco ordered by credit limit in descending order are:
1. Bert Katz
2. Madallyn Ladd
3. Henrietta Snodgrass
SELECT AI chat what is Autonomous AI Database;
"RESPONSE"
"An Autonomous AI Database is a cloud database service provided by Oracle Corporation. Some key features of Oracle Autonomous AI Database include:
- Fully automated and self-driving - The database automatically upgrades, patches, tunes, and backs itself up without any human intervention required.
- Self-securing - The database uses machine learning to detect threats and automatically apply security updates.
- Self-repairing - The database monitors itself and automatically recovers from failures and errors without downtime.
- Self-scaling - The database automatically scales compute and storage resources up and down as needed to meet workload demands.
- Serverless - The database is accessed as a cloud service without having to manually provision any servers or infrastructure.
- High performance - The database uses Oracle's advanced automation and machine learning to continuously tune itself for high performance.
- Multiple workload support - Supports transaction processing, analytics, graph processing, etc in a single converged database.
- Fully managed - Oracle handles all the management and administration of the database. Users just load and access their data.
- Compatible - Supports common SQL and Oracle PL/SQL for easy migration from on-prem Oracle databases.
So in summary, an Oracle Autonomous AI Database is a fully automated, self-driving, self-securing, and self-repairing database provided as a simple cloud service. The automation provides high performance, elasticity, and availability with minimal human labor required."
--
--Clear the profile
--
BEGIN
DBMS_CLOUD_AI.CLEAR_PROFILE;
END;
/
PL/SQL procedure successfully completed.
--
--Drop the profile
--
EXEC DBMS_CLOUD_AI.DROP_PROFILE('AWS');
PL/SQL procedure successfully completed.