2013年10月16日水曜日

Oracle APEX - send email to multiple admin accounts / 複数の管理者にメールを送る

English Follows Japanese

入力フォームでCreateボタンが押されてDBへのデータ挿入が終わった後に、複数のアプリケーション管理者にメールを送信する。
また、前提条件としてアプリのUser名はメールアドレスとする

1) 複数の管理者メールアドレスをフォームのHidden項目に入れる
  Hidden項目を作成し(P15_MAIL_TO)、以下のようにSourceを編集
  
  ##Source Valueは以下のSQL
    select ADMIN_USERNAME
    from APEX_ACCESS_CONTROL, APEX_ACCESS_SETUP
    where
    APEX_ACCESS_SETUP.ID = APEX_ACCESS_CONTROL.SETUP_ID and
    APEX_ACCESS_SETUP.APPLICATION_ID = v('APP_ID') and
    ADMIN_PRIVILEGES = 'ADMIN'
  ##SQLの結果ではメールアドレスがコロンで区切られるのでPost Calculationでコロンをカンマに置き換えておく
    REPLACE(:P15_MAIL_TO,':',',')

2) 入力フォーム編集画面で新規プロセスを作成する
  
  
##ToにP15_MAIL_TOのHidden項目を指定する
  もちろんこのプロセスのConditionはCreateボタンを押した際に設定しておく
  
  

--------------------------
   
In this case, new email will be sent to multiple admin accounts after page submit for creation of new data on a form. The user name of admin accounts should be email addresses.


1) create new hidden box on the form for storing multiple email addresses
    I have created P15_MAIL_TO as a hidden box with the following setup.
  
  ##SQL query for obtaining colon separated email addresses from APEX_ACCESS records
    select ADMIN_USERNAME
    from APEX_ACCESS_CONTROL, APEX_ACCESS_SETUP
    where
    APEX_ACCESS_SETUP.ID = APEX_ACCESS_CONTROL.SETUP_ID and
    APEX_ACCESS_SETUP.APPLICATION_ID = v('APP_ID') and
    ADMIN_PRIVILEGES = 'ADMIN'
  ##You need to replace colons to comma for email setting
    REPLACE(:P15_MAIL_TO,':',',')

2) create new process on the page editor
  
  
##The value of "To" should be the value of P15_MAIL_TO
  
  



















  

2013年9月30日月曜日

Oracle APEX - Multiple Active Reports/Tabular Forms on one APEX page / アクティブレポートやタービュラーフォームを1ページに表示する

English Follows Japanese
通常、APEXでは1ページに複数のアクティブレポートやタービュラーフォームを表示することは出来ません。
ですので、通常のHTML作成と同じようにiFrameやDivやEmbed Objectタグを使用します。

以下では、Page1にアクティブレポートまたはタービュラーフォームを複数表示させるタブを作成します。

1) ページ1に表示させたいページ2を作成する

2) ページ2のページ編集でページテンプレートを"ポップアップ"にする

3) 共有コンポーネント > セキュリティ属性 > ブラウザ・セキュリティに行き、フレームへの組み込みを”許可”にします

4) ページ1で以下のようなHTMLのリージョンを作成します。

 DIVを使用する場合:
 <br/><div id="testdiv"></div>
 <script type="text/javascript">
 $('#testdiv').load('f?p=&APP_ID.:2:&SESSION.');
 </script>

 Embed Objectを使用する場合:
 <object data="f?p=&APP_ID.:2:&SESSION." width="100%" height="100%">
  <embed src="f?p=&APP_ID.:2:&SESSION." width="100%" height="100%"> </embed>
  Error: Embedded data could not be displayed.
 </object>

 iFrameを使用する場合:
 <IFRAME src="f?p=&APP_ID.:2:&SESSION."
  name="reportframe" id ="reportframe"
  style="width:120%;height:120%"
 scrolling="auto" />

 ##注意!DIVでは値の更新は不可能です。iFrameはIEがうまく動作しないなどあるので私はObjectを使用しました。
参考URL(英語): http://roelhartman.blogspot.jp/2009/03/two-interactive-reports-on-one-page.html


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

iFrame/Div/Embed Object is very useful to show multipul Active Reports or Tabular Forms on one APEX page.

The below is to show Active Reports/Tabular Form(Page 2) on Page 1

1) Create page 2 you want to show on page 1

2) on page 2, change Page Template to "Popup"

3) Shared Component > Security Attribute > Browser Security, set Embed in Frame to "Allow"

