APEX環境の作成
git clone https://github.com/ujnak/apex-podman-setup.git
% git clone https://github.com/ujnak/apex-podman-setup.git
Cloning into 'apex-podman-setup'...
remote: Enumerating objects: 363, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 363 (delta 6), reused 0 (delta 0), pack-reused 348 (from 2)
Receiving objects: 100% (363/363), 103.60 KiB | 639.00 KiB/s, done.
Resolving deltas: 100% (200/200), done.
%
apex-podman-setup % sh config_apex.sh <SYSのパスワード> <APEX管理者パスワード>
% cd apex-podman-setup
apex-podman-setup % sh config_apex.sh <SYSPassword> <APEXPassword>
Trying to pull container-registry.oracle.com/database/free:latest...
Getting image source signatures
Copying blob sha256:3c19df83dc536c431f1f991013d53f88157d03afed4452c014b3a0deb32add62
Copying blob sha256:769e9048b21fc9ec5c1af97cb44cf1298993838fee496c6a6cf471cbd9656e0c
Copying blob sha256:7ce287ddcf023475b16b98c11a145816110e4870844f6008eb11fc12cb98bc13
Copying blob sha256:fb5a2405efd168f49f8b9ef5d65df63abcc4e71805762287ea271ca04152c917
Copying blob sha256:60b151ee286ca7b9cf8876c091384ce0e3f46f723f383b74d573f5f3c8a83181
Copying blob sha256:67273d20686cb6adc472d07c54f5b2ecacab066d73d41b419e64be5141d9c063
Copying blob sha256:18c61db4fa1af28adfb01c770f0c8d8e367ca55026f565bbb2f604fb983b223d
[中略]
ORDS: Release 25.2 Production on Fri Jul 04 07:19:48 2025
Copyright (c) 2010, 2025, Oracle.
Configuration:
/etc/ords/config
The global setting named: standalone.static.path was set to: /opt/oracle/apex/images
apex
apex
ynakakoshi@nsmacbookintel apex-podman-setup %
apex-podman-setup % mkdir oml
apex-podman-setup %
https://docs.oracle.com/en/database/oracle/machine-learning/oml4py/2-23ai/mlpug/install-oml4py-client-linux-premises-databases.html
apex-podman-setup % ls oml/
Python-3.12.6.tgz V1048628-01.zip
apex-podman-setup %
podman exec apex-db ./work/config_oml4py.sh
apex-podman-setup % podman exec apex-db sh ./work/config_oml4py.sh
Oracle Linux 8 BaseOS Latest (x86_64) 4.6 MB/s | 102 MB 00:21
Oracle Linux 8 Application Stream (x86_64) 3.5 MB/s | 72 MB 00:20
Oracle Linux 8 Development Packages (x86_64) 3.6 MB/s | 216 MB 01:00
Last metadata expiration check: 0:00:59 ago on Fri Jul 4 07:37:54 2025.
Package openssl-1:1.1.1k-14.el8_6.x86_64 is already installed.
Dependencies resolved.
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
bzip2-devel x86_64 1.0.6-28.el8_10 ol8_baseos_latest 224 k
[中略]
Oracle Machine Learning for Python 2.1 Client.
Copyright (c) 2018, 2025 Oracle and/or its affiliates. All rights reserved.
Checking platform .................. Pass
Checking Python .................... Pass
Checking dependencies .............. Pass
Checking OML4P version ............. Pass
Current configuration
Python Version ................... 3.12.6
PYTHONHOME ....................... /home/oracle/python
Existing OML4P module version .... 2.1
Operation ........................ Install/Upgrade
Found existing installation: oml 2.1
Uninstalling oml-2.1:
Successfully uninstalled oml-2.1
Processing ./client/oml-2.1-cp312-cp312-linux_x86_64.whl
Installing collected packages: oml
Successfully installed oml-2.1
Done
apex-podman-setup %
OML4Rの環境を構成します。以下のリンク先よりOML4Rのサポート・パッケージを含むアーカイブoml4r-supporting-linux-x86-64-2.0.zipをダウンロードし、ディレクトリomlの下に配置します。
https://www.oracle.com/database/technologies/oml4r-downloads.html
ディレクトリoml以下に、これらのファイルが配置されている状態です。
apex-podman-setup % ls oml
oml4r-supporting-linux-x86-64-2.0.zip V1048628-01.zip
Python-3.12.6.tgz
apex-podman-setup %
OML4Pyと同様に、OML4Rの構成スクリプトconfig_oml4r.shを、データベースのコンテナで実行します。
podman exec apex-db ./work/config_oml4r.sh
apex-podman-setup % podman exec apex-db sh ./work/config_oml4r.sh
Oracle Linux 8 BaseOS Latest (x86_64) 37 kB/s | 4.3 kB 00:00
Oracle Linux 8 Application Stream (x86_64) 93 kB/s | 4.5 kB 00:00
Oracle Linux 8 CodeReady Builder (x86_64) - Uns 5.6 MB/s | 13 MB 00:02
Oracle Linux 8 Addons (x86_64) 5.4 MB/s | 39 MB 00:07
Dependencies resolved.
======================================================================================================================
Package Arch Version Repository Size
======================================================================================================================
Installing:
R x86_64 4.0.5-1.0.1.el8 ol8_addons 21 k
cairo-devel x86_64 1.15.12-6.el8 ol8_appstream 273 k
Installing dependencies:
R-core x86_64 4.0.5-1.0.1.el8 ol8_addons 59 M
R-devel x86_64 4.0.5-1.0.1.el8 ol8_addons 102 k
adobe-mappings-cmap noarch 20171205-3.el8 ol8_appstream 2.1 M
adobe-mappings-cmap-deprecated noarch 20171205-3.el8 ol8_appstream 118 k
[中略]
* installing *binary* package 'statmod' ...
* DONE (statmod)
* installing *binary* package 'tibble' ...
* DONE (tibble)
* installing *binary* package 'tidyselect' ...
* DONE (tidyselect)
* installing *binary* package 'utf8' ...
* DONE (utf8)
* installing *binary* package 'vctrs' ...
* DONE (vctrs)
Making 'packages.html' ... done
apex-podman-setup %
以上で、OML4PyとOML4Rの構成が完了しました。
sql sys/[SYSのパスワード]@localhost/freepdb1 as sysdba
apex-podman-setup % sql sys/[SYSのパスワード]@localhost/freepdb1 as sysdba
SQLcl: 金 7月 04 17:29:00 2025のリリース25.1 Production
Copyright (c) 1982, 2025, Oracle. All rights reserved.
接続先:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
SQL>
APEXのワークスペースとそれに紐づくスキーマおよびワークスペースの管理者ユーザーを作成します。
SQL> @create_workspace APEXDEV ADMIN <パスワード> <メールアドレス>
SQL>
SQL> define WKSPNAME = &1
SQL> define ADMINNAME = &2
SQL> define ADMINPASS = &3
SQL> define ADMINMAIL = &4
SQL>
SQL> -- create default parsing shema for worksapce.
SQL> @create_schema WKSP_&WKSPNAME
SQL> set echo on
SQL>
SQL> define SCHEMA = &1
SQL>
SQL> -- create database user for apex parsing sdchema on Oracle Database Free
SQL> create user if not exists &SCHEMA default tablespace users temporary tablespace temp quota unlimited on users;
旧:create user if not exists &SCHEMA default tablespace users temporary tablespace temp quota unlimited on users
新:create user if not exists WKSP_APEXDEV default tablespace users temporary tablespace temp quota unlimited on users
User WKSP_APEXDEVは作成されました。
[中略]
PL/SQLプロシージャが正常に完了しました。
SQL>
SQL> commit;
コミットが完了しました。
SQL> exit
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04から切断されました
apex-podman-setup %
以上でAPEXのワークスペースとそれに紐づくスキーマが作成されました。再度データベースにSYSで接続し、スキーマにOML4PyとOML4Rの処理に必要な権限とロールを与えます。
grant create mining model to <スキーマ名>;
grant db_developer_role, pyqadmin, rqadmin to <スキーマ名>;
grant execute on ctx_ddl to <スキーマ名>;
apex-podman-setup % sql sys/********@localhost/freepdb1 as sysdba
SQLcl: 金 7月 04 17:36:58 2025のリリース25.1 Production
Copyright (c) 1982, 2025, Oracle. All rights reserved.
接続先:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04
SQL> grant create mining model to wksp_apexdev;
Grantが正常に実行されました。
SQL> grant db_developer_role, pyqadmin, rqadmin to wksp_apexdev;
Grantが正常に実行されました。
SQL> grant execute on ctx_ddl to wksp_apexdev;
Grantが正常に実行されました。
SQL> exit
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.8.0.25.04から切断されました
ynakakoshi@nsmacbookintel apex-podman-setup %
以上で準備は完了です。
APEXアプリケーションの作成
declare
l_script clob;
begin
l_script := :P3_SCRIPT;
l_script := replace(:P3_SCRIPT, CHR(13)||CHR(10),CHR(10)); -- remove CR
sys.pyqScriptCreate(
v_name => :P3_NAME,
v_script => l_script,
v_global => false,
v_overwrite => ( :REQUEST = 'SAVE' )
);
end;
begin
sys.pyqScriptDrop(
v_name => :P3_NAME,
v_global => false,
v_silent => false
);
end;
Name: pyqFun1
Script:
func = lambda: "Hello World from a lambda!"
ボタン作成をクリックします。SELECT name, value
FROM table(pyqEval(
NULL,
'XML',
'pyqFun1'));
最初にExample 13-17 Using the pyqEval Functionを実行します。PythonスクリプトpyqFun1はすでに作成済みです。
PythonスクリプトmyLinearRegressionModelを作成します。このファンクションは、scikit-learnの線形回帰モデルを訓練し、そのモデルをOMLのデータストアに保存します。
Pythonスクリプトsample_iris_tableを作成します。このファンクションは、Irisデータセットを読み込んで整形し、指定した数だけランダムにサンプリングして返します。
Example 13-20 Using the pyqGroupEval Functionの例を実行します。