Solved

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

Posted on 2014-01-14
3
772 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 73

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 73

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 73

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

707 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

13 Experts available now in Live!

Get 1:1 Help Now