Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Decode in Oracle

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 31
    Comment on it

    DECODE is a function in Oracle and is used to provide if-then-else type of logic to SQL. It is not available in MySQL or SQL Server.

     

    It is only used for the MySql server and in the Oracle server for the case like   manipulation that we perform in the SQL server.

     

    Decode is like the conditional statement that is used for the manipulation of the data stored in the tables.

     

     

    SELECT DECODE ( "column_name", "search_value_1", "result_1",
    ["search_value_n", "result_n"],
    {"default_result"} ); 

     

     

    So it is mainly used for the database except the Sql Server database it could be used to create a column alias for the display values when we want.

     

     

    SELECT DECODE(EmpFirstName,
      'Himanshu', 'H',
      'Mayank', 'M',
      'Ravi', 'R',
      'Others') [EmpMiddleName], [EmpLastname], [EmpAddress]
    FROM [EmployeeDetails] 

     

     

    If we want it to manipulate something based on some condition for the table data it will do this  also for the database programmer.

     

     

    SELECT DECODE(StudentMarks,
      >60, 'C',
      >70, 'B',
      >80, 'A',
      'Below Standard') [StudentName], [StudentClass]
    FROM [StudentDetails] 

     

    Oracle

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: