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

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条回答 默认 最新

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

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB中的fft问题
    • ¥30 哈夫曼编码译码器打印树形项目
    • ¥20 求完整顺利登陆QQ邮箱的python代码
    • ¥15 怎么下载MySQL,怎么卸干净原来的MySQL
    • ¥15 网络打印机Ip地址自动获取出现问题
    • ¥15 求局部放电案例库,用于预测局部放电类型
    • ¥100 QT Open62541
    • ¥15 stata合并季度数据和日度数据
    • ¥15 谁能提供rabbitmq,erlang,socat压缩包,记住版本要对应
    • ¥15 Vue3 中使用 `vue-router` 只能跳转到主页面?