End of Line Problem (Oracle skip 0x0D char)
350254Jun 6 2005 — edited Jun 7 2005Hi,
I created a table
CREATE TABLE TEST_TABLE (COL VARCHAR2(255));
And I would like to insert a string in COL column.
This string may end with CR (Carriage Return, ASCII code 0x0D = 13) + LF (Line Feed, ASCII code 0x0A = 10)
I made a file Test.sql, which contain these lines :
COMMIT;
With an HexaDecimal File Editor, I've replace § and µ with characters wich have 0x0D and 0x0A respectively.
So It is like if I was writing my SQL command :
INSERT INTO TEST_TABLE(COL) VALUES ('This is CR '||CHR(13)||', this is LF '||CHR(10)||', and this is CR+LF '||CHR(13)||CHR(10));
When I execute my Test.sql file in SQL Plus (Oracle 9i), It works, and reply 1 row inserted.
But when I select the line :
SELECT COL, LENGTH(COL) LEN FROM TEST_TABLE;
Oracle replies :
COL LEN
--------------------------- ---------
This is CR â, this is LF 45
, and this is CR+LF
The â is placed at the first 0x0D char place.
The last 0x0D char have disappered.
The last 0x0A chars are displayed as end of line.
And the length mean that that both 0x0D and 0x0A chars aren't count (actual length of string is 48, so 48 chars - 2 0x0A chars - 1 disappered 0x0D char is 46 ...)
So, according to this, I've tried :
SELECT COL, LENGTH(COL) LEN, ASCII(SUBSTR(COL,12,1)) CR, ASCII(SUBSTR(COL,25,1)) LF, ASCII(SUBSTR(COL,45,1)) CR2, ASCII(SUBSTR(COL,46,1)) LF2 FROM TEST_TABLE;
It replies :
COL
--------------------------------------------------------- LEN CR LF CR2 LF2
---------- ---------- ---------- ---------- ----------
This is CR â, this is LF
, and this is CR+LF
45 13 10 10
So, my problem is that 0x0D char and 0x0A chars are only keeped when they aren't together. Indeed when they are placed together, Oracle only keep 0x0A char.
I prefere not to analyse each string I have to insert in database searching 0x0D 0x0A couple to replace it by CHR(13)||CHR(10) because it will dramatically slow down my process. Is there a solution to force Oracle to keep in database 0x0D 0x0A together without automatically replacing it by a single 0x0A char ?
Thanks for your help
Nicolas