“column not allowed here” error in INSERT statement

前端 未结 8 2422
心在旅途
心在旅途 2020-12-05 17:39

I created this table called LOCATION by doing this:

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


        
相关标签:
8条回答
  • 2020-12-05 18:21

    Like Scaffman said - You are missing quotes. Always when you are passing a value to varchar2 use quotes

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

    So one (') starts the string and the second (') closes it.

    But if you want to add a quote symbol into a string for example:

    My father told me: 'you have to be brave, son'.

    You have to use a triple quote symbol like:

    'My father told me: ''you have to be brave, son''.'

    *adding quote method can vary on different db engines

    0 讨论(0)
  • 2020-12-05 18:25

    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');
    
    0 讨论(0)
提交回复
热议问题