Friday, June 28, 2019

Oracle Home inventory is corrupted LsInventorySession failed: OracleHomeInventory

Oracle Home inventory is corrupted LsInventorySession failed: OracleHome Inventory

[oratest@slctest01 OPatch]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.3
Copyright (c) 2012, Oracle Corporation.  All rights reserved.


Oracle Home       : /u01/oracle/testdb/11.2.0
Central Inventory : /u01/oraInventory
   from           : /u01/oracle/testdb/11.2.0/oraInst.loc
OPatch version    : 11.2.0.3.3
OUI version       : 11.2.0.3.0
Log file location : /u01/oracle/testdb/11.2.0/cfgtoollogs/opatch/opatch2013-05-15_10-27-12AM_1.log

List of Homes on this system:

Inventory load failed... OPatch cannot load inventory for the given Oracle Home.
Possible causes are:
   Oracle Home dir. path does not exist in Central Inventory
   Oracle Home is a symbolic link
   Oracle Home inventory is corrupted
LsInventorySession failed: OracleHomeInventory gets null oracleHomeInfo

OPatch failed with error code 73


Solution

I was able to solve this issue; Follow the steps below:

 1. Login to the server.
 2. cd $ORACLE_HOME/oui/bin
 $ ./attachHome.sh
 Starting Oracle Universal Installer...

 Checking swap space: must be greater than 500 MB. Actual 196608 MB Passed
 Preparing to launch Oracle Universal Installer from /tmp/OraInstall2012-06-27_03-07-48AM. Please wait ...
 3. Re-run the same command and it is going to work.

 [oratest@slctest01 ~]$ opatch lsinventory

Thursday, June 13, 2019

Oracle E-Business Suite Current patch level

 SELECT ABBREVIATION,
             NAME,
             TYPE,
             CODELEVEL,
             BASELINE
       FROM AD_TRACKABLE_ENTITIES
       WHERE ABBREVIATION IN ('ad',
                          'txk',
                          'fnd',
                          'fwk',
                          'atg_pf',
                          'icx')
      ORDER BY ABBREVIATION;

Defragment Concurrent Tables

--DEFRAGMENT
---Defragment the tables periodically to reclaim unused space / improve performance

alter table APPLSYS.FND_CONCURRENT_REQUESTS move;
alter table APPLSYS.FND_CRM_HISTORY move;
alter table APPLSYS.FND_CONCURRENT_PROCESSES move;
alter table APPLSYS.FND_CRM_HISTORY move;
alter table APPLSYS.FND_ENV_CONTEXT move;
alter table APPLSYS.FND_TEMP_FILES move;



--select owner, index_name, status from dba_indexes
--where table_owner = upper('APPLSYS') and
--table_name in ('FND_CONCURRENT_REQUESTS','FND_CRM_HISTORY','FND_CONCURRENT_PROCESSES','FND_CRM_HISTORY','FND_ENV_CONTEXT','FND_TEMP_FILES');


--alter index <owner>.<index_name> rebuild online;

alter index APPLSYS.FND_CONCURRENT_PROCESSES_N2 rebuild online;
alter index APPLSYS.FND_CONCURRENT_PROCESSES_N1 rebuild online;
alter index APPLSYS.FND_CONCURRENT_PROCESSES_U1 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N10 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N11 rebuild online;
alter index APPS.FND_CONCURRENT_REQUESTS_F1 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N9 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N2 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_U1 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N1 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N3 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N4 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N5 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N6 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N7 rebuild online;
alter index APPLSYS.FND_CONCURRENT_REQUESTS_N8 rebuild online;
alter index APPLSYS.FND_CRM_HISTORY_U1 rebuild online;
alter index APPLSYS.FND_CRM_HISTORY_U2 rebuild online;
alter index APPLSYS.FND_ENV_CONTEXT_U1 rebuild online;
alter index APPLSYS.FND_TEMP_FILES_N1 rebuild online;
alter index APPLSYS.FND_TEMP_FILES_N2 rebuild online;


--exec fnd_stats.gather_table_stats ('APPLSYS','FND_CONCURRENT_REQUESTS',PERCENT=>99);

exec fnd_stats.gather_table_stats ('APPLSYS','FND_CONCURRENT_REQUESTS',PERCENT=>99);
exec fnd_stats.gather_table_stats ('APPLSYS','FND_CRM_HISTORY',PERCENT=>99);
exec fnd_stats.gather_table_stats ('APPLSYS','FND_CONCURRENT_PROCESSES',PERCENT=>99);
exec fnd_stats.gather_table_stats ('APPLSYS','FND_CRM_HISTORY',PERCENT=>99);
exec fnd_stats.gather_table_stats ('APPLSYS','FND_ENV_CONTEXT',PERCENT=>99);
exec fnd_stats.gather_table_stats ('APPLSYS','FND_TEMP_FILES',PERCENT=>99);

