2023年6月2日金曜日

アップデートされたサンプル・スキーマのインストール

更新: 2026年2月2日 インストールするサンプルスキーマをv23.3に更新

最近、GitHubからダウンロードできるオラクル・データベースのサンプル・スキーマが更新されました。以前よりもインストールが容易になった、とのことなので確認してみます。

1年以上前にサンプル・スキーマをAutonomous Databaseにインストールしようとした記事があります。その時点のサンプル・スキーマと比較すると、bus_intelligenceinfo_exchangeshippingのサンプルが無くなっています。また、order_entryproduct_mediaは含まれていますが、これらは更新されていないようです。

customer_ordershuman_resourcessales_historyの3つサンプルは更新され、それぞれ個別にインストールできるようになりました。

Autonomous Databaseでは、sales_history(スキーマSH)はバンドルされているため、customer_ordershuman_resourcesがインストールできるサンプルになります。

サンプル・スキーマのGitHubリポジトリは以下になります。

https://github.com/oracle-samples/db-sample-schemas

今回はOracle AI Database 26ai Freeにサンプル・スキーマをインストールしてみます。PDBとしてFREEPDB1が作成済みで、このPDBにインストールします。

サンプル・スキーマのバージョン23.3のアーカイブをダウンロードします。

curl -OL https://github.com/oracle-samples/db-sample-schemas/archive/refs/tags/v23.3.zip

[oracle@localhost ~]$ curl -OL https://github.com/oracle-samples/db-sample-schemas/archive/refs/tags/v23.3.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0

100 11.6M    0 11.6M    0     0   872k      0 --:--:--  0:00:13 --:--:-- 2851k

[oracle@localhost ~]$ 


ダウンロードされたv23.3.zipを展開します。ディレクトリdb-sample-schemas-23.3が作成されます。

unzip v23.1.zip

[oracle@localhost ~]$ unzip v23.3.zip 

Archive:  v23.3.zip

e3325a83e56c516815844025418a96ecaf219751

   creating: db-sample-schemas-23.3/

 extracting: db-sample-schemas-23.3/.gitignore  

  inflating: db-sample-schemas-23.3/LICENSE.txt  

  inflating: db-sample-schemas-23.3/README.md  

  inflating: db-sample-schemas-23.3/README.txt  

  inflating: db-sample-schemas-23.3/SECURITY.md  

   creating: db-sample-schemas-23.3/customer_orders/

  inflating: db-sample-schemas-23.3/customer_orders/README.md  

 

[中略]


  inflating: db-sample-schemas-23.3/sales_history/sh_create.sql  

  inflating: db-sample-schemas-23.3/sales_history/sh_install.sql  

  inflating: db-sample-schemas-23.3/sales_history/sh_populate.sql  

  inflating: db-sample-schemas-23.3/sales_history/sh_uninstall.sql  

  inflating: db-sample-schemas-23.3/sales_history/supplementary_demographics.csv  

  inflating: db-sample-schemas-23.3/sales_history/times.csv  

[oracle@localhost ~]$ 


ディレクトリdb-sample-schemas-23.3に移動し、内容を確認します。

cd db-sample-schemas-23.3/
ls

[oracle@localhost ~]$ cd db-sample-schemas-23.3/

[oracle@localhost db-sample-schemas-23.3]$ ls

customer_orders  LICENSE.txt  product_media  README.txt     SECURITY.md

human_resources  order_entry  README.md      sales_history

[oracle@localhost db-sample-schemas-23.3]$ 


最初にcustomer_ordersをインストールします。ディレクトリcustomer_ordersに移動し、sqlplusでデータベースに接続してco_install.sqlを実行します。SYSDBAは不要になったので、system(Autonomous Databaseの場合はadmin)で作業ができるようになりました。

sqlplus system/<SYSTEMのパスワード>@localhost/freepdb1
@co_install

