Results 1 to 5 of 5

Thread: Case statement in oracle database

  1. #1
    Join Date
    Jul 2009
    Posts
    188

    Case statement in oracle database

    Hello sir ,

    I am learning the PL/SQL programming and at the first stage of the development always curious to know the newer things in the database programming,I need to know How many ways we can implement the conditional statement in the PL/SQL programming.

    The conditional statements definitions are much closer to the definition of other languages.If you have some ideas about this then please help me.

    Thanks.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Case statement in oracle database

    Hello dude,
    You can include the conditional statement anywhere in your but that should be under the execution section of the code.

    It performs the same as the IF ELSE statements,you can create a condition in your program using IF ELSE statement and one more way is using CASE statement .The case statement provides the same functionality as the IF statement gives.It depends on you whatever you want to choose.It is introduces and applied with oracle 9i, 10g, 11g.

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Syntax for Case statement

    Starting from version Oracle 9i, you can use the case statement to specify the conditional statement within an SQL statement. It perform the same functionality of an IF-THEN-ELSE statement.

    The syntax to define the CASE statement -
    Code:
    CASE  [ expression ]
      WHEN condition_1 THEN result_1
      WHEN condition_2 THEN result_2
      ...
      WHEN condition_n THEN result_n
      ELSE result
    END
    Where the [ expression ] is optional,it shows the value to compare it with the list of conditions and the condition_1 is specified condition and result_1 is statement which would get print when the condition would be true and you can specify another condition as above.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Example of CASE statement

    The CASE statement can be evaluated as IF-ELSE statement.I am going to show you an example which will make the use of CASE expression more clear.

    The example will match the condition and choose the category according to their salary.

    Code:
    select Emp_sal, case when Emp_sal < 2000 then 'Payment_category 1' 
                     when Emp_sal < 3000 then 'Payment_category 2' 
                     when Emp_sal < 4000 then 'Payment_category 3' 
                     else 'Payment_category 4' 
                end 
    from employees_data;
    The query using CASE statement and will allow the category according to payment given by to employee.The salary of particular employee would be checked with three conditions and if not found to all then will be send to the category 4th.

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Nesting of CASE statement

    You can perform the nesting of CASE statement when you need more and more condition statement depends on the requirement of program.

    As you noted earlier,there are so many ways to define the CASE statement.I am going to show you an example contains the nested CASE statement.

    The example is as follows-

    Code:
    select (case when <condition> then
                                (case when <condition> then 'value '
                                      else 'value'
                                 end)
                 when <conditio> then
                                (case when <condition> then 'value '
                                      else 'value'
                                 end)
                 else 'value'
            end) 
    from  <table_name>
    where  <condition>;

Similar Threads

  1. insert into select statement for database
    By Aidan 12 in forum Software Development
    Replies: 5
    Last Post: 09-03-2010, 10:08 PM
  2. Use the CASE Statement in a SQL SELECT Clause
    By Abraham.J in forum Software Development
    Replies: 3
    Last Post: 12-08-2009, 01:52 PM
  3. How to use SQL Case Statement Syntax
    By Suzane in forum Software Development
    Replies: 3
    Last Post: 30-07-2009, 02:47 PM
  4. Bash case statement help on Ubuntu
    By _Gentoo_Nile_ in forum Operating Systems
    Replies: 3
    Last Post: 29-07-2009, 12:02 AM
  5. SWITCH....CASE statement in C#
    By Aadarsh in forum Software Development
    Replies: 1
    Last Post: 10-11-2008, 05:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,452,268.62026 seconds with 17 queries