问题
Some of the column values in my table are enclosed within double quotes and I need to remove those double quotes. The problem is, I am not able to view the double quotes symbol in SQL Developer (version 4.2.0.16.260). But when I copy the data to Notepad++, there I am getting double quotes. I tried instr
to get the position of double quotes, its returning the result 0. Also I tried to replace double quotes with blank, but they are not being removed.
Below is the data I see when copied to Notepad++. 2 records are displayed. I'm trying to take the distinct value from these 2 values. But I am not able to.
"Testdata
"
Testdata
回答1:
The column value in the database table does not have double quotes.
When you copy the data from the results grid, SQL Developer is adding them as part of the copy operation, to help you out. (There's probably way to ask it not to, but I can't immediately see one.) It's doing that because the first value you're getting has a trailing new line character. I can duplicate what you're seeing if I do:
select 'Testdata' || chr(10) from dual
union all
select 'Testdata' from dual;
If I run as a script, the script output window shows:
'TESTDATA
---------
Testdata
Testdata
Here the newline is lost, and copy and pasting from that doesn't preserve it. If I run as a statement the data in the query result window looks the same:
but if I copy that data from the grid and paste it (anywhere, not just in Notepad++) I also see:
"Testdata
"
Testdata
... so the newline is preserved, and is enclosed in double-quotes so whatever it is pasted into (I'm guessing this is targeted at Excel) understands that it is a single value, including that newline character.
Im trying to take the distinct value from these 2 values
The problem is that they are not, in fact, distinct; one has a newline, the other does not.
If you want to ignore that and treat them as the same you can trim off the trailing newline:
select distinct rtrim(col, chr(10))
from your_table;
Demo with the same sample data:
-- CTE for sample data
with your_table (col) as (
select 'Testdata' || chr(10) from dual
union all
select 'Testdata' from dual
)
select col
from your_table;
COL
---------
Testdata
Testdata
-- CTE for sample data
with your_table (col) as (
select 'Testdata' || chr(10) from dual
union all
select 'Testdata' from dual
)
select distinct rtrim(col, chr(10)) as col
from your_table;
COL
---------
Testdata
来源:https://stackoverflow.com/questions/55954665/how-to-remove-hidden-double-quotes-in-column-values-of-sql-developer