I'm trying to add row information to my table using INSERT INTO and I keep getting
ORA-00984: column not allowed here
Here is what I'm trying to insert:
INSERT INTO cp2850Tutor
VALUES (100,'05-JAN-2008',Active);
I've tried putting quotes around Active and that gets a different error:
ORA-01722: invalid number
It is best practice to explicitly state the columns that you are inserting into
E.g
Insert into cp2850Tutor (IQ, JOINED_DATE, STATUS)
Values (100,'05-JAN-2008', 1);
If you show us your DDL more help is possible
if any constraint is applied to the columns, check for symantec errors
eg: if the column datatype is varchar2
but the constraint applied is :
check ( clm_name > 3 ) -- wrong one
check ( length( clm_name) > 3 ) -- correct one
Related
I have a table projects in postgreSQL that looks like below
id. project_name. col3. col4
1111. test. ... ...
I want to insert a new row for a new id only if the id does not already exist. So I wrote below query
INSERT INTO projects(id, project_name)
VALUES("1234", "Test_Project")
ON CONFLICT (id)
DO NOTHING
But it throws me an error
Query 1 ERROR: ERROR: column "1234" does not exist
LINE 2: VALUES("1234", "Test_Project_...
Please suggest.
** EDIT**
The id column in the table is a uuid and not unique. There can be multiple rows with the same id. Based on GMBs suggestion, I tried below
INSERT INTO projects(id, project_name)
VALUES('1234', 'Test_Project')
ON CONFLICT (create unique index on projects(id))
DO NOTHING
I get below error with it
Query 1 ERROR: ERROR: syntax error at or near "create"
LINE 3: ON CONFLICT (create unique index on projects(id...
I am new to this so I am sure missing something obvious.
Use single quotes for literal strings. Double quotes stand for identifiers (such as column names or table names) - hence the error that you are getting:
INSERT INTO projects(id, project_name)
VALUES('1234', 'Test_Project')
ON CONFLICT (id)
DO NOTHING
That said, I would suspect that id is of integer datatype. If so, don't quote it at all:
INSERT INTO projects(id, project_name)
VALUES(1234, 'Test_Project')
ON CONFLICT (id)
DO NOTHING
Can someone tell me what is going on here?
So I have a simple table location and it only has two columns; one is a number and the other varchar2.
I'm simply trying to insert some data into the locations table so I can get cracking with the other larger datasets but keep getting this damn error every time.
Error starting at line : 7 in command -
INSERT INTO location
VALUES (1, 'Head Office')
Error report -
ORA-01722: invalid number
NOTE: Before down-voting, YES - I have seen others posting about this but is usually for something less obvious than my situation where they are trying to enter a string into a number field or a number into a string field!
In my case however, the data in the INSERT statement is a number AND the data type is also NUMBER!
DATA STRUCTURE:
CREATE TABLE location(
locID NUMBER(4) NOT NULL,
locName VARCHAR2(100) NOT NULL
);
INSERT STATEMENT:
INSERT INTO location
VALUES (1, 'Head Office');
The error code can be seen above there where I first mentioned it.
Thanks in advance.
P.S. It may be worth mentioning that the ID field in 'location' table is being used as a FOREIGN KEY in a separate table 'employees'. I have however, checked that the data types matched!
EDIT #1: I'm using ORACLE SQL Developer
Always include the columns when doing an insert:
INSERT INTO location (locId, locname)
VALUES (1, 'Head Office');
From your description of the problem, this should not actually fix it. This is just a good habit.
The above is correct SQL for your table. If the error continues to happen it is probably coming from a trigger on the table.
Think like its stupid, you are getting number error from "head office" not from 1. Actually you are trying to insert string into number.
If you dont want to write column names to insert you should totally define all values in insert in place as located in table. I assume your table structure is
locId|locNumber
So your insert should be like below
insert into table values (1,'head office')
I hope you understand shortcut logic
How to make the Column in Oracle DB which contains All Numeral values except certain:
I know the solution is based on some regex like to except all values we have the regex '*'.
Try this:
CREATE TABLE tt (
b NUMBER,
CONSTRAINT special_numbers_chk CHECK (TRIM(REGEXP_REPLACE(to_char(b,'99999999999999999'), '[01254]*', '')) IS NULL)
);
INSERT INTO TT VALUES (122);
1 row(s) inserted.
INSERT INTO TT VALUES (123);
ORA-02290: check constraint (XXXX_DVLP.SPECIAL_NUMBERS_CHK) violated
select * from tt;
b
-------
122
I use explicit conversion to char (specified the mask) to prevent sql injection and not to be depended from the DB environment, thus I need to get rid of spaces from the the conversion result to get null value, this is why I use TRIM.
P.S.: specify your sequence of numbers in the square brackets
I am trying to insert a row in a table using VIEW as
INSERT INTO FIELDI18N(LANGUAGE_ID) VALUES (1);
but it gives me following error:
Error starting at line 5 in command:
INSERT INTO FIELDI18N(LANGUAGE_ID) VALUES (1)
Error at Command Line:5 Column:22
Error report:
SQL Error: ORA-01733: virtual column not allowed here
01733. 00000 - "virtual column not allowed here"
*Cause:
*Action:
Any Clue ?
Added the View Definition:
CREATE OR REPLACE VIEW FIELDI18N("FIELDID", "NAME", "TYPE", "DESCRIPTION", "LANGUAGE_ID")
AS
(SELECT field.fieldid,
field.type,
NVL(i18n.name, field.name) name,
NVL(i18n.description, field.description) description,
i18n.language_id
FROM fields field
JOIN i18n_fields i18n
ON (field.fieldid = i18n.fieldid)
);
LANGUAGE_ID is probably a calculated field, or in any case the database cannot infer what change is to be made to the tables underlying the view based on the change you are requiring. Have to see the view definition code to know.
I believe that in order to do an insert or update using a view that all of the tables in the view must be joined via a primary key. This is to prevent duplicates caused by the view which cannot be updated.
Is there a very good reason you are not just inserting into the underlying table? If you can, just insert into the table directly and avoid this complication.
What are you expecting Oracle to do? Are you expecting it to insert a new record into i18n_fields?
If you really want to do it like this you will need to create an INSTEAD OF trigger because Oracle can't figure out which of the underlying tables it should insert into when your run your insert statement.
I keep getting this error message when trying to change the data type of my column:
alter table x modify column order_date date NOT NULL;
ERROR at line 1
ORA-00905 missing keyword
I not sure where I am going wrong, as I am aware there are many types of dates in sql?
Many thanks
The MODIFY clause does not take COLUMN as a keyword. This will work:
alter table x modify order_date date NOT NULL;
The syntax is documented in the Oracle SQL reference. Find out more.
We only need to include COLUMN with commands which have several different possibilities. For instance, with the ALTER TABLE ... DROP command, because we can drop columns, constraints or partitions....
alter table x drop column order_date ;
"when I tried entering NOT NULL, it said the table needed to be empty"
You should be able to apply a NOT NULL constraint, providing all the rows in the table have a value in the order_date column. The error message you get is quite clear:
ORA-01758 table must be empty to add mandatory (NOT NULL) column
This means your column has some rows without values. So, you need to update the table and populate those rows with some value; what you will use as a default depends on your business rules.