开发者

Different column types on INNER JOIN

开发者 https://www.devze.com 2023-04-09 23:49 出处:网络
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

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' )
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号