Home » SQL & PL/SQL » SQL & PL/SQL » comparing values in select
comparing values in select [message #8397] Fri, 15 August 2003 19:54 Go to next message
Dushm
Messages: 11
Registered: September 2002
Junior Member
Hi,

I have a select statement which selects around 15 fields.
Then i have a sencond select statement which also select these 15 fileds from another set of tables. I now have to compare and see if any of the field values are different.
If there is a difference then i need to insert this different fields and its value into another table.

I think we can do this by having 15 If statements and comparing for the changed fields , but my question is, Is there any other efficient way doing this other than having 15 IF statements.

Any help is greatly appreciated.

-Dushm
Re: comparing values in select [message #8401 is a reply to message #8397] Sun, 17 August 2003 19:25 Go to previous message
Shailender Mehta
Messages: 49
Registered: June 2003
Member
Use a MINUS command to print out the differences between the two select's.

Here's a example,

Test Db>select * from test1;

COL1 COL2 COL3 COL4 COL5
----- ----- ----- ----- -----
COL1 COL2 COL3 COL4 COL5
Val1 Val2 Val3 Val4 Val5
abc def ghi jkl mno
a123 b124 c125 d126 e127
0123 0124 0125 0126 0127

Test Db>select * from test2;

COL1 COL2 COL3 COL4 COL5
----- ----- ----- ----- -----
COL1 COL2 COL3 COL4 COL5
Value Value Value Value Valu5
1 2 3 4
abc def jkl jkl mno
a123 b124 c125 d0126 e127
0123 0124 0125 0126 0127

select col1, col2, col3, col4, col5
from test1
MINUS
select col1, col2, col3, col4, col5
from test2
/

This will print out all rows from table test1 which
does not match the results fetched from table test2.

If you want the results the other way i.e. the driving table to be test2, just change the query to :-

select col1, col2, col3, col4, col5
from test2
MINUS
select col1, col2, col3, col4, col5
from test1
Previous Topic: How to handle single quotes in dynamic SQL.
Next Topic: Broken korean characters while using utl_file.fopen
Goto Forum:
  


Current Time: Thu Apr 25 09:21:56 CDT 2024