I’m converting some MySQL 5.0 functions to Oracle 11g.
I need to place an IF inside a case but get an error (missing right parenthesis)
this is my code
SELECT SUM(
CASE PTIPO
WHEN 0 THEN (SELECT IF(A.NT = 0) THEN A.VALOR ELSE 0 END IF FROM DUAL)
WHEN 1 THEN (SELECT IF(A.NT = 1) THEN A.VALOR ELSE 0 END IF FROM DUAL)
WHEN 2 THEN (SELECT IF(A.NT = 1) THEN A.VALOR ELSE -A.VALOR END IF FROM DUAL)
END)
INTO nresp
FROM mov_caja a
JOIN enc_movp b ON a.docid = b.docid
JOIN c_caja c ON a.cajaid = c.cajaid
WHERE c.cajaid
IF / ELSEare used for flow control inside functions and prepared statments, rather than for assembling conditions in single statements.Really you just need to nest another
CASEinside using its other syntactic formatCASE WHEN <condition> THEN <value>: