Solved

Oracle PL/SQL Case statement

Posted on 2014-10-02
6
340 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
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extract Currency data from a string and put them in a new field 3 47
grant user/role question 11 36
run sql script from putty 4 164
Email query results in HTML 6 37
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

685 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