ORA-6504结果集变量的类型不匹配

时间:2017-07-30 23:49:20

标签: database oracle stored-procedures plsql plsqldeveloper

我正在尝试打印我在我的程序中查询过的两个表中不匹配的记录(按某些标准)

    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;

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

根据提供的信息,听起来过程cmm_st_mismatch中的一个或两个查询没有正确的列列表。在匿名块中,声明接收ref游标的两个变量记录

l_rec est_entity%rowtype;
m_rec est_entity_cmm%rowtype;

被声明为行类型。从中获取的引用游标必须具有与rowtype变量声明中引用的表相同的数量,类型和列顺序。从您描述的错误来看,存在不匹配。