Tuesday, 31 March 2020

Query to get the profile option values from backend

 select fpo.profile_option_id 
       ,fpo.profile_option_name 
       ,fpo.user_profile_option_name 
       ,decode(level_id,10001,'Site'           
                       ,10002,'Application'
                       ,10003,'Responsibility'
                       ,10004,'User'
                       ,10006,'Organization') profile_level 
       ,decode(level_id,10002, (select application_name 
                                from apps.fnd_application_vl 
                                where application_id = level_value ) 
                       ,10003, (select responsibility_name 
                                from apps.fnd_responsibility_vl 
                                where responsibility_id = level_value) 
                       ,10004, (select user_name 
                                from apps.fnd_user 
                                where user_id = level_value) 
                       ,10006, (select name   
                                from apps.hr_all_organization_units     
                                where organization_id = level_value)) level_value 
       ,profile_option_value 
  from apps.fnd_profile_options_vl fpo 
      ,apps.fnd_profile_option_values fpov 
  where fpo.profile_option_id = fpov.profile_option_id 
  and   (fpo.profile_option_name like 'Profilename' 
         or fpo.user_profile_option_name like <user Profile Option name>); 

Examples of dynamic SQL (EXECUTE IMMEDIATE)


DECLARE
   sql_stmt    VARCHAR2(200);
   plsql_block VARCHAR2(500);
   emp_id      NUMBER(4) := 7566;
   salary      NUMBER(7,2);
   dept_id     NUMBER(2) := 50;
   dept_name   VARCHAR2(14) := 'PERSONNEL';
   location    VARCHAR2(13) := 'DALLAS';
   emp_rec     emp%ROWTYPE;
BEGIN
   EXECUTE IMMEDIATE 'CREATE TABLE bonus (id NUMBER, amt NUMBER)';
   sql_stmt := 'INSERT INTO dept VALUES (:1, :2, :3)';
   EXECUTE IMMEDIATE sql_stmt USING dept_id, dept_name, location;
   sql_stmt := 'SELECT * FROM emp WHERE empno = :id';
   EXECUTE IMMEDIATE sql_stmt INTO emp_rec USING emp_id;
   plsql_block := 'BEGIN emp_pkg.raise_salary(:id, :amt); END;';
   EXECUTE IMMEDIATE plsql_block USING 7788, 500;
   sql_stmt := 'UPDATE emp SET sal = 2000 WHERE empno = :1
      RETURNING sal INTO :2';
   EXECUTE IMMEDIATE sql_stmt USING emp_id RETURNING INTO salary;
   EXECUTE IMMEDIATE 'DELETE FROM dept WHERE deptno = :num'
      USING dept_id;
   EXECUTE IMMEDIATE 'ALTER SESSION SET SQL_TRACE TRUE';
END;

Monday, 23 March 2020

Script to Assign Responsiblity to USER from backend script

-- ----------------------------------------------------------
-- Add Responsibility to Oracle FND User
-- -----------------------------------------------------------
DECLARE
    lc_user_name                        VARCHAR2(100)    := 'USER1';
    lc_resp_appl_short_name   VARCHAR2(100)    := 'FND';
    lc_responsibility_key          VARCHAR2(100)    := 'APPLICATION_DEVELOPER';
    lc_security_group_key        VARCHAR2(100)    := 'STANDARD';
    ld_resp_start_date                DATE                        := TO_DATE(sysdate);
    ld_resp_end_date                 DATE                        := NULL;

BEGIN
     fnd_user_pkg.addresp
     (   username           => lc_user_name,
        resp_app             => lc_resp_appl_short_name,
        resp_key             => lc_responsibility_key,
        security_group  => lc_security_group_key,
        description         => NULL,
        start_date           => ld_resp_start_date,
        end_date            => ld_resp_end_date
    );

 COMMIT;

EXCEPTION
            WHEN OTHERS THEN
                        ROLLBACK;
                        DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;