Solved

How do I format the dates when creating table?

Posted on 2009-07-08
6
236 Views
Last Modified: 2012-05-07
How do I properly format the dates in the following?
Date_Added & Date_Modified
Thanks!
Beth
CREATE TABLE CUSTOMER_SHIPPING_ADDRESS                           
  ( CUSTOMER_SHIP_ID (8,0) NOT NULL    
  , CUSTOMER_NO NUMBER(8,0) NOT NULL
  , CUSTOMER_SHIP_TYPE CHAR(1)
  , DATE_ADDED DATE(1)
  , DATE_MODIFIED DATE(30)
  , ADDRESS_1_SHIP VARCHAR2(50)
  , ADDRESS_2_SHIP VARCHAR2(50)
  , CITY_SHIP VARCHAR2(30)
  , STATE_SHIP VARCHAR2(20)
  , ZIPCODE_SHIP NUMBER(5,0)
  , COUNTRY_SHIP VARCHAR2(30)
  , CONSTRAINT CUSTOMER_SHIPPING_ADDRESS_PK PRIMARY KEY(CUSTOMER_SHIP_ID)           
  , CONSTRAINT CUST_SH_TYPE CHECK (CUSTOMER_SHIP_TYPE IN ('W', 'M', 'D', 'O'))
  , CONSTRAINT CUSTOMER_SHIPPING_ADDRESS_FK     FOREIGN KEY (CUSTOMER_NO)  
  , REFERENCES CUSTOMER(CUSTOMER_NO))                
                           
;

Open in new window

0
Comment
Question by:ba_trainer
6 Comments
 
LVL 17

Expert Comment

by:pssandhu
ID: 24804849
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24804865
>>DATE_ADDED DATE(1)
>>, DATE_MODIFIED DATE(30)

THis is not the correct syntax. Just use DATE or TIMESTAMP

DATE_ADDED DATE
, DATE_MODIFIED DATE


dates are not stored in any special format, they are only formatted when you query them, using the default NLS_DATE_FORMAT as the default format, or using TO_CHAR() functions to explicitly format.

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24804883
Normally you don't format dates in the data structure.  It will store the date as the system needs it.  Now what matters is what format / language your system is setup to handle as that is how it will interpret literal dates if not specified.  You will want to format dates on output.

BTW, don't believe you need (1) or (30) with DATE data type.  Don't believe that even does anything, but maybe I am wrong as I am more of a MS SQL Server guy myself.
0
 
LVL 48

Expert Comment

by:schwertner
ID: 24805558
DATE type in Oracle has fixed internal format and length and format.
The designer uses the DATE or TIMESTAMP type to declare them.

Because the input of the DATE is in character string we use
TO_DATE conversion function like

TO_DATE('12-7-2008 14:15:55','mm-DD-yyyy hh24:MI:SS')
0
 
LVL 32

Expert Comment

by:awking00
ID: 24805786
See attached.
comments.txt
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

829 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