Solved

minus gives me results but i see no difference

Posted on 2013-12-27
11
318 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
join a table with user_tab_columns in oracle 3 69
Pivoting oracle table 9 74
Migration from sql server to oracle (IF then else condition ) 13 44
return value based on substr 10 51
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

726 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