日期:2014-05-17  浏览次数:20726 次

创建存储过程
就是一个存储过程里包括创 建表 插入数据 使用游标循环打印 例子就行 不要实现什么功能

------解决方案--------------------
SQL code
CREATE OR REPLACE PROCEDURE p01 IS 
v_sql VARCHAR2(1000);
BEGIN 
  v_sql:='CREATE TABLE student(no VARCHAR2(5),sname VARCHAR2(10))';
  execute IMMEDIATE v_sql;
END p01;

EXEC p01;

CREATE OR REPLACE PROCEDURE p02 IS 
cur_stu sys_refcursor;
temp VARCHAR2(5);
BEGIN 
  INSERT INTO student VALUES ('001','张三');
  INSERT INTO student VALUES ('002','李四');
  INSERT INTO student VALUES ('003','王五');
  COMMIT;
  OPEN cur_stu FOR 'select no from student';
  LOOP
  FETCH cur_stu INTO temp;
  EXIT WHEN cur_stu%NOTFOUND;
    Dbms_Output.put_line('=='||temp);
  END LOOP;
END p02;

EXEC p02;

output:
23  PL/SQL block, executed in 0.078 sec.
    ==001                               
    ==002                               
    ==003                               
    Total execution time 0.094 sec.