Solved

I have a question regarding the syntax for creating a table in Oracle

Posted on 2014-01-14
3
792 Views
Last Modified: 2014-01-27
Hi Experts,
I have a question regarding the syntax for creating a table in Oracle.  In particular, with my date field.  Please see my create table syntax below and tell me if it's correct.  Thank you very much in advance.

CREATE TABLE INVOICE_TEST
(INVOICE_NO NUMBER (5),
INVOICE_DATE  DATE, ‘MM/DD/YYYY’,
CUSTOMER _ID NUMBER (5),
QTY NUMBER (6),
NET_SALES NUMBER (6)); 

Open in new window


mrotor
0
Comment
Question by:mainrotor
  • 3
3 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 39779693
do not include a format on the date column, also you had a space in the customer_id name


CREATE TABLE INVOICE_TEST
(INVOICE_NO NUMBER (5),
INVOICE_DATE  DATE,
CUSTOMER_ID NUMBER (5),
QTY NUMBER (6),
NET_SALES NUMBER (6));
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39779699
Dates (and timestamps) have their own internal format that has NOTHING to do with how you enter or present those values.

mm/dd/yyyy is a TEXT format for when you extract a date value and display it using TO_CHAR
whether implicitly or explicitly
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39779771
As examples,  I can insert data into the invoice_test table in multiple ways...


insert into invoice_test (invoice_date) values (:x); -- this is a bind variable of type DATE

insert into invoice_test(invoice_date) values (date '2013-01-14');  -- this is an ISO date literal


insert into invoice_test(invoice_date) values (timestamp '2013-01-14 12:34:56');  -- this is an ISO timestamp literal that will be implicitly converted to a date (losing fractional seconds which were 0 anyway in this example)


insert into invoice_test(invoice_date) values('2014-01-14 11:57:32');  -- this is an implicit conversion of a string to a date.  This will work in MY session but probably not yours unless you change your default conversion format

insert into invoice_test(invoice_date) values(to_date('2014-01-14 11:57:32','yyyy-mm-dd hh24:mi:ss'));  -- this is an explicit conversion of a string to a date.  This is reliable across all sessions and clients


internally the date are stored as 7 bytes and don't look anything like the text representations I've used above.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

830 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