mysql从一加到100_MYSQL用存储过程求1到100累加

匿名用户

1级

2013-06-29 回答

mysql> delimiter |

mysql> create procedure p1(OUT vout int

-> begin

-> declare v1 int default 1;

-> declare v2 int default 0;

-> while v1<=100 DO

-> set v2=v2+v1;

-> set v1=v1+1;

-> end while;

-> SET vout=v2;

-> end;

-> |

Query OK, 0 rows affected (0.00 sec)

mysql> call p1(@count);

-> |

Query OK, 0 rows affected (0.00 sec)

mysql> select @count|

+--------+

| @count |

+--------+

| 5050 |

+--------+

1 row in set (0.00 sec)

mysql> delimiter ;

mysql>________________________mysql> delimiter |

mysql> create procedure p2(OUT vout int )

-> begin

-> d

你可能感兴趣的:(mysql从一加到100)