Skip to Main Content
  • Questions
  • How can one insert a carriage return

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Aron .

Asked: May 02, 2000 - 1:20 pm UTC

Last updated: December 04, 2015 - 2:40 am UTC

Version:

Viewed 100K+ times! This question is

You Asked

How can one insert a carriage return or
line-feed into a text field so that one can "force" a blank line
between paragraphs in a form in a way that it
will also print as multiple paragraphs?



and Tom said...


Carriage returns = 13
Line Feeds = 10
Tabs = 9

(and other ascii codes..) Once you know the code, getting them from the database is easy. There is a function chr() that will take the ascii code and return the character. So, if you:

myString := 'Some Text' || chr(10) || 'Some more Text....';

that'll build a string that has a newline (line feed) in it.



Rating

  (51 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, November 02, 2002 - 11:54 am UTC


chr() not working

Sikandar Hayat Awan, December 31, 2002 - 5:15 am UTC

Hi TOM,
I want to use carriage return or line feed but facing in the following way,

SCOTT > select 'A' || chr(10) || 'B' from dual;

'A'
---
A

SCOTT > ed
Wrote file afiedt.buf

1* select 'A' || chr(13) || 'B' from dual
SCOTT > /

'A'
---
A
B
When I copied it on your side it is ok but in my sql plus window it is A{balck box}B.

SQL Plus 8.0.6 and Oracle 8.1.7.

Tom Kyte
December 31, 2002 - 8:50 am UTC

and you forgot one thing "windows"....


On Unix, LINEFEED (chr(10)) is the "end of line" marker. Bill long ago decided that on DOS, CARRIAGE RETURN/LINEFEED (chr(13)||chr(10)) should be the end of line marker.




hard returns

mo, December 31, 2002 - 10:00 am UTC

Tom:

Are "Carriage returns" = "Hard Returns" while
"Line Feeds" = "Wrap End of Line every number of characters".



Tom Kyte
December 31, 2002 - 10:07 am UTC

don't know -- doesn't matter. "wrap end of line every number of characters" sounds more like LRECL from the mainframe -- the logical record length. They don't have end of lines typically...

\r\n = dos end of line.
\n = unix end of line


\r = chr(13)
\n = chr(10)

use what you need based on the platform you want.

chr(13) || chr(10) has not solved it

Sikandar Hayat Awan, December 31, 2002 - 12:15 pm UTC

Ya you are right that I am using MS Windows. I wish to swith this plate form but I think Unix is very difficult?

Now what I am doing wrong,
SCOTT > select 'A' || chr(13) || chr(10) || 'B' from dual;
'A'|
----
A{black box)


SCOTT >



Tom Kyte
December 31, 2002 - 1:05 pm UTC

stop using the 'gui'


Start -> run -> sqlplus.exe

do it in character mode.


ops$tkyte@ORA920> select 'A' || chr(13) || chr(10) || 'B' from dual;

'A'|
----
A
B


ops$tkyte@ORA920>



Unix difficult?  Hah, windows - now I find that hard cause nothing but nothing can be done without a mouse, without a gui display.  Ease of use?  I doubt it.  I never get questions from unix people like "i set the utl_file_dir to an NFS mounted disk, now when I try to access it, it doesn't work".  I get tons of questions from windows people like "i set the utl_file_dir to a windows share, now when I try to access it from the explorer -- it works but the database doesn't see it, why not?"


The list goes on.  Unix is not "hard".  Windows to me is painfully hard.  Give me grep, sed, awk and a good shell and I'm set to do whatever I need.  Give me windows and I need to buy the MKS toolkit just to make it bearable.... 

Even Character mode has not solved it

Sikandar Hayat Awan, January 01, 2003 - 12:30 am UTC

Result is same even in character mode,

Output from character mode,
c:\sqlplus.exe

SCOTT > select 'A' || chr(10) || 'B' from dual;

'A'
---
A

SCOTT >

Tom Kyte
January 01, 2003 - 8:30 am UTC

sorry -- i don't have windows anywhere -- I've never seen such behavior personally (when I did have windows, this worked fine).

Third party SQL Editor is working fine

Sikandar Hayat Awan, January 01, 2003 - 12:56 am UTC

Just for your info............


Dear TOM,
With a third parth SQL Editor it is working fine on the same machine and OS.

select 'alter tablespace '||tablespace_name||' begin backup;' || chr(10) ||
'host copy '||file_name||' &destination\&dbsid\ >> &temp\hotbackup.log' || chr(10) ||
'alter tablespace '||tablespace_name||' end backup;' || chr(10)
from dba_data_files;

OUTPUT

alter tablespace XNID begin backup;
host copy D:\ORACLE\PRODDATA\XNID01.DBF X:\Sikandar\Backup_hot\PROD\ >> D:\Sikandar\Backup_hot\Temp\hotbackup.log
alter tablespace XNID end backup;

But my requirement is to do with sqlplus. I am trying to follow Metalink Note : 152111.1.

Tom Kyte
January 01, 2003 - 10:19 am UTC

well, first of all -- suggest you cease and desist your approach to backups right now. That is a certain recipe for DISASTER. (copy won't work really either on open files, ocopy would but it still is a disaster waiting to happen)

You do not have the necessary control to verify that the copy actually succeeded. You'll blindly believe "my backups are OK" -- when in fact they are not.

What if the alter fails? How do you detect that?

Strongly urge you to use RMAN instead, for your own protection. windows is not powerful enough to script in without tons of help -- RMAN is that help.


But if you persist in this bad idea... do this:

set feedback off
set serveroutput on size 1000000
set linesize 512
set trimspool on
spool badidea.sql
begin
for x IN ( select tablespace_name, file_name from dba_data_files )
loop
dbms_output.put_line( 'alter tablespace ' || x.tablespace ||
' begin backup;' );
dbms_output.put_line( 'host ocopy ' || x.file_name ||
' &dest\&dbsid ' );
dbms_output.put_line( 'alter tablespace ' || x.tablespace ||
' end backup;' );
end loop;
end;
/
spool off
@badidea






Of course I want to use RMAN

Sikandar Hayat Awan, January 01, 2003 - 10:51 am UTC

Dear TOM,
You are right that RMAN is more powerful and reliable but I am unable to use RMAN due to following reasons,

1- Unable to find step by step implementation Procedure
2- I have to maintain another database (RMAN Repository)
3- As I can't keep on the same machine so need another machine.
4- Recovery steps
5- I need some practice of it

All the steps will be ok if I will get a proper document of it. I have read from Oracle Manuals but unable to do all from there. May be lack of time or....

I am anxiously waiting for your response as this will be a great achievement to implement RMAN.

Thanks for saying it BadIdea as now I will try my best to implement RMAN to remove this bad idea.

Really I appreciate your ideas.

Tom Kyte
January 01, 2003 - 11:17 am UTC

1) did you try the documentation?
2) the documentation tells you that a repository offers
more features -- but is not a requirement
3) see #1 again please. By the way -- what is the POINT of backing up onto the
same machine? the whole point of backing up is to get it ELSEWHERE.
4) huh?
5) well your current approach isn't going to be very workable in the real world.
At best it gives you a false sense of security.

