Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove newlines in oracle sql

Currently in address column in test table,i have data in following format,

12th street

Test avenue

Test_City

but in the output,i would require it in following format,

12th street Test avenue Test_City.

Could any one please tell me the query to use to display it in the required manner.

like image 948
manju Avatar asked Nov 12 '14 09:11

manju


People also ask

How do I remove paragraph marks in SQL Developer?

Assuming this is SQL Developer, go to Tools->Preferences (or on Mac, find that under the SQL Developer menu). Expand the Code Editor section and click on Display. Untick "Show whitespace characters" (second checkbox in the list). You can check for defined shortcuts under Preferences, in the Shortcut Keys section.

How do you change a line break in Oracle?

CHR(10) is used to insert line breaks, CHR(9) is for tabs, and CHR(13) is for carriage returns. In the example above, we wanted to remove all occurrences of the line break, of the tab, and of the carriage return, so we used CHR(10) , CHR(9) , and CHR(13) .

What is CHR 10 and CHR 13 in Oracle?

CHR(10) -- Line feed. CHR(13) -- Carriage return. You can use them in insert like this, INSERT INTO table_name (columne_name) VALUES ('ABC' || CHR (9) || 'DEF' || CHR (10) || 'GHI' || CHR (13) || 'JKL') Here is the complete list of ascii values. http://www.asciitable.com/


3 Answers

You can try this:

select regexp_replace(your_address,'[[:space:]]',' ') from your_tab; 
like image 114
Cyryl1972 Avatar answered Oct 10 '22 13:10

Cyryl1972


Just strip chr(13) and chr(10) from the string:

declare
   teststring   varchar2 (32767) := ' This is the value

that I chose';
begin
   dbms_output.put_line (teststring);
   dbms_output.put_line (replace (replace (teststring, chr (13), ''), chr (10), ' '));
end;

The result:

 This is the value

that I chose
 This is the value  that I chose

Two spaces since I put in two returns in the text.

like image 21
Olafur Tryggvason Avatar answered Oct 10 '22 12:10

Olafur Tryggvason


Try this:

translate(' example ', chr(10) || chr(13) || chr(09), ' ') 

The above will replace all line breaks (chr(10)), all tabs (chr(09)) and all carriage returns (chr(13)) with a space (' ').

Just replace ' example ' with your field name on wish you want to have the characters removed.

like image 25
Flavio Caduff Avatar answered Oct 10 '22 13:10

Flavio Caduff