当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
的哪种类型?
答案 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;
...