• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Set to null...

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem...
I'm working with JSP and PL/SQL procedures.
I have a form where users are able to enter text that will be used in a search. I've written a procedure to run the search, but some of the fields are optional so I use the NVL(x,y) function.
Basically what that does is check to see if the value is null and uses 'y' if it is, and 'x' if it is not.
So... What I need to do is be sure that when I call this procedure the value is either something the user entered... or null.
The problem is- instead of getting NULL when the user doesn't enter anything- I'm getting "". How can I make a variable be NULL?
I thought that I could do a check- like this:
if ( myVar.equals( "" ) ) myVar = null;
But that doesn't seem to be working.
Is there something I can do in my entry form? Is there some way to force a variable to be null?
Thanks in advance.
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably need to trim it. Try this...
if (myVar.trim().equals(""))
 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that's the problem. I already checked the value of the variable and- when the user doesn't enter anything myVar = "". When I try to set the variable to null...
myVar = null;
...it becomes the string "null" it doesn't become null. So when I send it to my procedure it searches for the value "null"... I need to send it NULL.
Any more ideas?
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think instead of checking the variable with "" try to find the length, if it is 0 set myVar to null.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
U can try this function also:
// ----------------------------------------------------------------------------
// Purpose: Check if input is a empty string
// Parameters: szStr - value to be checked
// Return: returns false if not blank else
// return true
// ----------------------------------------------------------------------------
function bCheckBlank(szStr)
{
for(var i = 0; i < szStr.length; i++) {
var c = szStr.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}


Mahesh
[ April 25, 2002: Message edited by: Mahesh Mamani ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic