Stored Objects  «Prev  Next»

Download and Set Up the Pet Store Project

Objective: Save the course scripts and prepare a dedicated Oracle practice schema for the Pet Store exercises. This activity is optional and unscored. There is no response to submit; use the verification page to check your results.

1. Download the Scripts

Save both files in a user-owned course folder, such as Documents\PetStore. If your browser displays a script instead of downloading it, use Save As and keep its .sql extension. Open each file in a text editor to confirm that it contains SQL, rather than an HTML error page. Keep an original copy and a separate copy for later exercises.

The revised setup creates five tables, MONTHLY_SALES, and PETSTORE_SEQ. It restores missing sample products and sales from the historical course fixture, uses explicit date formats, and corrects sale 22's inconsistent totals. The five-table design is unchanged. Product-package membership remains an intended relationship without a self-referencing foreign key.

Validation status: These scripts have been reviewed against Oracle documentation and checked for sample-data consistency. Execution testing in Oracle is pending.

2. Prepare the Practice Account

You need an Oracle database and SQL*Plus or SQLcl. Review the course requirements for Oracle AI Database 26ai Free installation options. A client alone does not install a database.

An administrator must create an empty, dedicated PETSTORE account in the intended pluggable database. For a default local Oracle Free installation, the service is typically localhost:1521/FREEPDB1. Use your actual hostname, port, and service. Do not create the course account in the CDB root.

The following is an administrator setup example, not part of the student download. Replace the password placeholder before execution and confirm that USERS is an appropriate permanent tablespace. On a managed database, ask its administrator to provision the account instead.

-- Run only in the intended practice PDB, as an authorized administrator.
-- Replace the password placeholder; do not use it as a shared password.
CREATE USER PETSTORE
    IDENTIFIED BY "REPLACE_WITH_YOUR_UNIQUE_PASSWORD"
    DEFAULT TABLESPACE USERS
    QUOTA 20M ON USERS;

GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE,
      CREATE VIEW, CREATE PROCEDURE, CREATE TRIGGER
TO PETSTORE;

The bounded quota provides space for this small project. The procedure and trigger privileges support later lessons. Do not grant the DBA role or broad ANY privileges to the student account. If PETSTORE already exists, inspect its contents with the administrator; do not delete or overwrite an existing schema to make this example work.

3. Connect as the Student

Open a terminal in the folder containing the downloaded scripts. Start a fresh SQL*Plus session with no unrelated work in progress:

sqlplus -L petstore@localhost:1521/FREEPDB1

Supply your own password at the prompt. Substitute the actual connection service when necessary. In SQLcl, use sql in place of sqlplus. Confirm the session before loading:

SELECT USER AS connected_user,
       SYS_CONTEXT('USERENV', 'CON_NAME') AS container_name
FROM dual;

The user should be PETSTORE and the container should be the intended practice PDB. The loader refuses administrative sessions, another current schema, the root container, and a nonempty schema. It also checks the six direct grants listed above.

4. Load Once into the Empty Schema

At the SQL prompt, execute:

@petstore.sql

The script creates all objects before inserting the sample rows. It then checks row counts, required objects, enabled keys, package references in the sample data, and sale totals. Only after those checks pass does it commit the sample data and print PETSTORE_SETUP_COMPLETE. It exits SQL*Plus on completion.

SQL or PL/SQL errors stop the script with a failure exit status. Also inspect the output for SQL*Plus client errors, such as SP2- messages; those are not all handled by WHENEVER SQLERROR. A returned operating-system prompt alone does not prove success.

If setup fails: retain the exact error text and correct its cause before continuing. Oracle DDL commits implicitly, so rollback does not remove tables already created. This script does not drop objects or reset a partial installation. Ask the administrator to inspect the dedicated practice schema and arrange a clean retry without destroying work you need.

5. Verify the Fresh Installation

Reconnect in a new session and run @petstore-verify.sql. The verifier makes no data or schema changes and does not consume a sequence value. It exits with rollback, so use a fresh session without pending exercise changes. Its exact fixture checks are intended for the initial load, not after you have modified data during later lessons.

Continue to Verify Your Pet Store Project Setup for expected counts, success markers, and troubleshooting. Then return to the Pet Store schema lesson.

Oracle references: creating a database user and SQL*Plus error handling.