create or replace procedure p_stuinfo is
v_sql varchar2(45);
begin
EXECUTE IMMEDIATE 'create table system.t_studentinfo(
stuid varchar2(10),
stuname varchar2(12),
score varchar2(10)
)';
EXECUTE IMMEDIATE 'insert into system.t_studentinfo values(''1'',''张三'',''A'')';
EXECUTE IMMEDIATE 'insert into system.t_studentinfo values(''2'',''李四'',''B'')';
commit;
v_sql:= 'select stuid,stuname,score from system.t_studentinfo';
for stu_record in (execute immediate v_sql) loop
dbms_output.put_line(stu_record.stuid||' '||stu_record.stuname||' '||stu_record.score);
end loop;
end;
------解决方案--------------------
- SQL code
create or replace procedure p_stuinfo isv_sql varchar2(200);stu_cur sys_refcursor;v_stuid varchar2(10);v_stuname varchar2(12);v_score varchar2(10);beginEXECUTE IMMEDIATE 'create table system.t_studentinfo( stuid varchar2(10), stuname varchar2(12), score varchar2(10) )';EXECUTE IMMEDIATE 'insert into system.t_studentinfo values(''1'',''张三'',''A'')'; EXECUTE IMMEDIATE 'insert into system.t_studentinfo values(''2'',''李四'',''B'')'; commit;v_sql:= 'select stuid,stuname,score from system.t_studentinfo';open stu_cur for v_sql;loop fetch stu_cur into v_stuid,v_stuname,v_score; exit when stu_cur%notfound; dbms_output.put_line(v_stuid||' '||v_stuname||' '||v_score);end loop;end;
代码迷推荐解决方案:oracle存储过程,http://www.daimami.com/search?q=177537