Solved

minus gives me results but i see no difference

Posted on 2013-12-27
11
313 Views
Last Modified: 2014-01-07
Hi,
i am  doing below query to see differences:

select frenchdesc from table a
minus
select frenchdesc from table b

and i am seeing the difference

but when i select the record in both table it looks same to me any idea why minus gives me results:


table a

"DIRECTEUR - SERVICES STÉRIELS
"
table b

"DIRECTEUR - SERVICES STÉRIELS
0
Comment
Question by:sam2929
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 23

Expert Comment

by:David
Comment Utility
It may be a typographic mistake, but the table B string is missing the <newline> closing ".  It is possible, albeit unlikely, that one of the two strings has unprintable characters.

If you would, provide a better sample of the two tables and the result set.  What I would expect is something like:

table a:
a
b
c

table b:
a
d

The result would be:
b
c
0
 

Author Comment

by:sam2929
Comment Utility
String missing was typo i think i know the problem one column is unicode and the other is not
any idea how can i see if the database support unicode or not
0
 
LVL 23

Expert Comment

by:David
Comment Utility
SELECT *
  FROM v$nls_parameters
 WHERE parameter LIKE '%CHARACTERSET'

Results?  And a web search on "Oracle unicode" will provide additional resources for your second question.  Also, which RDBMS version are you running?
0
 

Author Comment

by:sam2929
Comment Utility
its 11g
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
Take a look at the individual bytes in the returned resultset:

select dump(frenchdesc) from (
select frenchdesc from table a
minus
select frenchdesc from table b
)

Then check the individual bytes from the two returned.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:sam2929
Comment Utility
This is what i find not sure what it means length are different when you say bytes what bytes mean here?


Typ=1 Len=80: 0,68,0,73,0,82,0,69,0,67,0,84,0,69,0,85,0,82,0,32,0,45,0,32,0,
32,0,73,0,78,0,86,0,69,0,83,0,84,0,73,0,83,0,83,0,69,0,77,0,69,0,
78,0,84,0,83,0,32,0,83,0,84,0,82,0,65,0,84,0,201,0,71,0,73,0,81,0,85,0,69


DIRECTEUR -  INVESTISSEMENTS STRATÉGIQUE


Typ=1 Len=41: 68,73,82,69,67,84,69,85,82,32,45,32,32,73,78,86,69,83,84,73,83,83,
69,77,69,78,84,83,32,83,84,82,65,84,195,137,71,73,81,85,69

DIRECTEUR -  INVESTISSEMENTS STRATÉGIQUE
0
 
LVL 20

Accepted Solution

by:
flow01 earned 500 total points
Comment Utility
Appears there is an extra chr(0) before each character. If i try to reproduce it I get different results depending on the tool I use.

Try with table_a
as
(
select 'DIRECTEUR -  INVESTISSEMENTS STRATÉGIQUE' frenchdesc from dual
)
, table_b
as
(select REGEXP_REPLACE(frenchdesc, '(.)', chr(0) || '\1' ) frenchdesc from table_a)
select frenchdesc from (
select frenchdesc from table_a
union all
select frenchdesc from table_b
)
/

in sqlplus i get
FRENCHDESC
--------------------------------------------------------------------------------
DIRECTEUR -  INVESTISSEMENTS STRATÉGIQUE
 D I R E C T E U R   -     I N V E S T I S S E M E N T S   S T R A T É G I Q U E
so chr(0) shows like a blank

in pl-sql developer
1      
2      DIRECTEUR -  INVESTISSEMENTS STRATÉGIQUE
so chr(0) ends display the value (if i set the chr(0) after each character i only see 'D'

May be your tool just does not show the value chr(0)
You could try removing it before making the comparison replace(frenchdesc,chr(0),null)
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
As dvz suggested above, it looks like it is a characterset issue.

Is one of the columns a NVARCHAR2 and one not?
Is it possible that one of the tables is from a database link to a remote database?

The one with the length of 80 looks like a 2Byte characterset.  If you remove the 0 bytes and compare them character by character, look at the "É".

They show two different codes.
201,71
195,137

This is why the minus returned them.
0
 

Author Comment

by:sam2929
Comment Utility
yes we pulling data from SAP which is remote access and its unicode .

we inserting it in oracle database which is varchar .

Are you suggesting i convert nvarchar to varchar and all should be good.
0
 
LVL 23

Expert Comment

by:David
Comment Utility
I'm missing where you every responded to my query, exactly which character set is your client session using?
0
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
when loading data from a unicode source (like Sap or Active Directory) and storing it in the oracle database tables as VARCHAR2 a conversion occurs from unicode across the setting of the language you use (probably WE8MSWIN1252) to 8-bit ascii.

if you then do a select on the saved data and compare that with a select of the original, they will differ
as you see in the bytes returned, but possibly not on the screen

if you want an exact match in the database without conversion
use NVARCHAR2 or NCLOB for the data holding characters
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now