你好,游客 登录 注册 搜索
背景:
阅读新闻

一段Oracle EBS中给指定用户增加指定职责的PLSQL脚本

[日期:2012-11-23] 来源:Linux社区  作者:t0nsha [字体:大 中 小]

2. Based on EBS R12.1/Oracle DB 11gR2

  1. DECLARE
  2. -- script to add user responsibility for R12.1/11gR2
  3. TYPE tab_user_list ISTABLEOF VARCHAR2 (100);
  4. TYPE arr_resp_list IS VARRAY (100) OF VARCHAR2 (100);
  5. -- user to be changed
  6. l_tab_user_list tab_user_list
  7. := tab_user_list ('LIAO'
  8. ,'KARL'
  9. ,'xx');
  10. -- responsibility to be added
  11. l_arr_resp_list arr_resp_list
  12. := arr_resp_list ('system Administrator'
  13. ,'Purchasing Super User'
  14. ,'Application Administrator');
  15. CURSOR cur_user (
  16. pc_username IN VARCHAR2)
  17. IS
  18. SELECT fu.user_id
  19. ,fu.user_name
  20. FROM fnd_user fu
  21. WHERE fu.user_name = pc_username
  22. AND TRUNC (SYSDATE) BETWEEN TRUNC (NVL (fu.start_date, SYSDATE))
  23. AND TRUNC (NVL (fu.end_date, SYSDATE));
  24. TYPE tab_user ISTABLEOF cur_user%ROWTYPE;
  25. l_tab_user tab_user;
  26. CURSOR cur_resp (
  27. pc_resp IN VARCHAR2)
  28. IS
  29. SELECT fa.application_id
  30. ,fa.application_short_name
  31. ,fr.responsibility_id
  32. ,fr.responsibility_name
  33. ,fr.responsibility_key
  34. ,fsg.security_group_key
  35. FROM fnd_application fa
  36. ,fnd_responsibility_vl fr
  37. ,fnd_security_groups fsg
  38. WHERELOWER (fr.responsibility_name) = LOWER (pc_resp)
  39. AND fa.application_id = fr.application_id
  40. AND fr.data_group_id = fsg.security_group_id;
  41. TYPE tab_resp ISTABLEOF cur_resp%ROWTYPE;
  42. l_tab_resp tab_resp;
  43. expt_no_user EXCEPTION;
  44. expt_no_resp EXCEPTION;
  45. l_expt_msg VARCHAR2 (2000);
  46. BEGIN
  47. --l_tab_user_list := tab_user_list ();
  48. IF (l_tab_user_list.COUNT = 0)
  49. THEN
  50. l_expt_msg := 'no user to change';
  51. RAISE expt_no_user;
  52. END IF;
  53. --l_arr_resp_list := arr_resp_list ();
  54. IF (l_arr_resp_list.COUNT = 0)
  55. THEN
  56. l_expt_msg := 'no resp to add';
  57. RAISE expt_no_resp;
  58. END IF;
  59. -- loop user
  60. <<loop_tab_user_list>>
  61. FOR idx_tab_user_list IN l_tab_user_list.FIRST .. l_tab_user_list.LAST
  62. LOOP
  63. DBMS_OUTPUT.put_line (
  64. '>>> '
  65. || idx_tab_user_list
  66. || ' , working for user ('
  67. || l_tab_user_list (idx_tab_user_list)
  68. || ') <<< ');
  69. -- check if user exist or active
  70. OPEN cur_user (l_tab_user_list (idx_tab_user_list));
  71. FETCH cur_user
  72. BULK COLLECT INTO l_tab_user;
  73. CLOSE cur_user;
  74. IF (l_tab_user.COUNT = 0)
  75. THEN
  76. DBMS_OUTPUT.put_line (
  77. 'user ('
  78. || l_tab_user_list (idx_tab_user_list)
  79. || ') is not exist or disabled');
  80. CONTINUE loop_tab_user_list;
  81. END IF;
  82. -- loop responsibility
  83. <<loop_arr_resp_list>>
  84. FOR idx_arr_resp_list IN l_arr_resp_list.FIRST .. l_arr_resp_list.LAST
  85. LOOP
  86. -- check if responsibility active
  87. OPEN cur_resp (l_arr_resp_list (idx_arr_resp_list));
  88. FETCH cur_resp
  89. BULK COLLECT INTO l_tab_resp;
  90. CLOSE cur_resp;
  91. IF (l_tab_resp.COUNT = 0)
  92. THEN
  93. DBMS_OUTPUT.put_line (
  94. 'resp ('
  95. || l_arr_resp_list (idx_arr_resp_list)
  96. || ') is not exist or disabled');
  97. CONTINUE loop_arr_resp_list;
  98. END IF;
  99. -- add resp for user
  100. DBMS_OUTPUT.put_line (
  101. 'Adding resp ('
  102. || l_arr_resp_list (idx_arr_resp_list)
  103. || ') for user ('
  104. || l_tab_user_list (idx_tab_user_list)
  105. || ')');
  106. fnd_user_pkg.addresp (
  107. username => l_tab_user_list (idx_tab_user_list)
  108. ,resp_app => l_tab_resp (1).application_short_name
  109. ,resp_key => l_tab_resp (1).responsibility_key
  110. ,security_group => l_tab_resp (1).security_group_key
  111. ,description => NULL
  112. ,start_date => TRUNC (SYSDATE)
  113. ,end_date => NULL);
  114. END LOOP loop_arr_resp_list;
  115. END LOOP loop_tab_user_list;
  116. COMMIT;
  117. EXCEPTION
  118. WHEN expt_no_user
  119. THEN
  120. DBMS_OUTPUT.put_line (l_expt_msg);
  121. ROLLBACK;
  122. WHEN expt_no_resp
  123. THEN
  124. DBMS_OUTPUT.put_line (l_expt_msg);
  125. ROLLBACK;
  126. END;
  127. /*
  128. >>> 1 , working foruser (LIAO) <<<
  129. Adding resp (system Administrator) foruser (LIAO)
  130. Adding resp (Purchasing Super User) foruser (LIAO)
  131. resp (Application Administrator) isnot exist or disabled
  132. >>> 2 , working foruser (KARL) <<<
  133. Adding resp (system Administrator) foruser (KARL)
  134. Adding resp (Purchasing Super User) foruser (KARL)
  135. resp (Application Administrator) isnot exist or disabled
  136. >>> 3 , working foruser (xx) <<<
  137. user (xx) isnot exist or disabled
  138. */
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款