case statemnent [message #620436] |
Fri, 01 August 2014 07:32 |
|
mist598
Messages: 1195 Registered: February 2013 Location: Hyderabad
|
Senior Member |
|
|
Hi,
If fullname is >2 then i need morethen 3 is not possible , if <2 then need to display Fullname
SELECT CASE
WHEN ( Length (:fullname) - Length (Replace (:fullname, '||', ':')) ) >
2 THEN
'morethen 3 is not possible'
WHEN ( Length (:fullname) - Length (Replace (:fullname, '||', ':')) ) <
2 THEN
'Full name'
ELSE 'Nothing'
END "name"
FROM dual
|
|
|
|
|
Re: case statemnent [message #620450 is a reply to message #620448] |
Fri, 01 August 2014 08:45 |
_jum
Messages: 577 Registered: February 2008
|
Senior Member |
|
|
Your statement "works" but has an unexpected result for len=2:
WITH data(fullname) AS
(SELECT 'AAAAAA' FROM dual UNION ALL
SELECT 'A||' FROM dual UNION ALL
SELECT 'A||||' FROM dual UNION ALL
SELECT 'A||||||' FROM dual UNION ALL
SELECT '' FROM dual UNION ALL
SELECT NULL FROM dual)
SELECT fullname, Replace (fullname, '||', ':')rep, Length (fullname) - Length (Replace (fullname, '||', ':'))len, CASE
WHEN ( Length (fullname) - Length (Replace (fullname, '||', ':')) ) >
2 THEN
'morethen 3 is not possible'
WHEN ( Length (fullname) - Length (Replace (fullname, '||', ':')) ) <
2 THEN
'Full name'
ELSE 'Nothing'
END name
FROM data;
FULLNAME REP LEN NAME
---------------------------------------------
AAAAAA AAAAAA 0 Full name
A|| A: 1 Full name
A|||| A:: 2 Nothing
A|||||| A::: 3 morethen 3 is not possible
Nothing
Nothing
[Updated on: Fri, 01 August 2014 08:47] Report message to a moderator
|
|
|
|
|
|
|