【问题标题】:ORA-6504 Type of result set variables does not matchORA-6504结果集变量的类型不匹配
【发布时间】:2018-01-06 10:21:35
【问题描述】:

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

    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;

有人可以帮忙吗?

【问题讨论】:

  • 由于我们看不到您的行号,请更具体地说明您的错误。
  • 这几行出现错误:l_rec est_entity%rowtype;m_rec est_entity_cmm%rowtype;
  • 您确定要从光标中的est_entity 表中检索所有列吗?
  • 第 9 行是从 p_rcl_recfetch

标签: database oracle stored-procedures plsql plsqldeveloper


【解决方案1】:

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

l_rec est_entity%rowtype;
m_rec est_entity_cmm%rowtype;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多