陪衬丶角色_Z 2020-05-29 11:16 采纳率: 33.3%
浏览 498
已采纳

oracle使用游标将一个表数据插入另一个表中报错

对于学生选课表sc(sno,cno,grade),创建相同结构的新表sc1,并将sc数据全部加入到sc1,然后通过游标对sc1进行成绩更新:
成绩为: 80~100 更新为5;
60~80, 更新为3;

低于60分,更新为0;
更新之后对比sc和sc1,查看更新效果


```declare
    sc1_sno sc1.sno%type;
    sc1_cno sc1.cno%type;
    sc1_grade sc1.grade%type;
    cursor  sc_cursor
    is select  sno,cno,grade from  sc;
begin 
  open sc_cursor;
  loop
    fetch sc_cursor into sc1_sno,sc1_cno,sc1_grade;
       exit when  sc_cursor % notfound;
       if sc1_grade>=80 then
          sc1_grade:=5;
       else 
          if sc1_grade<60 then
          sc1_grade:=0;
          else 
          sc1_grade:=3;
          end if;
        end if;
      insert into sc1(sno,cno,grade) values (sc1_sno,sc1_cno,sc1_grade);
  end loop;
    close sc_cursor; 
  commit;
 end;
错误报告:
ORA-00001: 违反唯一约束条件 (STUDENT.SYS_C004830)
ORA-06512: 在 line 21
00001. 00000 -  "unique constraint (%s.%s) violated"
*Cause:    An UPDATE or INSERT statement attempted to insert a duplicate key.
           For Trusted Oracle configured in DBMS MAC mode, you may see
           this message if a duplicate entry exists at a different level.
*Action:   Either remove the unique restriction or do not insert the key.

  • 写回答

1条回答 默认 最新

  • 关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用