日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 存储过程 嵌套if_mysql存储过程if嵌套if的写法

發(fā)布時間:2025/3/19 数据库 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 存储过程 嵌套if_mysql存储过程if嵌套if的写法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

類似語法上的問題,其實可以參考一下手冊中的說明和例子。

MySQL 5.4 Reference Manual12.8.6.1. IF Statement

IF search_condition THEN statement_list

[ELSEIF search_condition THEN statement_list] ...

[ELSE statement_list]

END IF

IF implements a basic conditional construct. If the search_condition evaluates to true, the corresponding SQL statement list is executed. If no search_condition matches, the statement list in the ELSE clause is executed. Each statement_list consists of one or more statements.

Note

There is also an IF() function, which differs from the IF statement described here. See Section 11.3, “Control Flow Functions”.

An IF ... END IF block, like all other flow-control blocks used within stored programs, must be terminated with a semicolon, as shown in this example:

DELIMITER //

CREATE FUNCTION SimpleCompare(n INT, m INT)

RETURNS VARCHAR(20)

BEGIN

DECLARE s VARCHAR(20);

IF n > m THEN SET s = '>';

ELSEIF n = m THEN SET s = '=';

ELSE SET s = '

END IF;

SET s = CONCAT(n, ' ', s, ' ', m);

RETURN s;

END //

DELIMITER ;

As with other flow-control constructs, IF ... END IF blocks may be nested within other flow-control constructs, including other IF statements. Each IF must be terminated by its own END IF followed by a semicolon. You can use indentation to make nested flow-control blocks more easily readable by humans (although this is not required by MySQL), as shown here:

DELIMITER //

CREATE FUNCTION VerboseCompare (n INT, m INT)

RETURNS VARCHAR(50)

BEGIN

DECLARE s VARCHAR(50);

IF n = m THEN SET s = 'equals';

ELSE

IF n > m THEN SET s = 'greater';

ELSE SET s = 'less';

END IF;

SET s = CONCAT('is ', s, ' than');

END IF;

SET s = CONCAT(n, ' ', s, ' ', m, '.');

RETURN s;

END //

DELIMITER ;

總結(jié)

以上是生活随笔為你收集整理的mysql 存储过程 嵌套if_mysql存储过程if嵌套if的写法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。