View在读写数据库中工作,但不在待机状态

时间:2016-12-15 19:34:10

标签: oracle readonly standby

问题:在生产中工作的视图不会在只读待机状态下返回数据。

Analysis so far -
1. All database objects are under a single schema owner1
2. The set_parm and get_parm procedures are declared / defined in packageA
3. The view is referenced in a procedure rpt in packageB.

此视图在prod(读/写oracle db)中有效,但在备用oracle db open中不返回数据。

这是权限问题吗?

-- declared in owner1.packageA.pks
TYPE parm_type IS TABLE OF varchar2(100) index BY VARCHAR2(30); 

-- declared in owner1.packageA.pkb
sv_parameters parm_type; 

-- In owner1.packageA.pkb

-- set_param
PROCEDURE set_parm(p_idx IN VARCHAR2,p_value IN VARCHAR2)
IS
BEGIN
   sv_parameters(TRIM(UPPER(p_idx))) := p_value;
   RETURN;
END set_parm;

PROCEDURE set_parm(p_idx IN VARCHAR2,p_value IN NUMBER)
IS
BEGIN
   set_parm(p_idx,TO_CHAR(p_value));
   RETURN;
END set_parm;

PROCEDURE set_parm(p_idx IN VARCHAR2,p_value IN DATE)
IS
BEGIN
   set_parm(p_idx,TO_CHAR(p_value,'YYYYMMDDHH24MISS'));
   RETURN;
END set_parm;

-- get_param
FUNCTION  get_parm(p_idx IN VARCHAR2) RETURN VARCHAR2
IS
BEGIN
   RETURN sv_parameters(TRIM(UPPER(p_idx)));
EXCEPTION
   WHEN NO_DATA_FOUND THEN
        RETURN NULL;
END get_parm;

FUNCTION  get_parm_number(p_idx IN VARCHAR2) RETURN NUMBER
IS
BEGIN
   RETURN TO_NUMBER(get_parm(p_idx));
END get_parm_number;

FUNCTION  get_parm_date(p_idx IN VARCHAR2) RETURN DATE
IS
BEGIN
   RETURN TO_DATE(get_parm(p_idx),'YYYYMMDDHH24MISS');
END get_parm_date;

-- owner1.packageB
PROCEDURE proc_rpt
(p_employer_id     IN  ptei_employers.employer_id%TYPE
,p_as_of_date      IN  DATE  DEFAULT TRUNC(ADD_MONTHS(SYSDATE,-1),'MONTH')
,p_result_set      OUT sa_constants.refcursor
)
IS

BEGIN
    -- set the session parameters needed by views
    owner1.packageA.set_parm('employer_id',p_employer_id);
    owner1.packageA.set_parm('from_date',p_as_of_date);

    OPEN p_result_set FOR
   WITH
    enr_plans AS
    ( 
        SELECT DISTINCT EMPLOYER_ID,inv_start_date ,plan_period ,plans_enrolled
         FROM   owner1.sa_inv_ppt_enrolments_v
    )
    ...
    ...
    ...;
END;

--  owner1.sa_inv_ppt_enrolments_v
CREATE OR REPLACE VIEW SA_INV_PPT_ENROLMENTS_V AS
with param as
    ( select  wwsa.sa_employer_reports_info.get_parm_number ('employer_id')  p_employer_id
             ,wwsa.sa_employer_reports_info.get_parm_date ('from_date')  p_from_date
      from dual
    )
    select  <column-list>
    from  wwsa.tbl1 id
         ,wwsa.tbl2 pm
         ,param
    where  and id.employer_id = param.p_employer_id            
           and id.invoice_start_date = param.p_from_date
           and id.employer_id  = pm.employer_id
           and id.plan_type_id = pm.plan_type_id
           and pm.PRICING_MODEL = 'PAPM'
           and id.invoice_start_date between  pm.start_date and (nvl(pm.end_date, id.invoice_start_date+1)) 
    group by <column-list>;

How i narrowed down on the issue :

When i explicitly set_parm for employer_id, from_date before calling the procedure rpt, i get data back in the cursor. But if i log out and log back in and comment out set_parm ( as below ), then i don't get data in the result.

So it appears that setting the parameters employer_id and from_date ( which are later used in the view via get_parm) is the issue.

-- this is a testing script
begin
  -- Call the procedure
  --owner1.packageA.set_parm('employer_id',29067);
  --owner1.packageA.set_parm('from_date',to_date('01-OCT-2016'));

  owner1.packageB.rpt(); -- calling proc with params
end;

0 个答案:

没有答案