Kyle Grage
Kyle Grage

Reputation: 765

PL/SQL update based on flag

I have a table "flags" containing flags with "name" and "value" where "name" is the name of the flag and "value" is either 'T' or 'F'

I would like to update a table based on a flag with name 'enable_feature' in the following manner:

BEGIN;
IF ((SELECT flags.value FROM flags WHERE flags.name = 'enable_feature') = 'T')
UPDATE... SET...;
ELSE
UPDATE... SET...;
END IF;
END;

My trouble seems to be in the IF statement. Specifically, i get the following error:

PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:

( - + case mod new not null continue avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe

How do I modify this statement such that I can perform an UPDATE/SET statement based on the value of 'enable_feature' (The UPDATE/SET statement is on a different table)

Upvotes: 0

Views: 3086

Answers (1)

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23747

DECLARE
  v flags.value%type;
BEGIN
  SELECT flags.value into v FROM flags WHERE flags.name = 'enable_feature';
  IF v = 'T' THEN
    UPDATE... SET...;
  ELSE
    UPDATE... SET...;
  END IF;
END;

Upvotes: 3

Related Questions