Solved

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

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

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

Suggested Solutions

Title # Comments Views Activity
PL SQL Developer 7 34
Sql Stored Procedure field variable 17 31
sql server computed columns 11 31
TSQL query to generate xml 4 33
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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.

776 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