Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将此Oracle SQL过程转换为Mysql过程_Mysql_Oracle_Stored Procedures - Fatal编程技术网

将此Oracle SQL过程转换为Mysql过程

将此Oracle SQL过程转换为Mysql过程,mysql,oracle,stored-procedures,Mysql,Oracle,Stored Procedures,我尝试使用联机sql到mysql转换工具,但它对我没有帮助。有人能帮我把这个过程转换成mysql版本吗 create or replace procedure avgmarks is cursor c_iamarks is select greatest(test1, test2) as a ,greatest(test1, test3) as b ,greatest(test3, test2) as c from

我尝试使用联机sql到mysql转换工具,但它对我没有帮助。有人能帮我把这个过程转换成mysql版本吗

create or replace procedure avgmarks is
   cursor c_iamarks is
      select greatest(test1, test2) as a
            ,greatest(test1, test3) as b
            ,greatest(test3, test2) as c
        from iamarks
       where finalia is null
         for update;
   c_a  number;
   c_b  number;
   c_c  number;
   c_sm number;
   c_av number;
begin
   open c_iamarks;
   loop
      fetch c_iamarks
         into c_a
             ,c_b
             ,c_c;
      exit when c_iamarks%notfound;
      --DBMS_OUTPUT.PUT_LINE(C_A || ' ' || C_B || ' ' || C_C);
      if (c_a != c_b)
      then
         c_sm := c_a + c_b;
      else
         c_sm := c_a + c_c;
      end if;
      c_av := c_sm / 2;
      --DBMS_OUTPUT.PUT_LINE('SUM = '||C_SM);
      --DBMS_OUTPUT.PUT_LINE('AVERAGE = '||C_AV);
      update iamarks
         set finalia = c_av
       where current of c_iamarks;
   end loop;
   close c_iamarks;
end;
/

在本例中,我计算的是三次测试中最好的两次得分的平均值,当我调用此过程时,它应该更改表中的值。

是否可以用单个update语句替换此过程

update iamarks
   set finalia = (case
                    when greatest(test1, test2) != greatest(test1, test3) then
                     greatest(test1, test2) + greatest(test1, test3)
                    else
                     greatest(test1, test2) + greatest(test3, test2)
                 end) / 2
 where finalia is null

我没有数据,因此无法确认该声明是否100%正确

是的,可以这样做。我已经这样做了,但我想知道如何将sql转换成mysql dats。嘿,你能帮我做更多的事情吗?我们在oracle中使用减号或除号,但我不知道在mysql中如何使用以下查询选择E.FNAME,E.LNAME从员工E中不存在的地方选择PNO从DNO='5'减号的项目中选择PNO从工作中选择E.SSN=SSN;嗨,因为我对mysql包一无所知,所以我选择了SQL选项。我想说什么都行。在MySQL中模拟减号运算符是一个更好的新问题。