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

新手,求解答
定义表S2,表结构同student表相同.编写存储过程,在过程中利用游标将student表中系别为'CS'的记录插入到表S2中

create or replace procedure s_test  as 
CURSOR c_job IS select * from student where sdept='CS';
c_row c_job%rowtype;
begin 
     open c_job; 
LOOP 
      FETCH c_job INTO c_row; 
      exit when c_job%notfound;
      dbms_output.put_line(c_row.sno||'-'||c_row.sname||'-'||c_row.sdept);
      INSERT INTO S2(sno,sname,sdept) VALUES(c_row.sno,c_row.sname,c_row.sdept); 
END LOOP; 
    END c_job;
end;
 答案错在哪里了?求改正
------解决方案--------------------

--既然表结构相同就不需要这样了
--可以这样做
insert into s2 select *from student where sdept='CS';
--存储过程都省略了。。

------解决方案--------------------
这个表结构相同 有好多种情况的,如果一张表是dblink过来的另外库的表,假如两个库的字符集不一致,即便表结构相同,也是各种报错的。

c_row c_job%rowtype; 改成student%rowtype  这样试试  另外 敢把错误贴出来么