Let's put it this way. In my opinion there is one thing the DBA cannot do wrong. They can do almost everything else wrong but if they cannot master backup and recovery in a bullet proof way -- well, they just are not a DBA at all. It is all about the data -- lose the data and who cares how fast the system USED TO BE.

Backup and recovery is the single most important topic for a DBA. It is what they need to know better then anything else in the world -- without exception. Take the time, live it, learn it -- do it right.




You want step by step backup and recovery then

Jim Kennedy, January 01, 2003 - 1:31 pm UTC

Shell out some money and by Oracle Backup and Recovery by Oracle Press. It has a lot of information and all the recovery scenerios and how to practice them. (Best to do that) Sigh, you will have to read the book.

Reading this DOC

Sikandar Hayat Awan, January 01, 2003 - 11:02 pm UTC

I am reading Metalink Note 120084.1 and 104798.1 seems very informative.

Reading a book is not problem for me but to Purchase a book from USA is really a hard time for me. The books are very expensive for us so we have to get info from online docs. This is due to currency coversion. Company is also not supporting.

TOM you are right that backup and recovery is the main activity of a DBA. Already I am using badidea and it was working fine for me. I have disk mirroring and RAID-5. My another requirement to implement RMAN is incremental backups as the data is growing day by day.

Tom Kyte
January 02, 2003 - 7:32 am UTC

There are reprints in your country of most of these books -- my book "Expert one on one Oracle" for example -- most of the Oracle press books as well. The reprints are priced in your local currency (believe me, I know, I get royalties based on what the book actually sells for -- it sells for much less in some countries than others)


You know -- I had both sides of a mirror fail within 5 minutes of eachother.

I've lost 2 out of 5 disks in raid-5 configuration (imagine what that does)....


that is is quote "working fine" means you have been pulled into that totally FALSE SENSE OF SECURITY.

backing up to the same machine is a recipe for disaster. When the machine totally fails then what?

backing up using "copy" invoked via SQLPlus's host command -- what happens when the copy fails and you have no way to recover from it?

I bet you even keep just ONE COPY of the backups -- meaning that you overwrite the last backup with the current backup. What happens when the disk fails in the middle of a backup? (don't laugh, I've seen it happen). You don't have your last good backup, you don't have a current backup, you have just lost your database.



"Expert" in other tongues...

Robert, January 02, 2003 - 10:06 am UTC

>>The reprints are priced in your local currency (...it sells for much less in some countries than others)

Just curious....are there any translated versions of "Expert" , into other languages, that is ?


Tom Kyte
January 02, 2003 - 10:11 am UTC