Creating ACL for UTL_SMTP

SELECT *
FROM dba_network_acls;

-- Create ACL and privilege
begin
  dbms_network_acl_admin.create_acl (
    acl         => 'utl_mail.xml',
    description => 'Allow mail to be send',
    principal   => 'APPS',
    is_grant    => TRUE,
    privilege   => 'connect'
    );
    commit;
end;

--Add Privilege

begin
  dbms_network_acl_admin.add_privilege (
  acl       => 'utl_mail.xml',
  principal => 'APPS',
  is_grant  => TRUE,
  privilege => 'resolve'
  );
  commit;
end


--Test1

begin
  dbms_network_acl_admin.assign_acl(
  acl  => 'utl_mail.xml',
  host => 'mail.company.com.sa'
  );
  commit;
end;

--Test2
begin
  utl_mail.send(
  sender     => 'fromuser@company.com',
  recipients => 'myname@company.com,user2@company.com, user3@company.com',
  message    => 'Test E-mail from ERP Database'
  );
  commit;
end;

Cost Manager Status

SELECT x.process_type "Name",
  DECODE(
  (SELECT '1' FROM fnd_concurrent_requests cr,
    fnd_concurrent_programs_vl cp,
    fnd_application a WHERE cp.concurrent_program_id = cr.concurrent_program_id
  AND cp.concurrent_program_name                     = x.process_name
  AND cp.application_id                              = a.application_id
  AND a.application_short_name                       = x.process_app_short_name
  AND phase_code                                    != 'C'
  ),'1','Active','Inactive') "Status",
  x.worker_rows "Worker Rows",
  x.timeout_hours "Timeout Hours",
  x.timeout_minutes "Timeout Minutes",
  x.process_hours "Process Interval Hours",
  x.process_minutes "Process Interval Minutes",
  x.process_seconds "Process Interval Seconds"
FROM
  (SELECT mipc.process_code ,
    mipc.process_status ,
    mipc.process_interval ,
    mipc.manager_priority ,
    mipc.worker_priority ,
    mipc.worker_rows ,
    mipc.processing_timeout ,
    mipc.process_name ,
    mipc.process_app_short_name ,
    a.meaning process_type ,
    FLOOR(mipc.process_interval    /3600) process_hours ,
    FLOOR((mipc.process_interval   - (FLOOR(mipc.process_interval/3600) * 3600))/60) process_minutes ,
    (mipc.process_interval         - (FLOOR(mipc.process_interval/3600) * 3600) - (FLOOR((mipc.process_interval - (FLOOR(mipc.process_interval/3600) * 3600))/60) * 60)) process_seconds ,
    FLOOR(mipc.processing_timeout  /3600) timeout_hours ,
    FLOOR((mipc.processing_timeout - FLOOR(mipc.processing_timeout/3600) * 3600)/60) timeout_minutes
  FROM mtl_interface_proc_controls mipc,
    mfg_lookups a
  WHERE a.lookup_type = 'PROCESS_TYPE'
  AND a.lookup_code   = mipc.process_code
  ) x
  -- WHERE x.PROCESS_TYPE = 'Cost Manager' -- uncomment this to display only the cost manager
ORDER BY 1;



SELECT request_id RequestId,
request_date RequestDt, concurrent_program_name,
phase_code Phase,
status_code Status FROM
fnd_concurrent_requests fcr,
fnd_concurrent_programs fcp
WHERE fcp.application_id = 702 AND
fcp.concurrent_program_name in ('CMCTCM', 'CMCMCW', 'CMCACW') AND
fcr.concurrent_program_id = fcp.concurrent_program_id AND
fcr.program_application_id = 702 AND fcr.phase_code <> 'C'


-- Pending Cost Transations
select count(*) from MTL_MATERIAL_TRANSACTIONS where COSTED_FLAG = 'N' --or COSTED_FLAG = 'N';
--and organization_id=317

select count(*) from MTL_MATERIAL_TRANSACTIONS where COSTED_FLAG = 'E'

select * from cst_lc_adj_interface


Select * from cst_lc_adj_interface

Select * from cst_lc_adj_interface_errors


select * from wip_cost_txn_interface

Cost Manager Datafix

select * from mtl_material_transactions where costed_flag = 'E';


