Solved

minus gives me results but i see no difference

Posted on 2013-12-27
11
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 23

Expert Comment

by:David
ID: 39742641
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
ID: 39743251
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
ID: 39743597
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:sam2929
ID: 39743662
its 11g
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39743955
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
 

Author Comment

by:sam2929
ID: 39746304
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
ID: 39746672
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 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39747053
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
ID: 39750033
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
ID: 39750298
I'm missing where you every responded to my query, exactly which character set is your client session using?
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39750334
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to take different types of Oracle backups using RMAN.

688 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