I have a Chinese copy, pretty different looking. Lots of symbols and then the word Oracle, more symbols then my name... There are russian ones and portugese as well. Probably others I'm not aware of.

Local Currencies

Adrian, January 02, 2003 - 10:43 am UTC

"The reprints are priced in your local currency (believe me, I know, I get royalties
based on what the book actually sells for -- it sells for much less in some countries than others)"

You must love it when us suckers in the UK buy your book then. US: $59.99 UK: £47.99 (~$76 at todays exchange rate)

Then again we seem to get fleeced on the exchange rates on most books.

Tom Kyte
January 02, 2003 - 10:49 am UTC

No -- in the UK the list should be (according to Amazon)

US List Price: $59.99
UK Equivalent: £37.40
Our Price: £33.66
You Save: £3.74 (10%)

you should only pay £33.66 at most (about $42) which is the same price as over this side of the lake.

</code> http://www.amazon.co.uk/exec/obidos/ASIN/1861004826/ <code>

translated editions..

robert, January 02, 2003 - 10:55 am UTC

>> I have a Chinese copy, pretty different looking. Lots of symbols and then the word Oracle, more symbols then my name...

Chinese "symbols" ? You mean characters ?...hmmm I will probably get a copy of that to keep around just for fun. Will let you know if the translation gets the ideas way too wrong (seen that in other translated tech books)

Eastern Economy Edition

Pawan, January 02, 2003 - 11:30 am UTC

I was recently talking to a friend that bought your book from India - Less than $15. The paper is not that good but has the same contents and in English.This is a cut and paste from one of the online book sites
Expert One-On-One Oracle
Kyte, Thomas
ISBN : 8173663874
Wrox Press ; Published: 6/ 2001;
Generally dispatched in 1 day.
Special Indian Price.
List Price : Rs. 675
Our Price : Rs. 675

If Larry Ellison really wants to make Oracle more popular then im my opinion he should make multiple copies of this book available in Libraries accross the world.


Amazon

Andrew Gilfrin, January 02, 2003 - 11:35 am UTC

I find Amazon.co.uk to be very very competetive on Computer books (but not so for other sutff).

I picked up Tom's book for around £33. It also makes me smile when they have New Price £33.60 or buy used for £38.00. I did actually by a second hand version of an Oracle book for £14, it was in perfect condition and the guy even left an offical copy of JDeveloper in the cover which I dont think should have been there.

Well worth a try and the transactions for second hand stuff are all delt with by amazon (you pay amazon and they pay the seller) so it feels much safer than something like e-bay.

For UK readers ...

Paul, January 02, 2003 - 11:51 am UTC

Click on
</code> http://www.bookbrain.co.uk/pricesearch.asp?isbn=1861004826 <code>
and take your pick!

Stop the whining and buy the books

Jim Kennedy, January 02, 2003 - 12:48 pm UTC

I usually pay out of my own pocket for my technical books. That way I don't have to track them down at work and if I go to another company I can take them with me. I find it difficult to believe that you can't get Tom's book and the Oracle Backup and Recovery Book locally. I have friends in India and they can purchase those books (not as nice paper, but very cheap) locally. I feel for you if your company is so short sighted that they won't shell out a little money to get some manuals to do your job correctly. They must not think the data is worth much.

I am in Pakistan not in India so no reprints

Sikandar Hayat Awan, January 02, 2003 - 11:19 pm UTC

Ya you all are right that there are reprints are available but not in Pakistan. We purchase reprints from India which has been stopped due to some political issues. Expecting soon to resume.

We have to purchase from amazon.com and the price comparison is as under,

USA $59.99 Pak = Rs 3599.4 + Shippment = Rs > 6000

In Pakistan the average salary is 6000 / month.
OCP 1 Paper Fee is 6500.

I will really suggest to Oracle not Microsoft that please provide your softwares and docs according to the local currency to promote Oracle in the backward countries. I can't explain how it is difficult to work with latest technologies. You can check how many people are from Pakistan or any other backward country on this site.
------------------------------------------------------------
Anyway coming back to our real issue,
TOM we daily move our backup to a DAT and keep last 6 backups in out archive. But still as you metioned any thing may happen. You are 100% right. So I am going to switch to RMAN as early as possible and in this regard I will really seek for your assistance which is vital.

I have raised a TAR on Metalink for chr(10) and they are working on it.

Confessions from a roll-your-own backup scripter

Mike, January 08, 2003 - 11:35 pm UTC

Tom:

Your advice on so many topics has been rock solid over the years but I guess I've made excuses for not converting totally to RMAN. No more excuses, I'm starting the conversion this week.

One question for you: we have many "older" (8.1.6 and 8.1.7) instances. Do you have any cautionary words or advice for implimenting RMAN on these "older" versions?

Thank you,

-Mike

Tom Kyte
January 09, 2003 - 7:06 am UTC

