Create a Playground - The Challenges of Scripting
Now that we have the database running and can connect to it, we need nice sample data to create good demos for more learning to come. Seasoned Oracle developers will remember the SCOTT or HR schemas. Let's use something different. My colleague Friedhold created an Oracle version of the Northwind database.
The easiest choice seems to be SQL Developer Web as we already have it. But it turned out that the web Worksheet cannot process longer scripts. It may refuse working, at least in my experience. So if we think we have to deal with more Oracle SQL*Plus scripts, a native tool is the only choice. To have a light weight standard command line tool for the database at hand seems to be a good idea, so let's go with SQL*Plus.
First we need to create a new Oracle schema as a home for our sample data:
CREATE USER "NORTHWIND" IDENTIFIED BY "password";
GRANT CREATE SESSION TO northwind;
GRANT CREATE table TO northwind;
GRANT CREATE SEQUENCE TO northwind;
GRANT CREATE PROCEDURE TO northwind;
GRANT CREATE TRIGGER TO northwind;
ALTER USER northwind QUOTA 200M ON DATA;
BEGIN
ORDS_ADMIN.ENABLE_SCHEMA(
p_enabled => TRUE,
p_schema => 'northwind',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'northwind',
p_auto_rest_auth => TRUE
);
COMMIT;
END;
/
This script can be executed in a SQL Editor of DBeaver or in the SQL Worksheet of the SQL Developer Web of our Cloud Database. Connect with the admin user. The last portion, the PL/SQL anonymous block enables access to the new schema from SQL Developer web and ORDS.
Now that we have the schema created, let's open the Northwind table creation script that we downloaded from Github in DBeaver. It looks like this:
Execute this as a script would be the next logical step but DBeaver does not really know about SQL*Plus specific commands like PROMPT. There are some ways out of that:
- Manually edit the script and remove Oracle specific script commands (suitable for small scripts)
- Use the Worksheet of the SQL Developer Web
- Download and install SQL Developer
- Download and install the SQL*Plus Add-On for the Oracle Instant Client
The easiest choice seems to be SQL Developer Web as we already have it. But it turned out that the web Worksheet cannot process longer scripts. It may refuse working, at least in my experience. So if we think we have to deal with more Oracle SQL*Plus scripts, a native tool is the only choice. To have a light weight standard command line tool for the database at hand seems to be a good idea, so let's go with SQL*Plus.
Download the SQL*Plus add-on from the Instant Client page and unzip the content to your instant client directory.
To make it work, there are three more things:
- Because this is a SQL*Net connection, we need to provide the location of the wallet in sqlnet.ora:
Edit the file in the [instantclient_home]/network/admin directory and set the wallet directory like:
WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY="/Users/kaimoeller/Applications/Oracle/instantclient_19_3/network/admin")))
Remember, we placed our ATP database wallet files there, now we need to tell SQL*Net where they are. - Set the TNS_ADMIN environment variable to the same directory according to your computer's operating system
- Add your instant client directory to the PATH variable of your system to access SQL*Plus from everywhere
Let's test it!
Yeah, we're connected! We have control over our cloud database from the SQL*Plus prompt.
Now we can run the northwind scripts. First the cr_Northwind.sql to create the tables, then the ins_Northwind.sql for the content.
Before running the ins_Northwind.sql script in an Oracle tool like SQL*Plus the line
SET DEFINE OFF
should be added on top. It prevents misinterpretation of ampersands as placeholders.
If this is all to much right now and SQL*Plus scripting is not needed in near future, just do the following:
- cr_Northwind.sql: Execute statement by statement in a DBeaver SQL Editor connected to the Northwind schema. For this, create a new connection like shown in the recent post. The same driver can be used for that.
- ins_Northwind.sql: This script runs in DBeaver just as is without modification.
Check the results in DBeaver, for example the content of the CUSTOMERS table. Recognize the correct display of the European special characters that come with the example data of this version. In my environment on a Mac, it worked right away. The database's character set AL32UTF8.
I think we have achieved a lot. We have access to a free Oracle ATP Database instance with its own provided Web UI, by a powerful desktop tool (DBeaver) and with the Oracle's standard scripting tool (SQL*Plus). It is populated with a good set of data to explore more.



Comments
Post a Comment