Solved

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

Posted on 2014-01-14
3
798 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Database 2007 - automating reports being sent by email 2 57
Dbms_job.change procedure 16 37
Using a combo box to search a form. 3 36
Convert summed columns to Rows 6 25
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

738 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