Skip to Main Content

Breadcrumb

May 4th

Question and Answer

Chris Saxon

Thanks for the question, Sergiu.

Asked: August 04, 2017 - 11:57 am UTC

Last updated: August 04, 2017 - 3:56 pm UTC

Version: oracle 11g

Viewed 10K+ times! This question is

You Asked

How can I use a SELECT CASE INTO to store a value in a local variable?


and Chris said...

Like you'd select any other column or expression into a variable!

You put your case statement in the select clause and into after between the select and from clauses:

set serveroutput on
declare
  l varchar2(10);
begin
  select case when 1=1 then 'THIS' else 'THAT' end 
  into   l from dual;
  
  dbms_output.put_line(l);
end;
/

THIS


Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library