Solved

Oracle PL/SQL Case statement

Posted on 2014-10-02
6
323 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
6 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
Comment Utility
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 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
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
Comment Utility
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
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

by:Dovberman
Comment Utility
Excellent.

Thanks,
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
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 48

Expert Comment

by:PortletPaul
Comment Utility
0

Featured Post

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.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

763 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

12 Experts available now in Live!

Get 1:1 Help Now