select *
   from org_acct_periods where acct_period_id=13481
   --where period_name like 'JUL-14'

select transaction_id,creation_date,organization_id,transaction_date,acct_period_id
from mtl_material_transactions where costed_flag = 'E';




UPDATE mtl_material_transactions
SET acct_period_id         = 13406,
    costed_flag            = 'N',
    transaction_group_id   = NULL,
    transaction_set_id     = NULL,
    ERROR_CODE             = NULL,
    error_explanation      = NULL
WHERE     costed_flag = 'E'
      AND acct_period_id = 13443
      AND ERROR_CODE = 'CST_MATCH_DATE_PERIOD'
      AND organization_id = 317
      AND transaction_id = 4146439;
     
     

Update MTL_MATERIAL_TRANSACTIONS
set COSTED_FLAG = 'N', TRANSACTION_GROUP_ID = NULL
where COSTED_FLAG = 'E' or COSTED_FLAG = 'N';


select count(*) from MTL_MATERIAL_TRANSACTIONS where COSTED_FLAG = 'E' or COSTED_FLAG = 'N';

Core HR SQL Queries

--Organization through Organization Hierarchy

SELECT NAME, TYPE, organization_id
                 FROM (SELECT hou.NAME, TYPE, organization_id
                         FROM hr_all_organization_units hou
                        WHERE organization_id IN (
                                 SELECT     organization_id_child
                                                              organization_id
                                       FROM (SELECT organization_id_child,
                                                    organization_id_parent,
                                                    org_structure_version_id
                                               FROM per_org_structure_elements
                                              WHERE org_structure_version_id IN (
                                                       SELECT posv.org_structure_version_id
                                                         FROM per_organization_structures pos,
                                                              per_org_structure_versions posv
                                                        WHERE primary_structure_flag =
                                                                           'Y'
                                                          AND pos.organization_structure_id =
                                                                 posv.organization_structure_id
                                                          AND pos.NAME =
                                                                 :p_x_org_hierarchy))
                                 CONNECT BY organization_id_child =
                                                   PRIOR organization_id_parent
                                 START WITH organization_id_child =
                                                             :x_organization_id)
                          AND UPPER (hou.TYPE) = :x_organization_type)
                WHERE ROWNUM = 1;

--Find Organization Manager Query
SELECT NVL
                         ((SELECT NVL (papf.person_id, 0)
                             FROM hr_all_organization_units org,
                                  hr_all_organization_units_tl org_tl,
                                  hr_organization_information org_info2,
                                  per_all_people_f papf
                            WHERE org_info2.organization_id =
                                                           org.organization_id
                              AND org_info2.org_information_context =
                                                     'Organization Name Alias'
                              AND org_info2.org_information2 = TO_CHAR (papf.person_id(+))
                              AND org.organization_id = org_tl.organization_id
                              AND org_tl.LANGUAGE = USERENV ('LANG')
                              AND org_tl.NAME = :x_org_name
                              AND papf.current_employee_flag = 'Y'
                              AND TRUNC (:x_effective_date)
                                     BETWEEN papf.effective_start_date
                                         AND papf.effective_end_date),
                          0
                         ) val
                 FROM DUAL;
               
--Find the List Users that have a particular Responsibility
select rg.user_id,fu.user_name,ppf.employee_number,ppf.full_name,rt.responsibility_name
from fnd_responsibility_tl rt,FND_USER_RESP_GROUPS_DIRECT rg,fnd_user fu, per_all_people_f ppf
where upper(RESPONSIBILITY_NAME) like '%APPROVALS MANAGEMENT BUSINESS ANALYST'
and rt.RESPONSIBILITY_ID = rg.RESPONSIBILITY_ID
and rg.user_id = fu.user_id
and fu.employee_id = ppf.person_id
and trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date


--Find total Active employee in the company
select ppf.employee_number,ppf.full_name,ppf.email_address
from per_all_people_f ppf
where ppf.current_employee_flag = 'Y'
and trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date
and ppf.employee_number is not null
and ppf.person_type_id = ( select person_type_id
from per_person_types
where user_person_type = 'Employee'
and business_group_id = ppf.BUSINESS_GROUP_ID
)

--Get Month Wise Hired Employees Head Count
select to_char(ORIGINAL_DATE_OF_HIRE,'MON') MM, COUNT(PERSON_ID) TOTAL from per_people_x
WHERE to_char(ORIGINAL_DATE_OF_HIRE,'RRRR') = '2017'
group by to_char(ORIGINAL_DATE_OF_HIRE,'MON')

