Type of Triangle in MYSQL

前端 未结 18 2394
执念已碎
执念已碎 2020-12-09 11:48

Problem statement:

Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the followin

18条回答
  •  天命终不由人
    2020-12-09 12:31

    this answer is working well in sql * plus but not in hackerrank i dont know why? try this.

    declare
     cursor mytriangle is select A,B,C from triangles;
     a triangles.A %type;
     b triangles.B %type;
     c triangles.C %type;
     begin
     open mytriangle;
     if mytriangle%isopen then
     loop
     fetch mytriangle into a,b,c;
     exit when mytriangle %notfound;
     case
     when a+b<=c or b+c<=a or a+c<=b then
     dbms_output.put_line('Not A Triangle');
     when a=b and b=c then
     dbms_output.put_line('Equilateral');
     when a=b or b=c or c=a then
     dbms_output.put_line('Isoceles');
     when a+b>=c and b+c>=a and a+c>=b and a!=b and b!=c and c!=a then
     dbms_output.put_line('Scalene');
     else
     dbms_output.put_line('');
     end case;
     end loop;
     close mytriangle;
     else dbms_output.put_line('cannot open the cursor');
     end if;
    end;
    

提交回复
热议问题