我建了两个表:
teachers:   列有tid, tname, bonus, depid(外键);
dept:   列有depname, depid然后将depname,avg(bonus) 放入到了视图teachers_view中要求:
1.控制台输入,如果是关键字是“计算机”的话,那么给高于平均工资的teacher加100,低于的加500;
   我写的语句如下,没编译出错误,但是没成功执行,请大家看看有什么问题:
declare
   v_dname dept.depname%type;
   v_avg teachers.bonus%type;
begin
  v_dname := '&输入系部名称';
  select avg into v_avg from teachers_view where dname=v_dname;
  case v_dname
    when '计算机%' then
       update teachers set bonus=bonus+500 where bonus<v_avg;
       update teachers set bonus=bonus+100 where bonus>v_avg;
  end case;
end;2.如果输入不是表中已有部门的话(假设是“计算机系以外的部门”),则输出如下图形内容:
   1
   2 2 
   3 3 3
   4 4 4 4
   自己写了java语句如下,怎么转换成oracle语言?
   for(int i=1;i<5;i++){
for(int n=1;n<=i;n++){
System.out.print(i);
}
System.out.println();
  }麻烦各位帮我解决一下,新手学习中,谢谢,不甚感激

解决方案 »

  1.   

    第2题输出图形,我用for语句写了:      for i in 1..4 loop
             for n in 1..i loop
                dbms_output.put_line(i);
             end loop;  
           end loop;  可是又遇到新问题,就是换行,每个数字都换行了
      

  2.   


    declare
      v_dname dept.depname%type;
      v_avg teachers.bonus%type;
    begin
      --v_dname := '&输入系部名称';  基本没用
      select avg into v_avg 
      from teachers_view 
      where dname like '计算机%';
      update teachers set bonus=bonus+500 where bonus<v_avg;
      update teachers set bonus=bonus+100 where bonus>v_avg;
    end;
      

  3.   


    declare
      v_avg teachers.bonus%type;
    begin
      select avg(bonus) into v_avg 
      from teachers_view 
      where dname like '计算机%';
      update teachers set bonus=bonus+500 where bonus<v_avg;
      update teachers set bonus=bonus+100 where bonus>v_avg;
    end;
      

  4.   

    谢谢楼上,第2题我刚才也解决了:
    for i in 1..4 loop
             for n in 1..i loop
                dbms_output.put(i);
             end loop;
        dbms_output.put_line('');
    end loop;
     
    做完倒觉得还蛮简单的,不过初学oracle,每天能进步一点点就好,再次谢谢
      

  5.   

    不过,现在还是有点小问题:    depname(系部名称)不只有一个,所以应该还得用到case语句;    另外,case里面输入的关键字具体语法怎么写,我尝试了一下,when '计算机%' 还是不行,应该怎么写?       (题目中所说关键字意思是:如果输入的是 计算机系 或者计算机  都可以)(还有其他系部:如数学系,物理系)
      

  6.   


    declare
      v_avg teachers.bonus%type;
      v_dname dept.depname%type;
    begin
      v_dname :='&输入部门名称';
      if instr(v_dname,'计算机')>0 then
         select avg(bonus) into v_avg 
         from teachers_view 
         where dname=v_dname;
         
         update teachers set bonus=bonus+500 where bonus<v_avg;
         update teachers set bonus=bonus+100 where bonus>v_avg;
      else
         null;
      end if;
      exception
        when others then
          dbms_output.put_line(sqlerrm);
    end;
      

  7.   

    ok,谢谢,晚安完整的代码:declare
      v_avg teachers.bonus%type;
      v_dname dept.depname%type;
      v_i int:=1;
      v_n int:=1;
    begin
      v_dname :='&输入部门名称';
      if instr(v_dname,'计算机')>0 then
         select avg into v_avg 
         from teachers_view 
         where dname=v_dname;
         update teachers set bonus=bonus+500 where bonus<v_avg;
         update teachers set bonus=bonus+100 where bonus>v_avg;
         //update teachers set bonus=0 where bonus is null;
         //update teachers set bonus=10000 where bonus>10000;
      else
          for i in 1..4 loop
             for n in 1..i loop
                dbms_output.put(i);
             end loop;
        dbms_output.put_line('');
        end loop;
      end if;
    exception
        when others then
          dbms_output.put_line('error');
    end;