#用在储存过程中: create procedure k() begin declare number int; )); case number then select '>0'; else select '=0'; end case; end$ #用在查询中: select case user when 'root' then 'yes' else 'no' end from mysql.user;select case when user='root' then 'yes' else 'no
循环结构 while create procedure name() begin while 条件 do SQL语句 end while; end$ create procedure aa6() begin ; do select number; ; end while; end$ mysql> create procedure aa6() -> begin -> declare number int default 0; -> w
--if/else语句 if 条件 then SQL语句 else SQL语句elseifSQL语句 end if; create procedure test1( number int ) begin then select user(); else select 'please input a number > 10'; end if; end$ mysql> create procedure test1( -> number int -> ) -> begin then
现在mysql上定义一个函数,一个储存过程 函数: delimiter \\ CREATE FUNCTION f2 ( num2 INT, num1 INT ) RETURNS INT BEGIN DECLARE a DEFAULT INT 1; SET a = num1 * num2; RETURN ( a ) ; END \\ delimiter; 函数式是计算两个值相乘的 在mysql的调用 select f2(9,5); -- 45 同时函数可以是配合select 函数 from 来使用
储存过程 DELIMITER // CREATE PROCEDURE pro1() BEGIN SELECT book_id,book_name,category FROM bookinfo t1 JOIN bookcategory t2 ON t1.book_category_id = t2.category_id; END// DELIMITER ; DELIMITER // ),OUT num INT) BEGIN DELETE FROM reader_info WHERE card_id