Using the judging criteria in the MySQL database

Source: Internet
Author: User

"Student grades A90 B80 C70 D60 E60 According to student number and student grade"

Select field list into variable list from table the Where condition deposits the values from the field list in a record into the variable list, the variables in the variable list must be defined in advance.

/*stored Procedure if control structure*/delimiter//CREATE PROCEDURE Marks_level (in Stu_no Int (4),In cla_no Int (4),out _level varchar (4) BeginDeclare_mark Int (4)default0; Select Mark into _mark from marks where Sid=stu_no and CID =Cla_no; if_mark >= 90Then set _level= "A"; ElseIf_mark>= 80Then set _level= "B"; ElseIf_mark >= 70Then set _level= "C"; ElseIf_mark >= 60Then set _level= "D"; ElseSet _level= "E"; End if;End;//Set @result= "";//Call Marks_level (, @result);//Select @result;// 

/*stored procedure case control Structure*/delimiter//CREATE PROCEDURE Marks_level_case (in Stu_no Int (4),In cla_no Int (4),out _level varchar (4) BeginDeclare_mark Int (4)default0; Select Mark into _mark from marks where Sid=stu_no and CID =Cla_no;  CaseWhen _mark>= 90Then set _level= "A"; When _mark>= 80Then set _level= "B"; When _mark>= 70Then set _level= "C"; When _mark>= 60Then set _level= "D"; ElseSet _level= "E"; End  Case;End;//Set @result = "";//Call Marks_level_case (@result);//Select @result;//

 /*   stored procedure while control structure  */ delimiter  // create procedure sums_while (in n int ( 4),  inout sums Int (  4 while  n>0 do   set sums  = sums + n;    Set n  = N-1;  end  while   end ; // set @result =0;call sums_while ( 10, @result); select @result;  

// CREATE PROCEDURE Sums_repeat (in    n int (4),    inout sums int (4)) Begin    Repeat           if            n>0 then = sums + N;         End if ;         = N-1;    Until n<0    end  repeat; End; //set @result =0; call Sums_repeat (@result); select @result;

 /*stored procedure cursor control structure*/delimiter//CREATE PROCEDURE Pro_cursor () BeginDeclarestu_no Int (11)default0; DeclareCla_mark Int (11)default0; Declaretag Int (11)default0; DeclareMoneys Int (11)default0; DeclareCUR1 cursor forSelect S. Sid,m.mark from student S leftJoinMarks m on s.sid = M.SID; Declare ExitHandler forSQLState "02000" set tag =1;    Open cur1;  while!tag Dofetch CUR1 into Stu_no,Cla_mark; ifCla_mark >= 90Then set Moneys= 500; ElseIfCla_mark >=80Then set Moneys= 400; ElseIfCla_mark >=70Then set Moneys= 300; ElseSet Moneys= 100; End if; Update student Set Moneys=moneys where sid=Stu_no; End  while; Close Cur1;End;//

Using the judging criteria in the MySQL database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.