Home » SQL & PL/SQL » SQL & PL/SQL » Truncate spaces in output
Truncate spaces in output [message #4406] Thu, 05 December 2002 05:27 Go to next message
ragha
Messages: 3
Registered: December 2002
Junior Member
Hi,

I am having some problem with the below query.
Eg -> If it is a April Month then the below query

select to_char(sysdate,'dd-month-yyyy') from dual;

will return '04-april -2003' ,in that how to truncate the space between april and hypen.

Thanks
Re: Truncate spaces in output [message #4407 is a reply to message #4406] Thu, 05 December 2002 05:57 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
SQL> select replace(to_char(add_months(sysdate,&nr),'DDMONTHYYYY'),' ','') new_date
  2    from dual;
Enter value for nr: 0
old   1: select replace(to_char(add_months(sysdate,&nr),'DDMONTHYYYY'),' ','') new_date
new   1: select replace(to_char(add_months(sysdate,0),'DDMONTHYYYY'),' ','') new_date

NEW_DATE
---------------
05DECEMBER2002

SQL> /
Enter value for nr: 5
old   1: select replace(to_char(add_months(sysdate,&nr),'DDMONTHYYYY'),' ','') new_date
new   1: select replace(to_char(add_months(sysdate,5),'DDMONTHYYYY'),' ','') new_date

NEW_DATE
---------------
05MAY2003


HTH,
MHE
Re: Truncate spaces in output [message #4413 is a reply to message #4407] Thu, 05 December 2002 10:44 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Actually, it's a lot easier than that (format modifier):

sql>select to_char(sysdate, 'dd-month-yyyy') from dual;
 
TO_CHAR(SYSDATE,'
-----------------
05-december -2002
 
1 row selected.
 
sql>select to_char(sysdate, 'dd-<b>FM</b>month-yyyy') from dual;
 
TO_CHAR(SYSDATE,'
-----------------
05-december-2002
 
1 row selected.
Previous Topic: Problems with dates
Next Topic: update from file dbf
Goto Forum:
  


Current Time: Wed May 15 07:38:34 CDT 2024