• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

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?
0
jknj72
Asked:
jknj72
  • 2
  • 2
  • 2
1 Solution
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
jknj72Author Commented:
Thanks!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now