How to connect to Oracle database and run SQL queries from matlab command line and database explorer App?

In this video it shows the steps to configure the Oracle database in the matlab environment using the database explorer. The it shows how one run a query on the connected database through the database explorer or Matlab commands/ script.

In this video it initially shows the result of connecting to the database through the Windows command prompt using sqlplus command.

I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com

Complete source code and other details:


connection = database("Oracle_Local", "CTXSYS", "CTXSYS");

Query = "select table_name from user_tables fetch first 10 rows only";

data = fetch(connection, Query)

close(conn);

Output:

>> Oracle_Database_Query

data =

  10×1 table

            TABLE_NAME         
    ___________________________

    {'DR$PARAMETER'           }
    {'DR$CLASS'               }
    {'DR$OBJECT'              }
    {'DR$OBJECT_ATTRIBUTE'    }
    {'DR$OBJECT_ATTRIBUTE_LOV'}
    {'DR$PREFERENCE'          }
    {'DR$PREFERENCE_VALUE'    }
    {'DR$INDEX'               }
    {'DR$INDEX_PARTITION'     }
    {'DR$INDEX_VALUE'         }

Steps to configure the database using the Explorer App:

Configuration saved:

To configure the above using command line, use below command:

conn = database('','CTXSYS','CTXSYS', ...
    'Vendor','Oracle', ...
    'driver', 'C:\Work\matlab\OracleDatabaseApp\ojdbc14.jar', ...
    'URL',['jdbc:oracle:thin:@(DESCRIPTION = ' ...
    '(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)' ...
    '(PORT = 1521)) (CONNECT_DATA = ' ...
    '(SERVER = DEDICATED) (SERVICE_NAME = XE) ) )']);

Connection details and steps also available on:

https://mathworks.com/help/database/ug/oracle-jdbc-windows.html

Then choose “Manual” option to enter the query manually and “Preview Query”:

JAR File:

https://drive.google.com/drive/folders/1XRSIc-driOh0EkGnLlrJ4M6EZSPLfs6O?usp=sharing

Oracle Database installation steps are available in the below link:

Leave a Reply