ユーザーCOに設定するパスワードと、ユーザーCOのデフォルト表領域を指定します。すでにユーザーCOが存在する場合に、上書きするかどうかを確認されます。

以上を指定するとユーザーCOが作成され、customer_ordersのサンプル・スキーマがインストールされます。

[oracle@localhost customer_orders]$ sqlplus system@localhost/freepdb1


SQL*Plus: Release 23.26.0.0.0 - Production on Mon Feb 2 14:09:09 2026

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


Enter password: ******

Last Successful login time: Fri Jan 30 2026 14:05:58 +09:00


Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> @co_install


Thank you for installing the Oracle Customer Orders Sample Schema.

This installation script will automatically exit your database session

at the end of the installation or if any error is encountered.

The entire installation will be logged into the 'co_install.log' log file.


Enter a password for the user CO: ******



Enter a tablespace for CO [USERS]: 

Do you want to overwrite the schema, if it already exists? [YES|no]: 

******  Creating CUSTOMERS table ....


Table created.


******  Creating STORES table ....


Table created.


******  Creating PRODUCTS table ....


Table created.


******  Creating ORDERS table ....


Table created.


[中略]


Installation

-------------

Verification:


Table         provided     actual

----------- ---------- ----------

customers          392        392

stores              23         23

products            46         46

orders            1950       1950

shipments         1892       1892

order_items       3914       3914

inventory          566        566


Thank you!

--------------------------------------------------------

The installation of the sample schema is now finished.

Please check the installation verification output above.


You will now be disconnected from the database.


Thank you for using Oracle Database!


Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0

[oracle@localhost customer_orders]$ 


customer_ordersのサンプルを削除するには、co_uninstall.sqlを実行します。ユーザーCOが、カスケード・オプション付きでドロップされます。

human_resourcesのインストール手順もほぼ同じです。ディレクトリhuman_resourcesに移動し、hr_install.sqlを実行します。スクリプトの実行にあたって確認される項目も同じです。

[oracle@localhost human_resources]$ sqlplus system@localhost/freepdb1


SQL*Plus: Release 23.26.0.0.0 - Production on Mon Feb 2 14:11:13 2026

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


Enter password: *******

Last Successful login time: Mon Feb 02 2026 14:09:11 +09:00


Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> @hr_install


Thank you for installing the Oracle Human Resources Sample Schema.

This installation script will automatically exit your database session

at the end of the installation or if any error is encountered.

The entire installation will be logged into the 'hr_install.log' log file.


Enter a password for the user HR: ******



Enter a tablespace for HR [USERS]: 

Do you want to overwrite the schema, if it already exists? [YES|no]: 

******  Creating REGIONS table ....


Table created.



Index created.



Table altered.


******  Creating COUNTRIES table ....


Table created.


[中略]


Installation

-------------

Verification:


Table         provided     actual

----------- ---------- ----------

regions              5          5

countries           25         25

departments         27         27

locations           23         23

employees          107        107

jobs                19         19

job_history         10         10


Thank you!

--------------------------------------------------------

The installation of the sample schema is now finished.

Please check the installation verification output above.


You will now be disconnected from the database.


Thank you for using Oracle Database!


Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0

[oracle@localhost human_resources]$ 


削除するには、hr_uninstall.sqlを実行します。ユーザーHRがカスケード・オプション付きで削除されます。

sales_historyも同じ手順です。インストールの際にはsh_install.sqlを実行します。アンインストールの場合は、sh_uninstall.sqlです。

[oracle@localhost sales_history]$ sqlplus system@localhost/freepdb1


SQL*Plus: Release 23.26.0.0.0 - Production on Mon Feb 2 14:13:45 2026

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


Enter password: ********

Last Successful login time: Mon Feb 02 2026 14:11:15 +09:00


Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> @sh_install


Thank you for installing the Oracle Sales History Sample Schema.

This installation script will automatically exit your database session

at the end of the installation or if any error is encountered.

The entire installation will be logged into the 'sh_install.log' log file.


Enter a password for the user SH: ********



Enter a tablespace for SH [USERS]: 

Do you want to overwrite the schema, if it already exists? [YES|no]: 


Start time: 02-FEB-26 02.13.56.589735 PM +09:00

******  Creating COUNTRIES table ....


Table created.


******  Creating CUSTOMERS table ....


Table created.


******  Creating PROMOTIONS table ....


Table created.


******  Creating PRODUCTS table ....


Table created.


[中略]


Installation

-------------

Verification:


Table                        provided     actual

-------------------------- ---------- ----------

channels                            5          5

costs                           82112          0

countries                          35         35

customers                       55500          0

products                           72         72

promotions                        503          0

sales                          918843          0

times                            1826          0

supplementary_demographics       4500          0


Thank you!

--------------------------------------------------------

The installation of the sample schema is now finished.

Please check the installation verification output above.


You will now be disconnected from the database.


Thank you for using Oracle Database!


Disconnected from Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0

[oracle@localhost sales_history]$ 


これらのサンプル・スキーマのインストール、アンインストールはとても容易になりました。

せっかくなので、order_entryproduct_mediaもインストールしてみます。これらのサンプル・スキーマはAutonomous Databaseにはインストールできません。

order_entryのREADMEにあるINSTALL_INSTRUCTIONSを見ると、以下のように記述されています。

## INSTALL INSTRUCTIONS

1. Run `perl -p -i.bak -e 's#__SUB__CWD__#'$(pwd)'#g' *.sql */*.sql */*.dat` in this folder

2. Connect as privileged user with rights to create another user (`SYSTEM`, `ADMIN`, etc.)

3. Run the `oe_main.sql` script passing on the following parameters:

    1. `OE` schema name password

    2. The tablespace name where to install the schema into

    3. The temporary tablespace name for the `OE` user

    4. The password of the `HR` user

    5. The `SYS` password

    6. The full path of this parent directory

    7. The full path of a directory where to write the install log file to

    8. The version number `3`

    9. The connect string for the database you connected to


**Note:** If the `OE` schema already exists, it is removed/dropped and 

        a fresh `OE` schema is installed.


