Execute Immediate(sql语句),执行后返回多条数据,怎么遍历其数据
1 回答
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超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 关注
- 1333 浏览
添加回答
举报
0/150
提交
取消