Solved

help with query, date format

Posted on 2013-05-16
3
470 Views
Last Modified: 2013-05-16
This query gives me error ORA-01843: not a valid month

the ship_date column which is the one i am trying to convert to 05/16/2013 format, is a NUMBER column in 20130516 format.

I've also tried to_char(ship_date, 'MM/DD/YYY') which gives me error ORA-01481: invalid number format model

select
TICKET_ID AS "ID",
VENDOR,
CONTRACT,
to_date(SHIP_DATE, 'MM/DD/YYY'),
trim(' ' from PO_NUMBER) PO_NUMBER,
trim(' ' from FEEDER_SCHOOL) FEEDER_SCHOOL,
CASE WHEN trim(' ' from CODE) = NCSCODE.ITEM THEN NCSCODE.CODES END CODE, 
UNIT_PRICE,
QTY,
to_char(QQTY, '9999.99') AS TOTAL_COST, 
' ' AS DESCRIPTION
from (week join S on feeder_school = FS and SHIP_DATE = SD) join NCSCODE on ITEM = trim(' ' from CODE) ;

Open in new window

0
Comment
Question by:FutureDBA-
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39172748
Go to a date first:

to_char(to_date(ship_date,'YYYYMMDD'), 'MM/DD/YYY')
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39172753
or just manipulate the string you have:
regexp_replace(20130516,'([[:digit:]]{4})([[:digit:]]{2})([[:digit:]]{2})','\2/\3/\1')
0
 

Author Closing Comment

by:FutureDBA-
ID: 39173559
This was the best solution for me as it is the easiest to understand.. Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now