2011/06/07

ログインユーザの取得 (Display the login user ID)

BI PublisherにログインしているユーザのIDを取得する方法について説明します。過去に数回、OTNで取り上げられています。
http://forums.oracle.com/forums/thread.jspa?threadID=1773888

ユーザIDおよびその他の情報の取得方法について、ここで整理します。

【SQLで指定する方法】
既存のSQLにxdo_user_nameを埋め込むことで取得できます。以下の例では、ログインユーザのIDで部門(deptno)を特定し、ユーザの所属する部門のデータのみを出力する様、制限をかけています。
select * from emp where deptno = (select deptno from emp where empno = :xdo_user_name)

主となるデータソースがSQLでない場合、以下のSQLを別途データセットに定義します。
select :xdo_user_name as user_id from dual
Figure 1: data source for 'xdo_user_name'


その後、作成したデータセットを以下の様に本体のデータソースと結合します。以下の例では、エクセルのデータと結合を行い、ログインしたユーザのIDがEMPNOと合致するレコードだけを抽出します。
Figure 2: data source join


なお、ユーザID以外にも以下の項目を取得することができます。
  • xdo_user_roles
  • xdo_user_report_oracle_lang
  • xdo_user_report_locale
  • xdo_user_ui_oracle_lang
  • xdo_user_ui_locale


以下のブログも併せて参照して下さい。
http://blogs.oracle.com/xmlpublisher/entry/who_is_on_first_but_what_langu



[Summary]
xdo_user_name provides current user name. The SQL below shows the record which belongs to the same deptno with current user.
select * from emp where deptno = (select deptno from emp where empno = :xdo_user_name)


In case when your data source is not SQL, you can join the following SQL with your data source (Figure 1 and Figure 2).
select :xdo_user_name as user_id from dual

Also, the following items are available.
  • xdo_user_roles
  • xdo_user_report_oracle_lang
  • xdo_user_report_locale
  • xdo_user_ui_oracle_lang
  • xdo_user_ui_locale
For details, please refer to the following links:

0 件のコメント:

コメントを投稿