Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

   

 

  Oracle Tips by Burleson

The case statement

Instead of nesting many if-then-else or if-then-else-then statements, another alternative is to use the case statement. The case statement allows you to perform a different set of commands depending upon the value associated with a string variable.

Using the case statement

echo -n " What type of pet do you have (dog, cat, etc.)? "

read pet

echo " "

case $pet in

dog) echo " So you have a dog ..."

echo " That's nice, so do I."

echo " My dog's name is Fido.";;

cat) echo " So you have a cat ..."

echo " I'm allergic to cats!";;

fish) echo " So you have fish ..."

echo " Can't take them for a walk .. ha, ha.";;

ferret) echo " Ferrets are cool!";;

*) echo " A $pet ... that's a funny pet";;

esac

echo " "

The case example script above asks the user what kind of pet they have and then provides different responses depending upon the type of pet answered. It looks for answers of “dog”, “cat”, “fish”, “ferret”, and “*”. The asterisk (*) matches any other answer supplied by the user. When a match is found by the case statement, all commands are executed until a double semi-colon (;;) is encountered.

When the example above is entered and saved to a file (we’ll learn this in the next chapter) called whatpet.ksh, we can run it as shown below:

Running the case script

$ ./whatpet.ksh

What type of pet do you have (dog, cat, etc.)? moose

A moose ... that's a funny pet

$ ./whatpet.ksh

What type of pet do you have (dog, cat, etc.)? dog

So you have a dog ...

That's nice, so do I.

My dog's name is Fido.
 

The above book excerpt is from:

Easy Linux Commands
Working Examples of Linux Command Syntax

ISBN: 0-9759135-0-6   

Terry Clark 

http://www.rampant-books.com/book_2005_1_linux_commands.htm 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2017

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

Remote Emergency Support provided by Conversational