Solved

Oracle PL/SQL Case statement

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

CASE V_UsrChoice
   WHEN 1
            THEN
                     SELECT A from dual
                     SELECT A1 from dual
   WHEN 2
            THEN      
                    SELECT B from dual
                    SELECT B1 from dual
END CASE
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
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
0
 
LVL 77

Accepted Solution

by:
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:
declare
	val1 char(1) := 'A' ;
	val2 char(1);
begin

	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);
end;
/
		    

Open in new window

0
 

Author Comment

by:Dovberman
ID: 40356942
Thanks,

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.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Closing Comment

by:Dovberman
ID: 40356944
Excellent.

Thanks,
0
 
LVL 49

Expert Comment

by:PortletPaul
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.
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40357087
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

729 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