Introduction:
APEX Assistant adds AI chat capability to all APEX code editors to assist you with writing SQL queries, debugging code, etc.
Pre-Requisite:
Before you can use APEX Assistant, you must create a Generative AI Service and enable the Used by App Builder setting. see my last blog post on how to configure Gen AI service in Oracle APEX using Open AI
To use APEX Assistant, log in to Apex workspace –> Go to the SQL Workshop -> go to SQL Commands and click on APEX Assistant. See my above blog post.
Here you will see APEX Assistant has 2 menu options:
-
Query Builder - Use Query Builder to get back a simple query.
In Query Builder mode, the AI assumes all questions are in the context of the customer schema in the database. For example, if you request that the AI create SQL for tables that do not exist in the database, APEX Assistant’s responses will not be constructive.
-
General Assistance - Use General Assistance for general conversation, and technical questions such as “Explain this” or “Improve this code.” In General Assistance mode, APEX Assistant prompts you with default options such as Use Selection, Improve Selection, and Explain Selection.
Let’s see how Query Builder works.
- From the menu, select Query Builder
- In the code editor, select the query and click Use Selection
-
You will see the query is APEX wizard
-
Type, your message here, enter the average salary of the employee by department name, and click send a message
-
APEX Assistant responds with a query. This is amazing!
- Here you can copy or insert to copy or insert the response into Code Editor. I click insert and you can see the code in Code Editor.
-
Now you can Run this code to get the result as well if you have this table in your schema.
-
I would like to show you another best features of APEX assistant which is Chat Widget memory (the context of the chat). For example, I asked how many belong to the department, Given the context in the chat, it already knew I was talking about employees. This is great!
- Now click Clear Chat.
Now Let’s see how General Assistance works:
- From the menu, select General Assistance
- Apex Assistant displays three options: - Use selection - Improve selection - Explain selection
- In the Code Editor, select the query and click Explain selection. APEX Assistant describes the query.
- Click Clear Chat to clear the chat windows.
- Next, I select the query and click on Use selection, APEX Assistant responds with How can I assist you with it?
- Now I click on Improve and the assistant improves the query and specifies what improvements were made.
- Now let me test one more thing, by purpose I made a mistake and I removed the semicolon after the manager used the below query and then selected Improve selection.
SELECT ID,
firstname,
lastname,
COUNTRY,
email,
position,
manager
GENDER
FROM customer
WHERE country = 'INDIA'
APEX assistant Improves the query and also corrects the query.
- Again, clear the chat.
So you can see how interesting is this APEX Assistant which can help in query generation, query correction, and query Improvement.