2017-07-30 55 views
-2

我想打印出我的兩個表不匹配(通過某些標準)ORA-6504型號不匹配

CREATE OR REPLACE PROCEDURE one_two_mismatch(p_rc OUT SYS_REFCURSOR, 
    p_rc2 OUT SYS_REFCURSOR) 
    AS 
    BEGIN 
    dbms_output.put_line('T1 Table'); 
    OPEN p_rc 
    FOR select t1.ENTITY_KEY, t1.ENTITY_ID, t1.COMPONENT_ID, t1.PARENT_KEY, 
    t1.ENTITY_TYPE_KEY from entity t1,(select entity_id from (select 
    c.entity_id, count(e.component_id) as ONE_CNT, count(c.component_id) as 
    TWO_CNT from entity e, entity_cmm c where e.entity_id = 
    c.entity_id group 
    by c.entity_id) where ONE_CNT <> TWO_CNT) t2 where t1.ENTITY_ID = 
    t2.ENTITY_ID; 

    dbms_output.put_line('T2 Table'); 
    OPEN p_rc2 
    FOR select t3.ENTITY_KEY, t3.ENTITY_ID, t3.COMPONENT_ID, t3.PARENT_KEY, 
    t3.ENTITY_TYPE_KEY from entity_cmm t3,(select entity_id from 
    (select c.entity_id, count(e.component_id) as ONE_CNT, 
    count(c.component_id) as TWO_CNT from est_entity e, entity_cmm c 
    where e.entity_id = c.entity_id group by c.entity_id) where ONE_CNT <> 
    TWO_CNT) 
    t4 where t3.ENTITY_ID = t4.ENTITY_ID; 
    END one_two_mismatch; 

我寫的記錄,我已經在我的程序如下查詢下面我在PL/SQL開發SQL窗口下面的語句來執行上面的過程,但我遇到的第9行的錯誤,表示結果的類型設置變量或查詢不匹配

declare 
    p_rc sys_refcursor; 
    p_rc2 sys_refcursor; 
    l_rec est_entity%rowtype; 
    m_rec est_entity_cmm%rowtype; 
    begin 
     one_two_MISMATCH(p_rc, p_rc2); 
    LOOP 
     FETCH p_rc INTO l_rec; 
     EXIT WHEN p_rc%NOTFOUND; 
     DBMS_OUTPUT.put_line(l_rec.ENTITY_KEY || ',' || l_rec.ENTITY_ID || 
     ',' || l_rec.COMPONENT_ID ||',' || l_rec.PARENT_KEY ||','|| 
     l_rec.ENTITY_TYPE_KEY); 
    END LOOP; 

    CLOSE p_rc; 

LOOP 
FETCH p_rc2 INTO m_rec; 
EXIT WHEN p_rc2%NOTFOUND; 
DBMS_OUTPUT.put_line(m_rec.ENTITY_KEY || ',' || m_rec.ENTITY_ID || ',' || 
m_rec.COMPONENT_ID ||',' || m_rec.PARENT_KEY ||','|| 
m_rec.ENTITY_TYPE_KEY); 
END LOOP; 

    CLOSE p_rc2; 
end; 

是否有人可以幫忙嗎?

+0

由於我們無法看到您的行號,請更具體地說明您的錯誤。 – Difster

+0

它給出了這些行錯誤: 'l_rec est_entity%ROWTYPE;'' m_rec est_entity_cmm%ROWTYPE;' –

+0

你確定你是在檢索光標從'est_entity'表中的所有列? – Incognito

回答

1

根據提供的信息,它聽起來像過程cmm_st_mismatch中的一個或兩個查詢沒有正確的列列表。在匿名塊中,聲明接收引用遊標記錄的兩個變量

l_rec est_entity%rowtype; 
m_rec est_entity_cmm%rowtype; 

被聲明爲行類型。從中獲取的引用遊標必須與rowtype變量聲明中引用的表具有相同的數量,類型和順序。從你描述的錯誤來看,存在着不匹配。