How to insert date values ​​in a table

How can I insert into a table with different entries using / with a date data type ?

insert into run(id,name,dob)values(&id,'&name',[what should I write here?]); 

I am using oracle 10g.

+25
sql oracle oracle10g datetime date-formatting
source share
5 answers

Since dob is a DATE data type, you need to convert the literal to DATE using TO_DATE and a suitable format model. Syntax:

 TO_DATE('<date_literal>', '<format_model>') 

For example,

 SQL> CREATE TABLE t(dob DATE); Table created. SQL> INSERT INTO t(dob) VALUES(TO_DATE('17/12/2015', 'DD/MM/YYYY')); 1 row created. SQL> COMMIT; Commit complete. SQL> SELECT * FROM t; DOB ---------- 17/12/2015 

The DATE data type contains date and time elements. If you are not worried about the time, you can also use the ANSI Date literal, which uses the fixed format 'YYYY-MM-DD' and is independent of NLS.

For example,

 SQL> INSERT INTO t(dob) VALUES(DATE '2015-12-17'); 1 row created. 
+28
source share

date must be inserted with two apostrophes. For example, if the date is 2018/10/20. May embed from these queries

Request -

 insert into run(id,name,dob)values(&id,'&name','2018-10-20') 
+4
source share

I have a combo box that is named as the date of the guarantee, and the combo box contains text like β†’ One year <- now, how can I insert this row type into the column of the Warranty date data type that is present in the SQL table named as tbl_Transaction

0
source share

insert values ​​into the run (id, name, dob) (& id, '& name', [what should I write here?]);

insert values ​​into the run (id, name, dob) (& id, '& name', TO_DATE ('& dob', 'YYYY-MM-DD'));

0
source share

let's assume that we create a transaction table using the SQl server management studio

 txn_id int, txn_type_id varchar(200), Account_id int, Amount int, tDate date ); 

with the date data type, we can insert the values ​​in a simple format: 'yyyy-mm-dd'

 INSERT INTO transactions (txn_id,txn_type_id,Account_id,Amount,tDate) VALUES (978, 'DBT', 103, 100, '2004-01-22'); 

Moreover, we can have different time formats, such as.

 DATE - format YYYY-MM-DD DATETIME - format: YYYY-MM-DD HH:MI:SS SMALLDATETIME - format: YYYY-MM-DD HH:MI:SS 
-one
source share

All Articles