Solved

Oracle PL/SQL Case statement

Posted on 2014-10-02
6
344 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:Dovberman
ID: 40356944
Excellent.

Thanks,
0
 
LVL 48

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 48

Expert Comment

by:PortletPaul
ID: 40357087
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Index on a Materialized View 5 59
date show only hh:mm 2 50
Migration from SQL server to oracle (XML input) 4 68
Oracle perfomance tuneing. 3 45
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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

734 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