开发者

Find similar data from different columns in Oracle

开发者 https://www.devze.com 2023-02-07 12:24 出处:网络
I have two columns like this. (TC_NO 开发者_如何学Gois 11 character, VER_NO is 10 character) TC_NOVER_NO

I have two columns like this. (TC_NO 开发者_如何学Gois 11 character, VER_NO is 10 character)

TC_NO        VER_NO
19262512794  1926251279    
31124177286  1111111111
31067179194  2222222222
65617278204  6561727820
31483188084  0000000000

What i want is, finding VER_NO's first 10 character is the same TC_NO's first 10 characters..

For example for this table the result should be:

TC_NO        VER_NO
19262512794  1926251279
65617278204  6561727820

How can I do that in Oracle?


select *
from MYTABLE
where substr(TC_NO,1,10) = VER_NO


Assuming you dont have nulls.

select *
from MYTABLE
where substr(TC_NO,1,10)=substr(VER_NO, 1, 10);

If you have nulls and you want them to be equal.

select *
from MYTABLE
where substr(NVL(TC_NO, '-'),1,10)=substr(NVL(VER_NO, '-'), 1, 10);

If you have nulls and you dont want them to be equal.

select *
from MYTABLE
where substr(NVL(TC_NO, '-'),1,10)=substr(NVL(VER_NO, '|'), 1, 10);
0

精彩评论

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