4) on Page 1, create a HTML Region and set the source as followings

For DIV Setting:
<br/><div id="testdiv"></div>
<script type="text/javascript">
$('#testdiv').load('f?p=&APP_ID.:2:&SESSION.');
</script>

For Embed Object Setting:
<object data="f?p=&APP_ID.:2:&SESSION." width="100%" height="100%">
<embed src="f?p=&APP_ID.:2:&SESSION." width="100%" height="100%"> </embed>
Error: Embedded data could not be displayed.
</object>

For iFrame Setting:
<IFRAME src="f?p=&APP_ID.:2:&SESSION."
name="reportframe" id ="reportframe"
style="width:120%;height:120%"
scrolling="auto" />

##Note that a user cannot update records on tabular forms with DIV tag. In addtion IE has always some trouble with iFrame so for me, object tag is the best choice.

Reference: http://roelhartman.blogspot.jp/2009/03/two-interactive-reports-on-one-page.html

2013年9月27日金曜日

Oracle APEX - Using Application Value in Scripts/ Script内でApplicationが保持している値を使用する

English Follows Japanese

Java Scriptでアプリケーションで保持している値を使用する場合
セッション値:'&APP_USER.'
HTMLのItemのValue: $v('XXXXXX')


SQLでアプリケーションで保持している値を使用する場合
セッション値:v('APP_USER')
HTMLのItemのValue: :XXXXX

-------------------------------------------
  
in Java Script
Session Values:'&APP_USER.'
HTML Item Value: $v('XXXXXX')


in SQL script
Session Value:v('APP_USER')
HTML Item Value: :XXXXX

Oracle APEX - APEX Evangelist Blog

Oracle Database 11g/12c Tips - Set password life time unlimited/ パスワード有効期限を無期限にする

English Follows Japanese

- ユーザのステータスをチェック
select * from dba_profiles;

- パスワードの有効期限を無期限にする
alter profile default limit password_life_time unlimited;

- パスワードのリセット
alter user [user] identified by [new password];

- ユーザロックの解除
alter user [user] account unlock;

---------------------------------------------
- check user status
select * from dba_profiles;

- set password life time unlimited
alter profile default limit password_life_time unlimited;

- reset password
alter user [user] identified by [new password];

- set user unlock
alter user [user] account unlock;

2013年9月25日水曜日

Oracle Database 12c Tips - Configure APEX / APEXを構成する

English Follows Japanese 

Oracle Database 12cにはデフォルトでAPEX(Oracle Application Express)がインストールされている。

APEXを構成し、使用可能にしてみる。
##なお、以下の設定ではOracle APEXリスナーやOracle HTTPサーバを使用せず、DBにEmbeddedされているPL/SQL Gatewayを使用する構成となる。

1)コマンドラインでORACLE_HOME\APEXフォルダに移動

