473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Traling spaces in result?

Why is it that rows returned from this statement have extra trailing
spaces?
I.e. today tuesday the returned string is "Tuesday " with the length
9.

SELECT TO_CHAR(SYSDATE, 'Day','nls_date_language=english'),
LENGTH(TO_CHAR(SYSDATE, 'Day','nls_date_language=english')) FROM dual

I am using oracle 8.1.7

I read somewhere on the internet that FM (Format Models?) could
solve this problem I have, but I thought that the 'Day' was the
actual FM.

I have temporary solved it using trim() but if I do a compare
between this and a column in the database I don't want to use trim()
everywhere.

Any other good solution.

/Ken1
Jul 19 '05 #1
1 3537

"Ken1" <ke**@tjohoo.se> wrote in message
news:3b**************************@posting.google.c om...
| Why is it that rows returned from this statement have extra trailing
| spaces?
| I.e. today tuesday the returned string is "Tuesday " with the length
| 9.
|
| SELECT TO_CHAR(SYSDATE, 'Day','nls_date_language=english'),
| LENGTH(TO_CHAR(SYSDATE, 'Day','nls_date_language=english')) FROM dual
|
| I am using oracle 8.1.7
|
| I read somewhere on the internet that FM (Format Models?) could
| solve this problem I have, but I thought that the 'Day' was the
| actual FM.
|
| I have temporary solved it using trim() but if I do a compare
| between this and a column in the database I don't want to use trim()
| everywhere.
|
| Any other good solution.
|
| /Ken1

default behavior for formats is for variable length strings to be blank
padded and variable length numbers to be zero padded, which is often
appropriate for tabular results (time elements added to default hire dates,
view with a fixed font to line up results):

SQL> select ename, to_char(hiredate, 'Month dd, yyyy hh24:mi') as hired
2 from emp
3 /
....

ENAME HIRED
---------- ------------------------
SMITH December 17, 1980 00:01
ALLEN February 20, 2001 00:02
WARD February 22, 1981 00:03
JONES April 02, 1981 00:04
MARTIN September 28, 2001 00:05
CLARK June 09, 1981 00:06
SCOTT December 09, 1982 00:07
KING November 17, 1981 00:08
TURNER September 08, 1981 00:09
Adams January 12, 1983 00:10
JAMES December 03, 1981 00:11
FORD December 03, 1981 00:12
MILLER January 23, 1982 00:13
'FM' (fill mode?) is a TOGGLE to turn padding on/off -- it is often used
multiple times within a format, as shown below:

used once, turns off all padding (including in number elements):

SQL> select
2 ename
3 , to_char(hiredate, 'fmMonth dd, yyyy hh24:mi') as hired
4 from emp
5 /
....

ENAME HIRED
---------- ------------------------
SMITH December 17, 1980 0:1
ALLEN February 20, 2001 0:2
WARD February 22, 1981 0:3
....
JAMES December 3, 1981 0:11
FORD December 3, 1981 0:12

used multiple times, so that the time element looks better (also switched
over to 12-hour time with the meridian indicator on this one)

SQL> select
2 ename
3 , to_char(hiredate, 'fmMonth dd, yyyy hh:fmmi am') as hired
4 from emp
5 /
....

ENAME HIRED
---------- ---------------------------
SMITH December 17, 1980 12:01 am
ALLEN February 20, 2001 12:02 am
....
JAMES December 3, 1981 12:11 am
FORD December 3, 1981 12:12 am

another couple multiple-use example:

SQL> select
2 ename
3 , to_char(hiredate, 'fmDay mm/fmdd/yyyy fmhh:fmmi:ss am') as hired
4 from emp
5 /
....

ENAME HIRED
---------- --------------------------------
SMITH Wednesday 12/17/1980 12:01:00 am
ALLEN Tuesday 2/20/2001 12:02:00 am
....
JAMES Thursday 12/03/1981 12:11:00 am
FORD Thursday 12/03/1981 12:12:00 am

(view this one in a fixed-font):

SQL> select
2 ename
3 , to_char(hiredate, 'Day fmmm/fmdd/yyyy fmhh:fmmi:ss am') as hired
4 from emp
5 /
....

ENAME HIRED
---------- --------------------------------
SMITH Wednesday 12/17/1980 12:01:00 am
ALLEN Tuesday 2/20/2001 12:02:00 am

-- mcs
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jay Chan | last post by:
I am trying to export data from a SQLServer database into a text file using a stored procedure. I want to be able to read it and debug it easily; therefore, I want all the columns to indent nicely....
2
by: Y. H. | last post by:
Hi, I'm having the following problem. I'm trying to write a simple parser for a script that looks like this: <command> , , , ... Giving an argument is optional. If it's not present...
5
by: Marco Gallo | last post by:
I've been trying to get rid of extra spaces in a table that I created with addresses in it. For instance in a field called TEST, I got the following address: " 1 main st Apt A "...
3
by: Moshe Foobar | last post by:
Hi, When i save a url into a string : string myURL = @"http://www.allmusic.com/cg/amg.dll?p=amg&sql=2surfer|rosa"; but when i d/l this page : WebClient myClient = new WebClient();...
12
by: Joriveek | last post by:
Hi, I have a little piece of program here Basically what it does is, it copies the strings of variable widths. The basis is until it finds a comma ",". The input is a CSV/Comma Separated...
3
by: Matthias Langbein | last post by:
Hi all, on one of my sites I want to give the user the possibility to upload a html file where I want to extract all that is within the <body>-tags. The upload works fine: <form id="uploadform"...
8
by: Joe Cool | last post by:
I need to map several columns of data from one database to another where the data contains multiple spaces (once occurance of a variable number or spaces) that I need to replace with a single...
3
by: afrobeard | last post by:
The following following code fails with the failiure:- File "test.py", line 27, in __main__.sanitize_number Failed example: sanitize_number('0321-4683113') Expected: '03214683113' Got:...
1
by: Ken1 | last post by:
Why is it that rows returned from this statement have extra trailing spaces? I.e. today tuesday the returned string is "Tuesday " with the length 9. SELECT TO_CHAR(SYSDATE,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.