--Provide a List of Active Employees along with their Supervisor’s Name and email address
select ppf.employee_number,ppf.full_name,ppf.email_address ,paaf.supervisor_id,sup.full_name,sup.email_address
from per_all_people_f ppf,per_all_assignments_f paaf,per_people_x sup
where ppf.current_employee_flag = 'Y'
and paaf.supervisor_id (+) = sup.person_id
and trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date
and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
and ppf.person_id = paaf.person_id
and ppf.employee_number is not null
--d ppf.employee_number = '39988'
and ppf.person_type_id = ( select person_type_id
from per_person_types
where user_person_type = 'Employee'
and business_group_id = ppf.BUSINESS_GROUP_ID
)

--Get the Employee Salary Increase Summary
select ppf.employee_number,ppf.full_name,ppp.proposed_salary_n,ppp.change_date
from per_pay_proposals ppp,per_all_people_f ppf,per_all_assignments_f paaf
where ppf.person_id = paaf.person_id
and paaf.assignment_id = ppp.assignment_id
and ppf.employee_number = ‘603167’
and trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date
and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
and ppp.approved = ‘Y’
and change_date = (select min(change_date) from per_pay_proposals where assignment_id = ppp.assignment_id and proposed_salary_n = ppp.proposed_salary_n)
order by ppp.change_date desc

--Get the History for An Employee’s Transfers in the company
--Get the list of employee who were terminated and have been rehired
select ppf.employee_number,ppf.full_name,ppf.email_address
from per_all_people_f ppf
where trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date
and person_id in
( select person_id
from (
select count(1),person_id
from per_periods_of_service
group by person_id
having count(1) > 1
)
)

--Get the List of Terminated Employees
select ppf.employee_number,ppf.full_name,ppf.email_address
from per_all_people_f ppf
where trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date
and current_employee_flag is null
and ppf.person_type_id = ( select person_type_id
from per_person_types
where user_person_type = 'Ex-employee'
and business_group_id = ppf.BUSINESS_GROUP_ID
)

--Get an Employees Leave History
select a.date_start,a.date_end,a.absence_days,
(select name from per_ABSENCE_ATTENDANCE_types
where ABSENCE_ATTENDANCE_TYPE_ID = a.ABSENCE_ATTENDANCE_TYPE_ID
and business_group_id =a.business_group_id) leave_type
from per_absence_attendances a
where person_id = (select person_id from per_all_people_f where employee_number = '1000063' and employee_number is not null)
order by date_start desc

--Get EIT Based information for employees
select ppf.employee_number,ppf.full_name, ppei.* from per_all_people_f ppf, per_people_extra_info ppei
where ppf.person_id = ppei.person_id
and trunc(sysdate) between ppf.effective_start_date and ppf.effective_end_date
and ppf.employee_number = '1000063'
--and ppei.information_type = 'XX_OTHER_DETAILS'

--Get SIT Based information for employees
select * from per_person_analyses ppa,per_analysis_criteria pac
where ppa.ANALYSIS_CRITERIA_ID = pac.ANALYSIS_CRITERIA_ID
and person_id = 115043
and pac.ID_FLEX_NUM =
(
select fis.ID_FLEX_NUM
from FND_ID_FLEXS fif, FND_ID_FLEX_STRUCTURES fis
where fif.ID_FLEX_CODE = fis.ID_FLEX_CODE
and id_flex_structure_code = ‘XX_PROBATION_EVALUATION’
)

--Get the List of all Organization which are below an organization in Org Hierarchy
--Get the List of all Organization which are Above an organization in Org Hierarchy
--Parent and Child Organizations List

select hp.name parent_org, hc.name child_organization
from PER_ORG_STRUCTURE_ELEMENTS pose, PER_ORG_STRUCTURE_VERSIONS posv, hr_all_organization_units hc, hr_all_organization_units hp
where 1=1
and pose.BUSINESS_GROUP_ID = posv.BUSINESS_GROUP_ID
and pose.ORGANIZATION_ID_CHILD = hc.organization_id
and pose.ORGANIZATION_ID_PARENT = hp.organization_id

--Get the Oracle Balance Values
SELECT pdb.defined_balance_id,dim.dimension_name
FROM pay_defined_balances pdb,
pay_balance_types typ,
pay_balance_dimensions dim
WHERE pdb.balance_type_id = typ.balance_type_id
AND pdb.balance_dimension_id = dim.balance_dimension_id
AND dim.legislation_code = ( SELECT legislation_code FROM per_business_groups WHERE business_group_id = 81)
AND UPPER (typ.balance_name) = UPPER ('Indemnity Days')
AND UPPER (dim.dimension_name) = UPPER ('Assignment Run');

