Create or Replace function decode (p_condition boolean, p_fist_val text, p_last_val text) returns text as$ $declare V_ret_val Text;begin/* Function Description: Analog ternary expression (condition-value1:value2); * Parameter Description: P_condition receive a Boolean expression such as: 1 = 1, 2 > 1, etc.; The latter two values are based on the true and false corresponding return value of p_condition * Implementation principle: P_condition to True return P_fist_val, otherwise return p_last_val */v_ret_val: = null; If True = P_condition then v_ret_val: = P_fist_val; elsif false = P_condition then v_ret_val: = P_last_val; End If; Return v_ret_val;end;$$ language plpgsql;--test Data Select decode (1=2, ' outer ', decode (1=1, ' inter1 ', ' inter2 '));
This article is from the "accumulate Kuibu to thousands of Miles" blog, please be sure to keep this source http://chnjone.blog.51cto.com/4311366/1658846
"Subtotal" PostgreSQL implements three-dimensional expression function