2)SQLPLUSでプラガブルDBに接続
  ・直接接続
    sqlplus sys/****@pdborcl as sysdba
  ・コンテナDB経由で接続
    sqlplus sys/**** as sysdba
    alter session set container = pdborcl;
     ##接続しているDB名の確認
     show con_name
     ####パラメータのDB_nameはコンテナDBもプラガブルDBも同一(コンテナDBの名前)になるのでDB_nameでの接続籍確認は不可

3)APEX構成スクリプトを実行
   @apxconf
    ##XDB HTTP Listner portはデフォルトの8080に指定
    ##Apex ADMINのパスワードは大文字1文字以上、数字1文字以上、記号1文字以上を含むこと
4)コンテナDBに接続しANONYMOUSアカウントをUNLOCKする
  alter user ANONYMOUS account unlock;

5)APEXCoreEngineユーザへのConnect権限を追加
  プラガブルDBへSYSDBAで接続
  以下のページの4.5.3.1 Granting Connect Privilegesに記載されている2つのスクリプトをコピペして実行
    http://st-doc.us.oracle.com/12/121/install.121/e17958/db_install.htm#HTMIG214

6)APEXのAdmin専用Pageへ接続
  http://hostname:port/apex/apex_admin
  User:ADMIN
  Password:上記のStep3で設定したPassword
  ##このADMIN専用ページはWorkspace名:INTERNAL

7)APEX Admin PageでUserのWorkspaceを作成

---これで構築は終了

おまけ)プラガブルDBのEM ExpressのPort番号を再設定
  exec DBMS_XDB_CONFIG.SETHTTPSPORT(5510)
  ##なぜかStep3の設定以降EM Expressへの接続が不可になったので再設定

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

APEX(Oracle Application Express) will be installed when installing Oracle Database 12c.

You can only configure to enable APEX on your DB

##The following is the way to use PL/SQL Gateway, embedded in DB, instead of Oracle APEX Listner or Oracle HTTP Server.
##My case is having one pluggable DB on one container DB.
##Container DB name : orcl
##Pluggable DB name : pdborcl

1)on command prompt, change your working directry to ORACLE_HOME\APEX

2)connect a pluggable DB through SQLPLUS as sysdba
  ・Direct connection
    sqlplus sys/****@pdborcl as sysdba
  ・Through the container DB
    sqlplus sys/**** as sysdba
    alter session set container = pdborcl;
     ##Confirm the db name you have made a connection
     show con_name
     ####You cannot ensure the DB name with DB parameter:DB_name, as the both have the same value for the parameter: this case, orcl

3)run APEX configuration script
   @apxconf
    ##XDB HTTP Listner port: 8080
    ##Apex ADMIN password requires one capital letter, one numeric character and one symbol letter(!$%#&, etc..)

4)on container DB, unlock ANONYMOUS account
  alter user ANONYMOUS account unlock;

5)on pluggable DB, Add connect privilege to APEXCoreEngine user
  copy and paste the two scripts from [4.5.3.1 Granting Connect Privileges] on the following URL
    http://st-doc.us.oraclele .com/12/121/install.121/e17958/db_install.htm#HTMIG214

6)go to APEX Admin Page
  http://hostname:port/apex/apex_admin
  User:ADMIN
  Password:teh password you have set on the Step3
  ##The Admin Page is also one APEX application -> Workspace name:INTERNAL

7)create new workspace on APEX Admin Page


Note: If you have configured EM Express for the pluggable DB, you might now face the issue you cannot access to the page. Here is the solution.
  Solution: re-set EX Express Port number on the pluggable DB
            exec DBMS_XDB_CONFIG.SETHTTPSPORT(5510)

2013年9月24日火曜日

Oracle Database 12c Tips - Configure EM for Pluggable Database/ Pluggable DatabaseにEM Expressを構成する

English follows Japanese:

Oracle Database 12c ではコンテナDBと一緒にPDBを作成するとコンテナDBにしかEMが自動構成されない。

なので、プラガブルDBに手動でEM Expressを構成する。

1) OS上でEM Expressに使用するポートが空いていることを確認する。
netstat –an | grep 5510
何もかえってこなければ現在使用されていないのでOK。
現在使用されているようであれば、5511とか使用されていないことが確認できたポートを使用することにする。

2) SYSDBA権限でプラガブルDBへ接続

3) EM Express用のHTTPsポートを指定
exec DBMS_XDB_CONFIG.SETHTTPSPORT(5510)

4) XDBユーザのパスワードを再設定
##EM ExpressではXDBディスパッチャを使用しWebアプリとしてのEM Expressを提供している。
##PDBにEM Expressを設定するとXDBのパスワードを再設定する必要がある。
   4-1) SYSDBA権限でコンテナDBへ接続
   4-2) select username,account_status from dba_users;でLOCKされているかEXPIREされているか確認
   4-3) alter user XDB account unlock identified by ******;で再設定

5) EM Expressへアクセス
https://localhost:5510/em

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

When created a pluggable DB with a container DB with DBCA, a EM Express has been configured for only the container DB.

The following is to configure EM Express for the pluggable DB

1) make sure the port you want to set for EM Express is not occupied
#for instance, I have used 5510 port
netstat –an | grep 5510
No reply means your machine is not using the port.
If the port has already used for some other application, you need to change the port like 5511...

2) Login to the pluggable DB as sysdba

3) set the port number to EM Express
exec DBMS_XDB_CONFIG.SETHTTPSPORT(5510)

4) reconfigure the password for XDB user on the container DB
##EM Express uses XML DB dispatcher as HTML/HTTP dispatcher for EM Express
##You need to set new password for XML DB user(XDB)
   4-1) login to the container DB as SYSDBA
   4-2) confirm if XDB user has not been locked nor expired.
         select username,account_status from dba_users;
   4-3) alter user XDB account unlock identified by ******;

5) Access to the EM Express for the pluggable DB
https://localhost:5510/em
##if the site required XDB user id and password, enter XDB and the password you have set.

2013年9月10日火曜日

Oracle Database 12c Tips - direct access to pluggable database/プラガブルデータベースに直接アクセス

English follows Japanese:

tnsnames.oraに以下を追加

PDBORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PDBORCL.localdomain)
    )
  )

これでSQLPLUSで直接接続できる。
sqlplus /nolog
conn system@PDBORCL


##注意点:SQL Developerではなぜかこの方法ではSIDでは接続できなかった。
なのでサービス名を指定した。サービス名はグローバルDB名だった。
プラガブルDBのグローバルDB名はコンテナDBのdb_domain名が後ろにつく。

例)
コンテナDBのGlobalDB名: cdb.oracle.com
プラガブルDB名: pdb1
SQL Developer接続時に入れるサービス名:pdb1.oracle.com


##Tips:接続先の確かめ方を簡略化
つなげた先がコンテナDBなのかプラガブルDB確かめるには
show con_name
というコマンドを実行しなければならないのが面倒なので、
[ORACLE_HOME]\sqlplus\admin\glogin.sqlに以下を追加。

   set sqlp "_USER'@'_CONNECT_IDENTIFIER> "

そうすると、SQLPLUSで接続した後に通常SQL>と表示されるところに以下のように記載される。
   時間 接続ユーザ名@接続先DB名
   例)18:21:48 SYSTEM@pdborcl
なので接続先がいつもわかって便利。

参照先:http://discus-hamburg.cocolog-nifty.com/mac_de_oracle/2013/07/oracle-database.html
---------------------------------------

Adding following in tnsnames.ora
ex) Container DB global name = ORCL.localdomain
    Pluggable DB = PDBORCL
PDBORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PDBORCL.localdomain)
    )
  )

Then you can access the pluggable Database Directory
sqlplus /nolog
conn system@PDBORCL

##For accessing Pluggable DB from SQL Developer, the above setting is not enough
You need to access with not SID but service name:PDBORCL.localdomain

Reference: http://discus-hamburg.cocolog-nifty.com/mac_de_oracle/2013/07/oracle-database.html

## Ensure which DB you have accessed
The simple way is to run the following command in SQLPLUS
show con_name

Here is the way you can always ensure where you are accessing.
Just add the following in [ORACLE_HOME]\sqlplus\admin\glogin.sql file.

   set sqlp "_USER'@'_CONNECT_IDENTIFIER> "

Next time you connect DB though SQLPLUS, you will see the following
   ex)18:21:48 SYSTEM@pdborcl
    which means you have made the connection to pdborcl instance as system user at 18:21:48.

Oracle Database 12c Tips - Open pluggable database/プラガブルデータベースをOpenする

English -> http://blog.contractoracle.com/2013/06/oracle-12c-need-to-start-container-and.html

以下の前提条件:
DBインストール時に以下のインスタンスを作成
 コンテナDB名:orcl
 プラガブルDB名:pdborcl

以下に3つの方法を記す
[方法1]コンテナDBから手動Open
[方法2]コンテナDBからプラガブルDBへ移動し手動Open
[方法3]コンテナStartup時に自動的にStartupするようにする

[方法1]コンテナDBから手動Open
1) コンテナDBに接続
    sqlplus /nolog
    conn sys as sysdba
    startup
2) プラガブルDBの状態確認
    select name, open_mode from v$pdbs;
    ##自動Openになってない場合(デフォルト)はMOUNT状態になっている
3) プラガブルDBのOpen
    alter pluggable database pdborcl open;
または
alter pluggable database all open;

[方法2]コンテナDBからプラガブルDBへ移動し手動Open
1) コンテナDBに接続
    sqlplus /nolog
    conn sys as sysdba
    startup
2) プラガブルDBの状態確認
    select name, open_mode from v$pdbs;
    ##自動Openになってない場合(デフォルト)はMOUNT状態になっている
3) プラガブルDBへ移動
    alter session set container=pdborcl;
4) 接続先のDBの名前の確認
    show con_name
    ##プラガブルDB名が表示される
5) プラガブルDBのStart
    shutsown;
startup;

[方法3]コンテナStartup時に自動的にStartupするようにする
1) コンテナDBに接続
    sqlplus /nolog
    conn sys as sysdba
    startup
2) トリガーを作成する
     create or replace trigger Sys.After_Startup
                          after startup on database
     begin
        execute immediate 'alter pluggable database all open';
     end;
     /
3) トリガーの確認
    shutdown immediate;
    startup
    select name, open_mode from v$pdbs;
##pdborclがREAD WRITEになっていることを確認

参照先:http://blog.contractoracle.com/2013/06/oracle-12c-need-to-start-container-and.html