SQL tutorial 49: CASE - Simple Case Expression in Oracle Database (1/2)
Key Takeaways
Creates roles in Oracle Database
Full Transcript
what's up internet welcome back once again I'm Manish from Rebellion rider.com today in this SQL tutorial we are going to learn Oracle case expression using case expression you can achieve the if then else logic in Oracle SQL that to without invoking any kind of SQL procedures case expression can do all the works of decode expression several books recommend using case over decode because case expression are easier to read in comparison of decode expression and also case expression is UNC compilant and forms part of the sql92 standard in Oracle there are two types of cases expression first is simple case expression second is search case expression let's try to understand these two case expression with the help of some queries but if you want to make some notes and read more about this topic then refer to the blog on my website which I have done just for you please have a look link is in the description box okay let's move ahead first let me connect to my database using my HR user here I am let me show you the user and as you can see the user is a CH okay the first case expression is simple case expression as the name just it is the simplest version of case expression in the other word we can say it is a flexible and the easiest version of the decode expression the syntax of simple case expression is simple case expression uses search expression to determine the return value means simple case expression evaluates all the input expression against the search expression Once A match is found the corresponding result is returned otherwise else result is displayed furthermore the else statement is optional so in case you omited then null is displayed when the simple case expression cannot find a match let's dig deeper at this concept using some queries for the demonstration I have created a table by the name of product let me show you as you can see this table has two columns product ID and company name but there is no column saying anything about product manufactured by these company so let's see how we can display the most manufactured product by this company by using simple case expression okay let me close this script output okay let's write the query okay let's format this query first if you want you can enclose this case block inside the parent syis like this okay here in the case block product ID column of the product table is our search expression and all the data of product ID column is our input expression the Oracle engine will try to evaluate all these input Expressions against the data from the product ID column if there is any match then it will return the corresponding result value for example when there is a value P1 in product ID column then Oracle engine will return cameras as the result for a better understanding let's execute this query and we got an error let me check oh sorry I forgot to put the comma here now let's execute once again and here is our result okay as you can see the column name of our case block is looking really ugly for that what we can do we can provide a column name to our case block okay let's execute once again okay now everything is okay as you can see the company corresponding to product ID P1 is Canon which produces cameras and similarly company corresponding to product ID P2 is luxara which produces I and so on but if you look at the last row of the result where product ID is P6 there we have the result WR from lse statement because there is no match for product ID P6 as there is no when and then pair for product ID P6 okay let's move ahead and write our second query let me close this query result whenever you specify a column name of a table as search expression as we did in our query one the Oracle engine treats all the data from this column as an array and matches all the input expression with every element of this array and if a match is found it Returns the corresponding result values in case you specify a string instead of a column name as a search expression then Oracle will find the first best fit match and return the corresponding result value so what is a first best fit match to answer this question let's write a query and see what does that mean okay let me first make some space here okay let's write our second query okay let me again format this query first let me again enclose this case block inside the parenthesis and here in the simple case the search expression is dog along with the four when then pairs the input expression of second and fourth pair is string dog which is a perfect match for our search expression but on executing this query Oracle engine will return the result value from the first best match which in our case is second pair let's execute as you can see the result is from our second pair let's take a look at the else statement of simple case as I have already told you that when there is no match for search expression then Oracle engine will Returns the AL statement for the demonstration let's change the input expression of second and fourth pair from dog to monkey and frog respectively let's close this query result okay now let's execute as you can see our result is sorry which is our else statement but else statement is optional and if you omit this then Oracle engine will return null let me first close this query result so let's delete this else statement and then execute the query again and as you can see see this time result is null there are few things which you must take care of while writing a case expression first the data type of all the input expression from 1 to n should match with that of search expression as well as with each other second similarly the data type of all the result from 1 to n along with the lse results should be the same for more example and in-depth knowledge of this concept go ahead and read my blog link is in the description box that's it for today's hope you learned something please hit the like button and don't forget to subscribe we'll see you soon with the second video video on this topic till then take care this is Manish
Original Description
Case expression let you perform IF-THEN-ELSE in oracle database. There are two type of case in oracle simple case expression and searched case expression. This SQL Tutorial 49 is about Simple Case Expression.
● What Is Case Expression
● Syntax of Simple Case Expression
● Query 1. Column name of a table as Search expression in CASE
● Query 2. String as Search expression in CASE
Celebrating 1000 subscribers. Thanks a lot guys for all your love and support.
------------------------------------------------------------------------
►►►LINKS◄◄◄
Blog: http://bit.ly/simple-case-expression
-------------------------------------------------------------------------
Copy Cloud referral link || Use this link to join copy cloud and get 20GB of free storage
https://copy.com?r=kb4rc1
--------------------------------------------------------------------------
►Make sure you SUBSCRIBE and be the first one to see my videos!
--------------------------------------------------------------------------
Amazon Wishlist: http://bit.ly/wishlist-amazon
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
►►►Find me on Social Media◄◄◄
Follow What I am up to as it happens on
https://twitter.com/rebellionrider
https://www.facebook.com/imthebhardwaj
http://instagram.com/rebellionrider
https://plus.google.com/+Rebellionrider
http://in.linkedin.com/in/mannbhardwaj/
http://rebellionrider.tumblr.com/
http://www.pinterest.com/rebellionrider/
You can also Email me at
RebellionRiderYT@gmail.com
Please please LIKE and SHARE my videos it makes me happy.
Thanks for liking, commenting, sharing and watching more of our videos
This is Manish from RebellionRider.com
♥ I LOVE ALL MY VIEWERS AND SUBSCRIBERS
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Manish Sharma · Manish Sharma · 56 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
▶
57
58
59
60
Oracle Database tutorials 1: How to install Oracle Database 11g on windows 7
Manish Sharma
Oracle Database tutorials 2:How To install SQL Developer on windows 7
Manish Sharma
Oracle Database tutorials 3:How to enable Line numbers in SQL Developer.
Manish Sharma
Oracle Database tutorials 4: database connectivity using SQL developer and command prompt
Manish Sharma
Oracle Database tutorials 5: how to Fetch Data using SELECT - SQL statement by Manish Sharma
Manish Sharma
Oracle Database11g tutorials 6 | | How to use Concatenation operator, character String
Manish Sharma
Oracle Database11g tutorials 7 | |SQL DISTINCT keyword || SQL tutorials
Manish Sharma
Canon EOS 600D 2 lens kit/Canon rebell EOS T3i 2 lens kit Unboxing
Manish Sharma
First look: ORACLE CERTIFIED ASSOCIATE (OCA) CERTIFICATE - ORACLE DATABASE ADMINISTRATOR
Manish Sharma
Oracle Database11g tutorials 8 || SQL DISTINCT with multiple columns |SQL Distinct with Two columns
Manish Sharma
Oracle Database11g tutorials 9 || What is archive log mode and how to enable archive log mode
Manish Sharma
Oracle Database11g tutorials 10 || SQL Single Row Function (SQL Functions )
Manish Sharma
Oracle Database11g tutorials 11: SQL case manipulation function in Oracle Database
Manish Sharma
how to add channel trailer and section on your youtube channel 2014
Manish Sharma
Oracle Database11g tutorials 12 || SQL Concat Function - SQL character manipulation function
Manish Sharma
Oracle Database11g tutorials 13 || SQL substr function / SQL substring function
Manish Sharma
Oracle Database11g tutorials 14 : How to CREATE TABLE using sql developer and command prompt
Manish Sharma
SQL tutorials 15 || How To CREATE TABLE using enterprise manager 11g
Manish Sharma
Oracle Database11g tutorials 16: How to uninstall oracle 11g from windows 7 64 bit
Manish Sharma
ORACLE CERTIFIED PROFESSIONAL(OCP) CERTIFICATE First look - ORACLE DATABASE ADMINISTRATOR
Manish Sharma
Plantronics audio 655 USB headset with Mic Unboxing and Review and Plantronics audio 655 Mic test
Manish Sharma
SQL tutorials 17: SQL Primary Key constraint, Drop primary Key
Manish Sharma
SQL tutorials 18: SQL Foreign Key Constraint By Manish Sharma
Manish Sharma
SQL tutorial 19: ON DELETE SET NULL clause of Foreign Key By Manish Sharma (RebellionRider)
Manish Sharma
SQL tutorials 20: On Delete Cascade Foreign Key By Manish Sharma (RebellionRider)
Manish Sharma
SQL tutorial 21: How To Rename Table in SQL using ALTER TABLE statement By Manish Sharma
Manish Sharma
SQL tutorial 22: How to Add / Delete column from an existing table using alter table
Manish Sharma
SQL tutorial 23: Rename and Modify Column Using Alter Table By Manish Sharma (RebellionRider)
Manish Sharma
SQL tutorial 24 :SQLJoins- Natural Join With ON and USING clause By Manish/Rebellionrider
Manish Sharma
Oracle Database11g tutorials 25: How to install Oracle Database 11g Express Edition R2 on Windows 7
Manish Sharma
SQL tutorial 26: Introduction to SQL Joins in Oracle Database
Manish Sharma
Vidcon 2014 YouTube Fan Funding: How to enable fan funding on YouTube Channel
Manish Sharma
SQL tutorial 27: Right Outer Join in SQL by Manish Sharma for RebellionRider
Manish Sharma
SQL tutorial 28: Left Outer Join By Manish Sharma / RebellionRider
Manish Sharma
SQL tutorial 29: Full Outer Join with example By Manish Sharma/ RebellionRider
Manish Sharma
SQL tutorial 30: Inner Join In SQL by Manish Sharma/RebellionRider
Manish Sharma
SQL tutorial 31 : SQL Cross Join In Oracle Database By Manish Sharma from RebellionRider
Manish Sharma
SQL tutorial 32: How To Insert Data into a Table Using SQL Developer
Manish Sharma
SQL tutorial 33:How To Insert Data into a Table Using SQL INSERT INTO dml statement
Manish Sharma
SQL tutorial 34: How to copy /Insert data into a table from another table using INSERT INTO SELECT
Manish Sharma
SQL tutorial 35: DELETE and TRUNCATE how to delete data from a table
Manish Sharma
SQL tutorial 36: how to create database using database configuration assistant DBCA
Manish Sharma
SQL tutorial 37: How to create NEW USER account using Create User statement in Oracle database
Manish Sharma
SQL tutorial 38: How to create user using SQL Developer in Oracle database
Manish Sharma
SQL tutorial 39: How to create user in oracle using Enterprise Manager
Manish Sharma
SQL tutorial 40: DBA Trick, How to drop a user when it is connected to the database
Manish Sharma
Motorola Moto G 2nd Generation / G2 Unboxing and Review
Manish Sharma
SQL tutorial 41: How to UNLOCK USER in oracle Database
Manish Sharma
SQL tutorial 42: How to Unlock user using SQL Developer By Manish Sharma RebellionRider
Manish Sharma
SQL tutorial 43: How to create an EXTERNAL USER in oracle database By Manish Sharma RebellionRider
Manish Sharma
SQL tutorial 44: How to import data from Microsoft Excel to Oracle Database using SQL Developer
Manish Sharma
SQL tutorial 45: Introduction to user Privileges in Oracle Database By Manish Sharma RebellionRider
Manish Sharma
SQL tutorial 46: What are System Privileges & How To Grant them using Data Control Language
Manish Sharma
SQL tutorial 47: How to Grant Object Privileges With Grant Option in Oracle Database
Manish Sharma
SQL tutorial 48: How to create Roles in Oracle Database
Manish Sharma
SQL tutorial 49: CASE - Simple Case Expression in Oracle Database (1/2)
Manish Sharma
SQL tutorial 50: CASE - Searched Case Expression In Oracle (2/2)
Manish Sharma
SQL tutorial 51: DECODE function in Oracle Database By Manish Sharma (RebellionRider)
Manish Sharma
Oracle Database Tutorial 52 : Data Pump expdp - How to Export full database using expdp
Manish Sharma
Oracle Database Tutorial 53 : Data pump expdp - How to Export tablespace in Oracle Database
Manish Sharma
Related AI Lessons
🎓
Tutor Explanation
DeepCamp AI