サンプルスキーマ(HR)を準備する
このページでは、サンプルスキーマ(HR)のダウンロード・インストール手順を解説します。
- サンプルスキーマ(HR)を作成する
サンプルスキーマのダウンロード
Section titled “サンプルスキーマのダウンロード”このデモではサンプルデータとしてHRスキーマ使用します。
サンプルスキーマは、GitHubで公開されているこちらのリンクよりファイルをダウンロードします。 なお、ここではoralleユーザーで実行しています。
GitHubレポジトリ:https://github.com/oracle-samples/db-sample-schemas
wget https://github.com/oracle-samples/db-sample-schemas/archive/refs/tags/v23.3.zipunzip v23.3.zip解凍後、db-sample-schemas-23.3/human_resources/hr_install.sql を実行しますので、お手元の環境に合わせてファイル名とパスを確認してください。
サンプルスキーマの詳細についてはこちらをご参照ください。
サンプルスキーマを作成する
Section titled “サンプルスキーマを作成する”HRスキーマを作成するために、まずDBに接続します。
-- PDBにSYSユーザーで接続[oracle@db-tut ~]$ sql sys/<password>@localhost:1521/freepdb1 as sysdba
-- 現在のコンテナとユーザー名を確認SQL> show con_name userCON_NAME------------------------------FREEPDB1USER is "SYS"続いて、先ほどダウンロードした db-sample-schemas-23.3/human_resources/hr_install.sql を実行します。
@/home/oracle/db-sample-schemas-23.3/human_resources/hr_install.sqlインストールが開始され、パスワードの入力を求められますので、HRユーザーのパスワードを入力します。
SQL> @/home/oracle/db-sample-schemas-23.3/human_resources/hr_install.sql
Thank you for installing the Oracle Human Resources Sample Schema.This installation script will automatically exit your database sessionat 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: ******************
USERSEnter a tablespace for HR [USERS]: <そのままEnter>Do you want to overwrite the schema, if it already exists? [YES|no]: <YESまたはYを入力>****** Creating REGIONS table ....
Table REGIONS created.
INDEX REG_ID_PK created.
Table REGIONS altered.
****** Creating COUNTRIES table ....
Table COUNTRIES created....Commit complete.
Installation verification____________________________Verification:
Table provided actual______________ ___________ _________regions 5 5countries 25 25departments 27 27locations 23 23employees 107 107jobs 19 19job_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.1.0.0 - Develop, Learn, and Run for FreeVersion 23.26.1.0.0インストールが完了後、結果にも表示がありますが、HRスキーマが正しく作成されていることを確認します。
select table_name from all_tables where owner = 'HR';結果は以下のようになります。
SQL> select table_name from all_tables where owner = 'HR';
TABLE_NAME______________COUNTRIESREGIONSLOCATIONSDEPARTMENTSJOBSEMPLOYEESJOB_HISTORY
7 rows selected.また、参考までですが、スキーマの構成は以下のようになっています。