最初に記載されている、以下のコマンドはthis folderで実行となっていますが、正確にはサンプル・スキーマが展開されたディレクトリです。今回の例ではdb-sample-schemas-23.3のディレクトリで実行します。また、このディレクトリには *.sql (*/*.sqlではない)のファイルは存在しないので、*.sqlの指定を除きます。この指定があると No such file or directory というエラーが発生しますが、一部のシェル(例えばzsh)ではエラーが発生すると文字列置換を実施しません。

perl -p -i.bak -e 's#__SUB__CWD__#'$(pwd)'#g' */*.sql */*.dat

[oracle@localhost db-sample-schemas-23.3]$ export PATH=$ORACLE_HOME/perl/bin:$PATH

[oracle@localhost db-sample-schemas-23.3]$ perl -p -i.bak -e 's#__SUB__CWD__#'$(pwd)'#g' */*.sql */*.dat

[oracle@localhost db-sample-schemas-23.3]$ 


ディレクトリorder_entryに移動し、インストール・スクリプトのoe_main.sqlを実行します。READMEに記載されているパラメータの説明には正しくないものがあります。

そのため、プロンプトの説明を参考にします。スクリプトはSYSで接続して実行します。

データ・ファイルの位置はoe_main.sqlがあるディレクトリです。READMEではthis parent directoryとなっている部分です。また、ログ・ファイルを書き出すディレクトリの指定の末尾に/が必要です。

[oracle@localhost order_entry]$ sqlplus sys@localhost/freepdb1 as sysdba


SQL*Plus: Release 23.26.0.0.0 - Production on Mon Feb 2 14:22:06 2026

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


Enter password: ********


Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> @oe_main


specify password for OE as parameter 1:

Enter value for 1: ******


specify default tablespeace for OE as parameter 2:

Enter value for 2: USERS


specify temporary tablespace for OE as parameter 3:

Enter value for 3: TEMP


specify password for HR as parameter 4:

Enter value for 4: ******


specify password for SYS as parameter 5:

Enter value for 5: ******


specify directory path for the data files as parameter 6:

Enter value for 6: /home/oracle/db-sample-schemas-23.3/order_entry/ 


writeable directory path for the log files as parameter 7:

Enter value for 7: /home/oracle/


specify version as parameter 8:

Enter value for 8: v3


specify connect string as parameter 9:

Enter value for 9: localhost/freepdb1


DROP USER oe CASCADE

          *

ERROR at line 1:

ORA-01918: user 'OE' does not exist

Help: https://docs.oracle.com/error-help/db/ora-01918/



old   1: CREATE USER oe IDENTIFIED BY &pass

new   1: CREATE USER oe IDENTIFIED BY oracle


User created.


old   1: ALTER USER oe DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs

new   1: ALTER USER oe DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS


User altered.


[中略]


Type body altered.



Type body altered.



PL/SQL procedure successfully completed.


Connected.


Synonym created.



Synonym created.



Synonym created.



Synonym created.



Synonym created.


SQL> 


order_entryを削除するには、drop user oe cascadeを実行します。

product_mediaのインストールは、おおむねorder_entryと同様です。

ディレクトリproduct_mediaに移動し、インストール・スクリプトpm_main.sqlを実行します。


[oracle@localhost product_media]$ sqlplus sys@localhost/freepdb1 as sysdba


SQL*Plus: Release 23.26.0.0.0 - Production on Mon Feb 2 14:27:29 2026

Version 23.26.0.0.0


Copyright (c) 1982, 2025, Oracle.  All rights reserved.


Enter password: ******


Connected to:

Oracle AI Database 26ai Free Release 23.26.0.0.0 - Develop, Learn, and Run for Free

Version 23.26.0.0.0


SQL> @pm_main


specify password for PM as parameter 1:

Enter value for 1: *****


specify default tablespeace for PM as parameter 2:

Enter value for 2: USERS


specify temporary tablespace for PM as parameter 3:

Enter value for 3: TEMP


specify password for OE as parameter 4:

Enter value for 4: oracle


specify password for SYS as parameter 5:

Enter value for 5: oracle


specify directory path for the PM data files as parameter 6:

Enter value for 6: /home/oracle/db-sample-schemas-23.3/product_media/


specify directory path for the PM load log files as parameter 7:

Enter value for 7: /home/oracle/


specify work directory path as parameter 8:

Enter value for 8: /home/oracle/db-sample-schemas-23.3/product_media/


specify connect string as parameter 9:

Enter value for 9: localhost/freepdb1


DROP USER pm CASCADE

          *

ERROR at line 1:

ORA-01918: user 'PM' does not exist

Help: https://docs.oracle.com/error-help/db/ora-01918/



old   1: CREATE USER pm IDENTIFIED BY &pass

new   1: CREATE USER pm IDENTIFIED BY oracle


User created.


old   1: ALTER USER pm DEFAULT TABLESPACE &tbs QUOTA UNLIMITED ON &tbs

new   1: ALTER USER pm DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS


User altered.


old   1: ALTER USER pm TEMPORARY TABLESPACE &ttbs

new   1: ALTER USER pm TEMPORARY TABLESPACE TEMP


User altered.

[中略]


Path used:      Conventional

Commit point reached - logical record count 15

Commit point reached - logical record count 16


Table PRINT_MEDIA:

  4 Rows successfully loaded.


Table TEXTDOCS_NESTEDTAB:

  12 Rows successfully loaded.


Check the log file:

  /home/oracle/pm_p_lob.log

for more information about the load.



PL/SQL procedure successfully completed.


SQL> 


product_mediaを削除するには、drop user pm cascadeを実行します。

今回の作業は以上になります。

Oracle APEXのアプリケーション作成の参考になれば幸いです。