2016-12-28 52 views
1

表列:ID,姓名,年齡兩排在Oracle數據庫比較和顯示列不匹配

第一排:

select 11, 'James', 22 from dual; 

這將返回

11 James 22 

第二行:

select * from supplier where id=11`; 

這將返回

11 Vinod 25 

現在,我想都行比較:

11 James 22 
11 Vinod 25 

它應該返回其中有差異的列。

名稱不匹配 年齡不匹配

我使用12C是有內置的功能,在Oracle中,這將解決這個問題。 或者我可以從中獲得相同解決方案的任何其他方式。

在此先感謝..

`

+0

都是你想要的行比較目前在同一個表中? – GurV

+0

我正在比較我的靜態數據行與表數據行 – vinod

+0

沒有這樣的內置功能。但實現起來很簡單。什麼是阻滯劑? – GurV

回答

3

您可以使用joindecode(可以使用case備選地),以找出是否列值匹配:

with cte(id, name, age) as (select 11, 'James', 22 from dual) 
select 
    s.id, 
    decode(s.name, t.name, null, 'Name mismatch') name_check, 
    decode(s.age, t.age, null, 'Age mismatch') age_check 
from supplier s 
inner join cte t 
on s.id = t.id 
where s.id = 11; 
+0

作品像魅力..感謝Gurwinder有一個美好的一天.. – vinod

+0

我也將嘗試與案例以及.. – vinod

相關問題