Search notes:

Oracle: Sample schemas

Oracle maintains a few sample schemas which are used in Oracle's documentation to demonstrate features and concepts of SQL and the database in general.
Starting with 21c, Sample Schemas are not part of a default Oracle installation, they can be cloned from the from the Github repository Oracle Database Sample Schemas.
These schemas are described in Oracle online database documentation (21c).
In previous releases, the sample schemas were supposed to be found under $ORACLE_HOME/demo/schema (see also $ORACLE_HOME/demo/schema/human_resources`).
Oracle's sample schemas are:
BI Business intelligence
HR Human Resources Among the sample schemas, the HR schema is the smallest and most sipmle one. The HR account is locked after the installation. See also $ORACLE_HOME/demo/schema/human_resources
IX Information Exchange
OE Order Entry Needs MDSYS (Oracle Option: Spatial and Graph[Oracle Spatial?) to be installed.
PM Product Media
SH Sales History
Some schemas are dependent on other schemas; they need to be installed in alphabetical order.

Cloning the github repository

$ git clone https://github.com/oracle/db-sample-schemas.git
$ cd db-sample-schemas
$ git tag
v12.1.0.2
v12.2.0.1
v18c
v19.2
v19c
v21.1
$ git switch --detach v19c
Update 2023-05-19: there is a new tag: v23.1

Installing the schemas

Use Perl for in place editing: __SUB__CWD__ must be replaced with the current directory.
Note that a perl interpreter is installed under $ORACLE_HOME/perl.
I use -Mopen="IO,:raw" to preserve Unix line endings in the files.

PowerShell

PS> perl.exe -Mopen="IO,:raw" -i -p -e "s#__SUB__CWD__#$($pwd -replace '\\', '/' )#g" (get-childItem *.sql,*/*.sql,*/*.dat)

Make sure the Oracle environment is correct

Linux/Unix shell:
$ source /usr/local/bin/oraenv

Windows: Grant access rights on some files

The Oracle Windows-Service that is running the instance needs to be able to read the files referenced in order_entry/createResources.sql, otherwise, errors like ORA-22288: file or LOB operation FILEOPEN failed and/or ORA-31001: Invalid resource handle or path name "/home/OE/purchaseOrder.xsd" will be thrown.
$oracle_service_name = 'NT SERVICE\OracleServiceORA19' 

$accessRule = new-object System.Security.AccessControl.FileSystemAccessRule `
   'NT SERVICE\OracleServiceORA19'                                , `
  ([System.Security.AccessControl.FileSystemRights]::FullControl) , `
  ([System.Security.AccessControl.AccessControlType]::Allow)

foreach ($file in get-childItem -recurse -file -include *xsd,*xsl,*.xml order_entry) {  
   $acl = get-acl $file.fullName
   $acl.AddAccessRule($accessRule)
   set-acl $file.fullName   $acl
}

Show executed script

For each line in the *.sql scripts that start with @, add another line that writes the name of the executed SQL script so that errors during the installation can be easier located.
perl.exe -Mopen="IO,:raw" -i'.bak' -p -e "s#^(\s*)@(.*)$#prompt exec script `$2;\n`$1\@`$2#" (get-childItem *.sql,*/*.sql)
Remove .bak files:
PS> get-childItem -re *.bak | % { rm $_}

Install

Because OE needs MDSYS, make sure that Oracle Spatial is installed.
Run the mksample.sql script in SQL*Plus. This script creates all 5 sample schemas. If any of those schemas already exists, they will be dropped first.
If set in the login.sql file, consider making sure that plsql_warnings is disabled in order to focus on error messages and not be distracted by warnings.
Note: the final slash in the path of the log directory seems to be required:
rem mkdir log
sqlplus system/iAmSystem
SQL> @mksample iAmSystem iAmSysdba hrPw oePw pmPw ixPw shPw biPw DATA TEMP log/ ora19
Start from a PowerShell command line and highlight errors and warnings:
sqlplus system/iAmSystem@Ora19 `@mksample iAmSystem iAmSysdba hrPw oePw pmPw ixPw shPw biPw DATA TEMP log/ ora19 | foreach-object {
   $line = $_
   $line = $line -replace '^(error|warning).*|^SP2-', "$([char]27)[38;5;9m$line$([char]27)[0m"
   $line = $line -replace '^(\s*exec script).*|^SP2-', "$([char]27)[32;5;9m$line$([char]27)[0m"
   $line
}

Update 2023-06-21

TODO

Unlocking HR

The HR account is supposed to be locked after the installation and must be unlocked befor logging on as HR. However, I found this information to be wrong. Anyway, the account can be unlocked with
SQ> alter user hr identified by your_password account unlock;

See also

$ORACLE_HOME/rdbms/admin/utlsampl.sql creates the sample schema SCOTT with the tables EMP, DEPT, SALGRADE and BONUS.

Index