Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"column not allowed here" error in INSERT statement

I created this table called LOCATION by doing this:

CREATE TABLE LOCATION( POSTCODE VARCHAR(10) PRIMARY KEY, STREET_NAME VARCHAR(20), CITY VARCHAR(20)); 

and when I try to add some date within the table it doesn’t work saying there is an error

INSERT INTO LOCATION VALUES(PQ95VM,'HAPPY_STREET','FRANCE'); 

error is saying

column not allowed here

like image 871
john Avatar asked May 08 '12 15:05

john


People also ask

How do I fix a column not allowed here in SQL?

The Solution To correct the error, the user can take a couple of approaches. First, the user could correct the INSERT statement by including a character value (instead of the column name). Additionally, if the user needs to include a column name, they could rewrite the INSERT statement with a sub-select.


2 Answers

You're missing quotes around the first value, it should be

INSERT INTO LOCATION VALUES('PQ95VM', 'HAPPY_STREET', 'FRANCE'); 

Incidentally, you'd be well-advised to specify the column names explicitly in the INSERT, for reasons of readability, maintainability and robustness, i.e.

INSERT INTO LOCATION (POSTCODE, STREET_NAME, CITY) VALUES ('PQ95VM', 'HAPPY_STREET', 'FRANCE'); 
like image 110
skaffman Avatar answered Sep 20 '22 18:09

skaffman


Some time, While executing insert query, we are facing:

Column not allowed here

error. Because of quote might missing in the string parameters. Add quote in the string params and try to execute.

Try this:

INSERT INTO LOCATION VALUES('PQ95VM','HAPPY_STREET','FRANCE'); 

or

INSERT INTO LOCATION (ID, FIRST_NAME, LAST_NAME) VALUES('PQ95VM','HAPPY_STREET','FRANCE'); 

http://www.drtuts.com/oracle-error-column-not-allowed-here/

like image 44
Vijayaragavan Avatar answered Sep 20 '22 18:09

Vijayaragavan