1 PostgreSQL if判断语句 2 1、语法: 3 if condition then 4 statement; 5 end if; 6 7 案例1: 8 do $$ 9 declare 10 a integer := 10; 11 b integer := 20; 12 begin 13 if a>b then 14 raise notice 'a is greater then b'; 15 end if; 16 17 if a<b then 18 raise notice 'a is less then b'; 19 end if; 20 21 if a=b then 22 raise notice 'a is equal to b '; 23 end if; 24 end; $$ 25 26 27 28 2、语法: 29 if then else 30 if condition then 31 statement1; 32 else 33 statement2; 34 end if; 35 36 案例: 37 do $$ 38 declare 39 a integer :=10; 40 b integer :=20; 41 begin 42 if a > b then 43 raise notice 'a is greater then b'; 44 else 45 raise notice 'a is not greater then b'; 46 end if; 47 48 end; $$ 49 50 51 52 3、语法: 53 if condition then 54 statement1; 55 elsif condition then 56 statement2; 57 ... 58 else 59 statementn; 60 end if; 61 62 案例: 63 do $$ 64 declare 65 a integer :=20; 66 b integer :=20; 67 begin 68 if a > b then 69 raise notice 'a is greater then b'; 70 elsif a = b then 71 raise notice 'a is equal to b'; 72 elsif a < b then 73 raise notice 'a is less then b'; 74 else 75 raise notice 'error'; 76 end if; 77 end; $$