Execute Immediate(sql語句),執(zhí)行后返回多條數(shù)據(jù),怎么遍歷其數(shù)據(jù)
1 回答

慕尼黑的夜晚無繁華
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個贊
Example 1:
Output:
A
B
C
DECLARE TYPE var_typ IS TABLE OF VARCHAR2(4000); cVars var_typ; cVar VARCHAR2(4000);BEGIN EXECUTE IMMEDIATE ' SELECT ''A'' cc FROM dual UNION SELECT ''B'' cc FROM dual UNION SELECT ''C'' cc FROM dual' BULK COLLECT INTO cVars; FOR i IN 1 .. cVars.COUNT LOOP cVar := cVars(i); dbms_output.put_line (cVar); END LOOP;END;/
Example 2:
Output:
A C
B D
C E
DECLARETYPE rec IS RECORD ( col1 VARCHAR2(30), col2 VARCHAR2(30) ); TYPE rec_table IS TABLE OF rec; results rec_table; tRow rec;BEGIN EXECUTE IMMEDIATE ' SELECT ''A'',''C'' FROM dual UNION SELECT ''B'',''D'' FROM dual UNION SELECT ''C'',''E'' FROM dual' BULK COLLECT INTO results; FOR i IN 1 .. results.COUNT LOOP tRow := results(i); dbms_output.put_line(tRow.col1 || ' ' || tRow.col2); END LOOP;END;/
- 1 回答
- 0 關(guān)注
- 1411 瀏覽
添加回答
舉報(bào)
0/150
提交
取消