dbTalk Databases Forums  

Does CHR(10) add an extra newline?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Does CHR(10) add an extra newline? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Brian Tkatch
 
Posts: n/a

Default Does CHR(10) add an extra newline? - 11-21-2007 , 11:06 AM






While writing a query to do some editting i wanted to use CHR(10) to
have a query do some formatting. It seems that whenever it is used, it
adds an extra newline at the end of the line.


SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
CONNECT BY LEVEL < 4)

A B
---------- -----------------------------------------
1
1

2
2

3
3


3 rows selected.

SQL>

How do i add a newline in middle of a line without adding at the end
as well?

B.

Reply With Quote
  #2  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-21-2007 , 12:48 PM






Brian Tkatch wrote:
Quote:
While writing a query to do some editting i wanted to use CHR(10) to
have a query do some formatting. It seems that whenever it is used, it
adds an extra newline at the end of the line.


SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
CONNECT BY LEVEL < 4)
No - your display simply is not wide enough.
Why don't you check out all possible settings in SQL*Plus?
the one you want is SET LINES[ize]

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...


Reply With Quote
  #3  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-21-2007 , 01:40 PM



On Nov 21, 12:48 pm, Frank van Bortel <frank.van.bor... (AT) gmail (DOT) com>
wrote:
Quote:
Brian Tkatch wrote:
While writing a query to do some editting i wanted to use CHR(10) to
have a query do some formatting. It seems that whenever it is used, it
adds an extra newline at the end of the line.

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
CONNECT BY LEVEL < 4)

No - your display simply is not wide enough.
Why don't you check out all possible settings in SQL*Plus?
the one you want is SET LINES[ize]

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...
I return the same results that you posted, using 10.2.0.3.0 on AIX:

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
2 CONNECT BY LEVEL < 4);

A B
-- -----------------------------------------
1
1

2
2

3
3

no matter how long my linesize. Also the method of introducing the
chr(10) into the text matters not:

SQL> variable lf varchar2
SQL> exec :lf := chr(10);

PL/SQL procedure successfully completed.

SQL> select rownum a, :lf||rownum b
2 from dual
3 connect by level < 4;

A B
--
------------------------------------------------------------------------
1
1

2
2

3
3


SQL>

I find no explanation of this behaviour on the web, thus I am at a
loss to explain it.

You may be relegated to using PL/SQL to produce the results you want
(presuming the following would be the results you desire):

begin
for i in (select rownum a, rownum b from dual connect by level < 4)
loop
dbms_output.put_line(i.a || chr(10) || chr(9) || i.b);
end loop;
end;
/

1
1
2
2
3
3

PL/SQL procedure successfully completed.


David Fitzjarrell


Reply With Quote
  #4  
Old   
Brian Tkatch
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-21-2007 , 01:49 PM



On Wed, 21 Nov 2007 19:48:11 +0100, Frank van Bortel
<frank.van.bortel (AT) gmail (DOT) com> wrote:

Quote:
Brian Tkatch wrote:
While writing a query to do some editting i wanted to use CHR(10) to
have a query do some formatting. It seems that whenever it is used, it
adds an extra newline at the end of the line.


SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
CONNECT BY LEVEL < 4)

No - your display simply is not wide enough.
My linesize is set to 156, which does not wordwrap normally.

B.

Quote:
Why don't you check out all possible settings in SQL*Plus?
the one you want is SET LINES[ize]



Reply With Quote
  #5  
Old   
Brian Tkatch
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-21-2007 , 01:53 PM



On Wed, 21 Nov 2007 11:40:24 -0800 (PST), "fitzjarrell (AT) cox (DOT) net"
<fitzjarrell (AT) cox (DOT) net> wrote:

Quote:
On Nov 21, 12:48 pm, Frank van Bortel <frank.van.bor... (AT) gmail (DOT) com
wrote:
Brian Tkatch wrote:
While writing a query to do some editting i wanted to use CHR(10) to
have a query do some formatting. It seems that whenever it is used, it
adds an extra newline at the end of the line.

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
CONNECT BY LEVEL < 4)

No - your display simply is not wide enough.
Why don't you check out all possible settings in SQL*Plus?
the one you want is SET LINES[ize]

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...

I return the same results that you posted, using 10.2.0.3.0 on AIX:

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
2 CONNECT BY LEVEL < 4);

A B
-- -----------------------------------------
1
1

2
2

3
3

no matter how long my linesize. Also the method of introducing the
chr(10) into the text matters not:

SQL> variable lf varchar2
SQL> exec :lf := chr(10);

PL/SQL procedure successfully completed.

SQL> select rownum a, :lf||rownum b
2 from dual
3 connect by level < 4;

A B

Thank you. I came up with it originally in a CASE statement, to create
CREATE VIEW statements. I worked around it by opening Word, and doing
a replace on ",^p^p". Though, i am quite curious why this is
happening.

And thanx for the example in PL/SQL.

B.


Reply With Quote
  #6  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-22-2007 , 06:32 AM



On 21 nov, 20:53, Brian Tkatch <N/A> wrote:
Quote:
On Wed, 21 Nov 2007 11:40:24 -0800 (PST), "fitzjarr... (AT) cox (DOT) net"



fitzjarr... (AT) cox (DOT) net> wrote:
On Nov 21, 12:48 pm, Frank van Bortel <frank.van.bor... (AT) gmail (DOT) com
wrote:
Brian Tkatch wrote:
While writing a query to do some editting i wanted to use CHR(10) to
have a query do some formatting. It seems that whenever it is used, it
adds an extra newline at the end of the line.

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
CONNECT BY LEVEL < 4)

No - your display simply is not wide enough.
Why don't you check out all possible settings in SQL*Plus?
the one you want is SET LINES[ize]

--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...

I return the same results that you posted, using 10.2.0.3.0 on AIX:

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
2 CONNECT BY LEVEL < 4);

A B
-- -----------------------------------------
1
1

2
2

3
3

no matter how long my linesize. Also the method of introducing the
chr(10) into the text matters not:

SQL> variable lf varchar2
SQL> exec :lf := chr(10);

PL/SQL procedure successfully completed.

SQL> select rownum a, :lf||rownum b
2 from dual
3 connect by level < 4;

A B

Thank you. I came up with it originally in a CASE statement, to create
CREATE VIEW statements. I worked around it by opening Word, and doing
a replace on ",^p^p". Though, i am quite curious why this is
happening.

And thanx for the example in PL/SQL.

B.
You normally would not create views "on the fly"...
Apart from that - there's no need for carriage returns in DDL,
but if you really want them, just embed the carriage return in the
statement:

SQL> select 'hello
2 world' from dual;

'HELLOWORLD'
------------
hello
world

And yes- there's an extra space before Hello on line 2.


Reply With Quote
  #7  
Old   
William Robertson
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-23-2007 , 01:36 AM



On Nov 21, 7:40 pm, "fitzjarr... (AT) cox (DOT) net" <fitzjarr... (AT) cox (DOT) net> wrote:
Quote:
On Nov 21, 12:48 pm, Frank van Bortel <frank.van.bor... (AT) gmail (DOT) com
wrote:

Brian Tkatch wrote:
While writing a query to do some editting i wanted to use CHR(10) to
have a query do some formatting. It seems that whenever it is used, it
adds an extra newline at the end of the line.

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
CONNECT BY LEVEL < 4)

No - your display simply is not wide enough.
Why don't you check out all possible settings in SQL*Plus?
the one you want is SET LINES[ize]

--
Regards,
Frank van Bortel

I return the same results that you posted, using 10.2.0.3.0 on AIX:

SQL> SELECT RowNum A, CHR(10) || RowNum B FROM (SELECT * FROM Dual
2 CONNECT BY LEVEL < 4);

A B
-- -----------------------------------------
1
1

2
2

3
3

no matter how long my linesize. Also the method of introducing the
chr(10) into the text matters not:

SQL> variable lf varchar2
SQL> exec :lf := chr(10);

PL/SQL procedure successfully completed.

SQL> select rownum a, :lf||rownum b
2 from dual
3 connect by level < 4;

A B
--
------------------------------------------------------------------------
1
1

2
2

3
3

SQL

I find no explanation of this behaviour on the web, thus I am at a
loss to explain it.

SET RECSEP OFF
The default setting is WRAP.
<http://download.oracle.com/docs/cd/B...er.102/b14357/
ch12040.htm#SQPUG097>

Or use a client other than SQL*Plus.


Reply With Quote
  #8  
Old   
Brian Tkatch
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-26-2007 , 08:21 AM



On Thu, 22 Nov 2007 04:32:22 -0800 (PST), Frank van Bortel
<frank.van.bortel (AT) gmail (DOT) com> wrote:

Quote:
On 21 nov, 20:53, Brian Tkatch <N/A> wrote:
On Wed, 21 Nov 2007 11:40:24 -0800 (PST), "fitzjarr... (AT) cox (DOT) net"
SNIP
You normally would not create views "on the fly"...
True. But i don't see what that has to do with anything. I did not
mean to sound like i was complaining how i want something to work. I
am asking why it works the way that it does.

Quote:
Apart from that - there's no need for carriage returns in DDL,
There is, if i want it to look pretty.

Actually, i despise redundancy, and enjoy an elegant solution. The
extra CR just plain bothers me, that is, if i know there is a way to
avoid it.

Quote:
but if you really want them, just embed the carriage return in the
statement:

SQL> select 'hello
2 world' from dual;

'HELLOWORLD'
------------
hello
world
I never even thought of doing that. Thanx!

Quote:
And yes- there's an extra space before Hello on line 2.
Heh, i used CHAR(9).

Perhaps i should just post the query i used. I'll never learn if i'm
too embarrassed to be shown my own mistakes. The TABLE names all start
with a four character prefix, a letter or number, two numbers, and an
underscore. The column names are prefixed similarly, minus the very
first character. It also has a SYNONYM with the number pointing to it,
for compliance with the numbered system.

