I have the following CASE in PL/SQL
CASE
WHEN v_line_item.custom_segment = 'CND1' THEN
v_current_col := v_col_lcy_tps;
WHEN v_line_item.custom_segment = 'CND2' THEN
v_current_col := v_col_lcy_ib;
WHEN v_line_item.custom_segment = 'CND3' THEN
v_current_col := v_col_lcy_gm;
WHEN v_line_item.custom_segment = 'CND4' THEN
v_current_col := v_col_lcy_pb;
WHEN v_line_item.custom_segment = 'CND5' THEN
v_current_col := v_col_lcy_bb;
END CASE;
The code compiles fine, but when I execute to stored proc I get the following error:
ORA-06592: CASE not found while executing CASE statement
So when I remove the CASE; the stored proc won’t compile. The only Examples I can get my hands on, uses the CASE in a select statement, I don’t want to use it in select statement, I want to set my variable without having a bunch of IF THEN ELSE statements.
If you use a
CASEstatement – the listings under theCASE– must match all conditions that you might encounter – either explicitly as you have done by usingor by using the
ELSEclause.Your code is hitting a situation where
v_line_item.custom_segmentdoesn’t match any of the givenCASEscenarios, hence Oracle raises this exception.You could add a catch-all condition
so that it matches all conditions.
Further reading: