dbTalk Databases Forums  

newbie:sql trim() in where clause not working

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss newbie:sql trim() in where clause not working in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
joes
 
Posts: n/a

Default newbie:sql trim() in where clause not working - 07-14-2006 , 09:16 AM






Hi

I have somestring entries which consists only of spaces. I like to get
rid of those entries but I can not "select" them. Both examples will
not return anything

select * from tableA where trim(field1) is NULL
select * from tableAt where trim(field1) = ''

Best options would be to do this during the importing job,
unfortunately I can not repat this import. So any other suggestions?

Many thanks in advance

regards
Mark


Reply With Quote
  #2  
Old   
Mark D Powell
 
Posts: n/a

Default Re: newbie:sql trim() in where clause not working - 07-14-2006 , 09:28 AM







joes wrote:
Quote:
Hi

I have somestring entries which consists only of spaces. I like to get
rid of those entries but I can not "select" them. Both examples will
not return anything

select * from tableA where trim(field1) is NULL
select * from tableAt where trim(field1) = ''

Best options would be to do this during the importing job,
unfortunately I can not repat this import. So any other suggestions?

Many thanks in advance

regards
Mark
Mark, look up the dump function in the SQL manual and exaimine some of
the columns in question to be sure the contents is one of more spaces
and not nulls or carriage returns, etc....

UT1 > l
1 select fld1, dump(fld1,10) Base10, dump(fld1,16) Base16
2 from marktest
3* where rownum = 1
UT1 > /

FLD1
----------
BASE10
--------------------------------------------------------------------------------
BASE16
--------------------------------------------------------------------------------
one
Typ=1 Len=3: 111,110,101
Typ=1 Len=3: 6f,6e,65


You should be able to use the LTRIM function to find the target rows:

UT1 > select * from marktest where ltrim(fld1) is null;

FLD1 FLD2 FLD3
---------- ---------- ---------
99 01-JAN-50

UT1 > select dump(fld1,10) from marktest where fld2 = 99;

DUMP(FLD1,10)
--------------------------------------------------------------------------------
Typ=1 Len=1: 32

HTH -- Mark D Powell --



Reply With Quote
  #3  
Old   
Charles Hooper
 
Posts: n/a

Default Re: newbie:sql trim() in where clause not working - 07-14-2006 , 09:34 AM



joes wrote:
Quote:
Hi

I have somestring entries which consists only of spaces. I like to get
rid of those entries but I can not "select" them. Both examples will
not return anything

select * from tableA where trim(field1) is NULL
select * from tableAt where trim(field1) = ''

Best options would be to do this during the importing job,
unfortunately I can not repat this import. So any other suggestions?

Many thanks in advance

regards
Mark
SELECT
*
FROM
TABLEA
WHERE
FIELD1 LIKE ' %';
(Note that there is a space before %)

SELECT
*
FROM
TABLEA
WHERE
SUBSTR(FIELD1,1,1)=' ';
(Note that there is a space between '')

SELECT
*
FROM
TABLEA
WHERE
NVL(LENGTH(TRIM(FIELD1)),0)=0;

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.



Reply With Quote
  #4  
Old   
joes
 
Posts: n/a

Default Re: newbie:sql trim() in where clause not working - 07-14-2006 , 10:02 AM



Many thanks for your help.
I did a "dump" and have seen that all entries have been spaces. I
BASE10 BASE16
Typ=1 Len=5: 32,32,32,0,0 Typ=1 Len=5: 20,20,20,0,0

Unfortunately your second suggestion did not work. The statement

Quote:
UT1 > select * from marktest where ltrim(fld1) is null;
did not return any reult.
hope that the other 2 characters '0' are ignored or are these null
characters?

regards
Mark


Mark D Powell schrieb:

Quote:
joes wrote:
Hi

I have somestring entries which consists only of spaces. I like to get
rid of those entries but I can not "select" them. Both examples will
not return anything

select * from tableA where trim(field1) is NULL
select * from tableAt where trim(field1) = ''

Best options would be to do this during the importing job,
unfortunately I can not repat this import. So any other suggestions?

Many thanks in advance

regards
Mark

Mark, look up the dump function in the SQL manual and exaimine some of
the columns in question to be sure the contents is one of more spaces
and not nulls or carriage returns, etc....

UT1 > l
1 select fld1, dump(fld1,10) Base10, dump(fld1,16) Base16
2 from marktest
3* where rownum = 1
UT1 > /

FLD1
----------
BASE10
--------------------------------------------------------------------------------
BASE16
--------------------------------------------------------------------------------
one
Typ=1 Len=3: 111,110,101
Typ=1 Len=3: 6f,6e,65


You should be able to use the LTRIM function to find the target rows:

UT1 > select * from marktest where ltrim(fld1) is null;

FLD1 FLD2 FLD3
---------- ---------- ---------
99 01-JAN-50

UT1 > select dump(fld1,10) from marktest where fld2 = 99;

DUMP(FLD1,10)
--------------------------------------------------------------------------------
Typ=1 Len=1: 32

HTH -- Mark D Powell --


Reply With Quote
  #5  
Old   
joes
 
Posts: n/a

Default Re: newbie:sql trim() in where clause not working - 07-14-2006 , 10:06 AM



Sorry for posting again but I did a small extension

select standort, dump(trim(fld1),10) Base10, dump(trim(fld1),16) Base16
from transaktion
where rownum = 1

in order to see if the null characters are an issue. The result is

BASE10 BASE16
Typ=1 Len=2: 0,0 Typ=1 Len=2: 0,0

So exist there a possibility to TRIM the null characters?

regards
Mark


joes schrieb:

