Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-01-14
3
Medium Priority
?
803 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

916 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