select pay_balance_pkg.get_value (P_Balance_ID, P_Assignment_Action_ID, trunc(sysdate))
from dual

--Trunc(Sysdate) will return you balance value as of Date, you can use any old date as per your requirement.

--Disable Responsibilities for Users
--Normally such requirement occurs when you want that no user should be able to logged in during any particular time like some upgrade project or any critical migration activity. You can disable the users by following query.  Al though direct updates are not allowed but since this table does not contain object version id column so we used queries mentioned below. Please consult Oracle Support if you want to double check the impact of using this update statement.

update fnd_responsibility a
set a.END_DATE = to_date(’05-APR-2016?)
where a.RESPONSIBILITY_KEY in
(      SELECT distinct b.RESPONSIBILITY_KEY
FROM FND_USER_RESP_GROUPS A,
FND_RESPONSIBILITY_VL B,
FND_USER C,
PER_ALL_PEOPLE_F D
WHERE A.responsibility_id = B.responsibility_id AND
C.user_id = A.user_id AND
(to_char(A.end_date) IS NULL   OR   A.end_date > sysdate)
AND C.user_name = D.EMPLOYEE_NUMBER
and (b.RESPONSIBILITY_KEY like ‘%LSG%’)
and C.EMPLOYEE_ID is not null
)

--In order to reset the responsibilities back to original state

update fnd_responsibility a
set a.END_DATE = NULL
where a.RESPONSIBILITY_KEY in
(      SELECT distinct b.RESPONSIBILITY_KEY
FROM FND_USER_RESP_GROUPS A,
FND_RESPONSIBILITY_VL B,
FND_USER C,
PER_ALL_PEOPLE_F D
WHERE A.responsibility_id = B.responsibility_id AND
C.user_id = A.user_id AND
(to_char(A.end_date) IS NULL   OR   A.end_date > sysdate)
AND C.user_name = D.EMPLOYEE_NUMBER
and (b.RESPONSIBILITY_KEY like ‘%LSG%’)
and C.EMPLOYEE_ID is not null
)
and end_date IS not NULL
and end_date = ’05-APR-2016?

--Provide the List of Employees current and Previous Assignment Details
--(shows  Employee Organization Change history. Like wise we can change the query to show the history of Grade, Payroll, Organization, Location, Position, Job change summary)

select
ppf.employee_number
,paaf.assignment_number
,ppf.full_name
,paaf.organization_id current_org_id
,paaf.effective_start_date Curr_org_start_date
,(select name from hr_all_organization_units where organization_id = paaf.organization_id) current_org_name
,paaf_prev.effective_start_date prev_org_start_date
,paaf_prev.organization_id prev_org_id
,(select name from hr_all_organization_units where organization_id = paaf_prev.organization_id) prev_org
from per_all_assignments_f paaf,per_all_assignments_f paaf_prev,pay_people_groups ppg,pay_people_groups ppg_prev,per_all_people_f ppf
where paaf_prev.effective_end_date + 1= paaf.effective_start_date
and paaf_prev.assignment_id = paaf.assignment_id
and paaf_prev.assignment_type = 'E'
and ppf.employee_number = '1000063'
and paaf.assignment_type = 'E'
and paaf.organization_id <> paaf_prev.organization_id
and paaf.PEOPLE_GROUP_ID = ppg.people_group_id
and paaf_prev.PEOPLE_GROUP_ID = ppg_prev.people_group_id
and paaf.effective_start_date between ppf.effective_start_date and ppf.effective_end_date
and paaf.person_id = ppf.person_id
order by paaf_prev.effective_start_date desc

--Employee Short Leave Details and Hours Calculation
select paa.person_id,paa.date_start, paa.date_end,time_start,time_end
,round ( ( ((substr(time_end,1,2) -substr(time_start,1,2)) * 60
+ (substr(time_end,4,2) -substr(time_start,4,2))) / 60 ) ,2) Hours
from per_absence_attendances paa,per_absence_Attendance_types paat
where paa.person_id = 68567
and paa.absence_attendance_type_id = paat.absence_attendance_type_id
and paat.name = 'Short Leave'
and paa.date_start between :P_Period_Start_date and :P_Period_End_date
and paa.date_end between :P_Period_Start_date and :P_Period_End_date

Some Tips About FNDLOAD

Data Synchronization  Data Synchronization is a process in which some setup data would be synchronized, and this would be more important w...