Oracle 23ai Database introduces an innovative feature called Select AI, which allows developers and DBAs to interact with the database using natural language prompts. This feature leverages the power of AI and machine learning models to simplify database management tasks.
Let’s explore the core parameters of the Select AI feature and how they can be applied in real-world scenarios:
1. runsql :
The runsql
parameter is the default action when using Select AI. It allows you to execute
SQL commands based on natural language input.
you don’t need to specify this parameter every time in the query as it is the default
action
This is
helpful when you're not sure how to formulate complex SQL queries and prefer
the AI to generate and run the SQL for you
Example:
SQL> select ai runsql how many customers exist; or SQL> select ai how many customers exist;
2. showsql
The showsql
parameter displays the SQL statement generated by Select AI for a natural language prompt without running it. This is useful if you want to review or fine-tune the SQL query before execution.
Example:
SQL> select ai showsql what customer is the largest by sales;
Response
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
SELECT c.cust_id, c.cust_last_name, SUM(s.amount_sold) AS total_sales
FROM sh.customers c
JOIN sh.sales s ON c.cust_id = s.cust_id
GROUP BY c.cust_id, c.cust_last_name
ORDER BY total_sales DESC
FETCH FIRST ROW ONLY
3. narrate
The narrate
parameter provides a natural language explanation of the SQL results. This is particularly useful for non-technical users who may not be familiar with interpreting SQL output directly.
Example:
SQL> select ai narrate how many customers exist;
Response
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
The CUSTOMER_COUNT is 55500, meaning there are 55500 customers in the CUSTOMERS table.
It's likely that this query was focused on counting the number of customers based on some criteria, and the result is simply the total number of customers that match that specific set of criteria.
This result is based on the schema and the query provided without any further information.
Feel free to provide more context or clarify the result you're looking for, and I'll be glad to refine it further based on that.
Let me know if you'd like me to explain anything else about this result or the query, and I'll be glad to do so!
Please provide any additional information or clarifications if you have them!
4. Explainsql:
The explainsql
parameter breaks down the generated SQL and provides an explanation in natural language. This can be particularly useful for developers who are learning SQL or want to understand how complex queries are constructed.
Example:
SQL> select ai explainsql how many customers in San Francisco are married;
Response
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
```sql
SELECT COUNT(*) count
FROM sh.customers
WHERE cust_state_province = 'California'
AND cust_city = 'San Francisco'
AND cust_martial_status = 'Married';
```
Explanation:
1. We are using the `sh` schema to query the `customers` table.
2. The `WHERE` clause has three conditions joined by the logical `AND` operator.
3. The first condition extracts customers from California state, specifically from the city of San Francisco.
4. The second condition further filters to include only the customers who are married.
5. Finally, the query will return the total number of married customers in San Francisco, California, with the count of matched rows.
5. Chat:
The chat
parameter generates a response from the AI model based on the prompt. When used with the conversation
option in the DBMS_CLOUD_AI.CREATE_PROFILE
function, it can incorporate schema metadata and previous interactions. This makes it highly interactive and adaptable to specific database contexts.
Example:
SQL> select ai chat which team win world football cup 2018;
Response
ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ
France was the 2018 FIFA World Cup Champion.
Conclusion
The Select AI feature in Oracle 23c AI Database streamlines the process of interacting with databases through natural language. It provides a range of options from running SQL, displaying queries, generating summaries, and explaining SQL, making it a valuable tool for both technical and non-technical users.
Comments
Post a Comment