Wednesday, August 10, 2016

Connecting to SQLPLUS/ASMCMD...SP2-1503: Unable to initialize Oracle call interface/UNKNOWN OCI STATUS 1804 OCIInitialize


This error indicate improper set of environment variables.  here is a scenario. there are other out there...


ERPDB1:/ERP1/11.1.0/ASM_1$ export ORACLE_HOME=/ERP1/11.1.0/ASM_1
ERPDB1:/ERP1/11.1.0/ASM_1$ export PATH=/ERP1/11.1.0/ASM_1/bin:$PATH
ERPDB1:/ERP1/11.1.0/ASM_1$ export ORACLE_SID=+ASM
ERPDB1:/ERP1/11.1.0/ASM_1$ sqlplus / as sysasm
SP2-1503: Unable to initialize Oracle call interface
SP2-0152: ORACLE may not be functioning properly
ERPDB1:/ERP1/11.1.0/ASM_1$ 


Confirmed instance is up, below

ERPDB1:/ERP1/11.1.0/ASM_1$ps -ef|grep pmon
  oracle  7012424        1   0   Jun 26      - 13:06 ora_pmon_PROD
  oracle  8585440        1   0   Jun 26      -  8:30 asm_pmon_+ASM

Unset ORA_TZFILE that normally come with ERP DB environment variable settings.

ERPDB1:/ERP1/PRODDB/db/tech_st/11.1.0/network/admin$ echo $ORA_TZFILE 
/ERP1/PRODDB/db/tech_st/11.1.0/oracore/zoneinfo/timezlrg.dat
ERPDB1:/ERP1/PRODDB/db/tech_st/11.1.0/network/admin$ unset ORA_TZFILE 
ERPDB1:/ERP1/PRODDB/db/tech_st/11.1.0/network/admin$  echo $ORA_TZFILE 


Hurry!

ERPDB1:/ERP1/PRODDB/db/tech_st/11.1.0/network/admin$ sqlplus / as sysasm

SQL*Plus: Release 11.1.0.7.0 - Production on Wed Oct 21 14:05:14 2015

Copyright (c) 1982, 2008, Oracle.  All rights reserved.


ASMCMD...

ORA-04091: table ... is mutating, trigger/function may not see it

this error occurs often times when we are thinking about performance and neglecting the mechanisms that trigger rely on.

simply checking the error code will bring us closer to the solution:

# oerr ora 4091
04091, 00000, "table %s.%s is mutating, trigger/function may not see it"
// *Cause: A trigger (or a user defined plsql function that is referenced in
//         this statement) attempted to look at (or modify) a table that was
//         in the middle of being modified by the statement which fired it.
// *Action: Rewrite the trigger (or function) so it does not read that table.

Above "Action" may be misleading and can restrict you focusing on only the trigger sql code.
I will extend Oracle answer to include, changing the dependent codes, and not necessarily the trigger sql code, for example, this is how below error was resolved in a live environment.


ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "TELECOM.SCP_PKG_COMPENSATE_SUB", line 118
ORA-04091: table TELECOM.SCP_COMPENSATE_SUB is mutating, trigger/function may not see it
ORA-06512: at "TELECOM.TRG_PREVENT_DUP", line 41
ORA-04088: error during execution of trigger


procedure prc_bulk_entry(p_msisdn_list varchar2,p_reward_id varchar2,p_reason varchar2,p_userid varchar2,p_jobid varchar2)
as
RetVal DBMS_SQL.varchar2_table;
dont_run exception;
begin

   retval := TELECOM.list_to_tbl ( p_msisdn_list );
   forall i in indices of retval
    insert into scp_compensate_sub(puid, msisdn, reward_id, reason, userid, jobid, status, load_date)
    values (seq_scp_queue.nextval,
           RetVal(i),
           p_reward_id,
           p_reason,
           p_userid,
           p_jobid,
          'Q',
         sysdate
       );
   
    commit;
exception
when others then
rollback;
raise dont_run;
end;

Note: There is a trigger on scp_compensate_sub table.
Why the mutation error: because "The FORALL statement is not a loop; it is a declarative statement to the PL/SQL engine: “Generate all the DML statements that would have been executed one row at a time, and send them all across to the SQL engine with one context switch.""  read more -->http://www.oracle.com/technetwork/issue-archive/2012/12-sep/o52plsql-1709862.html

to resolve this error, we simply convert the FORALL to FOR LOOP statement.


procedure prc_bulk_entry(p_msisdn_list varchar2,p_reward_id varchar2,p_reason varchar2,p_userid varchar2,p_jobid varchar2)
as
RetVal DBMS_SQL.varchar2_table;
dont_run exception;
begin

   retval := TELECOM.list_to_tbl ( p_msisdn_list );
   --forall i in indices of retval
   for i in 1..retval.COUNT loop
    insert into scp_compensate_sub(puid, msisdn, reward_id, reason, userid, jobid, status, load_date)
    values (seq_scp_queue.nextval,
           RetVal(i),
           p_reward_id,
           p_reason,
           p_userid,
           p_jobid,
          'Q',
         sysdate
       );
    commit;
    end loop;
    --dbms_lock.sleep(10);
exception
when others then
rollback;
raise dont_run;
end;