问题
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