Oracle PL/SQL Case statement

Posted on 2014-10-02
Last Modified: 2014-10-02
Can I perform more than one operation for a case?

CASE V_UsrChoice
   WHEN 1
                     SELECT A from dual
                     SELECT A1 from dual
   WHEN 2
                    SELECT B from dual
                    SELECT B1 from dual
Question by:Dovberman
LVL 24

Expert Comment

by:Phillip Burton
ID: 40356900
Don't believe so.

Why not:

CASE V_UsrChoice
   WHEN 1
            THEN A
   WHEN 2
            THEN  B
END CASE as first,
CASE V_UsrChoice
   WHEN 1
            THEN A1
   WHEN 2
            THEN  B1
END CASE as second
LVL 76

Accepted Solution

slightwv (䄆 Netminder) earned 500 total points
ID: 40356903
In PL/SQL yes.

Don't think so in native SQL.

Take a look at the complete test case below:
	val1 char(1) := 'A' ;
	val2 char(1);

	case val1
		when 'A' then
		   select 'B' into val2 from dual;
		   select 'C' into val2 from dual;
		when 'B' then
		   select 'D' into val2 from dual;
		   select 'E' into val2 from dual;
	end case;
	dbms_output.put_line('Val: ' || val2);

Open in new window


Author Comment

ID: 40356942

I have not yet built the SQL statements and wanted to simplify the question.

This is just part of a more complex PL/SQL function.

It's good to know that a case structure can be used to execute multiple SQL statements for a single case.
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Closing Comment

ID: 40356944

LVL 48

Expert Comment

ID: 40357084
just as a comment..

a "case EXPRESSION" would not allow those multiple operations

a "case STATEMENT" will

Not sure if Oracle's documentation makes that distinction but it exists in other products.
LVL 48

Expert Comment

ID: 40357087

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Migrating an SQL 2008 database to Oracle 12c 3 90
sql query 5 70
What is the version of ojdbc6.jar 2 41
1 FROM DUAL wont work with additional columns ?? 4 27
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now