Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search new line char in oracle table?

I have an issue with a file that's created from data (in format of bytes) returned from the database.
the problem is that there is a few newlines in the file.
i would like to know if there is a way to write a where clause to check if some record has a newline character?

like image 515
meilechh Avatar asked Nov 20 '12 21:11

meilechh


People also ask

What is new line character in Oracle?

A newline is usually \n .

What is CHR 10 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.


3 Answers

Using the CHR function to look for the ASCII value:

select *
from your_table
where instr(your_text_col, chr(10)) > 0;

If you want to search for carriage returns, that would be chr(13).

like image 106
APC Avatar answered Oct 19 '22 15:10

APC


You can write something like:

SELECT id
  FROM table_name
 WHERE field_name LIKE '%'||CHR(10)||'%'
;

(|| is the concatenation operator; CHR(10) is the tenth ASCII character, i.e. a newline.)

like image 28
ruakh Avatar answered Oct 19 '22 14:10

ruakh


Depending on the platform, a newline will generally either be a CHR(10) (Unix) or a CHR(13) followed by a CHR(10) (Windows). There are other options for other more esoteric platforms, but 99.999% of the time, it will be one of these two.

You can search the data in a column looking for one or both characters

SELECT instr( column_name, CHR(10) ) position_of_first_lf,
       instr( column_name, CHR(13) || CHR(10) ) position_of_first_cr_lf
  FROM table_name
 WHERE instr( column_name, CHR(10) ) > 0
like image 36
Justin Cave Avatar answered Oct 19 '22 15:10

Justin Cave