【问题标题】:converting this Oracle SQL procedure to Mysql procedure将此 Oracle SQL 过程转换为 Mysql 过程
【发布时间】:2018-05-07 05:33:50
【问题描述】:

我尝试使用在线 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;
/

在此我正在计算 3 次测试中最好的两个分数的平均值,当我调用此程序时,它应该更改表中的值。

【问题讨论】:

    标签: mysql oracle stored-procedures


    【解决方案1】:

    可以用单个更新语句替换过程吗?

    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 数据。
    • 嘿,你能帮我做一件事吗?我们在 oracle 中使用 MINUS 或 EXCEPT 但我不知道在 mysql 中使用什么来进行以下查询 SELECT E.FNAME, E.LNAME FROM EMPLOYEE E WHERE NOT EXISTS((SELECT PNO FROM PROJECT WHERE DNO='5' ) MINUS (SELECT PNO FROM WORKS_ON WHERE E.SSN=SSN));
    • 嗨,由于我对 mysql 包一无所知,所以我选择了 SQL 选项。不管我说什么。最好作为一个新问题来模拟 MySQL 中的减号运算符。
    猜你喜欢
    • 2021-08-17
    • 2016-04-21
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 2019-10-19
    • 2020-09-28
    相关资源
    最近更新 更多