• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set to null...

 
George Larry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
V Srinivasan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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.
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic