18.8.3 Using APEX Assistant

Use integrated AI Chat capability (called APEX Assistant) in Code Editors within App Builder.

Note:

Before you can use APEX Assistant, you must create an Generative AI Service and enable the Used by App Builder setting. See Managing Generative AI Services.

Tip:

APEX Assistant can also generate data models. For more information, see Creating a Data Model Using AI in Oracle APEX SQL Workshop Guide.

APEX Assistant adds AI chat capability to all APEX code editors to assist you with writing SQL queries, debugging code, and so on. To enable an iterative chat experience, the Chat Widget memorizes the context of the chat until the Clear Chat button is pressed. For example, given the SQL Query Builder use case below, a developer might ask 'add department information of the employee to the query'. Given the context in the chat, the Generative AI Service uses this information to enhance the existing query to include the desired information asked by the developer.

Caution:

AI-generated code may contain errors or security risks. Oracle recommends you always review and validate all code before use.

To use APEX Assistant:

  1. Create an Generative AI Service and enable the Used by App Builder setting. See Managing Generative AI Services.
  2. Access a Code Editor. The examples that follow show the Code Editor in Page Designer.
  3. Click APEX Assistant on the menu bar.


    The first time you access APEX Assistant a consent dialog appears. Review the dialog carefully and click Accept to continue. APEX Assistant appears in the right pane.



    Note that the APEX Assistant menu contains two 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 your request that the AI create SQL for tables that do not exist in the database, APEX Assistant's responses will not be very helpful.

    • General Assistance - Use General Assistance for general conversation, 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.

  4. Query Builder Example: Show average salary by department.
    1. From the menu, select Query Builder (if not already selected).
    2. In the Code Editor, select the query and click Use Selection.
    3. In Type your message here, enter show average salary of employee by department name and click Send Message.
    4. APEX Assistant responds with a query as shown in the following example.
    5. Click Copy or Insert to copy or insert the response into the Code Editor.
    6. To clear the chat window, click Clear Chat.

    Tip:

    If a query throws an error, APEX Assistant switches to General Assistance mode. Click Help me fix this.
  5. General Assistance example: Explain a selected query:
    1. From the menu, select General Assistance.

      APEX Assistant displays three options:

      • Use selection
      • Improve selection
      • Explain selection
    2. In the Code Editor, select the query and click Explain selection.

      APEX Assistant responds and describes the query.



    3. To clear the chat window, click Clear Chat.
  6. General Assistance example: Help with SQL query errors:

    If your query throws an error, APEX Assistant can help troubleshoot the problem.

    For example, suppose you have the following query and have inadvertently left off the "s" at the end the table name.

    select rowid,
           ID,
           PROJECT,
           TASK_NAME,
           START_DATE,
           END_DATE,
           STATUS,
           ASSIGNED_TO,
           COST,
           BUDGET
    from EBA_DEMO_IR_PROJECT
    where (nvl(:P3_STATUS,'0') = '0' or :P3_STATUS = status)

    Since the table name should be EBA_DEMO_IR_PROJECTS, if you validate or try to run the query it throws the error:

    ORA-20999: Failed to parse SQL query! ORA-06550: line 11, column 24: ORA-00942: table or view does not exist.

    1. In the error, click Help me fix this.

      APEX Assistant reviews the code and error and suggests the table name may not be spelled correctly.



    2. To clear the chat window, click Clear Chat.