WITH
Info
AS
(
SELECT
Owner,
Table_Name,
MAX(Column_Id) Total_Columns,
MAX(FLOOR(LENGTH(Column_Name) / 8)) Tabs
FROM
All_Tab_Columns
GROUP BY
Owner,
Table_Name
)
SELECT
SUBSTR
(
CASE
WHEN Columns.Column_Id = 1 THEN
'CREATE OR REPLACE VIEW ' ||
INITCAP(SUBSTR(Columns.Table_Name, 9))
Quote:
| CHR(10) || 'AS'
| CHR(10) || ' SELECT'
| CHR(10)
END
| CHR(09) || Columns.Column_Name
| RPAD(CHR(09), (Tabs - FLOOR(LENGTH(Column_Name) / 8)) + 1,
CHR(09))
| INITCAP(SUBSTR(Columns.Column_Name, 8,
LENGTH(Columns.Column_Name) - 9))
| CASE
WHEN Columns.Column_Id = Info.Total_Columns THEN
CHR(10) || 'FROM'
Quote:
| CHR(10) || CHR(09) || Columns.Table_Name ||
';'
| CHR(10) || CHR(10)
| 'CREATE OR REPLACE SYNONYM V'
| SUBSTR(Columns.Table_Name, 5, 3)
| ' FOR ' ||
INITCAP(SUBSTR(Columns.Table_Name, 9)) || ';'
ELSE ','
END,
1,
150
) Statement
FROM
All_Tab_Columns Columns,
Info
WHERE
Columns.Owner = 'xxx'
AND Columns.Table_Name LIKE 'xxxxx%'
AND Columns.Owner = Info.Owner
AND Columns.Table_Name = Info.Table_Name
ORDER BY
Columns.Table_Name,
Columns.Column_Id;

B.


Reply With Quote
  #9  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-26-2007 , 12:41 PM



Brian Tkatch wrote:
Quote:
On Thu, 22 Nov 2007 04:32:22 -0800 (PST), Frank van Bortel
frank.van.bortel (AT) gmail (DOT) com> wrote:

On 21 nov, 20:53, Brian Tkatch <N/A> wrote:
On Wed, 21 Nov 2007 11:40:24 -0800 (PST), "fitzjarr... (AT) cox (DOT) net"
SNIP
You normally would not create views "on the fly"...

True. But i don't see what that has to do with anything. I did not
mean to sound like i was complaining how i want something to work. I
am asking why it works the way that it does.
It is quite often an indication of (bad) SQL Server habits
being ported to Oracle. Oracle does things differently; it's
better to start with that in mind. Creating objects on the fly
is something that should not be permitted in any environment,
even SQL Server.
For SQL Server, temporary tables may be an exception.

I just wanted to point that out... There's one exception, I can
think of - when delivering an update (or install) script for
maintenance purposes.

Quote:
Apart from that - there's no need for carriage returns in DDL,

There is, if i want it to look pretty.
Well - who's going to see the code? It was my understanding the code
being generated was to be executed, using dynamic SQL?
[snip!]
--
Regards,
Frank van Bortel

Top-posting is one way to shut me up...


Reply With Quote
  #10  
Old   
Brian Tkatch
 
Posts: n/a

Default Re: Does CHR(10) add an extra newline? - 11-26-2007 , 02:00 PM



On Mon, 26 Nov 2007 19:41:26 +0100, Frank van Bortel
<frank.van.bortel (AT) gmail (DOT) com> wrote:

Quote:
Brian Tkatch wrote:
On Thu, 22 Nov 2007 04:32:22 -0800 (PST), Frank van Bortel
frank.van.bortel (AT) gmail (DOT) com> wrote:

On 21 nov, 20:53, Brian Tkatch <N/A> wrote:
On Wed, 21 Nov 2007 11:40:24 -0800 (PST), "fitzjarr... (AT) cox (DOT) net"
SNIP
You normally would not create views "on the fly"...

True. But i don't see what that has to do with anything. I did not
mean to sound like i was complaining how i want something to work. I
am asking why it works the way that it does.

It is quite often an indication of (bad) SQL Server habits
being ported to Oracle. Oracle does things differently; it's
better to start with that in mind. Creating objects on the fly
is something that should not be permitted in any environment,
even SQL Server.
For SQL Server, temporary tables may be an exception.
Although i have worked with SQL Server, i don't think i picked up any
bad habits from it. Most of my DB training is from DB2 and Oracle.

Quote:
I just wanted to point that out... There's one exception, I can
think of - when delivering an update (or install) script for
maintenance purposes.


Apart from that - there's no need for carriage returns in DDL,

There is, if i want it to look pretty.

Well - who's going to see the code? It was my understanding the code
being generated was to be executed, using dynamic SQL?
[snip!]
Yep, just for me. But still, if it can look nice, it might as well. I
consider it good training at the very least.

B.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.