案例陈述中的例外情况

时间:2017-08-28 13:58:00

标签: psql business-logic

如何在案例陈述中抛出异常?我相信signal是正确的陈述。案例陈述是在“' corp'在名称中找到,然后在列中有1,但如果单词' dollar'在名称

Name                     Is_comp
Dollar Tree Corp       
First Hand Corp           1

Select 
when name like 'corp' 
then 1 
end as is_comp

1 个答案:

答案 0 :(得分:0)

我认为,根据您所寻找的内容,您只需要一个更高级的CASE声明:

SELECT
    CASE 
        WHEN 
            name LIKE ANY ('%corp%','%llc%','%inc%') /*list of names with wildcards*/
            AND name not like '%Finch%' /*don't match on finch%/ 
            AND name not like ANY ('%Finch%','%Brian%') /*or optionally don't match on any of these name substrings*/
            THEN 1 
        END 'is_comp'
FROM <table>