Quick question in PL/SQL

Doing a

var1 VARCHAR2;

 "Select fieldA into var1 from TableA"

If LENGTH(var1) = 0 then
    do this
else
    do this
end if;

Is there a better way of checking for a value for this?
jknj72Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
if var1 is NULL, then length will be null

try  


if VAR1 is NULL then
    do this
else
    do this
end if;


or use case

case
      when var1 is null then
              do this
       else
               do this
end case;

functionally identical,  some prefer CASE over IF, especially if you multiple conditions  but it's still only a cosmetic preference
0
slightwv (䄆 Netminder) Commented:
Probably not.

You "could" do the following but I seriously doubt it helps with performance:
var1 number;

  "Select length(fieldA) into var1 from TableA"

 If var1 = 0 then
     do this
 else
     do this
 end if;
0
slightwv (䄆 Netminder) Commented:
OH, check for a value or not, not the length of the returned value...

sdstuber is correct.

Unless the select returns no rows, then you might need a no_data_found exception.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

jknj72Author Commented:
>>if var1 is NULL, then length will be null

What if its an string with spaces in it '     '
Can I do a TRIM and then check for NULL?
0
sdstuberCommented:
>>> Can I do a TRIM and then check for NULL?

yes

if trim(VAR1) is NULL then


case when trim(VAR1) is NULL
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jknj72Author Commented:
Thanks!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.