简体   繁体   中英

RPAD and CASE statment - Oracle SQL - Missing Right Parenthesis Error

Trying to incorporate a CASE statement in the select statement. One works, but this one returns the error "missing right parenthesis."

|| CASE WHEN RPAD (RA.TAX_ID,9) IS NOT NULL THEN (RA.TAX_ID,9) ELSE '999999999',9) END

Here's an edited version of the query to give context. The second case statement works.

    >SELECT DISTINCT
    > RPAD ('D', 1)
    > || CASE WHEN RPAD (RA.TAX_ID,9) IS NOT NULL THEN (RA.TAX_ID,9) ELSE  '999999999',9) END

    > || CASE WHEN RPAD (RA.ACCOUNT_ENTITY_IND, 1) = 'P' THEN 'I' ELSE ' ' END
    > || RPAD (RA.LAST_NAME, 20)
    > || RPAD (RA.FIRST_NAME, 20)
    > || RPAD (' ', 10)
    > AS HEADER_ROW

Both the then and else elements are malformed.

 || CASE WHEN RPAD (RA.TAX_ID,9) IS NOT NULL THEN (RA.TAX_ID,9) ELSE  '999999999',9) END
                                                  ^         ^^^                  ^^^

Presumably the then is supposed to be another rpad() call, but the else looks like it should be a simple literal:

 || CASE WHEN RPAD (RA.TAX_ID,9) IS NOT NULL THEN RPAD (RA.TAX_ID,9) ELSE  '999999999' END

If you use an IDE like SQL Developer it will highlight simple syntax mistakes like this for you.

coalesce()会不会更简单?

|| COALESCE(RPAD(RA.TAX_ID,9), '999999999') ||

您是否在这里没有看到未封闭的括号:==>'999999999',9)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM