访问连接的元素

时间:2014-12-05 16:26:48

标签: oracle plsql oracle-apex

SELECT仅与CELLS表一起使用时,代码可以正常工作。但是,当有来自多个表的连接时,下面的类型不再合适。

PROCEDURE drawComponent(title IN VARCHAR2, tbl IN VARCHAR2, link IN VARCHAR2) IS

TYPE ref_typ IS REF CURSOR;
var_ref ref_typ;
rec CELLS%ROWTYPE;

BEGIN
    OPEN var_ref FOR 'SELECT CELLS.ID as CELLID, CELLS.NUM as CELLNUM, CELLS.' || link || ' as ID, ' || tbl || '.REMOVED as REMOVED FROM CELLS LEFT OUTER JOIN ' || tbl || ' ON CELLS.' || link || ' = ' || tbl || '.ID ORDER BY CELLS.NUM';

    loop
        FETCH var_ref INTO rec;
        EXIT WHEN var_ref%NOTFOUND;
        htp.p(rec.CELLID);
    end loop;
END;

问题是我应该声明rec的哪种类型?

1 个答案:

答案 0 :(得分:1)

您无法获取弱动态参考光标的记录类型。

因此,您最好的选择可能是根据您需要的各种列的类型定义自定义RECORD喜欢的东西:

...

TYPE rec_typ IS RECORD (
  CELLID CELLS.ID%TYPE,
  CELLNUM CELLS.NUM%TYPE,
  ID NUMBER,     -- or whatever type suits your needs
  REMOVED NUMBER  -- or whatever type suits your needs
);
rec rec_type;

...