just to test, test, test -- backup and recovery is the most important thing. Make sure to actually test that which you've backed up to make sure you can actually use it under pressure (when you need to)

chr(10) issue resolved

Sikandar Hayat Awan, January 14, 2003 - 5:29 am UTC

The issues has resolved in the following way,
TAR# 2727029.995

SQL> set wrap on
SQL> select 'A' || chr(10) || 'B' from dual;
'A'
---
A
B
SQL> set wrap off
SQL> /
'A'
---
A
SQL> set wrap on
SQL> /
'A'
---
A
B
SQL> 
 

Sridhar Kolluru, February 03, 2003 - 3:32 pm UTC

Tom I used your site all the time it is very very very to the power of infintiy times useful

displaying carriage return on web page

mary, May 14, 2003 - 10:10 am UTC

Tom, i'm having trouble capturing carriage returns when they are submitted in an html form. The user enters alot of text in a form box, hitting the return key where they want it and then submit it (goes to database). However, when I display their comments from the database, none of the carriage returns show up (the text entered is just one continuous glob of words on the same line).

If I store html breaks (<br>) in the data where they hit the carriage return, it works, but I don't want them to have to type <br> every time they want a new line. When I save the form, I am using the trim() function. Could this be causing the problem?

Sorry if this is off the topic. (The database is Oracle though).

Tom Kyte
May 14, 2003 - 3:17 pm UTC

<pre>
their text
with line breaks
will appear as
they entered it
</pre>

without the pre tag -- it'll wrap it as it (the browser) wants.

you could alternatively

htp.p( replace( l_text, chr(10), '<br>' ) );

as well



Disregard Last Posting

mary, May 14, 2003 - 12:53 pm UTC

I think I figured it out. I'm creating a function in the database that I will use when selecting the data for the field in question. The function will replace chr(13) with <br /> and chr(10) with <p />.

i'll try pre tag

mary, May 14, 2003 - 11:40 pm UTC

thanks Tom. I'll try the <pre> tag.

No wonder the 'ask a question' is rarely available

A reader, July 08, 2003 - 10:15 am UTC

RMAN?
Books?
Chinese characters?
Backups?
Windows v. Unix?

reader

gre, August 13, 2003 - 4:16 pm UTC

Hi Tom,

I am currently working on extract table from oracle(data warehouse).and load the flat file to another data warehosue.

What is the general strategy to handle the Chr(10), chr(13)
this kind of special characters. I saw some scripts some times handle them some times do not care of them.

Thank you!


Tom Kyte
August 13, 2003 - 4:19 pm UTC

why would you dump and load?

is this oracle to oracle?

do you have my book "expert one on one oracle"?


reader

gre, August 13, 2003 - 6:07 pm UTC

Hi Tom,

1.We will extract some tables from a local Oracle
warehouse and send the gziped flat files by FTP to another
ORACLE date warehouse(not local) to load weekly.

2. Yes, I have your book.
Which Chapert has the related topic ?


Thank you!








GRE, August 13, 2003 - 6:11 pm UTC

Hi TOM,

Sorry I am wrong. The remote one is Teradata .

That means FROM Oracle to Teradata.

Thank you!

Tom Kyte
August 13, 2003 - 7:26 pm UTC

you need to ask teradata "what format shall i put the files in so you can ingest them" then...

I cannot tell you how to format a file for teradata's loader that includes newlines.


the chapter on sqlldr in my book tells you how the file would be formatted with Oracle.

Want RMAN Examples Step by Step? OBE is the answer :)

pasko, August 14, 2003 - 3:27 am UTC

Hi Tom,

i just wanted to point out that , i find the Oracle By Examples Online Series to be very useful and easy to follow:

If somebody wants a step by step RMAN back-up Examples, they can go to :

</code> http://otn.oracle.com/obe/paa/index.html <code>

click: Oracle9i Release 9.2.0.2
and then click : 7. Develop a Highly-Available Database Environment
and then click : 7. Performing Backups and Recovering your Database using Oracle9i Recovery Manager





Counting carriage returns in a column ?

Vishal Sharma, November 19, 2003 - 12:24 pm UTC

I have a table like

user_comments(comment_id NUMBER(9) PRIMARY KEY,
user_name VARCHAR2(50),
comments VARCHAR2(2000) ) ;

comments field has carriage returns as it is a multiline field on the form where users record their comments.
In the same application, different forms, i pull their comments. I want to resize my comment (POP UP)window
depending on how many lines (Carriage returns) are present in the comment for a given comment_id.

I know that :

