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.
The CASE statement selects a sequence of statements to execute. To select the sequence, the CASE statement uses a selector (an expression whose value is used to select one of several alternatives) or, in the searched CASE statement, multiple search conditions.
The PL/SQL CASE statement facilitates you to execute a sequence of satatements based on a selector. A selector can be anything such as variable, function or an expression that the CASE statement checks to a boolean value. The CASE statement works like the IF statement, only using the keyword WHEN.
The CASE statement has two types: simple CASE statement and searched CASE statement. Both types of the CASE statements support an optional ELSE clause.
Can CASE statements be nested? type_pre, As we see, Oracle allows nested CASE operators.
If you use a CASE
statement - the listings under the CASE
- must match all conditions that you might encounter - either explicitly as you have done by using
WHEN v_line_item.custom_segment = 'CND1' THEN
v_current_col := v_col_lcy_tps;
WHEN v_line_item.custom_segment = 'CND2' THEN
or by using the ELSE
clause.
Your code is hitting a situation where v_line_item.custom_segment
doesn't match any of the given CASE
scenarios, hence Oracle raises this exception.
You could add a catch-all condition
ELSE
-- do some work here, raise an exception or log it.
so that it matches all conditions.
Further reading:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With