Run SQL Scripts

A SQL script is a set of SQL statements. You can create SQL scripts in Oracle Machine Learning Notebooks, save them as .json files in your system. You can share the notebook.json files with other users as well.

To run SQL scripts in Oracle Machine Learning:
  1. Log in to Oracle Machine Learning using your credentials provided by your Oracle Machine Learning Administrator.
  2. In the Oracle Machine Learning home page, click Run SQL Script. The SQL Query Scratchpad opens.
  3. In the SQL Query Scratchpad, after %script, press enter.
  4. In the next line in the SQL Query Scratchpad, type the SQL script as shown in the screenshot. The SQL script in this example, contains two parts:
    • The first part of the script contains the SQL statement CREATE TABLE to create a table named small_table. It defines the table name, table column, data types, and size. In this example, the column names are NAME, ID1, ID2, ID3, ID4, and TEXT.
    • The second part of the script begins with the keyword BEGIN. It inserts 100 rows in to the table small_table.

    Note:

    When using the CREATE statement with a primary key, it fails and displays the error message
    Insufficient privileges.
    This error occurs due to restricted profiles in the database. Contact your database administrator or the designated security administrator to grant the required privileges. For more information, see Using Oracle Autonomous Data Warehouse Cloud.
  5. Once you have finished writing the SQL script, click Run.
  6. After you have created the SQL script, you can share it with other users:
    • Export SQL script: In the SQL Query Scratchpad, click the export icon export icon to save it as a .json file in your system.
    • Import SQL script: In the Notebooks page, click Import to import the SQL file saved as a .json file in to your notebook.
After the SQL script is successfully imported, it is listed in the Notebooks page. Click the SQL script that is listed here to open and edit it in the Notebook editor. You can also save the SQL script as a notebook template in Personal Templates, Shared, or in the Examples.