Run Natural Language Query in the Data Analysis Tool

You can query the Oracle Autonomous Database by using Natural Language Query rather than having to write SQL Query.

Prerequisites

To utilize the Natural Language Query, you must have:
  • An OpenAI, or Cohere or An Azure OpenAI account service with credit
  • An access to DBMS_CLOUD_AI package.
Note

You can run Natural Language Queries on both Analytic Views and Tables.

Generate SQL Queries From Natural Language on Analytic Views

To run a natural language query from SQL query on Analytic Views, perform the following steps:

Let's say you wish to view sales amount in a categorized way.

  1. On the Data Analysis home page, click on any of the Analytic Views you wish to query.


    Description of av-sales.png follows

    In this example, you will query the SH_SALES_HISTORY Analytic View.

    This opens the Analyses page.

  2. Select Natural Language. Selecting Natural Language opens the SQL worksheet area with a predefined SQL query on the worksheet area.
    Description of natural-language.png follows

    Note

    You can view Natural Language option only after you have configured and set AI profile using the Use Select AI to Generate SQL from Natural Language Prompts procedure and set the Data Studio Settings wizard on the Connections page.
  3. Enter the following natural Query you wish to run on SH_SALES_HISTORY in the Natural Query field: show me amount sold by category.
  4. Click Generate Query.
    Description of result-query.png follows

  5. After the tool generates the query, the Query Result tab displays the result of the query. You can also view the graphical representation of the contents of the PLAN_TABLE in the Explain Plan tab.

    You can alternatively view the query result in chart view by switching the display mode in Chart View or Diagram View.

Generate SQL Queries from Natural Language on Tables

Follow the procedure mentioned below to generate SQL queries from Natural Language on Tables:

Let’s say you want to view the product with the minimum product price.
  1. On the Data Analysis home page, click on any of the Tables you wish to query. In this example, we select the PRODUCTS table.


    Description of analysis-page.png follows

    This opens the Analyses page with a query that retrieves all the columns from the selected table PRODUCTS.

  2. Select Use Natural Query.


    Description of product-page.png follows

  3. Selecting Use Natural Query lets you select multiple tables from the Select Tables icon.
    Note

    You can view Natural Language option only after you have configured and set AI profile using the Use Select AI to Generate SQL from Natural Language Prompts procedure and set the Data Studio Settings wizard on the Connections page.


    Description of select-tables.png follows

    Select the tables you wish to generate the SQL query from. You can use the columns from the selected table in the text field where you enter the Natural Query.

    Note

    You can click Tabular View, drag and drop columns from the navigator to the Columns and Filter drop area to select the intended columns to query.


    Description of note-image.png follows

  4. Click Base Query mode of visualization to enter Natural Language.

    Enter the following in the Natural Query Text field: show me the minimum product price with the product.


    Description of natural-query-tables.png follows

    Click Generate Query.

    Selecting Generate Query converts the Natural language to the equivalent SQL query and displays results under the Query Results tab.

    You can alternatively view the query result in tabular view, pivot, and chart view. You can drag and drop rows, columns, and filters from the Tables Browser to the drop area.

    Note

    From the Chart view you can view the result in horizontal and vertical sheet.