一.格式
if exists(條件判斷) {執行語句1} else {執行語句2}
二.實例
--現有數據表:【Table1】
--查詢語句: Select1: select cols1 from Table1 where cols1=0
--更新語句: Update1: update Table1 set cols1=1 where cols1=0
--添加語句: Insert1: insert into Table1 cols1 values(0)
if exists(Select1) Update1 else Insert1
--如果 Table1 表中存在字段值 cols1 =0 則將cols1 的值改爲1,否則添加數據 cols1 =0
--exists()作爲條件判斷,當 Select1 查詢結果不爲空,則返回true,執行 if 下屬的語句,如果 Select1 結果爲空,返回false,執行 else的下屬語句。
--not exists() 反之。