So I got two tables that I'll reference with a INNER JOIN. In one side the column type is Number(3, 0)
and in the other is Varchar(150)
. Seeing that I CAN'T change the data types, I have to Cast it on the join. But, on the table that the column is varchar the string always have 3 digits like '001', '010' or even '100' and so on...
My solution is use Case
on the join like this:
INNER JOIN TAB1 ON TAB1.VAR开发者_Python百科CHAR_COL = Cast(Case...), AS Varchar(150)
The Case
have to format the number to a string with the tree digits prefixed, like mentioned above.
If data comes like '1', Case have to format as '001', if comes like '10', it will change to '010'...
Help me with the Case
.
Edit: The varchar column have some values that aren't numbers, so casting it show an error.
Doesn't seem like any need for CASE
at all.
TAB1.VARCHAR_COL = TO_CHAR( TAB2.NUMBER_COL, '000' )
精彩评论