DEV Community

Discussion on: If Statement Golf: what's the longest one you've seen?

Collapse
 
scottishross profile image
Ross Henderson

I don't know if this counts, but this is a multi-nested CASE statement in one of my dynamic SQL queries. CASE acts as a if-then-else statement.

case 
    when LIST_TYPE = 1 
    then 
        case when NEW_TAB = 0 
             then apex_util.prepare_url('f?p=' || 'INSITE' || ':10000:' || :APP_SESSION || '::::P0_MENU_ID:' ||  MENU_ID)
             else 'javascript:apex.navigation.openInNewWindow(' || chr(39) || utl_url.unescape(LINK_TARGET) || chr(39) || ')'
        end
    when LIST_TYPE = 2 
    then 
        case 
            when NEW_TAB = 0 
            then apex_util.prepare_url('f?p=' || APP_ALIAS || ':' || LINK_TARGET || ':' || :APP_SESSION)
            else 'javascript:apex.navigation.openInNewWindow(' || chr(39) || 'f?p=' || APP_ALIAS || ':' || LINK_TARGET || ':' || :APP_SESSION || chr(39) || ')'
        end
    when LIST_TYPE = 3
    then apex_util.prepare_url('f?p=' || 'INSITE' || ':10000:' || :APP_SESSION || ':' || 'APPLICATION_PROCESS=GET_FILE:::P0_MENU_ID:' || MENU_ID)
    else null
end as LINK_TARGET, 
Collapse
 
jsn1nj4 profile image
Elliot Derhay • Edited

I was actually going to see if I could refactor it, but I'm not exactly a SQL pro (see what I did there?)

Thanks for sharing though! Even gave me something new to look at (SQL cases).