I'm beginning to understand the benefits of not using varchar for keying, as explained here
I am working with a DB2 database which I didn't setup which has a large table (20M+ rows) with a varchar key field. The table structure is as so:
key_field | matching_field1
000-XXX | 123
0000-XXX | 456
00-XXXXX | 789
The key_field
is of variable length. I'm trying to use the key_field
to link to a smaller table with 4k rows. The problem is that there is trailing space after the characters in the key_field
. I know this because if I search for a specific string using
SELECT * WHERE key_field LIKE '000-XXX'
there is no match, but if I try '000-XXX%'
then the row is selected. I assume this is the same reason I cannot key to my second table which contains a corresponding key_field
but which has been trimmed so there are no trailing whitespaces.
Assuming I cannot edit, duplicate or transpose this large table (at least not en masse due to resource limitations), is there a way to key it to the smaller table (4k rows) containing the same key_field
?
I can edit and manipulate the smaller table.
Update: running the query below using RTRIM
, I'm getting an error.
Query:
SELECT RTRIM(foreign_key)
FROM Small_Table
EXCEPT SELECT RTRIM(key_field)
FROM Big_Table
The error:
NUMBER OF ROWS DISPLAYED IS 0
SQLCODE = -904, ERROR: UNSUCCESSFUL EXECUTION CAUSED BY AN
UNAVAILABLE RESOURCE. REASON 00C90084, TYPE OF RESOURCE 00000100, AND
RESOURCE NAME DB2-MANAGED SPACE WITHOUT SECONDARY ALLOCATION OR
USER-MANAGED SPACE IN MYDB_NAME