MySQL學習之流程控制

2021-10-01 12:26:49 字數 778 閱讀 4425

# 流程控制

# case when .. then ... else ... end

# case [test] when[val1] then [result]...else [default] end

如果test和valn相等,則返回resultn,否則返回default

# if(isnull(), t, f)

如果test是真,返回t;否則返回f

例如: select lession_name,

if(isnull(views),1

,0)from lession_views;

# ifnull(arg1,arg2)

如果arg1不是空值,返回arg1,否則返回arg2

例如: select lession_name,ifnull( views,0)

+1000

from lession_views;

# nullif(arg1,arg2)

如果arg1=arg2返回null;否則返回arg1

# if ... then ... end if;

# if ... then ... else ... end if;

# if ... then ... elseif ... then ... else... end if;

# ps: while num < 10 do .... end while;

# ps: repeat ... until num >= 5 end repeat;

Mysql之流程控制語句

這篇部落格主要是總結一下mysq中的流程控制語句的用法,主要是 case,if,ifnull,nullif 1.case case value when compare value then result when compare value then result else result end ...

MySQL之流程控制結構

順序結構 程式從上往下依次執行 分支結構 程式按條件進行選擇執行,從兩條或多條路徑中選擇一條執行 if函式 case結構 case 表示式或字段 when 值1 then 語句1 when 值2 then 語句2 else 語句n end case case when 條件1 then 語句1 wh...

JS學習之流程控制

doctype html utf 8 流程控制 分支 title 的語法結構 if 條件表示式 if 3 5 3.案例 進入網咖 彈出乙個輸入框。要求使用者輸入年齡,如果年齡大於等於18歲,允許進入網咖 var age prompt 請輸入您的年齡 if age 18 else 案例 判斷閏年 接受...