select instr(comments, instr(chr(10) ) from user_comments where comment_id = 1 ;

will give me first ocuurance of carraige return.

What will be good way of getting total no. of ocuurences in this context ???


Tom Kyte
November 21, 2003 - 11:40 am UTC

  1* select ename, length(ename)-length( replace(ename,'A','') ) "A's" from emp
ops$tkyte@ORA920LAP> /

ENAME             A's
---------- ----------
SMITH               0
ALLEN               1
WARD                1
JONES               0
MARTIN              1
BLAKE               1
CLARK               1
SCOTT               0
KING                0
TURNER              0
ADAMS               2
JAMES               1
FORD                0
MILLER              0

14 rows selected.


replace 'A' with chr(10) for newlines. 

In Contunuation

Vishal Sharma, December 04, 2003 - 9:31 am UTC

Tom,
The query is great. Helps me find the total lines in Comments. It would be great if I can get the characters in longets line in comments. I mean a result set like

Assuming 'A' is chr(10) in above shown result set

ENAME A's Charactrs_IN_Longets_Line
---------- ---------- --------------------------
SMITH 0 5
ALLEN 1 4
WARD 1 2
JONES 0 5
MARTIN 1 4
BLAKE 1 2
CLARK 1 2
SCOTT 0 5
KING 0 4
TURNER 0 6
ADAMS 2 2
JAMES 1 3
FORD 0 4
MILLER 0 6


Thanks a lot for last answer. Everytime you get some question, you answer it in most efficient and straight way.


Tom Kyte
December 04, 2003 - 9:59 am UTC

is "longets" really "longest" the "longest" (or largest, or line with the most characters)?

we'd probably be writing a plsql function for that.


ops$tkyte@ORA920PC> create or replace type str2tblType as table of varchar2(4000);
  2  /
 
Type created.
 
ops$tkyte@ORA920PC>
ops$tkyte@ORA920PC> create or replace function str2tbl( p_str in varchar2, p_delim in varchar2 default ',' ) return str2tblType
  2  PIPELINED
  3  as
  4      l_str      long default p_str || p_delim;
  5      l_n        number;
  6  begin
  7      loop
  8          l_n := instr( l_str, p_delim );
  9          exit when (nvl(l_n,0) = 0);
 10          pipe row( ltrim(rtrim(substr(l_str,1,l_n-1))) );
 11          l_str := substr( l_str, l_n+1 );
 12      end loop;
 13      return;
 14  end;
 15  /
 
Function created.
 
ops$tkyte@ORA920PC>
ops$tkyte@ORA920PC>
ops$tkyte@ORA920PC> drop table t;
 
Table dropped.
 
ops$tkyte@ORA920PC> create table t
  2  as
  3  select ename, 'Hows this going to ' || chr(10) || ' work?'  || chr(10) || ' i have no idea' cmt
  4   from scott.emp;
 
Table created.
 
ops$tkyte@ORA920PC>
ops$tkyte@ORA920PC>
ops$tkyte@ORA920PC> select ename, length(cmt)-length(replace(cmt,'a','')) "A's",
  2         (select max(length(column_value)) from TABLE(str2tbl(cmt))) max_length
  3    from t;
 
ENAME             A's MAX_LENGTH
---------- ---------- ----------
SMITH               2         42
ALLEN               2         42
WARD                2         42
JONES               2         42
MARTIN              2         42
BLAKE               2         42
CLARK               2         42
SCOTT               2         42
KING                2         42
TURNER              2         42
ADAMS               2         42
JAMES               2         42
FORD                2         42
MILLER              2         42
 
14 rows selected.
 

is one approach 

Great

Vishal Sharma, December 04, 2003 - 10:29 am UTC

I am already using PL/Sql to get no. of lines and the number of characters in largest the lines. I was wondering if there could be some way to do both of them in a SQL query.
Though this answer heled me a lot.

Thanks


Hidden characters

Tony, December 04, 2003 - 1:29 pm UTC

Hi Tom,
Thanks a lot for all your help.
I'm trying to find some hidden characters in one of the fields in my table.
if I run the following sql I get a space at the end of field value(for all rows in the table)

select 'x' || comment || 'x' from cmt_t ;

xCARTHAGE , MO 64836. This is a test. x
xabc , xy 64836. This is a test. x
........
.....
...
Now if I run the follwing query(with one blank in the where clause) I don't get back any row:

select comment from cmt_t where comment like '% ';

That means the comment field doesn't contain blanks but some hidden characters that are not visible to me.

Can you please tell me if there is a way to find these hidden characters.

Thanks a lot

Tom Kyte
December 04, 2003 - 2:58 pm UTC

select dump( comment ) from cmt_t;

that'll give you a byte by byte dump


or

select ascii( substr(comment,length(comment)-1) ) from cmt_t;

that'll get you the ascii code of the "bad" character.

extra line chr(10)

A reader, April 01, 2005 - 3:09 am UTC

Hi

when I run this query I get an extra line

select 1 || chr(10) || 2 "TEST" from user_objects where rownum < 3;

TEST
----
1
2

1
2


The extra line is between first 2 and second 1. Why is this?

I want a result like

TEST
----
1
2
1
2

How can we achive it?
Tried in both windows and unix

Tom Kyte
April 01, 2005 - 8:28 am UTC

SQL> set recsep off
 

Special Characters

Raghavarao.RV, July 11, 2005 - 6:42 am UTC

Hi Tom

As this article is related to special characters I have a query while inserting a record. There is a product like 'HAIR & CARE'. I want to insert this value into the table where I need to use the special character '&'. When I am using '&' character, the SQL is prompting for the value to enter which I dont want. There is an alternative way while inserting I can use 'AND' instead of '&' symbol. My question is - Is there any way to insert such type of special characters in Oracle as this feature is available in C, C++ using a '\' character.

Thanks in Advance
Raghav

Tom Kyte
July 11, 2005 - 11:21 am UTC

& is only an issue in SQLPLUS.

sqlplus is seeing the & and saying "ah, must prompt user for input"

SQL> set define off

disables that. 

Special characters

Raghav, July 18, 2005 - 1:55 am UTC

Hi Tom

Thank you very much. This solution has worked out and solved my problem.

regards
raghav



Chr(10) gives an extra new line for each row

A reader, May 03, 2006 - 6:45 pm UTC

Tom,

When I use chr(10) to break the columns into multiple rows, I get an extra blank line after each row.  I am trying to get continous lines.  I tried various set options but could not get rid of the blank line.

SQL> select
  2    object_name || chr(10) ||
  3    object_id || chr(10) ||
  4    object_type || chr(10) ||
  5    status || chr(10) ||
  6    created as usr_obj
  7  from user_objects
  8  where rownum < 5;

USR_OBJ
----------------------------------------------
/10297c91_SAXAttrList
111965
JAVA CLASS
VALID
22-DEC-00
<----------------------------------- blank line
/109a284b_OracleXMLStaticQuery
112092
JAVA CLASS
VALID
22-DEC-00
<----------------------------------- blank line
/10b116c5_JservAdmin
195938
JAVA CLASS
VALID
16-OCT-02
<----------------------------------- blank line
/10ee10ae_XMLErrorMesg_sv_SEpr
112003
JAVA RESOURCE
VALID
22-DEC-00

SQL> 

Thanks in advance! 

Tom Kyte
May 04, 2006 - 1:54 am UTC

<b>don't play around as sys!</b>


ops$tkyte@ORA9IR2> set recsep off
ops$tkyte@ORA9IR2> select
  2    object_name || chr(10) ||
  3    object_id || chr(10) ||
  4    object_type || chr(10) ||
  5    status || chr(10) ||
  6    created as usr_obj
  7  from user_objects
  8  where rownum < 5;

USR_OBJ
-------------------------------------------------------------------------------
A
34139
TABLE
VALID
03-MAY-06
B
34140
TABLE
VALID
03-MAY-06
BLOBDATA
34126
TABLE
VALID
02-MAY-06
BLOBDATA_TEMP
34127
TABLE
VALID
02-MAY-06
 

how to store control characters ?

reader, June 28, 2006 - 5:28 am UTC

Hi Tom,

I am having following "SWIFT" message,

^A{1:F01BACBIGBCAXXX0000000000}{2:W960XXXXXXXXXXXXXXX}{4:^M
:20:SWIFTCLIENT^M
:25:09999891635654315USD^M
:28C:00106/00001^M
:60F:C067626USD10389,00^M
:61:0676271627D9592321,MMMCLRHV//0999981273^M
HV^M
:61:0676277627D9672710,00NGGCSI060627//099990462^M
STANDING INSTR^M
:86:TO - 99999-999999-999-USD^M
:62F:C067627USD0,00^M
-}^C

I want to store this message as shown above in a table. ( Saving Control Characters such as ^A, ^M, ^C ). Objective is to display message as orginial message without change in size by single byte. Otherwise swift may not accept this message.

How can I do this ?

thanks & regards
reader

Tom Kyte
June 28, 2006 - 7:47 am UTC

use a blob and store the raw data.

Exactlly what I was looking for

Karen Talarico, October 04, 2007 - 9:58 am UTC

Thanks for the question Aron and thanks for the answer Tom!

Randy, January 25, 2008 - 1:32 pm UTC

Tom,
  Is there a way to remove extra carriage returns after the text?  For example, say I have the following query:

select 'Hows this going to ' || chr(10) || ' work?'  || chr(10) || ' i have no idea' || chr(10) || chr(10) "Query" 
from dual


and of course I get 

Query
--------------------------------------------
Hows this going to
 work?
 i have no idea



SQL> 

How would one go about removing the carriage returns after the last line "i have no idea".  In certain cases I want the carriage returns in the text body so I don't want to use replace(text,chr(10),'') because that would remove all carriage returns.  I only want to remove the ones at the end.  Is this even possible?

Thanks in advance,
Randy

Tom Kyte
January 28, 2008 - 6:48 am UTC

rtrim( string, chr(10) );


A reader, January 29, 2008 - 8:24 am UTC

I can't believe it was this easy! I've been looking for a solution for months and the answer was right in front of me the entire time. Thank you for your help!

Randy

A reader, April 04, 2008 - 12:31 am UTC

How can i get only those rows which contain carriage return.
Tom Kyte
April 04, 2008 - 10:26 am UTC

where column like '%'||chr(13)||'%'

or

where instr(column,chr(13))>0

or

A reader, April 04, 2008 - 1:17 pm UTC

replace(column,chr(13))!=column

chr(10) is working very wrong on solaris 10

Deba, April 09, 2008 - 7:15 am UTC

Hi Tom,

We have just moved from solaris 9 to solaris 10. Now it is giving me problem.

I logon to any user in database and | do following

CREATE TABLE z ( Xy VARCHAR2(1000));

INSERT INTO z VALUES('1'||CHR(10)||'2');

COMMIT;


Now I login to UNIX OS and I do following :

/export/home/batch/interface/scripts> sqlplus -s ymdbaadm@stprod1.channel4.local

set head off echo off feedback off pages 0 term off serverout on linesize 1000
spool c.txt
DECLARE
ll VARCHAR2(1000) :='';
BEGIN
SELECT xy INTO ll FROM z;
dbms_output.put_line(ll);
END;
/
1
2
spool off;
exit
/export/home/batch/interface/scripts> pg c.txt
1
2








/export/home/batch/interface/scripts> echo "`/usr/bin/cat c.txt `" |/usr/bin/mailx -v -s "zzzz" -r "zz@channel4.co.uk"
"ddas@channel4.co.uk"

After receiving mail, if open the body then I can find out the "!" character. But I am not able to paste that "!" character here.

Not only that in c.txt file you can see the extra lines.

Now from the same OS account , I also do the follwoing:

DECLARE
l_v_logfilename VARCHAR2(20) ;
file_status utl_file.file_type;
BEGIN
l_v_logfilename := 'test.txt';
file_status := utl_file.fopen('/export/home/batch/interface/scripts',l_v_logfilename,'W');
utl_file.put_line(file_status,TO_CHAR(SYSDATE, 'HH24:MI:SS DD-MM-YYYY') || REPLACE('Mail format testingt'||' test date:10-JAN-2008'||' Please.#Contact system Admin # or Contact stellar application admin.' ,'#',CHR(10))||': '||'Final Test');
utl_file.fclose(file_status);
END;
/

In this case, it is generating test.txt file and if I mail the contents of the file through mailx , then formatting is correct and there is no "!" character.

/export/home/batch/interface/scripts> pg test.txt
11:50:23 09-04-2008Mail format testingt test date:10-JAN-2008 Please.
Contact system Admin
or Contact stellar application admin.: Final Test


So I firmly belive that in 1st case, we are inserting the chr(10) into table 1st , then we are fetching the data and writing into file. So I believe that there is problem in conversion. Due to this there are extra lines as well. But previously on solrais everything was running fine.

But if I use the pl/sql and directly write chr(10) to a file, then there is no problem.

I am also giving you the prfile setting of Oracle for that OS user :

SID="STPROD1"
INTERFACE_HOME_DIR=/export/home/batch/interface;export INTERFACE_HOME_DIR
echo ${INTERFACE_HOME_DIR}
ORACLE_BASE=/nas/orasoft/mars; export ORACLE_BASE
ORACLE_HOME=/nas/orasoft/mars/product/10.2.0/dbms; export ORACLE_HOME
LD_LIBRARY_PATH=${ORACLE_HOME}/lib:/usr/lib:${ORACLE_HOME}/ctx/lib:.; export LD_LIBRARY_PATH
ORA_NLS33=${ORACLE_HOME}/ocommon/nls/admin/data; export ORA_NLS33
PATH=${INTERFACE_HOME_DIR}/scripts:/usr/bin:/etc:/usr/local/bin:/usr/ccs/bin:/usr/ucb:/usr/openwin/bin:${ORACLE_HOME}/ctx/bin:${ORACLE_HOME}/bin:.; export PATH
TNS_ADMIN=$ORACLE_HOME/network; export TNS_ADMIN
NLS_LANG="ENGLISH_UNITED KINGDOM.WE8ISO8859P1"; export NLS_LANG

Could you plesae explain where is the problem ? Is there any problem in my nls settings ?

Thanks
Deba

Tom Kyte
April 09, 2008 - 2:53 pm UTC

the ! is being done by your smtp server. ! (and =) are common replacement characters.

We are not doing "chr(10)" wrong, your smtp gateway is doing something you are not expecting

please - you can telnet to your smtp server and verify this, remove Oracle from the equation.


chr(10)

deba, April 10, 2008 - 9:16 am UTC

Hi Tom,

My solaris version is 10 and oracle is 10.2.0.3.

if I logon to any user in database and | do following

CREATE TABLE z ( Xy VARCHAR2(1000));

INSERT INTO z VALUES('1'||CHR(10)||'2');

COMMIT;


Now I login to UNIX OS and I do following :

/export/home/batch/interface/scripts> sqlplus -s ymdbaadm@stprod1.channel4.local

set head off echo off feedback off pages 0 term off serverout on linesize 1000
spool c.txt
DECLARE
ll VARCHAR2(1000) :='';
BEGIN
SELECT xy INTO ll FROM z;
dbms_output.put_line(ll);
END;
/
1
2
spool off;
exit
/export/home/batch/interface/scripts> cat -vet c.txt
1$
2







$

Could you please tell me why it is producing so many blank spaces in the second line ?

Thanks
Deba
Tom Kyte
April 10, 2008 - 11:27 am UTC

do you have trimout on or off

look to the sqlplus settings - they are all documented. sqlplus is a very very very simple report writing tool/interactive environment - all of its settings are documented

trimout or trimspool - look at those.

How to work with CR

A reader, May 20, 2010 - 5:00 am UTC

TOM,

In a table column id data type is number(2)

And when i select * from tabl where id =9 is not giving the o/p

but select * from tabl where trim(id)=9 is giving the ans

Though i did
update tabl set id=trim(id)
also of no use..

So suggest me the correct answer for this..
Tom Kyte
May 24, 2010 - 11:33 am UTC

sounds like the number is not nine, but nine........something, and the implicit conversion is 'fixing it'


ops$tkyte%ORA9IR2> create table t ( x number );

Table created.

ops$tkyte%ORA9IR2> insert into t values ( 9.0000000000000000000000000001 );

1 row created.

ops$tkyte%ORA9IR2> select * from t;

         X
----------
         9

ops$tkyte%ORA9IR2> select * from t where x = 9;

no rows selected

ops$tkyte%ORA9IR2> select x,dump(x) from t where x > 8 and x < 10;

         X
----------
DUMP(X)
-------------------------------------------------------------------------------
         9
Typ=2 Len=16: 193,10,1,1,1,1,1,1,1,1,1,1,1,1,1,2


ops$tkyte%ORA9IR2> select x,dump(x) from t where trim(x) = 9;

no rows selected



do that last two queries for us - and CUT AND PASTE the results here.

Carriage return VB6 to Oracle Database

A reader, July 03, 2011 - 10:59 pm UTC

How about the using carriage return from VB6.0 Code to Oracle Database.?
Tom Kyte
July 05, 2011 - 7:55 am UTC

that, quite simply, makes no sense to me.

what does it mean to use a 'carriage return'? It is just a character to us, you don't really 'use it'

and what does VB6.0 have to do with it, how does a programming language affect whatever this is?

CHR(10) Behavior

A reader, November 22, 2013 - 4:26 am UTC


-- -------------------------------------------------------------------
-- SQL #1
-- -------------------------------------------------------------------
SELECT 'HEADER' text FROM dual
UNION ALL
SELECT '--------------' text FROM dual
UNION ALL
SELECT 'line 1' text FROM dual;

TEXT
--------------
HEADER
--------------
line 1

-- -------------------------------------------------------------------
-- SQL #2
-- -------------------------------------------------------------------
SELECT 'HEADER' || CHR(10) || '--------------' text FROM dual
UNION ALL
SELECT 'line 1' text FROM dual;

TEXT
--------------
HEADER
--------------
>>>> Question: why is there an empty line here?
line 1

I didn't get new line in query result

Ramya, March 13, 2015 - 12:13 pm UTC

hi tom ,
I used
select 'a'||chr(13)||chr(10)||'b' from dual;
and
select 'a'||chr(10)||'b' from dual;
but i didn't get new line in my result and the result i got is
a
-----
ab
I am using windows os and oracle version 3.2 what is problem in this . how can i inert new line inbetween these two letters...
please help me out

Toufiq, July 27, 2015 - 10:13 am UTC

Hi Tom,

i have SWIFT message and want to spool it to .txt file
but when i run .sql it added new blank line after each record.
I want to remove this blank newline.

query is simple

select colname from tablename

here colname has SWIFT message
i tried set recsep off but when i ran it with it, this command skipped. dont know any internal settings.

please help!!!

Create view issue

Felipe, December 03, 2015 - 10:02 pm UTC

Hi tom, I'm trying to execute a sql file in order to create a view, but the view has at least 160 columns. the sqlplus show me the next error:
SP2-0027: Input is too long (> 2499 characters) - line ignored

I'm try to insert the CR as chr(10), but doesn't work,

how the first line of create is ignored, the sqlplus show me all the select in my prompt,that is huge....

can you help me?
Connor McDonald
December 04, 2015 - 2:40 am UTC

SQL> select .... <my very long sql>

will eventually hit a limit. You need it to be split, eg

SQL> select
2 ...
3 ...
4 ...
5 etc

But as long as your file is segmented like that, it should be processed fine in SQL Plus

Perfect.

A reader, December 17, 2015 - 2:16 pm UTC

Just perfect.