ORA-00917: Missing Comma SQL Oracle error - sql

I am using Oracle SQL and have just altered a table and added a column named Date_Employed
ALTER TABLE Employees ADD Date_Employed date;
My problem is that whenever I try to insert a value into the Date_Employed column i get an error ORA-00917: Missing comma when I type in the code below
INSERT INTO Employees(Date_Employed) VALUES (26 September 2001);
I would like to know whether the method I am using to try to input data into the column is correct? and if it is not, what is the correct way to insert date data into the column?
Also, I would like to know, why I am getting the error I described?

Use a proper date format for Oracle and enclose it in single quotes:
INSERT INTO Employees(Date_Employed)
VALUES (DATE '2001-09-26');

INSERT INTO
Employees (Date_Employed)
VALUES
(TO_DATE('2003/05/03 21:02:44', 'yyyy/mm/dd hh24:mi:ss'));
You are getting error because oracle is not able to understand the date format you have given.

Related

How to add timestamp data to PostgreSQL table?

I am trying to add some data to a PostgreSQL table using INSERT TO on pgAdmin4.
This is the code that I am trying to run;
INSERT INTO raw(id,object_id, confidence, timestamp)
VALUES (1,9.0,0.012145853244069600,2020-05-20 13:02:52.281964)
And I am getting the following response;
ERROR: syntax error at or near "13"
I am quite new to SQL and PostgreSQL, so go easy on me. I assume that it is something wrong with handling time related data.
Use single quotes:
INSERT INTO raw(id,object_id, confidence, timestamp)
VALUES (1,9.0,0.012145853244069600,'2020-05-20 13:02:52.281964')

Insert Date and String on table

I have a table with the following properties:
U. TRADE_ID VARCHAR2
TRADE_DATE DATE
PRICE NUMBER(10.2)
Once I get the data from a file, the colums are as follow:
PSD231,03051982,50.1
My question is, are those the correct datatypes for the table? I'm getting the input from the file for the first sql column as a String. But I can't display it. I think I'm missing something in the sql part. How can I create a new sql row filled with data so I can test it? This is what I tried and works:
insert into myTable(TRADE_ID, TRADE_DATE, PRICE)
values('PSD231', date '2011-01-01', 10.4);
but I'm trying create a query with the date in the format:
01-01-2011, not like the above
"What if I wanted to insert the values like this: 10062019 in the format ddmmyyyy instead of how I have it in the query: 2011-01-01 "
Just put single quotes around the date, '10062019', and make sure it is in the correct date format for your region (ddmmyyyy in your case).
insert into myTable (TRADE_ID, TRADE_DATE, PRICE)
values ('PSD231', '20110101', 10.4);
To change date formats, use the CONVERT function e.g
SELECT CONVERT(varchar, getdate(), 1)
There is a nice list for the convert function here
Since you have defined the first field as a varchar type, it should be more like,
insert into myTable(TRADE_ID, TRADE_DATE, PRICE)
values('PSD231','2011-01-01', '10');
Values should be enclosed into single quotes when they are being inserted.

row is not inserting due to SP2-0552 error

I was trying to insert a row in a table. The below given error occurred while inserting
I don't know for what reason it occurred
SQL> insert into priya1 values ('CB','000304105000','A023596','MSC','A',05/7/2013
5:33:57 AM);
SP2-0552: Bind variable "33" not declared.
The error occurs because your date string is not correct, it is not even a string and because in many cases it will not be recognized as a date. Don't depend on defaults for date formats that happen to be in effect, make sure that your code always works by specifying what you insert.
In this case use:
create table z (z date);
insert into z (z) values (to_date('05/7/2013 5:33:57 AM','dd/mm/yyyy hh:mi:ss am'));
1 rij is aangemaakt.
i found an another way for this problem i solved using the given below query and then i inserted rows without adding to_date
alter session set nls_date_format='yyyy/mm/dd hh:mi:ss am';
it may be case when data contains single quote also produces this error for date column. in that case replace single quote with two single quotes. then record will insert
put the date time value in single quote
insert into priya1 values ('CB','000304105000','A023596','MSC','A','05/7/2013
5:33:57 AM');

How to Insert table column values: month & day from column datetype

I'm using Oracle 11g Schema
I want to select the month and day from a date concatenate it and put it into a column.
The syntax I have here makes sense but its throwing an error of..
INSERT INTO OB_SELECT_LST12_SPG WED
VALUES (((TO_CHAR(TO_DATE('RET_DATE', MM))||( TO_CHAR(TO_DATE('RET_DATE', DD)));
"SQL Error: ORA-00907: missing right parenthesis"
Any help is greatly appreciated.
Thanks.
Some points first...
Your table name has a space in in
Your not enough columns error is caused by you having more than one column in the table
You really shouldn't be doing this at all
If ret_date is a column don't encapsulate it in quotation marks (') as you won't be able to convert the string 'ret_date' into a date.
However, assuming ret_date is a string that looks like 13-06-2012
insert into ob_select_lst12_spg_wed (my_column)
values(to_char(to_date(:ret_date,'dd-mm-yyyy'),'mmdd'));
If ret_date is a date data-type then you can remove the inner conversion.
insert into ob_select_lst12_spg_wed (my_column)
values(to_char(:ret_date,'mmdd'));
to_char and to_date both make use of datetime format models, which have a number of options.
Please don't do this though. Always store dates as dates
From your comments ret_date is a date and the column wed is a character. You're getting the error bind variable not declared because you haven't specified the variable. I'm going to assume that ret_date is in another table as it's a date, in which case lose the values key-word and insert directly from that table:
insert into ob_select_lst12_spg (wed)
select to_char(ret_date,'mmdd')
from the_other_table
This shouldn't be required though, you can always convert a date into whatever you want on exit from the database. If you don't store it as a date in the database then it's easy for errors and incorrect values to creep in. I personally would change the column wed to a date, in which case your query becomes the very simple:
insert into ob_select_list12_spg (wed)
select ret_date
from the_other_table
You can then use the correct datetime format model for your needs when selecting from the database.
Sample query to get date, month from date column:
Select ((To_Char(to_date('01-FEB-73','dd-mon-yy'), 'MM'))
||( To_Char(to_date('01-JAN-73','dd-mon-yy'), 'dd')))
from dual;
if RET_DATE is date datatype then use
insert into table_name (columname)
Select ((To_Char(RET_DATE, 'MM'))
||( To_Char(RET_DATE, 'dd')))
from dual;
You are missing extra parentheses. Number of opened ( was 8 and closed ) was 5
INSERT INTO OB_SELECT_LST12_SPG(WED)
VALUES ((TO_CHAR(TO_DATE(RET_DATE, MM)))||( TO_CHAR(TO_DATE(RET_DATE, DD))));
Update
Make sure other columns are not required (i.e. Allow NULLs)

Date time string insert to db

Hi I am trying to insert the following to SQL Server 2005:
INSERT INTO tb_UserLoginTimes (UserID, LoginDateTime)
VALUES (1235,2010/07/06 10:38:44)
But am getting the following error.
Incorrect syntax near '10'.
Do I need to escape the colon?
If so how do I do that?
Real noob at this so my apologies.
It looks like you simply need to enclose your date in quotes:
... VALUES (1235, '2010/07/06 10:38:44')
Try it out in the SEDE. If you leave out the quotes, you'll get the same syntax error you're reporting.
Instead of 2010/07/06 10:38:44 use the ANSI SQL Standard (YYYYMMDD HH:MM:SS)
'20100706 10:38:44'