Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert date values into table

How can I insert into table with different input using / ,with date datatype?

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

I'm using oracle 10g.

like image 941
AbIr Chanda Avatar asked Dec 17 '15 08:12

AbIr Chanda


People also ask

How do you insert a date in a table?

A DATE data type contains both date and time elements. If you are not concerned about the time portion, then you could also use the ANSI Date literal which uses a fixed format 'YYYY-MM-DD' and is NLS independent. For example, SQL> INSERT INTO t(dob) VALUES(DATE '2015-12-17'); 1 row created.

How do you add a date to a table in SQL?

The following command is used to insert values into the table. Query: SET DATEFORMAT dmy; INSERT INTO GFG_user (Id, Dt, Address) VALUES ('1','23.11. 2021', 'German');

How do you insert date into values?

INSERT INTO Syntax 1. Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...)


1 Answers

Since dob is DATE data type, you need to convert the literal to DATE using TO_DATE and the proper format model. The syntax is:

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 

A DATE data type contains both date and time elements. If you are not concerned about the time portion, then you could also use the ANSI Date literal which uses a fixed format 'YYYY-MM-DD' and is NLS independent.

For example,

SQL> INSERT INTO t(dob) VALUES(DATE '2015-12-17');  1 row created. 
like image 52
Lalit Kumar B Avatar answered Oct 06 '22 00:10

Lalit Kumar B