Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display a field's hidden characters in the result of a query in Oracle?

Tags:

oracle

plsql

I have two rows that have a varchar column that are different according to a Java .equals(). I can't easily change or debug the Java code that's running against this particular database but I do have access to do queries directly against the database using SQLDeveloper. The fields look the same to me (they are street addresses with two lines separated by some new line or carriage feed/new line combo).

Is there a way to see all of the hidden characters as the result of a query?I'd like to avoid having to use the ascii() function with substr() on each of the rows to figure out which hidden character is different.

I'd also accept some query that shows me which character is the first difference between the two fields.

like image 257
Chris Williams Avatar asked Feb 23 '11 15:02

Chris Williams


People also ask

How do you pass special characters in Oracle query?

Answer: Oracle handles special characters with the ESCAPE clause, and the most common ESCAPE is for the wildcard percent sign (%), and the underscore (_). For handling quotes within a character query, you must add two quotes for each one that is desired. This will display "Larry's the Man!": select 'Larry''s the Man!'

How do I show special characters in SQL Developer?

To do this, execute the query select ascii('🍁') from dual; To get the character (such as 🍁) into the query code, you need to somehow copy it and then paste it into the code editor in SQL Developer. The way I do this is to copy the character from one of many sites on the Web that lists Unicode characters.


1 Answers

Try

select dump(column_name) from table

More information is in the documentation.

As for finding the position where the character differs, this might give you an idea:

create table tq84_compare (
  id  number,
  col varchar2(20)
);

insert into tq84_compare values (1, 'hello world');
insert into tq84_compare values (2, 'hello' || chr(9) || 'world');

with c as (
 select
  (select col from tq84_compare where id = 1) col1,
  (select col from tq84_compare where id = 2) col2
 from
  dual
),
l as (
  select
  level l from dual
  start with 1=1
  connect by level < (select length(c.col1) from c)
)
select 
  max(l.l) + 1position
from c,l
  where substr(c.col1,1,l.l) = substr(c.col2,1,l.l);
like image 58
René Nyffenegger Avatar answered Sep 22 '22 15:09

René Nyffenegger