Avatar of kalees
kalees
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Help with Oracle IF statment

Hi All,

I am looking to extract a date from a notes box which will always appear after the # symbol. I have achieved this with the following line of code

SUBSTR (FINE_NOTES,(INSTR (FINE_NOTES, '#')+1)) AS "Received Date",

I am now attempting to take it one stage further to return NULL if the # symbol is not present as there is other text in the notes box which I do not require. I have tried with the following code but am getting errors and I am struggling to see the issue.

IF INSTR (FINE_NOTES, '#') THEN SUBSTR(INSTR (FINE_NOTES, '#')+1) ELSE NULL END IF) AS "Received Date",


Any help greatly appreciated,

Keith.
Oracle DatabaseSQL

Avatar of undefined
Last Comment
Nitin Sontakke

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rgonzo1971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Nitin Sontakke

Or hopefully...

IIF(INSTR (FINE_NOTES, '#') != 0, SUBSTR(INSTR (FINE_NOTES, '#')+1),  NULL) AS "Received Date", 

Open in new window


I am more of a T-SQL developer than PL/SQL one, so please take it with table-spoon of salt!
kalees

ASKER
Perfect solution, many thanks
PortletPaul

FYI only:

To my knowledge up till now IIF() is not supported by PL/SQL and (I think) also isn't part f the SQL standards either.
Which is why I always prefer case expressions even for T-SQL.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Nitin Sontakke

I googled and found it here. So pasted the solution. Only after seeing your posted I noticed that it is part of MDX and not of PL/SQL.

Thank you!