Home » SQL & PL/SQL » SQL & PL/SQL » REPLACE(column,chr(10),'/r')) does not work
REPLACE(column,chr(10),'/r')) does not work [message #568799] Tue, 16 October 2012 13:00 Go to next message
annenoe
Messages: 4
Registered: October 2012
Location: Mountain View, CA
Junior Member
First - newbie - please excuse me if I make a newbie mistake
Second - I'm not an uber developer - just enough SQL to be dangerous

Problem:
I am doing simple search to report across two systems when fields are not identical (they are supposed to be). Then I report the data. I am outputting the data in spool files that we'll post so we can see the details. I am forcing .xls extension so they can be opened in Excel. I am building a tab-delimited file, e.g., sys1.first_name||chr(9)||sys2.first_name.
Everything is working fine with one exception. The problem is there are some records with embedded tab and return characters in the data fields that will (obviously) screw up the data when opened by Excel. e.g., the embedded tab pushes the data out one column, the return splits the record. NOTE: I do NOT want to clean the data. Part of what I'm reporting is that one system is removing tabs and returns and the other is not. So I want these to report.
I was able to successfully do this: replace(sys1.first_name,chr(9),'/t')||chr(9)||replace(sys1.first_name,chr(9),'/t') which then replaces the embedded tab with the '/t' so we can see why it failed the match. But when I tried replace(sys1.first_name,chr(10),'/r') it doesn't work. It puts in the /r but keeps the return character. I know chr(10) is correct b/c select first_name from customer where first_name like '%'|| chr(10) ||'%'; returns the data. But when I do select replace(first_name,chr(10),'/r') from customer where first_name like '%'|| chr(10) ||'%'; it keeps the return character (the name still takes up two lines) then just puts the '/r' right after the return char.

Can someone explain what I'm doing wrong here?
Re: REPLACE(column,chr(10),'/r')) does not work [message #568800 is a reply to message #568799] Tue, 16 October 2012 13:07 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: REPLACE(column,chr(10),'/r')) does not work [message #568802 is a reply to message #568800] Tue, 16 October 2012 13:13 Go to previous messageGo to next message
annenoe
Messages: 4
Registered: October 2012
Location: Mountain View, CA
Junior Member
Sure...
Have googled - the only thing I found was the replace - which works with tabs but not return char, thus I'm here
Oracle version is 11.2.0.3.0 64 bit version
Regarding posting the entire SQL, it's just the replace statement. And I'm not getting an error but let me try again:
select replace(first_name,chr(10),'/r') from customer where first_name like '%'|| chr(10) ||'%'; returns the following two lines in the field:
Jason
/rM.
Re: REPLACE(column,chr(10),'/r')) does not work [message #568803 is a reply to message #568802] Tue, 16 October 2012 13:25 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
OS name & version?
It is not clear to me what exactly you start with & what the expected/desired results are supposed to look like
Re: REPLACE(column,chr(10),'/r')) does not work [message #568804 is a reply to message #568803] Tue, 16 October 2012 13:30 Go to previous messageGo to next message
annenoe
Messages: 4
Registered: October 2012
Location: Mountain View, CA
Junior Member
sorry - OS? PL/SQL 11.2.3.0? I'm using Toad if that helps.

So when I do the replace tab, I end up with "Jason/tM." When I replace a return character, I was expecting "Jason/rM.", i.e., the returns characters are removed when I spool the data. As I said, replace(first_name,chr(9),'/t') correctly removes the tab. But when I do replace(first_name,chr(10),'/r') it does *not* remove the return. It puts in the /r but keeps the return. Just don't understand why the tab works but the return does not.
Re: REPLACE(column,chr(10),'/r')) does not work [message #568805 is a reply to message #568804] Tue, 16 October 2012 13:46 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
What does Posting Guideline #5 say?

post results from following SQL

SELECT DUMP(FIRST_NAME) FROM CUSTOMER;
Re: REPLACE(column,chr(10),'/r')) does not work [message #568806 is a reply to message #568805] Tue, 16 October 2012 13:51 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
the return is probably chr(10)||chr(13).

Use Blackswan's sql above to check.
Re: REPLACE(column,chr(10),'/r')) does not work [message #568808 is a reply to message #568806] Tue, 16 October 2012 14:23 Go to previous messageGo to next message
annenoe
Messages: 4
Registered: October 2012
Location: Mountain View, CA
Junior Member
Again, sorry.
FIRST_NAME
"Typ=1 Len=14: 67,97,115,101,110,105,13,10,76,105,110,101,32,50"

Now I see it! I didn't know about the dump command. CookieMonster,replace(last_name,chr(13)||chr(10),'/r') works.

Thanks so much.

Re: REPLACE(column,chr(10),'/r')) does not work [message #568817 is a reply to message #568808] Tue, 16 October 2012 17:08 Go to previous message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
This is a case where operating system matters.
Windows uses chr(13)||chr(10) to mark the end of a line.
Unix just uses chr(10)
Previous Topic: Procedure Help
Next Topic: logon trigger error
Goto Forum:
  


Current Time: Fri May 16 15:51:13 CDT 2025