Accessing joined elements

旧城冷巷雨未停 提交于 2019-12-11 09:38:17

问题


Below code works when SELECT is working only with CELLS table. However, when there is join from multiple table, below type is no more suitable.

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;

Question is what type I should declare rec?


回答1:


You can't get the record type of a weak dynamic ref cursor.

So, your best bet is probably to define a custom RECORD based on the type of the various columns you need. Something like that:

...

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;

...


来源:https://stackoverflow.com/questions/27320391/accessing-joined-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!