Quote:
Many thanks for your help.
I did a "dump" and have seen that all entries have been spaces. I
BASE10 BASE16
Typ=1 Len=5: 32,32,32,0,0 Typ=1 Len=5: 20,20,20,0,0

Unfortunately your second suggestion did not work. The statement

UT1 > select * from marktest where ltrim(fld1) is null;

did not return any reult.
hope that the other 2 characters '0' are ignored or are these null
characters?

regards
Mark


Mark D Powell schrieb:

joes wrote:
Hi

I have somestring entries which consists only of spaces. I like to get
rid of those entries but I can not "select" them. Both examples will
not return anything

select * from tableA where trim(field1) is NULL
select * from tableAt where trim(field1) = ''

Best options would be to do this during the importing job,
unfortunately I can not repat this import. So any other suggestions?

Many thanks in advance

regards
Mark

Mark, look up the dump function in the SQL manual and exaimine some of
the columns in question to be sure the contents is one of more spaces
and not nulls or carriage returns, etc....

UT1 > l
1 select fld1, dump(fld1,10) Base10, dump(fld1,16) Base16
2 from marktest
3* where rownum = 1
UT1 > /

FLD1
----------
BASE10
--------------------------------------------------------------------------------
BASE16
--------------------------------------------------------------------------------
one
Typ=1 Len=3: 111,110,101
Typ=1 Len=3: 6f,6e,65


You should be able to use the LTRIM function to find the target rows:

UT1 > select * from marktest where ltrim(fld1) is null;

FLD1 FLD2 FLD3
---------- ---------- ---------
99 01-JAN-50

UT1 > select dump(fld1,10) from marktest where fld2 = 99;

DUMP(FLD1,10)
--------------------------------------------------------------------------------
Typ=1 Len=1: 32

HTH -- Mark D Powell --


Reply With Quote
  #6  
Old   
akkha1234 (AT) gmail (DOT) com
 
Posts: n/a

Default Re: newbie:sql trim() in where clause not working - 07-14-2006 , 03:00 PM



alternatively, try

select * from table a where length(trim(field1)) = 0

Charles Hooper wrote:
Quote:
joes wrote:
Hi

I have somestring entries which consists only of spaces. I like to get
rid of those entries but I can not "select" them. Both examples will
not return anything

select * from tableA where trim(field1) is NULL
select * from tableAt where trim(field1) = ''

Best options would be to do this during the importing job,
unfortunately I can not repat this import. So any other suggestions?

Many thanks in advance

regards
Mark

SELECT
*
FROM
TABLEA
WHERE
FIELD1 LIKE ' %';
(Note that there is a space before %)

SELECT
*
FROM
TABLEA
WHERE
SUBSTR(FIELD1,1,1)=' ';
(Note that there is a space between '')

SELECT
*
FROM
TABLEA
WHERE
NVL(LENGTH(TRIM(FIELD1)),0)=0;

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.


Reply With Quote
  #7  
Old   
Sybrand Bakker
 
Posts: n/a

Default Re: newbie:sql trim() in where clause not working - 07-14-2006 , 03:17 PM



On 14 Jul 2006 13:00:03 -0700, "akkha1234 (AT) gmail (DOT) com"
<akkha1234 (AT) gmail (DOT) com> wrote:

Quote:
alternatively, try

select * from table a where length(trim(field1)) = 0
Please do not top post

--
Sybrand Bakker, Senior Oracle DBA


Reply With Quote
  #8  
Old   
Mark D Powell
 
Posts: n/a

Default Re: newbie:sql trim() in where clause not working - 07-15-2006 , 05:07 PM




joes wrote:
Quote:
Many thanks for your help.
I did a "dump" and have seen that all entries have been spaces. I
BASE10 BASE16
Typ=1 Len=5: 32,32,32,0,0 Typ=1 Len=5: 20,20,20,0,0

Unfortunately your second suggestion did not work. The statement

UT1 > select * from marktest where ltrim(fld1) is null;

did not return any reult.
hope that the other 2 characters '0' are ignored or are these null
characters?

regards
Mark


Mark D Powell schrieb:

joes wrote:
Hi

I have somestring entries which consists only of spaces. I like to get
rid of those entries but I can not "select" them. Both examples will
not return anything

select * from tableA where trim(field1) is NULL
select * from tableAt where trim(field1) = ''

Best options would be to do this during the importing job,
unfortunately I can not repat this import. So any other suggestions?

Many thanks in advance

regards
Mark

Mark, look up the dump function in the SQL manual and exaimine some of
the columns in question to be sure the contents is one of more spaces
and not nulls or carriage returns, etc....

UT1 > l
1 select fld1, dump(fld1,10) Base10, dump(fld1,16) Base16
2 from marktest
3* where rownum = 1
UT1 > /

FLD1
----------
BASE10
--------------------------------------------------------------------------------
BASE16
--------------------------------------------------------------------------------
one
Typ=1 Len=3: 111,110,101
Typ=1 Len=3: 6f,6e,65


You should be able to use the LTRIM function to find the target rows:

UT1 > select * from marktest where ltrim(fld1) is null;

FLD1 FLD2 FLD3
---------- ---------- ---------
99 01-JAN-50

UT1 > select dump(fld1,10) from marktest where fld2 = 99;

DUMP(FLD1,10)
--------------------------------------------------------------------------------
Typ=1 Len=1: 32

HTH -- Mark D Powell --
Zero is the null character. You have managed to insert trailing nulls
into your character columns. You can use the RTRIM function to remove
all characters that appear in a set. If you trimmed both the null
character and the space character you should end up with a null column.

HTH -- Mark D Powell --



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.