Using OCI cli to create table and index

The Command Line Interface (CLI) provides the same core capabilities as the Oracle Cloud Infrastructure Console and provides additional commands that can extend the Console's functionality. The CLI is convenient for developers or anyone who prefers the command line to a GUI.

The CLI is a small footprint tool that can be used with the Console to complete Oracle Cloud Infrastructure tasks. The CLI has commands to run scripts that extend the console functionality. The CLI is built on the Oracle Cloud Infrastructure SDK for Python. The Python code makes calls to Oracle Cloud Infrastructure APIs to provide the functionality implemented for the various services. These are REST APIs that use HTTPS requests and responses.

See Quickstart to install oci-cli.

Create Table and Index

You can use the oci cli commands to create a nosql table and an index on a nosql table.

Configuring the CLI: You can use these optional configurations to extend CLI functionality. The CLI supports using a file for CLI-specific configurations. You can:
  • Specify a default profile.
  • Set default values for command options so you don't have to type them into the command line.
  • Define aliases for commands. For example, using "ls" as an alias for list.
  • Define aliases for options. For example, using "--ad" as an alias for --availability-domain.
  • Define named queries that are passed to the --query option.

See Configuring the CLI for more details.

Using the CLI: You can use CLI to access Oracle Cloud Infrastructure and carry out service-related tasks. The CLI has an interactive mode that provides automatic command completion and parameter information and suggestions. See Using the CLI for more details.

Create Table: An example to create a table using oci cli is shown below:
vi baggageInfo.sql

CREATE TABLE IF NOT EXISTS stream_acct( 
acct_id INTEGER, 
profile_id LONG, 
profile_name STRING, 
account_expiry TIMESTAMP, 
acct_data JSON,  
PRIMARY KEY(acct_id) 
);

DDL_TABLE=$(cat baggageInfo.nosql)
echo $DDL_TABLE
oci nosql table create --compartment-id "$COMP_ID" \
--name stream_acct --ddl-statement "$DDL_TABLE" \
--is-auto-reclaimable false \
--table-limits="{\"maxReadUnits\": 50, \"maxStorageInGBs\": 25, \"maxWriteUnits\": 50 }" \
--wait-for-state SUCCEEDED --wait-for-state FAILED
Create Index: An example to create an index on a nosql table using oci cli is shown below:
oci nosql index create --index-name "$IND_NAME" \
--table-name-or-id stream_acct --compartment-id $COMP_ID \
--keys "[  {  \"columnName\": \"profile_name\"}]" \
--wait-for-state SUCCEEDED --wait-for-state FAILED