Regarding Character field

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
das_nirmalya
Participant
Posts: 59
Joined: Thu Mar 20, 2008 12:11 am

Regarding Character field

Post by das_nirmalya »

I am populating one CHAR(6) filed of a table from another tables Varchar2 filed.
But after poulating done when i am trying to fire a query in Oracle with
where cond <Column_name>='value' , though value exist in table , yet it showing no record. Reason is that there may be some space etc padded with the value.

I have tried with trim,StripWhiteSpace in DataStage, pls give solutions
nsd
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:? A CHAR field automatically pads with spaces to the full length, that's the nature of the beast. Either match the field size in your test, use a 'like' wildcard comparison or trim it in the expression.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

Most databases will allow you to search without the trailing spaces, at least I know DB2 and Teradata do this:

Code: Select all

select count(*) from mytable where codefield = 'ABC'
is equivalent to

Code: Select all

select count(*) from mytable where codefield = 'ABC    '
as long as the whitespace at the end is truly spaces. My guess is your problem is not trailing spaces but padding that is NOT spaces. We have had instances where if we did not explicitly specify the pad character as a space, it was padding with hex 00 (NULL). Check the value of APT_STRING_PADCHAR and make sure it is set to a space.

You can also test the hex values in the data in the database to see what is actually in the field. In Teradata the function is char2hexint(char-field), and on DB2 the function is hex(char-field). If the end of your char field is populated with 202020 (hex 20 is an ASCII space), then it is fine. If it is populated with 000000 (hex 00 is an ASCII null char) or some other value, then that is the issue.

Hope this helps...

brad.
It is not that I am addicted to coffee, it's just that I need it to survive.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

[sigh] True, true, true. Oracle as well. It was a long day and a late night, guess we need the equivalent of gmail's "Mail Goggles" here. Or just I do. :wink:

I would agree, the padding more than likely isn't spaces in this particular case.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

Try coffee. I've heard rumors that some find it very good and mentally stimulating. Just rumors, though :)

Brad.
It is not that I am addicted to coffee, it's just that I need it to survive.
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

Brad,

Good tip about APT_STRING_PADCHAR.

Having a DB2 background when I first used Oracle many years ago, there are too many strange Oracle-isms to generalize. For instance, your example holds true if codefield is defined as CHAR. It does not hold true if codefield is defined as VARCHAR2. In DB2, your example works when codefield is CHAR or VARCHAR.

The most annoying Oracle-ism for me is the way that it interprets an empty string to mean NULL :roll: .

Mike
Post Reply